From c11f5c9ef081173eaa9ab4c4a82e6f624f863c63 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Fri, 22 Sep 2023 15:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9api=20=E5=AF=B9=E6=8E=A5=E4=BF=A1=E6=81=AF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wvp/api/device/DeviceController.java | 15 +++++-- .../wvp/api/docking/DockingController.java | 2 + .../wvp/service/device/DeviceService.java | 41 +++++++++++++++++-- .../gb28181/wvp/service/wvp/WvpService.java | 5 ++- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/device/DeviceController.java b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/device/DeviceController.java index d239048..fdf8f48 100644 --- a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/device/DeviceController.java +++ b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/device/DeviceController.java @@ -22,6 +22,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Optional; @Slf4j @Tag(name = "设备信息") @@ -50,9 +51,9 @@ public class DeviceController { @Operation(summary = "根据设备编码(21位) 查询指定设备信息") @GetJson("/info/deviceCode") - public JsonResponse> infoByDeviceCode(@RequestParam String deviceCode) { - List wvpProxyDevice = deviceService.getDeviceByDeviceCode(deviceCode); - return JsonResponse.success(wvpProxyDevice); + public JsonResponse infoByDeviceCode(@RequestParam String deviceCode) { + Optional wvpProxyDevice = deviceService.getDeviceByDeviceCode(deviceCode); + return JsonResponse.success(wvpProxyDevice.orElse(null)); } @Operation(summary = "根据国标id(20位) 查询指定设备信息") @@ -80,9 +81,15 @@ public class DeviceController { @Operation(summary = "根据主键 id 删除指定设备") @JsonMapping(value = "/delete/id",method = {RequestMethod.GET,RequestMethod.DELETE}) - public JsonResponse deleteByGbDeviceId(@RequestParam Long id){ + public JsonResponse deleteById(@RequestParam Long id){ WvpProxyDevice wvpProxyDevice = new WvpProxyDevice(); wvpProxyDevice.setId(id); return JsonResponse.success(deviceService.deleteDevice(wvpProxyDevice)); } + + @Operation(summary = "根据主键id修改设备信息") + @PostJson("/modify") + public JsonResponse updateById(@RequestBody WvpProxyDevice device){ + return JsonResponse.success(deviceService.modifyDevice(device)); + } } diff --git a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/docking/DockingController.java b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/docking/DockingController.java index f59bc1b..37ed51c 100644 --- a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/docking/DockingController.java +++ b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/docking/DockingController.java @@ -9,6 +9,7 @@ import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig; import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking; import cn.skcks.docking.gb28181.wvp.service.docking.DockingService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springdoc.core.annotations.ParameterObject; import org.springdoc.core.models.GroupedOpenApi; @@ -16,6 +17,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RestController; +@Tag(name = "设备/平台对接") @RestController @JsonMapping("/docking") @RequiredArgsConstructor diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/device/DeviceService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/device/DeviceService.java index 6258397..0be4dfb 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/device/DeviceService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/device/DeviceService.java @@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import java.text.MessageFormat; import java.util.List; +import java.util.Objects; import java.util.Optional; import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; @@ -32,9 +33,8 @@ public class DeviceService { s.where(WvpProxyDeviceDynamicSqlSupport.id, isEqualTo(id))); } - public List getDeviceByDeviceCode(String deviceCode){ - return deviceMapper.select(s-> - s.where(WvpProxyDeviceDynamicSqlSupport.deviceCode,isEqualTo(deviceCode))); + public Optional getDeviceByDeviceCode(String deviceCode){ + return deviceMapper.selectOne(s->s.where(WvpProxyDeviceDynamicSqlSupport.deviceCode,isEqualTo(deviceCode)).limit(1)); } public List getDeviceByGbDeviceId(String gbDeviceId){ @@ -163,4 +163,39 @@ public class DeviceService { } return pageInfo; } + + @SneakyThrows + public boolean modifyDevice(WvpProxyDevice device){ + if(device == null){ + return false; + } + Long id = device.getId(); + if(id == null){ + throw new JsonException("id 不能为空"); + } + + String deviceCode = device.getDeviceCode(); + if(StringUtils.isNotBlank(deviceCode)){ + WvpProxyDevice existDevice = getDeviceByDeviceCode(deviceCode).orElse(null); + if(existDevice != null && !Objects.equals(existDevice.getId(), device.getId())){ + throw new JsonException(MessageFormat.format("设备编码 {0} 已存在", deviceCode)); + } + } + + String gbDeviceId = device.getGbDeviceId(); + String gbDeviceChannelId = device.getGbDeviceChannelId(); + if(gbDeviceId != null && StringUtils.isBlank(gbDeviceId)){ + throw new JsonException("国标id 不能为空"); + } + if(gbDeviceChannelId != null && StringUtils.isBlank(gbDeviceChannelId)){ + throw new JsonException("通道 不能为空"); + } + if(StringUtils.isNotBlank(gbDeviceId) && StringUtils.isNotBlank(gbDeviceChannelId)){ + WvpProxyDevice existDevice = getDeviceByGbDeviceIdAndChannel(gbDeviceId, gbDeviceChannelId).orElse(null); + if(existDevice != null && !Objects.equals(existDevice.getId(), device.getId())){ + throw new JsonException(MessageFormat.format("国标id {0} ,通道 {1} 已存在", gbDeviceId, gbDeviceChannelId)); + } + } + return deviceMapper.updateByPrimaryKeySelective(device) > 0; + } } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java index 6d88af9..43f9338 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java @@ -41,6 +41,7 @@ import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -71,12 +72,12 @@ public class WvpService { @SneakyThrows public void video(HttpServletRequest request, HttpServletResponse response, String deviceCode, Date startTime, Date endTime) { - List wvpProxyDeviceList = deviceService.getDeviceByDeviceCode(deviceCode); + Optional wvpProxyDeviceList = deviceService.getDeviceByDeviceCode(deviceCode); if (wvpProxyDeviceList.isEmpty()) { writeErrorToResponse(response, JsonResponse.error("设备不存在")); return; } - WvpProxyDevice wvpProxyDevice = wvpProxyDeviceList.get(0); + WvpProxyDevice wvpProxyDevice = wvpProxyDeviceList.get(); String deviceId = wvpProxyDevice.getGbDeviceId(); String channelId = wvpProxyDevice.getGbDeviceChannelId(); log.info("设备编码 (deviceCode=>{}) 查询到的设备信息 国标id(gbDeviceId => {}), 通道(channelId => {})", deviceCode, deviceId, channelId);