优化区域树

结构优化
648540858 2023-11-16 14:24:50 +08:00
parent 7d064b0830
commit b96c9317e8
8 changed files with 116 additions and 21 deletions

View File

@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType;
import com.genersoft.iot.vmp.service.bean.*;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToRegion;
import com.github.pagehelper.PageInfo;
import java.util.ArrayList;
@ -66,4 +67,8 @@ public interface ICommonGbChannelService {
void updateChannelToGroup(UpdateCommonChannelToGroup commonGbChannel);
void removeFromGroup(UpdateCommonChannelToGroup params);
void removeFromRegion(UpdateCommonChannelToRegion params);
void updateChannelToRegion(UpdateCommonChannelToRegion params);
}

View File

@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.storager.dao.GroupMapper;
import com.genersoft.iot.vmp.storager.dao.RegionMapper;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToRegion;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
@ -686,4 +687,19 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
commonGbChannelMapper.removeFromGroupByGroupId(params.getCommonGbBusinessGroupID());
}
}
@Override
public void removeFromRegion(UpdateCommonChannelToRegion params) {
if (!params.getCommonGbIds().isEmpty()) {
commonGbChannelMapper.removeRegionGroupByIds(params.getCommonGbIds());
}
if (!ObjectUtils.isEmpty(params.getCommonGbCivilCode().trim())){
commonGbChannelMapper.removeFromRegionByRegionId(params.getCommonGbCivilCode());
}
}
@Override
public void updateChannelToRegion(UpdateCommonChannelToRegion params) {
commonGbChannelMapper.updateChannelToRegion(params);
}
}

View File

@ -15,6 +15,7 @@ import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.util.Collection;
import java.util.Collections;
@ -42,7 +43,9 @@ public class RegionServiceImpl implements IRegionService {
public void add(Region region) {
assert region.getCommonRegionName() != null;
assert region.getCommonRegionDeviceId() != null;
assert region.getCommonRegionParentId() != null;
if (ObjectUtils.isEmpty(region.getCommonRegionParentId().trim())) {
region.setCommonRegionParentId(null);
}
region.setCommonRegionCreateTime(DateUtil.getNow());
region.setCommonRegionUpdateTime(DateUtil.getNow());
regionMapper.add(region);

View File

@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.service.bean.Group;
import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToRegion;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
@ -375,14 +376,14 @@ public interface CommonGbChannelMapper {
void removeGroupInfo(@Param("groupList") List<Group> groupList);
@Update({"<script>" +
"<foreach collection='commonGbChannel.commonGbIds' item='item' separator=';'>" +
"<foreach collection='param.commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" SET common_gb_business_group_id = #{commonGbChannel.commonGbBusinessGroupID}" +
" SET common_gb_business_group_id = #{param.commonGbBusinessGroupID}" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
"</script>"})
void updateChannelToGroup(@Param("commonGbChannel") UpdateCommonChannelToGroup commonGbChannel);
void updateChannelToGroup(@Param("param") UpdateCommonChannelToGroup param);
@Update({"<script>" +
"<foreach collection='commonGbIds' item='item' separator=';'>" +
@ -407,4 +408,32 @@ public interface CommonGbChannelMapper {
"<foreach collection='regionList' item='item' open='(' separator=',' close=')' > #{item.commonRegionDeviceId}</foreach>" +
"</script>")
void removeRegionInfo(@Param("regionList") List<Region> regionList);
@Update({"<script>" +
"<foreach collection='commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" SET common_gb_civilCode = null" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
"</script>"})
void removeRegionGroupByIds(@Param("commonGbIds") List<Integer> commonGbIds);
@Update({"<script>" +
" UPDATE" +
" wvp_common_gb_channel" +
" SET common_gb_civilCode = null" +
" WHERE common_gb_civilCode = #{commonGbCivilCode}" +
"</script>"})
void removeFromRegionByRegionId(@Param("commonGbCivilCode") String commonGbCivilCode);
@Update({"<script>" +
"<foreach collection='param.commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" SET common_gb_civilCode = #{param.commonGbCivilCode}" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
"</script>"})
void updateChannelToRegion(@Param("param") UpdateCommonChannelToRegion param);
}

View File

@ -14,21 +14,21 @@ public interface RegionMapper {
" </script>")
List<Region> getChildren(@Param("parentDeviceId") String parentDeviceId);
@Insert("INSERT INTO wvp_common_region (" +
@Insert(" <script>" +
"INSERT INTO wvp_common_region (" +
" common_region_device_id, " +
" common_region_name, " +
" common_region_parent_id, " +
" common_region_path, " +
"<if test='region.commonRegionParentId != null'>common_region_parent_id, </if>" +
" common_region_create_time, " +
" common_region_update_time ) " +
" VALUES (" +
" #{commonRegionDeviceId}, " +
" #{commonRegionName}, " +
" #{commonRegionParentId}, " +
" #{commonRegionPath}, " +
" #{commonRegionCreateTime}, " +
" #{commonRegionUpdateTime})")
int add(Region region);
" #{region.commonRegionDeviceId}, " +
" #{region.commonRegionName}, " +
"<if test='region.commonRegionParentId != null'> #{region.commonRegionParentId}, </if>" +
" #{region.commonRegionCreateTime}, " +
" #{region.commonRegionUpdateTime})" +
" </script>")
int add(@Param("region") Region region);
@Delete("delete from wvp_common_region where common_region_device_id = #{regionDeviceId}")
int deleteByDeviceId(@Param("regionDeviceId") String regionDeviceId);
@ -84,11 +84,11 @@ public interface RegionMapper {
@Update(value = {" <script>" +
" UPDATE wvp_common_region " +
" SET" +
" common_region_update_time=#{commonRegionUpdateTime}," +
" common_region_device_id=#{commonRegionDeviceId}," +
" common_region_name=#{commonRegionName}," +
" common_region_parent_id=#{commonRegionParentId}" +
" WHERE common_region_id=#{commonRegionId}" +
" common_region_update_time=#{region.commonRegionUpdateTime}," +
" common_region_device_id=#{region.commonRegionDeviceId}," +
" common_region_name=#{region.commonRegionName}," +
" common_region_parent_id=#{region.commonRegionParentId}" +
" WHERE common_region_id=#{region.commonRegionId}" +
" </script>"})
void update(@Param("region") Region region);

View File

@ -0,0 +1,26 @@
package com.genersoft.iot.vmp.vmanager.bean;
import java.util.List;
public class UpdateCommonChannelToRegion {
private String commonGbCivilCode;
private List<Integer> commonGbIds;
public String getCommonGbCivilCode() {
return commonGbCivilCode;
}
public void setCommonGbCivilCode(String commonGbCivilCode) {
this.commonGbCivilCode = commonGbCivilCode;
}
public List<Integer> getCommonGbIds() {
return commonGbIds;
}
public void setCommonGbIds(List<Integer> commonGbIds) {
this.commonGbIds = commonGbIds;
}
}

View File

@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType;
import com.genersoft.iot.vmp.service.ICommonGbChannelService;
import com.genersoft.iot.vmp.service.bean.*;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToRegion;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.Operation;
@ -179,7 +180,22 @@ public class CommonChannelController {
commonGbChannelService.removeFromGroup(params);
}
@Operation(summary = "从区域中移除通道")
@ResponseBody
@PostMapping("/region/remove")
public void removeFromRegion(@RequestBody UpdateCommonChannelToRegion params){
assert params.getCommonGbCivilCode() != null || !params.getCommonGbIds().isEmpty();
commonGbChannelService.removeFromRegion(params);
}
@Operation(summary = "为通道添加分组")
@ResponseBody
@PostMapping("/region/update")
public void updateChannelToRegion(@RequestBody UpdateCommonChannelToRegion params){
assert params.getCommonGbCivilCode() != null;
assert !params.getCommonGbIds().isEmpty();
commonGbChannelService.updateChannelToRegion(params);
}
}

View File

@ -60,8 +60,8 @@ public class RegionController {
@Operation(summary = "删除区域")
@Parameter(name = "regionDeviceId", description = "区域编码", required = true)
@ResponseBody
@DeleteMapping("/delete")
public void delete(@RequestBody String regionDeviceId){
@GetMapping("/delete")
public void delete(String regionDeviceId){
assert regionDeviceId != null;
boolean result = regionService.deleteByDeviceId(regionDeviceId);
if (!result) {