Commit c8d2e6be by 罗志长

fix: 网络信息编辑

parent a15f0218
...@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl; ...@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -682,21 +683,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -682,21 +683,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
String deviceId = dto.getDeviceId(); String deviceId = dto.getDeviceId();
UserServerInfo usrServerInfo = dto.getUsrServerInfo(); UserServerInfo usrServerInfo = dto.getUsrServerInfo();
log.info("写入设备属性请求参数:{}",JSON.toJSONString(dto)); log.info("写入设备属性请求参数:{}",JSON.toJSONString(dto));
Map<String, Object> map = Maps.newHashMap(); String value = JSON.toJSONString(usrServerInfo);
map.put("usrServerInfo",JSON.toJSONString(usrServerInfo)); boolean needWrite = true;
/* String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map);
if (StringUtils.isNotEmpty(result)) {
throw new RuntimeException("设备写入失败:" + result);
}*/
List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda() List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda()
.eq(PlatDeviceOther::getOriDeviceId, deviceId)); .eq(PlatDeviceOther::getOriDeviceId, deviceId));
if (CollectionUtils.isNotEmpty(platDeviceOtherList)) {
PlatDeviceOther platDeviceOther = platDeviceOtherList.get(0);
UserServerInfo existInfo = new UserServerInfo();
existInfo.setAddr(platDeviceOther.getProtocolAddress());
existInfo.setPort(platDeviceOther.getProtocolPort() != null ? Integer.valueOf(platDeviceOther.getProtocolPort()) : null);
existInfo.setUsername(platDeviceOther.getProtocolAccount());
existInfo.setPassword(platDeviceOther.getProtocolPassword());
String jsonString = JSON.toJSONString(existInfo);
needWrite = !value.equals(jsonString);
}
if (needWrite) {
ThreadUtil.sleep(200); // 受限于设备不支持同时写入 稍微延迟一点执行(前端先修改属性再修改网络信息)
Map<String, Object> map = Maps.newHashMap();
map.put("usrServerInfo", value);
String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map);
if (StringUtils.isNotEmpty(result)) {
throw new RuntimeException("设备写入失败:" + result);
}
}
for (PlatDeviceOther platDeviceOther : platDeviceOtherList) { for (PlatDeviceOther platDeviceOther : platDeviceOtherList) {
platDeviceOther.setProtocolAccount(usrServerInfo.getUsername()); platDeviceOther.setProtocolAccount(usrServerInfo.getUsername());
platDeviceOther.setProtocolPassword(usrServerInfo.getPassword()); platDeviceOther.setProtocolPassword(usrServerInfo.getPassword());
platDeviceOther.setProtocolAddress(usrServerInfo.getAddr()); platDeviceOther.setProtocolAddress(usrServerInfo.getAddr());
platDeviceOther.setProtocolPort(usrServerInfo.getPort() == null ? "" : usrServerInfo.getPort().toString()); platDeviceOther.setProtocolPort(usrServerInfo.getPort() == null ? "" : usrServerInfo.getPort().toString());
platDeviceOther.setSecureId(usrServerInfo.getSecureId());
platDeviceOther.setSecureKey(usrServerInfo.getSecureKey());
platDeviceOtherService.updateById(platDeviceOther); platDeviceOtherService.updateById(platDeviceOther);
} }
} }
......
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