完善行政区划管理

This commit is contained in:
648540858
2024-07-31 15:07:54 +08:00
parent 3ce973d2ee
commit 7ee3cdb801
11 changed files with 268 additions and 127 deletions

View File

@@ -10,6 +10,12 @@ import lombok.Data;
@Schema(description = "区域树")
public class RegionTree {
/**
* 数据库Id
*/
@Schema(description = "数据库Id")
private int dbId;
/**
* 区域国标编号
*/

View File

@@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceType;
import com.genersoft.iot.vmp.gb28181.bean.IndustryCodeType;
import com.genersoft.iot.vmp.gb28181.bean.NetworkIdentificationType;
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToRegionBYGbDeviceParam;
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToRegionParam;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
@@ -111,7 +112,22 @@ public class CommonChannelController {
@Operation(summary = "通道删除行政区划", security = @SecurityRequirement(name = JwtUtils.HEADER))
@PostMapping("/region/delete")
public void deleteChannelToRegion(@RequestBody ChannelToRegionParam param){
Assert.isTrue(param.getChannelIds().isEmpty() && ObjectUtils.isEmpty(param.getCivilCode()),"参数异常");
Assert.isTrue(!param.getChannelIds().isEmpty() || !ObjectUtils.isEmpty(param.getCivilCode()),"参数异常");
channelService.deleteChannelToRegion(param.getCivilCode(), param.getChannelIds());
}
@Operation(summary = "通道设置行政区划-根据国标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@PostMapping("/region/device/add")
public void addChannelToRegionBYGbDevice(@RequestBody ChannelToRegionBYGbDeviceParam param){
Assert.notEmpty(param.getDeviceIds(),"参数异常");
Assert.hasLength(param.getCivilCode(),"未添加行政区划");
channelService.addChannelToRegionBYGbDevice(param.getCivilCode(), param.getDeviceIds());
}
@Operation(summary = "通道删除行政区划-根据国标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@PostMapping("/region/device/delete")
public void deleteChannelToRegionBYGbDevice(@RequestBody ChannelToRegionBYGbDeviceParam param){
Assert.notEmpty(param.getDeviceIds(),"参数异常");
channelService.deleteChannelToRegionBYGbDevice(param.getDeviceIds());
}
}

View File

@@ -0,0 +1,11 @@
package com.genersoft.iot.vmp.gb28181.controller.bean;
import lombok.Data;
import java.util.List;
@Data
public class ChannelToRegionBYGbDeviceParam {
private List<Integer> deviceIds;
private String civilCode;
}

View File

@@ -313,6 +313,7 @@ public interface CommonGBChannelMapper {
" select " +
" coalesce(gb_device_id, device_id) as id," +
" coalesce(gb_name, name) as label, " +
" id as db_id, " +
" 1 as type, " +
" true as is_leaf " +
" from wvp_device_channel " +
@@ -341,4 +342,18 @@ public interface CommonGBChannelMapper {
@SelectProvider(type = ChannelProvider.class, method = "queryByIdsOrCivilCode")
List<CommonGBChannel> queryByIdsOrCivilCode(@Param("civilCode") String civilCode, @Param("ids") List<Integer> ids);
@Update(value = {" <script>" +
" UPDATE wvp_device_channel " +
" SET gb_civil_code = null" +
" WHERE id in "+
" <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbId}</foreach>" +
" </script>"})
int removeCivilCodeByChannels(List<CommonGBChannel> channelList);
@SelectProvider(type = ChannelProvider.class, method = "queryByCivilCode")
List<CommonGBChannel> queryByCivilCode(@Param("civilCode") String civilCode);
@SelectProvider(type = ChannelProvider.class, method = "queryByGbDeviceIds")
List<CommonGBChannel> queryByGbDeviceIds(List<Integer> deviceIds);
}

View File

@@ -70,6 +70,7 @@ public interface RegionMapper {
" device_id as id," +
" name as label, " +
" parent_device_id," +
" id as db_id," +
" 0 as type," +
" false as is_leaf" +
" from wvp_common_region " +

View File

@@ -132,6 +132,24 @@ public class ChannelProvider {
return sqlBuild.toString() ;
}
public String queryByGbDeviceIds(Map<String, Object> params ){
StringBuilder sqlBuild = new StringBuilder();
sqlBuild.append(getBaseSelectSql());
sqlBuild.append("where device_db_id in ( ");
Collection<Integer> ids = (Collection<Integer>)params.get("deviceIds");
boolean first = true;
for (Integer id : ids) {
if (!first) {
sqlBuild.append(",");
}
sqlBuild.append(id);
first = false;
}
sqlBuild.append(" )");
return sqlBuild.toString() ;
}
public String queryByIdsOrCivilCode(Map<String, Object> params ){
StringBuilder sqlBuild = new StringBuilder();
sqlBuild.append(getBaseSelectSql());
@@ -157,4 +175,11 @@ public class ChannelProvider {
}
return sqlBuild.toString() ;
}
public String queryByCivilCode(Map<String, Object> params ){
StringBuilder sqlBuild = new StringBuilder();
sqlBuild.append(getBaseSelectSql());
sqlBuild.append("where gb_civil_code = #{civilCode} ");
return sqlBuild.toString() ;
}
}

View File

@@ -49,4 +49,12 @@ public interface IGbChannelService {
void addChannelToRegion(String civilCode, List<Integer> channelIds);
void deleteChannelToRegion(String civilCode, List<Integer> channelIds);
void deleteChannelToRegionByCivilCode(String civilCode);
void deleteChannelToRegionByChannelIds(List<Integer> channelIds);
void addChannelToRegionBYGbDevice(String civilCode, List<Integer> deviceIds);
void deleteChannelToRegionBYGbDevice(List<Integer> deviceIds);
}

View File

@@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
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.ArrayList;
import java.util.Collection;
@@ -352,8 +353,55 @@ public class GbChannelServiceImpl implements IGbChannelService {
}
@Override
@Transactional
public void deleteChannelToRegion(String civilCode, List<Integer> channelIds) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByIdsOrCivilCode(civilCode, channelIds);
if (!ObjectUtils.isEmpty(civilCode)) {
deleteChannelToRegionByCivilCode(civilCode);
}
if (!ObjectUtils.isEmpty(channelIds)) {
deleteChannelToRegionByChannelIds(channelIds);
}
}
@Override
public void deleteChannelToRegionByCivilCode(String civilCode) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByCivilCode(civilCode);
if (channelList.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
}
int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList);
// TODO 发送通知
// if (result > 0) {
// try {
// // 发送catalog
// eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE);
// }catch (Exception e) {
// log.warn("[多个通道添加行政区划] 发送失败,数量:{}", channelList.size(), e);
// }
// }
}
@Override
public void deleteChannelToRegionByChannelIds(List<Integer> channelIds) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByIds(channelIds);
if (channelList.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
}
int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList);
// TODO 发送通知
// if (result > 0) {
// try {
// // 发送catalog
// eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE);
// }catch (Exception e) {
// log.warn("[多个通道添加行政区划] 发送失败,数量:{}", channelList.size(), e);
// }
// }
}
@Override
public void addChannelToRegionBYGbDevice(String civilCode, List<Integer> deviceIds) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByGbDeviceIds(deviceIds);
if (channelList.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
}
@@ -368,4 +416,13 @@ public class GbChannelServiceImpl implements IGbChannelService {
}
}
}
@Override
public void deleteChannelToRegionBYGbDevice(List<Integer> deviceIds) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByGbDeviceIds(deviceIds);
if (channelList.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
}
int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList);
}
}