addModel(@RequestPart("file") @Validated MultipartFile file){
String methodDescribe = getMethodDescribe("addModel");
+ //1.录入通用字典
csDevModelService.addDict(file);
+ //2.解析模板数据
csDevModelService.addModel(file);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsLineModelController.java b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsLineModelController.java
index f259ded..2b0619a 100644
--- a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsLineModelController.java
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsLineModelController.java
@@ -1,13 +1,25 @@
package com.njcn.access.controller;
+import com.njcn.access.pojo.po.CsLineModel;
+import com.njcn.access.service.ICsLineModelService;
+import com.njcn.common.pojo.annotation.OperateInfo;
+import com.njcn.common.pojo.enums.common.LogEnum;
+import com.njcn.common.pojo.enums.response.CommonResponseEnum;
+import com.njcn.common.pojo.response.HttpResult;
+import com.njcn.common.utils.HttpResultUtil;
+import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
-
import org.springframework.web.bind.annotation.RestController;
-import com.njcn.web.controller.BaseController;
+
+import java.util.List;
/**
*
@@ -24,7 +36,27 @@ import com.njcn.web.controller.BaseController;
@AllArgsConstructor
public class CsLineModelController extends BaseController {
+ private final ICsLineModelService csLineModelService;
+ @OperateInfo(info = LogEnum.BUSINESS_COMMON)
+ @PostMapping("/add")
+ @ApiOperation("新增模板监测点")
+ @ApiImplicitParam(name = "csLineModel", value = "监测点信息", required = true)
+ public HttpResult add(@RequestBody CsLineModel csLineModel){
+ String methodDescribe = getMethodDescribe("add");
+ csLineModelService.add(csLineModel);
+ return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
+ }
+
+ @OperateInfo(info = LogEnum.BUSINESS_COMMON)
+ @PostMapping("/addList")
+ @ApiOperation("批量新增模板监测点")
+ @ApiImplicitParam(name = "list", value = "监测点集合", required = true)
+ public HttpResult addList(@RequestBody List list){
+ String methodDescribe = getMethodDescribe("addList");
+ csLineModelService.addList(list);
+ return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
+ }
}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java
index 66143f1..7466a23 100644
--- a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java
@@ -98,7 +98,7 @@ public class MqttMessageHandler {
* @param message
* @param payload
*/
- @MqttSubscribe(value = "/Dev/Reg/{edgeId}",qos = 1)
+ @MqttSubscribe(value = "/Dev/DevReg/{edgeId}",qos = 1)
@Transactional(rollbackFor = Exception.class)
public void devOperation(String topic, MqttMessage message, @NamedValue("edgeId") String nDid, @Payload String payload){
log.info("收到注册应答响应--->" + nDid);
@@ -143,21 +143,20 @@ public class MqttMessageHandler {
throw new BusinessException(AccessResponseEnum.MODEL_VERSION_ERROR);
}
//校验前置传递的装置模板库中是否存在
+ List modelId = new ArrayList<>();
list.forEach(item->{
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
if (Objects.isNull(po)){
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
}
+ modelId.add(po.getId());
});
- //fixme 这边先写死模板id,后期要选择电能质量的模板来确定监测点个数
- String modelId = "1";
List lineList = csLineModelService.getMonitorNumByModelId(modelId);
String key = "LINE" + nDid;
//存储监测点模板信息,用于界面回显
redisUtil.saveByKeyWithExpire(key,lineList,600L);
//存储模板id
- //todo 这边也是要调整的
String key2 = "MODEL" + nDid;
redisUtil.saveByKeyWithExpire(key2,modelId,600L);
}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDataArrayMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDataArrayMapper.java
new file mode 100644
index 0000000..c8d9204
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDataArrayMapper.java
@@ -0,0 +1,16 @@
+package com.njcn.access.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.njcn.access.pojo.po.CsDataArrayPO;
+
+/**
+ *
+ * 数据集表 Mapper 接口
+ *
+ *
+ * @author xuyang
+ * @since 2023-08-01
+ */
+public interface CsDataArrayMapper extends BaseMapper {
+
+}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDataSetMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDataSetMapper.java
new file mode 100644
index 0000000..d8bbc32
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDataSetMapper.java
@@ -0,0 +1,16 @@
+package com.njcn.access.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.njcn.access.pojo.po.CsDataSetPO;
+
+/**
+ *
+ * 数据集表 Mapper 接口
+ *
+ *
+ * @author xuyang
+ * @since 2023-08-01
+ */
+public interface CsDataSetMapper extends BaseMapper {
+
+}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDevModelMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDevModelMapper.java
new file mode 100644
index 0000000..2c03b1e
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsDevModelMapper.java
@@ -0,0 +1,25 @@
+package com.njcn.access.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.njcn.csdevice.pojo.dto.DataArrayDTO;
+import com.njcn.csdevice.pojo.param.CsDevModelQueryListParm;
+import com.njcn.csdevice.pojo.param.CsDevModelQueryParm;
+import com.njcn.csdevice.pojo.po.CsDevModelPO;
+import com.njcn.csdevice.pojo.vo.CsDevModelPageVO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ *
+ * Description:
+ * 接口文档访问地址:http://serverIP:port/swagger-ui.html
+ * Date: 2023/4/10 11:28【需求编号】
+ *
+ * @author clam
+ * @version V1.0.0
+ */
+public interface CsDevModelMapper extends BaseMapper {
+
+}
\ No newline at end of file
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDataArrayService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDataArrayService.java
new file mode 100644
index 0000000..be5ec34
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDataArrayService.java
@@ -0,0 +1,30 @@
+package com.njcn.access.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.njcn.access.pojo.po.CsDataArrayPO;
+import com.njcn.access.pojo.po.CsDataSetPO;
+
+import java.util.List;
+
+/**
+ *
+ * 数据集表 服务类
+ *
+ *
+ * @author xuyang
+ * @since 2023-08-01
+ */
+public interface ICsDataArrayService extends IService {
+ /**
+ * 新增详细数据集
+ * @param csDataArrayPo
+ */
+ void add(CsDataArrayPO csDataArrayPo);
+
+ /**
+ * 批量新增数据集
+ * @param list
+ */
+ void addList(List list);
+
+}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDataSetService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDataSetService.java
new file mode 100644
index 0000000..2654f5e
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDataSetService.java
@@ -0,0 +1,29 @@
+package com.njcn.access.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.njcn.access.pojo.po.CsDataSetPO;
+
+import java.util.List;
+
+/**
+ *
+ * 数据集表 服务类
+ *
+ *
+ * @author xuyang
+ * @since 2023-08-01
+ */
+public interface ICsDataSetService extends IService {
+ /**
+ * 新增数据集
+ * @param csDataSetPo
+ */
+ void add(CsDataSetPO csDataSetPo);
+
+ /**
+ * 批量新增数据集
+ * @param list
+ */
+ void addList(List list);
+
+}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsLineModelService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsLineModelService.java
index 234b525..7e13522 100644
--- a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsLineModelService.java
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsLineModelService.java
@@ -17,8 +17,20 @@ public interface ICsLineModelService extends IService {
/**
* 获取模板下监测点个数
- * @param id 模板Id
+ * @param list 模板Id集合
*/
- List getMonitorNumByModelId(String id);
+ List getMonitorNumByModelId(List list);
+
+ /**
+ * 新增模板监测点信息
+ * @param csLineModel
+ */
+ void add(CsLineModel csLineModel);
+
+ /**
+ * 批量新增模板监测点信息
+ * @param list
+ */
+ void addList(List list);
}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDataArrayServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDataArrayServiceImpl.java
new file mode 100644
index 0000000..c31fea9
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDataArrayServiceImpl.java
@@ -0,0 +1,32 @@
+package com.njcn.access.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.njcn.access.mapper.CsDataArrayMapper;
+import com.njcn.access.pojo.po.CsDataArrayPO;
+import com.njcn.access.service.ICsDataArrayService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ *
+ * 数据集表 服务实现类
+ *
+ *
+ * @author xuyang
+ * @since 2023-08-01
+ */
+@Service
+public class CsDataArrayServiceImpl extends ServiceImpl implements ICsDataArrayService {
+
+
+ @Override
+ public void add(CsDataArrayPO csDataArrayPo) {
+ this.save(csDataArrayPo);
+ }
+
+ @Override
+ public void addList(List list) {
+ this.saveBatch(list,1000);
+ }
+}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDataSetServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDataSetServiceImpl.java
new file mode 100644
index 0000000..134b11a
--- /dev/null
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDataSetServiceImpl.java
@@ -0,0 +1,31 @@
+package com.njcn.access.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.njcn.access.mapper.CsDataSetMapper;
+import com.njcn.access.pojo.po.CsDataSetPO;
+import com.njcn.access.service.ICsDataSetService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ *
+ * 数据集表 服务实现类
+ *
+ *
+ * @author xuyang
+ * @since 2023-08-01
+ */
+@Service
+public class CsDataSetServiceImpl extends ServiceImpl implements ICsDataSetService {
+
+ @Override
+ public void add(CsDataSetPO csDataSetPo) {
+ this.save(csDataSetPo);
+ }
+
+ @Override
+ public void addList(List list) {
+ this.saveBatch(list,1000);
+ }
+}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDevModelServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDevModelServiceImpl.java
index 5f35a04..c8e9325 100644
--- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDevModelServiceImpl.java
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDevModelServiceImpl.java
@@ -1,16 +1,22 @@
package com.njcn.access.service.impl;
import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.IdUtil;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.enums.DataModel;
import com.njcn.access.enums.TypeEnum;
+import com.njcn.access.mapper.CsDevModelMapper;
import com.njcn.access.pojo.dto.data.*;
-import com.njcn.access.pojo.dto.devModel.ApfDto;
-import com.njcn.access.pojo.dto.devModel.ClDevDto;
-import com.njcn.access.pojo.dto.devModel.TemplateDto;
+import com.njcn.access.pojo.dto.devModel.*;
+import com.njcn.access.pojo.po.CsDataArrayPO;
+import com.njcn.access.pojo.po.CsDataSetPO;
+import com.njcn.access.pojo.po.CsLineModel;
+import com.njcn.access.service.ICsDataArrayService;
+import com.njcn.access.service.ICsDataSetService;
import com.njcn.access.service.ICsDevModelService;
+import com.njcn.access.service.ICsLineModelService;
import com.njcn.access.utils.JsonUtil;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.LogUtil;
@@ -22,6 +28,7 @@ import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.api.EleEvtFeignClient;
import com.njcn.system.api.EpdFeignClient;
+import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.param.EleEpdPqdParam;
import com.njcn.system.pojo.param.EleEvtParam;
import com.njcn.system.pojo.po.Dic;
@@ -66,6 +73,14 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
private final EleEvtFeignClient eleEvtFeignClient;
+ private final ICsDataSetService csDataSetService;
+
+ private final ICsDataArrayService csDataArrayService;
+
+ private final CsDevModelMapper csDevModelMapper;
+
+ private final ICsLineModelService csLineModelService;
+
@Override
@Transactional(rollbackFor = {Exception.class})
public void addModel(MultipartFile file) {
@@ -79,12 +94,18 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
String filePath = "";
//1.录入cs_dev_model表,记录装置型号和模板记录
CsDevModelPO csDevModelPo = addCsDevModel(templateDto,filePath);
+ //2.录入数据集、详细数据(主设备、模块、监测设备)
+ analysisDataSet(templateDto,csDevModelPo.getId());
+ //3.录入监测点模板表(记录当前模板有几个监测点,治理类型的模板目前规定1个监测点,电能质量模板根据逻辑子设备来)
+ addCsLineModel(templateDto,csDevModelPo.getId());
+ //todo 这边软件信息和监测点信息需要接入后询问设备,然后记录
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
+ @Transactional(rollbackFor = {Exception.class})
public void addDict(MultipartFile file) {
String json = null;
try {
@@ -105,13 +126,21 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
if (!Objects.isNull(po)){
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
}
- CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
- csDevModelAddParm.setDevTypeName(templateDto.getDevType());
- csDevModelAddParm.setName(templateDto.getDevType());
- csDevModelAddParm.setVersionNo(templateDto.getVersion());
- csDevModelAddParm.setTime(templateDto.getTime());
- csDevModelAddParm.setFilePath(filePath);
- return devModelFeignClient.addDevModel(csDevModelAddParm).getData();
+ CsDevModelPO model = new CsDevModelPO();
+ model.setDevTypeName(templateDto.getDevType());
+ model.setName(templateDto.getDevType());
+ model.setVersionNo(templateDto.getVersion());
+ model.setVersionDate(Date.valueOf(templateDto.getTime()));
+ model.setFilePath(filePath);
+ model.setStatus ("1");
+ //fixme 先用数据类型来区分模板的类型
+ if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
+ model.setType(0);
+ } else {
+ model.setType(1);
+ }
+ csDevModelMapper.insert(model);
+ return model;
}
/**
@@ -516,5 +545,289 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
}
}
+ /**
+ * 解析数据集、详细数据
+ */
+ private void analysisDataSet(TemplateDto templateDto,String pId){
+ List setList = new ArrayList<>();
+ List arrayList = new ArrayList<>();
+ List dataSetList = templateDto.getDataSet();
+ //逻辑设备录入
+ if (CollectionUtil.isNotEmpty(dataSetList)){
+ dataSetList.forEach(item1->{
+ String id = IdUtil.fastSimpleUUID();
+ CsDataSetPO csDataSetPo = new CsDataSetPO();
+ csDataSetPo.setId(id);
+ csDataSetPo.setPid(pId);
+ csDataSetPo.setName(item1.getName());
+ csDataSetPo.setAnotherName(item1.getName());
+ csDataSetPo.setIdx(item1.getIdx());
+ csDataSetPo.setPeriod(item1.getPeriod());
+ csDataSetPo.setStoreFlag(item1.getStoreFlag());
+ csDataSetPo.setDataList(String.join(",",templateDto.getDataList()));
+ csDataSetPo.setType(0);
+ setList.add(csDataSetPo);
+ List list = item1.getDataArrayDtoList();
+ if(CollectionUtil.isNotEmpty(list)) {
+ int i = 0;
+ for (DataArrayDto item2 : list) {
+ List po = findDict(id,templateDto,item2.getType(),item2.getIdx());
+ for (CsDataArrayPO p : po) {
+ p.setIdx(item2.getIdx());
+ p.setSort(i);
+ i++;
+ arrayList.add(p);
+ }
+ }
+ }
+ });
+ }
+ //逻辑子设备数据录入
+ List clDevList = templateDto.getClDevDtoList();
+ if (CollectionUtil.isNotEmpty(clDevList)){
+ clDevList.forEach(item3->{
+ List clDataSetList = item3.getDataSet();
+ if (CollectionUtil.isNotEmpty(clDataSetList)){
+ clDataSetList.forEach(item4->{
+ String id = IdUtil.fastSimpleUUID();
+ CsDataSetPO csDataSetPo = new CsDataSetPO();
+ csDataSetPo.setId(id);
+ csDataSetPo.setPid(pId);
+ csDataSetPo.setName(item4.getName());
+ csDataSetPo.setAnotherName(item4.getName());
+ csDataSetPo.setIdx(item4.getIdx());
+ csDataSetPo.setPeriod(item4.getPeriod());
+ csDataSetPo.setStoreFlag(item4.getStoreFlag());
+ csDataSetPo.setDataList(String.join(",",item3.getDataList()));
+ //fixme 先用数据类型来区分模板的类型
+ if (item3.getDataList().contains("Apf") || item3.getDataList().contains("Dvr")){
+ csDataSetPo.setType(1);
+ } else {
+ csDataSetPo.setType(2);
+ }
+ csDataSetPo.setClDev(item3.getClDid());
+ setList.add(csDataSetPo);
+ List list = item4.getDataArrayDtoList();
+ if(CollectionUtil.isNotEmpty(list)) {
+ int i = 0;
+ for (DataArrayDto item2 : list) {
+ List po = findDict(id,templateDto,item2.getType(),item2.getIdx());
+ for (CsDataArrayPO p : po) {
+ p.setIdx(item2.getIdx());
+ p.setSort(i);
+ i++;
+ arrayList.add(p);
+ }
+ }
+ }
+ });
+ }
+ });
+ }
+ if(CollectionUtil.isNotEmpty(setList)) {
+ csDataSetService.addList(setList);
+ }
+ if(CollectionUtil.isNotEmpty(arrayList)) {
+ csDataArrayService.addList(arrayList);
+ }
+ }
+
+ /**
+ * 根据DataArray获取详细数据
+ * @param templateDto
+ * @param type
+ * @param idx
+ */
+ private List findDict(String pid, TemplateDto templateDto, String type, Integer idx) {
+ List list = new ArrayList<>();
+ String id = dicDataFeignClient.getDicDataByCode(type).getData().getId();
+ String name = null,phase = null;
+ switch (type) {
+ case DataModel.APF:
+ log.info("查询apf字典数据");
+ List apfList = templateDto.getApfDto();
+ ApfDto apfDto = apfList.get(idx);
+ name = apfDto.getName();
+ phase = apfDto.getPhase() == null ? "M":apfDto.getPhase();
+ break;
+ case DataModel.EVT:
+ log.info("查询evt字典数据");
+ List evtList = templateDto.getEvtDto();
+ EvtDto evtDto = evtList.get(idx);
+ name = evtDto.getName();
+ phase = evtDto.getPhase() == null ? "M":evtDto.getPhase();
+ break;
+ case DataModel.ALM:
+ log.info("查询alm字典数据");
+ List almList = templateDto.getAlmDto();
+ AlmDto almDto = almList.get(idx);
+ name = almDto.getName();
+ phase = almDto.getPhase() == null ? "M":almDto.getPhase();
+ break;
+ case DataModel.STS:
+ log.info("查询sts字典数据");
+ List stsList = templateDto.getStsDto();
+ StsDto stsDto = stsList.get(idx);
+ name = stsDto.getName();
+ phase = stsDto.getPhase() == null ? "M":stsDto.getPhase();
+ break;
+ case DataModel.PARM:
+ log.info("查询parm字典数据");
+ List parmList = templateDto.getParmDto();
+ ParmDto parmDto = parmList.get(idx);
+ name = parmDto.getName();
+ phase = parmDto.getPhase() == null ? "M":parmDto.getPhase();
+ break;
+ case DataModel.SET:
+ log.info("查询set字典数据");
+ List setList = templateDto.getSetDto();
+ SetDto setDto = setList.get(idx);
+ name = setDto.getName();
+ phase = setDto.getPhase() == null ? "M":setDto.getPhase();
+ break;
+ case DataModel.CTRL:
+ log.info("查询ctrl字典数据");
+ List ctrlList = templateDto.getCtrlDto();
+ CtrlDto ctrlDto = ctrlList.get(idx);
+ name = ctrlDto.getName();
+ phase = ctrlDto.getPhase() == null ? "M":ctrlDto.getPhase();
+ break;
+ case DataModel.EPD:
+ log.info("查询epd字典数据");
+ List epdList = templateDto.getEpdDto();
+ EpdPqdDto epdDto = epdList.get(idx);
+ name = epdDto.getName();
+ phase = epdDto.getPhase() == null ? "M":epdDto.getPhase();
+ break;
+ case DataModel.PQD:
+ log.info("查询pqd字典数据");
+ List pqdList = templateDto.getPqdDto();
+ EpdPqdDto pqdDto = pqdList.get(idx);
+ name = pqdDto.getName();
+ phase = pqdDto.getPhase() == null ? "M":pqdDto.getPhase();
+ break;
+ case DataModel.BMD:
+ log.info("查询bmd字典数据");
+ List bmdList = templateDto.getBmdDto();
+ BmdDto bmdDto = bmdList.get(idx);
+ name = bmdDto.getName();
+ phase = bmdDto.getPhase() == null ? "M":bmdDto.getPhase();
+ break;
+ case DataModel.DI:
+ log.info("查询di字典数据");
+ List diList = templateDto.getDiDto();
+ DiDto diDto = diList.get(idx);
+ name = diDto.getName();
+ phase = diDto.getPhase() == null ? "M":diDto.getPhase();
+ break;
+ case DataModel.DO:
+ log.info("查询do字典数据");
+ List doList = templateDto.getDoDto();
+ DoDto doDto = doList.get(idx);
+ name = doDto.getName();
+ phase = doDto.getPhase() == null ? "M":doDto.getPhase();
+ break;
+ case DataModel.INSET:
+ log.info("查询inset字典数据");
+ List inSetList = templateDto.getInSetDto();
+ InSetDto inSetDto = inSetList.get(idx);
+ name = inSetDto.getName();
+ phase = inSetDto.getPhase() == null ? "M":inSetDto.getPhase();
+ break;
+ default:
+ break;
+ }
+ EleEpdPqd eleEpdPqd = epdFeignClient.findByParam(name,id,phase).getData();
+ if (Objects.isNull(eleEpdPqd)){
+ throw new BusinessException(AccessResponseEnum.DICT_MISSING);
+ }
+ if (!Objects.isNull(eleEpdPqd.getHarmStart()) && !Objects.isNull(eleEpdPqd.getHarmEnd())){
+ for (int i = eleEpdPqd.getHarmStart(); i <= eleEpdPqd.getHarmEnd(); i++) {
+ if (!Objects.isNull(eleEpdPqd.getStatMethod())){
+ String[] statMethodList = eleEpdPqd.getStatMethod().split(",");
+ for (String stat : statMethodList) {
+ CsDataArrayPO csDataArrayPo = new CsDataArrayPO();
+ csDataArrayPo.setPid(pid);
+ csDataArrayPo.setDataId(eleEpdPqd.getId());
+ csDataArrayPo.setName(eleEpdPqd.getName() + "_" + i);
+ csDataArrayPo.setAnotherName(i + "次" +eleEpdPqd.getShowName());
+ csDataArrayPo.setStatMethod(stat);
+ csDataArrayPo.setDataType(eleEpdPqd.getDataType());
+ csDataArrayPo.setPhase(eleEpdPqd.getPhase());
+ list.add(csDataArrayPo);
+ }
+ } else {
+ CsDataArrayPO csDataArrayPo = new CsDataArrayPO();
+ csDataArrayPo.setPid(pid);
+ csDataArrayPo.setDataId(eleEpdPqd.getId());
+ csDataArrayPo.setName(eleEpdPqd.getName() + "_" + i);
+ csDataArrayPo.setAnotherName(i + "次" +eleEpdPqd.getShowName());
+ csDataArrayPo.setStatMethod(eleEpdPqd.getStatMethod());
+ csDataArrayPo.setDataType(eleEpdPqd.getDataType());
+ csDataArrayPo.setPhase(eleEpdPqd.getPhase());
+ list.add(csDataArrayPo);
+ }
+ }
+ } else {
+ if (!Objects.isNull(eleEpdPqd.getStatMethod())){
+ List statMethodList = Arrays.asList(eleEpdPqd.getStatMethod().split(","));
+ statMethodList.forEach(stat->{
+ CsDataArrayPO csDataArrayPo = new CsDataArrayPO();
+ csDataArrayPo.setPid(pid);
+ csDataArrayPo.setDataId(eleEpdPqd.getId());
+ csDataArrayPo.setName(eleEpdPqd.getName());
+ csDataArrayPo.setAnotherName(eleEpdPqd.getShowName());
+ csDataArrayPo.setStatMethod(stat);
+ csDataArrayPo.setDataType(eleEpdPqd.getDataType());
+ csDataArrayPo.setPhase(eleEpdPqd.getPhase());
+ list.add(csDataArrayPo);
+ });
+ } else {
+ CsDataArrayPO csDataArrayPo = new CsDataArrayPO();
+ csDataArrayPo.setPid(pid);
+ csDataArrayPo.setDataId(eleEpdPqd.getId());
+ csDataArrayPo.setName(eleEpdPqd.getName());
+ csDataArrayPo.setAnotherName(eleEpdPqd.getShowName());
+ csDataArrayPo.setStatMethod(eleEpdPqd.getStatMethod());
+ csDataArrayPo.setDataType(eleEpdPqd.getDataType());
+ csDataArrayPo.setPhase(eleEpdPqd.getPhase());
+ list.add(csDataArrayPo);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * 根据模板文件来录入监测点模板
+ */
+ private void addCsLineModel(TemplateDto templateDto,String pId) {
+ List result = new ArrayList<>();
+ //fixme 先用数据类型来区分模板的类型
+ if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
+ CsLineModel csLineModel = new CsLineModel();
+ csLineModel.setLineId(IdUtil.fastSimpleUUID());
+ csLineModel.setPid(pId);
+ csLineModel.setName("治理监测点");
+ csLineModel.setPosition(dicDataFeignClient.getDicDataByCode(DicDataEnum.OUTPUT_SIDE.getCode()).getData().getId());
+ result.add(csLineModel);
+ } else {
+ List list = templateDto.getClDevDtoList();
+ list.forEach(item->{
+ CsLineModel csLineModel = new CsLineModel();
+ csLineModel.setLineId(IdUtil.fastSimpleUUID());
+ csLineModel.setPid(pId);
+ //fixme 默认第一个监测点是负载侧,第二个是电网测
+ if (Objects.equals(item.getClDid(),1)){
+ csLineModel.setName("负载侧监测点");
+ csLineModel.setPosition(dicDataFeignClient.getDicDataByCode(DicDataEnum.LOAD_SIDE.getCode()).getData().getId());
+ } else if (Objects.equals(item.getClDid(),2)){
+ csLineModel.setName("电网侧监测点");
+ csLineModel.setPosition(dicDataFeignClient.getDicDataByCode(DicDataEnum.GRID_SIDE.getCode()).getData().getId());
+ }
+ result.add(csLineModel);
+ });
+ }
+ csLineModelService.addList(result);
+ }
}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java
index 0d8a1db..cc9d4f0 100644
--- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java
@@ -1,6 +1,9 @@
package com.njcn.access.service.impl;
import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.TypeReference;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.AccessResponseEnum;
@@ -142,8 +145,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
po.setPosition(item.getPosition());
po.setVolGrade(item.getVolGrade());
//todo 目前ct、pt数据不确定 后期补
- //po.setPtRatio(item.getPtRatio());
- //po.setCtRatio(item.getCtRatio());
+// po.setPtRatio(item.getPtRatio());
+// po.setCtRatio(item.getCtRatio());
po.setStatus(1);
csLinePoList.add(po);
CsLedgerParam param = new CsLedgerParam();
@@ -165,16 +168,19 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
//3.监测点拓扑图表录入关系
csLineTopologyFeignClient.addList(appLineTopologyDiagramPoList);
//4.新增装置-模板关系
- String modelId = redisUtil.getObjectByKey("MODEL" + devAccessParam.getNDid()).toString();
- CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
- csDevModelRelationAddParm.setDevId(vo.getId());
- csDevModelRelationAddParm.setModelId(modelId);
- devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm);
+ List modelId = objectToList(redisUtil.getObjectByKey("MODEL" + devAccessParam.getNDid()));
+ modelId.forEach(item->{
+ CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
+ csDevModelRelationAddParm.setDevId(vo.getId());
+ csDevModelRelationAddParm.setModelId(item);
+ devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm);
+ });
redisUtil.delete("MODEL" + devAccessParam.getNDid());
//5.修改装置状态
equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
//6.装置接入之后再设置心跳时间,超时改为掉线
//redisUtil.saveByKeyWithExpire("MQTT:" + devAccessParam.getNDid(), Instant.now().toEpochMilli(),180L);
+ //todo 需要将设备运行状态改为在线
//7.绑定装置和人的关系
CsDeviceUserPO po = new CsDeviceUserPO();
po.setPrimaryUserId(RequestUtil.getUserIndex());
@@ -201,7 +207,19 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
accessDto.setNDid(nDid);
accessDto.setDevType(devType);
reqAndResParam.setMsg(accessDto);
- publisher.send("/Pfm/Reg/"+nDid, PubUtils.obj2json(reqAndResParam),1,false);
+ publisher.send("/Pfm/DevReg/"+nDid, PubUtils.obj2json(reqAndResParam),1,false);
+ }
+
+ public List objectToList(Object object) {
+ List urlList = new ArrayList<>();
+ if (object != null) {
+ if (object instanceof ArrayList>) {
+ for (Object o : (List>) object) {
+ urlList.add((String) o);
+ }
+ }
+ }
+ return urlList;
}
}
diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLineModelServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLineModelServiceImpl.java
index feae297..fcb6e4c 100644
--- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLineModelServiceImpl.java
+++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsLineModelServiceImpl.java
@@ -20,8 +20,18 @@ import java.util.List;
public class CsLineModelServiceImpl extends ServiceImpl implements ICsLineModelService {
@Override
- public List getMonitorNumByModelId(String id) {
- return this.lambdaQuery().eq(CsLineModel::getPid,id).list();
+ public List getMonitorNumByModelId(List list) {
+ return this.lambdaQuery().in(CsLineModel::getPid,list).list();
+ }
+
+ @Override
+ public void add(CsLineModel csLineModel) {
+ this.save(csLineModel);
+ }
+
+ @Override
+ public void addList(List list) {
+ this.saveBatch(list,1000);
}
}