临时提交
This commit is contained in:
@@ -52,6 +52,16 @@ public class GlobalExceptionHandler {
|
||||
public WVPResult<String> exceptionHandler(HttpRequestMethodNotSupportedException e) {
|
||||
return WVPResult.fail(ErrorCode.ERROR400);
|
||||
}
|
||||
/**
|
||||
* 断言异常处理
|
||||
* @param e 异常
|
||||
* @return 统一返回结果
|
||||
*/
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public WVPResult<String> exceptionHandler(IllegalArgumentException e) {
|
||||
return WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -60,7 +70,7 @@ public class GlobalExceptionHandler {
|
||||
* @return 统一返回结果
|
||||
*/
|
||||
@ExceptionHandler(ControllerException.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<WVPResult<String>> exceptionHandler(ControllerException e) {
|
||||
return new ResponseEntity<>(WVPResult.fail(e.getCode(), e.getMsg()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -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.ChannelToRegionParam;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
@@ -15,6 +16,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -97,4 +99,19 @@ public class CommonChannelController {
|
||||
}
|
||||
return channelService.queryList(page, count, query, online, hasCivilCode);
|
||||
}
|
||||
|
||||
@Operation(summary = "通道设置行政区划", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@PostMapping("/region/add")
|
||||
public void addChannelToRegion(@RequestBody ChannelToRegionParam param){
|
||||
Assert.notEmpty(param.getChannelIds(),"通道ID不可为空");
|
||||
Assert.hasLength(param.getCivilCode(),"未添加行政区划");
|
||||
channelService.addChannelToRegion(param.getCivilCode(), param.getChannelIds());
|
||||
}
|
||||
|
||||
@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()),"参数异常");
|
||||
channelService.deleteChannelToRegion(param.getCivilCode(), param.getChannelIds());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -76,11 +77,11 @@ public class RegionController {
|
||||
}
|
||||
|
||||
@Operation(summary = "删除区域")
|
||||
@Parameter(name = "regionDeviceId", description = "区域编码", required = true)
|
||||
@Parameter(name = "deviceId", description = "区域编码", required = true)
|
||||
@ResponseBody
|
||||
@DeleteMapping("/delete")
|
||||
public void delete(String deviceId){
|
||||
assert !ObjectUtils.isEmpty(deviceId);
|
||||
Assert.hasLength(deviceId, "区域编码(deviceId)不需要存在");
|
||||
boolean result = regionService.deleteByDeviceId(deviceId);
|
||||
if (!result) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败");
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.genersoft.iot.vmp.gb28181.controller.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChannelToRegionParam {
|
||||
|
||||
private String civilCode;
|
||||
private List<Integer> channelIds;
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.dao.provider.ChannelProvider;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@@ -290,7 +291,7 @@ public interface CommonGBChannelMapper {
|
||||
|
||||
|
||||
@SelectProvider(type = ChannelProvider.class, method = "queryByIds")
|
||||
List<CommonGBChannel> queryByIds(List<CommonGBChannel> commonGBChannelList);
|
||||
List<CommonGBChannel> queryByIds(Collection<Integer> ids);
|
||||
|
||||
@Delete(value = {" <script>" +
|
||||
" delete from wvp_device_channel" +
|
||||
@@ -328,4 +329,16 @@ public interface CommonGBChannelMapper {
|
||||
" <foreach collection='allChildren' item='item' open='(' separator=',' close=')' > #{item.deviceId}</foreach>" +
|
||||
" </script>"})
|
||||
int removeCivilCode(List<Region> allChildren);
|
||||
|
||||
|
||||
@Update(value = {" <script>" +
|
||||
" UPDATE wvp_device_channel " +
|
||||
" SET gb_civil_code = #{civilCode}" +
|
||||
" WHERE id in "+
|
||||
" <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbId}</foreach>" +
|
||||
" </script>"})
|
||||
int updateRegion(@Param("civilCode") String civilCode, @Param("channelList") List<CommonGBChannel> channelList);
|
||||
|
||||
@SelectProvider(type = ChannelProvider.class, method = "queryByIdsOrCivilCode")
|
||||
List<CommonGBChannel> queryByIdsOrCivilCode(@Param("civilCode") String civilCode, @Param("ids") List<Integer> ids);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.genersoft.iot.vmp.gb28181.dao.provider;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelProvider {
|
||||
@@ -93,20 +97,64 @@ public class ChannelProvider {
|
||||
}
|
||||
|
||||
public String queryInListByStatus(Map<String, Object> params ){
|
||||
return " <script>" + getBaseSelectSql() +
|
||||
" where gb_status=#{status} and id in " +
|
||||
" <foreach collection='commonGBChannelList' item='item' open='(' separator=',' close=')' > " +
|
||||
" #{item.gbId}" +
|
||||
" </foreach>" +
|
||||
" </script>" ;
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where gb_status=#{status} and id in ( ");
|
||||
|
||||
List<CommonGBChannel> commonGBChannelList = (List<CommonGBChannel>)params.get("ids");
|
||||
boolean first = true;
|
||||
for (CommonGBChannel channel : commonGBChannelList) {
|
||||
if (!first) {
|
||||
sqlBuild.append(",");
|
||||
}
|
||||
sqlBuild.append(channel.getGbId());
|
||||
first = false;
|
||||
}
|
||||
sqlBuild.append(" )");
|
||||
return sqlBuild.toString() ;
|
||||
}
|
||||
|
||||
public String queryByIds(Map<String, Object> params ){
|
||||
return " <script>" + getBaseSelectSql() +
|
||||
" where id in " +
|
||||
" <foreach collection='commonGBChannelList' item='item' open='(' separator=',' close=')' > " +
|
||||
" #{item.gbId}" +
|
||||
" </foreach>" +
|
||||
" </script>" ;
|
||||
StringBuilder sqlBuild = new StringBuilder();
|
||||
sqlBuild.append(getBaseSelectSql());
|
||||
sqlBuild.append("where id in ( ");
|
||||
|
||||
Collection<Integer> ids = (Collection<Integer>)params.get("ids");
|
||||
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());
|
||||
sqlBuild.append("where ");
|
||||
if (params.get("civilCode") != null) {
|
||||
sqlBuild.append(" gb_civil_code = #{civilCode} ");
|
||||
if (params.get("ids") != null) {
|
||||
sqlBuild.append(" OR ");
|
||||
}
|
||||
}
|
||||
if (params.get("ids") != null) {
|
||||
sqlBuild.append(" id in ( ");
|
||||
Collection<Integer> ids = (Collection<Integer>)params.get("ids");
|
||||
boolean first = true;
|
||||
for (Integer id : ids) {
|
||||
if (!first) {
|
||||
sqlBuild.append(",");
|
||||
}
|
||||
sqlBuild.append(id);
|
||||
first = false;
|
||||
}
|
||||
sqlBuild.append(" )");
|
||||
}
|
||||
return sqlBuild.toString() ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.service;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface IGbChannelService {
|
||||
@@ -13,7 +14,7 @@ public interface IGbChannelService {
|
||||
|
||||
int delete(int gbId);
|
||||
|
||||
void delete(List<CommonGBChannel> commonGBChannelList);
|
||||
void delete(Collection<Integer> ids);
|
||||
|
||||
int update(CommonGBChannel commonGBChannel);
|
||||
|
||||
@@ -44,4 +45,8 @@ public interface IGbChannelService {
|
||||
PageInfo<CommonGBChannel> queryList(int page, int count, String query, Boolean online, Boolean hasCivilCode);
|
||||
|
||||
void removeCivilCode(List<Region> allChildren);
|
||||
|
||||
void addChannelToRegion(String civilCode, List<Integer> channelIds);
|
||||
|
||||
void deleteChannelToRegion(String civilCode, List<Integer> channelIds);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,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.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -279,8 +280,8 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
|
||||
@Override
|
||||
public void updateChannelStreamIdentification(DeviceChannel channel) {
|
||||
assert !ObjectUtils.isEmpty(channel.getId());
|
||||
assert !ObjectUtils.isEmpty(channel.getStreamIdentification());
|
||||
Assert.isTrue(channel.getId() > 0, "通道ID必须存在");
|
||||
Assert.hasLength(channel.getStreamIdentification(), "码流标识必须存在");
|
||||
if (ObjectUtils.isEmpty(channel.getStreamIdentification())) {
|
||||
log.info("[重置通道码流类型] 设备: {}, 码流: {}", channel.getDeviceId(), channel.getStreamIdentification());
|
||||
}else {
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -67,8 +68,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(List<CommonGBChannel> commonGBChannelList) {
|
||||
List<CommonGBChannel> channelListInDb = commonGBChannelMapper.queryByIds(commonGBChannelList);
|
||||
public void delete(Collection<Integer> ids) {
|
||||
List<CommonGBChannel> channelListInDb = commonGBChannelMapper.queryByIds(ids);
|
||||
if (channelListInDb.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -331,4 +332,40 @@ public class GbChannelServiceImpl implements IGbChannelService {
|
||||
// TODO 是否需要通知上级, 或者等添加新的行政区划时发送更新通知
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChannelToRegion(String civilCode, List<Integer> channelIds) {
|
||||
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByIds(channelIds);
|
||||
if (channelList.isEmpty()) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
|
||||
}
|
||||
int result = commonGBChannelMapper.updateRegion(civilCode, channelList);
|
||||
// 发送通知
|
||||
if (result > 0) {
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE);
|
||||
}catch (Exception e) {
|
||||
log.warn("[多个通道添加行政区划] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteChannelToRegion(String civilCode, List<Integer> channelIds) {
|
||||
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByIdsOrCivilCode(civilCode, channelIds);
|
||||
if (channelList.isEmpty()) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
|
||||
}
|
||||
int result = commonGBChannelMapper.updateRegion(civilCode, channelList);
|
||||
// 发送通知
|
||||
if (result > 0) {
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE);
|
||||
}catch (Exception e) {
|
||||
log.warn("[多个通道添加行政区划] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -41,8 +42,8 @@ public class RegionServiceImpl implements IRegionService {
|
||||
|
||||
@Override
|
||||
public void add(Region region) {
|
||||
assert region.getName() != null;
|
||||
assert region.getDeviceId() != null;
|
||||
Assert.hasLength(region.getName(), "名称必须存在");
|
||||
Assert.hasLength(region.getDeviceId(), "国标编号必须存在");
|
||||
if (ObjectUtils.isEmpty(region.getParentDeviceId().trim())) {
|
||||
region.setParentDeviceId(null);
|
||||
}
|
||||
@@ -95,7 +96,7 @@ public class RegionServiceImpl implements IRegionService {
|
||||
|
||||
@Override
|
||||
public PageInfo<Region> queryChildRegionList(String regionParentId, int page, int count) {
|
||||
assert regionParentId != null;
|
||||
Assert.hasLength(regionParentId, "上级行政区划编号必须存在");
|
||||
PageHelper.startPage(page, count);
|
||||
List<Region> all = regionMapper.getChildren(regionParentId);
|
||||
return new PageInfo<>(all);
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -121,8 +122,8 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
|
||||
public String addTask(String app, String stream, MediaServer mediaServerItem, String startTime, String endTime,
|
||||
String callId, String remoteHost, boolean filterMediaServer) {
|
||||
// 参数校验
|
||||
assert app != null;
|
||||
assert stream != null;
|
||||
Assert.notNull(app,"应用名为NULL");
|
||||
Assert.notNull(stream,"流ID为NULL");
|
||||
if (mediaServerItem.getRecordAssistPort() == 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "为配置Assist服务");
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -174,7 +175,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
}
|
||||
|
||||
private void delete(StreamProxy streamProxy) {
|
||||
assert streamProxy != null;
|
||||
Assert.notNull(streamProxy, "代理不可为NULL");
|
||||
if (streamProxy.getPulling() != null && streamProxy.getPulling()) {
|
||||
stopProxy(streamProxy);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -247,8 +248,9 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean update(StreamPush streamPush) {
|
||||
Assert.notNull(streamPush, "推流信息不可为NULL");
|
||||
Assert.isTrue(streamPush.getId() > 0, "推流信息ID必须存在");
|
||||
log.info("[更新推流]:id: {}, app: {}, stream: {}, ", streamPush.getId(), streamPush.getApp(), streamPush.getStream());
|
||||
assert streamPush.getId() != null;
|
||||
StreamPush streamPushInDb = streamPushMapper.select(streamPush.getId());
|
||||
if (!streamPushInDb.getApp().equals(streamPush.getApp()) || !streamPushInDb.getStream().equals(streamPush.getStream())) {
|
||||
// app或者stream变化
|
||||
@@ -602,6 +604,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
}
|
||||
});
|
||||
streamPushMapper.batchDel(streamPushList);
|
||||
gbChannelService.delete(commonGBChannelList);
|
||||
gbChannelService.delete(ids);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user