|
|
@@ -2,9 +2,19 @@ package com.yunfeiyun.agmp.iotm.device.service.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
+import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
+import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
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.reqvo.IotDeviceconnAddReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.mapper.IotDeviceconnMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.device.service.IIotDeviceconnService;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.service.ITosDevicetypeService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -20,6 +30,9 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
@Autowired
|
|
|
private IotDeviceconnMapper iotDeviceconnMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ITosDevicetypeService tosDevicetypeService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询设备连接配置
|
|
|
*
|
|
|
@@ -53,6 +66,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
@Override
|
|
|
public int insertIotDeviceconn(IotDeviceconn iotDeviceconn)
|
|
|
{
|
|
|
+ iotDeviceconn.setTid(SecurityUtils.getTid());
|
|
|
return iotDeviceconnMapper.insertIotDeviceconn(iotDeviceconn);
|
|
|
}
|
|
|
|
|
|
@@ -91,4 +105,46 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
{
|
|
|
return iotDeviceconnMapper.deleteIotDeviceconnById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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(),"连接名称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ TosDevicetype tosDevicetype = tosDevicetypeService.selectTosDevicetypeByDevtypeBid(devtypeBid);
|
|
|
+ if(tosDevicetype == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备型号不存在");
|
|
|
+ }
|
|
|
+ if(IotDeviceconnTypeEnum.COMMON.getCode().equals(devconnType)){
|
|
|
+ devconnConfig = tosDevicetype.getDevTypeConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+ int status = insertIotDeviceconn(iotDeviceconn);
|
|
|
+
|
|
|
+ // Todo 发送消息,创建设备连接
|
|
|
+ return status;
|
|
|
+ }
|
|
|
}
|