|
|
@@ -18,6 +18,7 @@ import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
|
|
|
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceAddReqVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceEditReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceMapper;
|
|
|
@@ -69,14 +70,10 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码不能为空");
|
|
|
}
|
|
|
|
|
|
- IotDeviceconn selectDeviceconn = new IotDeviceconn();
|
|
|
- selectDeviceconn.setDevconnBid(devconnBid);
|
|
|
- List<IotDeviceconn> iotDeviceconnList = iotDeviceconnService.selectIotDeviceconnList(selectDeviceconn);
|
|
|
- if(iotDeviceconnList == null || iotDeviceconnList.isEmpty()){
|
|
|
- throw new RuntimeException("设备连接不存在");
|
|
|
+ IotDeviceconn iotDeviceconn = iotDeviceconnService.selectIotDeviceconnByBid(devconnBid);
|
|
|
+ if(iotDeviceconn == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备连接不存在");
|
|
|
}
|
|
|
-
|
|
|
- IotDeviceconn iotDeviceconn = iotDeviceconnList.get(0);
|
|
|
String devName = iotDeviceconn.getDevtypeName();
|
|
|
if(devCodeList.length == 1){
|
|
|
devName = reqVo.getDevName();
|
|
|
@@ -142,6 +139,53 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
return iotDeviceListResVoList;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int editIotDevice(IotDeviceEditReqVo reqVo) {
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String devName = reqVo.getDevName();
|
|
|
+ String devCode = reqVo.getDevCode();
|
|
|
+ String devconnBid = reqVo.getDevconnBid();
|
|
|
+ if(StringUtils.isEmpty(devName) || StringUtils.isEmpty(devCode)){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"参数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice iotDevice = selectIotDeviceByDevBid(devBid);
|
|
|
+ if(iotDevice == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDeviceconn oldIotDeviceconn = iotDeviceconnService.selectIotDeviceconnByBid(iotDevice.getDevconnBid());
|
|
|
+
|
|
|
+ IotDeviceconn newIotDeviceconn = iotDeviceconnService.selectIotDeviceconnByBid(devconnBid);
|
|
|
+ if(newIotDeviceconn == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备连接不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice selectIotDevice = new IotDevice();
|
|
|
+ selectIotDevice.setFirmBid(newIotDeviceconn.getFirmBid());
|
|
|
+ selectIotDevice.setDevCode(devCode);
|
|
|
+ selectIotDevice.setDevtypeBid(newIotDeviceconn.getDevtypeBid());
|
|
|
+
|
|
|
+ List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice);
|
|
|
+ Set<String> devSet = new HashSet<>();
|
|
|
+ for (IotDevice item : iotDeviceList) {
|
|
|
+ devSet.add(item.getFirmBid() + item.getDevtypeBid() + item.getDevCode());
|
|
|
+ }
|
|
|
+ String devKey = iotDevice.getFirmBid() + iotDevice.getDevtypeBid() + iotDevice.getDevCode();
|
|
|
+ devSet.remove(devKey);
|
|
|
+ if(!devSet.isEmpty()){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备编码已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ iotDevice.setDevName(devName);
|
|
|
+ iotDevice.setDevCode(devCode);
|
|
|
+ iotDevice.setDevconnBid(newIotDeviceconn.getDevconnBid());
|
|
|
+ iotDevice.setDevModifier(SecurityUtils.getUserId());
|
|
|
+ iotDevice.setDevModifieddate(DateUtils.dateTimeNow());
|
|
|
+
|
|
|
+ return updateIotDevice(iotDevice, oldIotDeviceconn, newIotDeviceconn);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询设备基础
|
|
|
*
|
|
|
@@ -207,8 +251,11 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateIotDevice(IotDevice iotDevice) {
|
|
|
+ public int updateIotDevice(IotDevice iotDevice, IotDeviceconn oldDeviceconn, IotDeviceconn newDeviceconn){
|
|
|
int result = iotDeviceMapper.updateIotDevice(iotDevice);
|
|
|
+ // TODO 发送消息
|
|
|
+ // 解除旧连接订阅
|
|
|
+ // 订阅新连接
|
|
|
sendToTosMsgService.sendIotDeviceUpdateMsg(iotDevice);
|
|
|
sendToIotsMsgService.sendIotDeviceUpdateMsg(iotDevice);
|
|
|
return result;
|