|
|
@@ -1,5 +1,6 @@
|
|
|
package com.yunfeiyun.agmp.iotm.device.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
@@ -11,6 +12,7 @@ import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.IotDeviceconnTypeEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.domain.IotDevconnConfigInfoVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.domain.reqvo.IotDeviceconnAddReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.domain.reqvo.IotDeviceconnListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.domain.resvo.IotDeviceconnListRspVo;
|
|
|
@@ -113,40 +115,75 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
public int addDeviceconn(IotDeviceconnAddReqVo reqVo) {
|
|
|
String devconnType = reqVo.getDevconnType();
|
|
|
String devtypeBid = reqVo.getDevtypeBid();
|
|
|
- String devconnName = reqVo.getDevconnName();
|
|
|
- String devconnConfig = reqVo.getDevconnConfig();
|
|
|
-
|
|
|
- if(StringUtils.isEmpty(devconnName)){
|
|
|
- throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接名称不能为空");
|
|
|
+ List<IotDevconnConfigInfoVo> devconnConfigList = reqVo.getDevconnConfigList();
|
|
|
+ if(devconnConfigList == null || devconnConfigList.isEmpty()){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接配置不能为空");
|
|
|
}
|
|
|
|
|
|
TosDevicetype tosDevicetype = tosDevicetypeService.selectTosDevicetypeByDevtypeBid(devtypeBid);
|
|
|
if(tosDevicetype == null){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备型号不存在");
|
|
|
}
|
|
|
- if(IotDeviceconnTypeEnum.COMMON.getCode().equals(devconnType)){
|
|
|
- devconnConfig = tosDevicetype.getDevTypeConfig();
|
|
|
+ IotDeviceconn selectIotDeviceconn = new IotDeviceconn();
|
|
|
+ selectIotDeviceconn.setDevtypeBid(devtypeBid);
|
|
|
+
|
|
|
+ List<IotDeviceconn> iotDeviceconnList = selectIotDeviceconnList(selectIotDeviceconn);
|
|
|
+ if(iotDeviceconnList != null && !iotDeviceconnList.isEmpty()){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备型号已存在连接配置");
|
|
|
}
|
|
|
|
|
|
- try{
|
|
|
- JSONArray jsonArray = JSONArray.parseArray(devconnConfig);
|
|
|
- if(jsonArray == null || jsonArray.isEmpty()){
|
|
|
- throw new Exception();
|
|
|
+ List<IotDeviceconn> insertIotDeviceconnList = new ArrayList<>();
|
|
|
+
|
|
|
+ if(IotDeviceconnTypeEnum.COMMON.getCode().equals(devconnType)){
|
|
|
+ IotDeviceconn iotDeviceconn = new IotDeviceconn();
|
|
|
+ iotDeviceconn.setDevconnBid(iotDeviceconn.getUUId());
|
|
|
+ iotDeviceconn.setDevtypeBid(devtypeBid);
|
|
|
+ iotDeviceconn.setDevconnType(devconnType);
|
|
|
+ iotDeviceconn.setDevconnName(IotDeviceconnTypeEnum.COMMON.getName());
|
|
|
+ iotDeviceconn.setDevconnConfig(tosDevicetype.getDevTypeConfig());
|
|
|
+ iotDeviceconn.setDevconnCreator(SecurityUtils.getUserId());
|
|
|
+ iotDeviceconn.setDevconnCreateddate(DateUtils.dateTimeNow());
|
|
|
+
|
|
|
+ insertIotDeviceconnList.add(iotDeviceconn);
|
|
|
+ }else{
|
|
|
+ String diffName = "";
|
|
|
+ for(IotDevconnConfigInfoVo devconnConfigInfo : devconnConfigList){
|
|
|
+ String devconnName = devconnConfigInfo.getDevconnName();
|
|
|
+ if(StringUtils.isEmpty(devconnName)){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接名称不能为空");
|
|
|
+ }
|
|
|
+ if(diffName.equals(devconnName)){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接名称不能重复");
|
|
|
+ }
|
|
|
+ String devconnConfig = devconnConfigInfo.getDevconnConfig();
|
|
|
+ if(StringUtils.isEmpty(devconnConfig)){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接配置不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try{
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(devconnConfig);
|
|
|
+ if(jsonArray == null || jsonArray.isEmpty()){
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接配置格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDeviceconn iotDeviceconn = new IotDeviceconn();
|
|
|
+ iotDeviceconn.setDevconnBid(iotDeviceconn.getUUId());
|
|
|
+ iotDeviceconn.setDevtypeBid(devtypeBid);
|
|
|
+ iotDeviceconn.setDevconnType(devconnType);
|
|
|
+ iotDeviceconn.setDevconnName(devconnName);
|
|
|
+ iotDeviceconn.setDevconnConfig(devconnConfig);
|
|
|
+ iotDeviceconn.setDevconnCreator(SecurityUtils.getUserId());
|
|
|
+ iotDeviceconn.setDevconnCreateddate(DateUtils.dateTimeNow());
|
|
|
+
|
|
|
+ insertIotDeviceconnList.add(iotDeviceconn);
|
|
|
+ diffName = devconnName;
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
- throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接配置格式错误");
|
|
|
}
|
|
|
|
|
|
- IotDeviceconn iotDeviceconn = new IotDeviceconn();
|
|
|
- iotDeviceconn.setDevconnBid(iotDeviceconn.getUUId());
|
|
|
- iotDeviceconn.setDevtypeBid(devtypeBid);
|
|
|
- iotDeviceconn.setDevconnType(devconnType);
|
|
|
- iotDeviceconn.setDevconnName(devconnName);
|
|
|
- iotDeviceconn.setDevconnConfig(devconnConfig);
|
|
|
- iotDeviceconn.setDevconnRemark(reqVo.getDevconnRemark());
|
|
|
- iotDeviceconn.setDevconnCreator(SecurityUtils.getUserId());
|
|
|
- iotDeviceconn.setDevconnCreateddate(DateUtils.dateTimeNow());
|
|
|
- int status = insertIotDeviceconn(iotDeviceconn);
|
|
|
+ int status = insertIotDeviceconnByBatch(insertIotDeviceconnList);
|
|
|
|
|
|
// Todo 发送消息,创建设备连接
|
|
|
return status;
|
|
|
@@ -163,4 +200,18 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
List<IotDeviceconnListRspVo> iotDeviceconnListRspVoList = iotDeviceconnMapper.listDeviceconn(reqVo);
|
|
|
return iotDeviceconnListRspVoList;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量新增设备连接配置
|
|
|
+ *
|
|
|
+ * @param iotDeviceconnList 设备连接配置列表
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertIotDeviceconnByBatch(List<IotDeviceconn> iotDeviceconnList) {
|
|
|
+ for (IotDeviceconn iotDeviceconn : iotDeviceconnList) {
|
|
|
+ iotDeviceconn.setTid(SecurityUtils.getTid());
|
|
|
+ }
|
|
|
+ return iotDeviceconnMapper.insertIotDeviceconnByBatch(iotDeviceconnList);
|
|
|
+ }
|
|
|
}
|