设备信息修改api
对接信息查询api
This commit is contained in:
parent
3e422e384b
commit
c11f5c9ef0
@ -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<List<WvpProxyDevice>> infoByDeviceCode(@RequestParam String deviceCode) {
|
||||
List<WvpProxyDevice> wvpProxyDevice = deviceService.getDeviceByDeviceCode(deviceCode);
|
||||
return JsonResponse.success(wvpProxyDevice);
|
||||
public JsonResponse<WvpProxyDevice> infoByDeviceCode(@RequestParam String deviceCode) {
|
||||
Optional<WvpProxyDevice> 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<Boolean> deleteByGbDeviceId(@RequestParam Long id){
|
||||
public JsonResponse<Boolean> deleteById(@RequestParam Long id){
|
||||
WvpProxyDevice wvpProxyDevice = new WvpProxyDevice();
|
||||
wvpProxyDevice.setId(id);
|
||||
return JsonResponse.success(deviceService.deleteDevice(wvpProxyDevice));
|
||||
}
|
||||
|
||||
@Operation(summary = "根据主键id修改设备信息")
|
||||
@PostJson("/modify")
|
||||
public JsonResponse<Boolean> updateById(@RequestBody WvpProxyDevice device){
|
||||
return JsonResponse.success(deviceService.modifyDevice(device));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<WvpProxyDevice> getDeviceByDeviceCode(String deviceCode){
|
||||
return deviceMapper.select(s->
|
||||
s.where(WvpProxyDeviceDynamicSqlSupport.deviceCode,isEqualTo(deviceCode)));
|
||||
public Optional<WvpProxyDevice> getDeviceByDeviceCode(String deviceCode){
|
||||
return deviceMapper.selectOne(s->s.where(WvpProxyDeviceDynamicSqlSupport.deviceCode,isEqualTo(deviceCode)).limit(1));
|
||||
}
|
||||
|
||||
public List<WvpProxyDevice> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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<WvpProxyDevice> wvpProxyDeviceList = deviceService.getDeviceByDeviceCode(deviceCode);
|
||||
Optional<WvpProxyDevice> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user