Commit e63e4fb8 by huangjy

fiix:编辑设备写入

parent 5d7de7f2
......@@ -93,6 +93,15 @@ public class PlatDeviceController {
return ApiResponseUtils.success();
}
@ApiOperation("编辑设备属性 ")
@PostMapping("editDeviceProperties1")
@AuthIgnore
@TenantIdIgnore
public ApiResponseEntity<?> editDeviceProperties1(@RequestBody PlatDeviceAttrWechatDTO dto) {
platDeviceService.editDeviceProperties(dto);
return ApiResponseUtils.success();
}
@ApiOperation("编辑设备网络属性 主要写入usrServerInfo信息")
@PostMapping("editDeviceNetInfo")
public ApiResponseEntity<?> editDeviceNetInfo(@RequestBody PlatDeviceNetAttrWechatDTO dto) {
......
......@@ -467,9 +467,11 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override
@Transactional(rollbackFor = Exception.class)
public void editDeviceProperties(PlatDeviceAttrWechatDTO dto) {
log.info("写入设备属性请求参数:{}",JSON.toJSONString(dto));
String deviceId = dto.getDeviceId();
Map<String, Object> map = getAttrMap(dto);
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = getPlatDeviceBaseAttrDTO(deviceId);
String reqJson = JSON.toJSONString(dto);
Map<String, Object> map = getReqMap(dto, platDeviceBaseAttrDTO);
log.info("写入设备属性请求参数:{}", reqJson);
String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map);
if (StringUtils.isNotEmpty(result)) {
throw new RuntimeException("设备写入失败:" + result);
......@@ -477,7 +479,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda()
.eq(PlatDeviceOther::getOriDeviceId, deviceId));
for (PlatDeviceOther platDeviceOther : platDeviceOtherList) {
platDeviceOther.setAttribute(JSON.toJSONString(map));
platDeviceOther.setAttribute(reqJson);
platDeviceOtherService.updateById(platDeviceOther);
}
if (dto.getRadarMount() != null) {
......@@ -489,6 +491,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
}
private PlatDeviceBaseAttrDTO getPlatDeviceBaseAttrDTO(String deviceId) {
PlatDeviceOther deviceOther = platDeviceOtherService.getOne(new QueryWrapper<PlatDeviceOther>().lambda()
.eq(PlatDeviceOther::getOriDeviceId, deviceId)
.last("limit 1"));
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = JSON.parseObject(deviceOther.getAttribute(), PlatDeviceBaseAttrDTO.class);
return platDeviceBaseAttrDTO;
}
private static Map<String, Object> getReqMap(PlatDeviceBaseAttrDTO dto, PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO) {
Map<String, Object> map = Maps.newHashMap();
if (!Objects.equals(platDeviceBaseAttrDTO.getRadarMode(), dto.getRadarMode())) {
map.put("radarMode", dto.getRadarMode());
}
if (!Objects.equals(platDeviceBaseAttrDTO.getRadarMount(), dto.getRadarMount())) {
map.put("radarMount", dto.getRadarMount());
}
if (!Objects.equals(platDeviceBaseAttrDTO.getRadarDelay(), dto.getRadarDelay())) {
map.put("radarDelay", dto.getRadarDelay() );
}
if (!Objects.equals(platDeviceBaseAttrDTO.getRadarDistance(), dto.getRadarDistance())) {
map.put("radarDistance", JSON.toJSONString(dto.getRadarDistance()));
}
if (!Objects.equals(platDeviceBaseAttrDTO.getRadarAngle(), dto.getRadarAngle())) {
map.put("radarAngle", JSON.toJSONString(dto.getRadarAngle()));
}
return map;
}
@Override
public void editDeviceNetInfo(PlatDeviceNetAttrWechatDTO dto) {
String deviceId = dto.getDeviceId();
......@@ -539,29 +569,27 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override
@Transactional(rollbackFor = Exception.class)
public void batchEditProperties(PlatDeviceAttrDTO dto) {
if (CollectionUtils.isEmpty(dto.getDeviceIdList())) {
List<String> deviceIdList = dto.getDeviceIdList();
if (CollectionUtils.isEmpty(deviceIdList)) {
return;
}
Map<String, Object> map = getAttrMap(dto);
List<String> resultList = Lists.newArrayList();
for (String deviceId : dto.getDeviceIdList()) {
String reqJson = JSON.toJSONString(dto);
for (String deviceId : deviceIdList) {
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = getPlatDeviceBaseAttrDTO(deviceId);
Map<String, Object> map = getReqMap(dto,platDeviceBaseAttrDTO);
String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map);
if (StringUtils.isNotEmpty(result)) {
resultList.add(result);
throw new RuntimeException("修改设备属性失败:" + result);
}
List<PlatDeviceOther> otherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda()
.eq(PlatDeviceOther::getOriDeviceId, deviceId)
.last("limit 1"));
.eq(PlatDeviceOther::getOriDeviceId, deviceId));
for (PlatDeviceOther platDeviceOther : otherList) {
platDeviceOther.setAttribute(JSON.toJSONString(map));
platDeviceOther.setAttribute(reqJson);
platDeviceOtherService.updateById(platDeviceOther);
}
}
if (CollectionUtils.isNotEmpty(resultList)) {
throw new RuntimeException("修改设备属性失败:" + resultList.get(0));
}
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment