iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/common/dto/ChannelSourceDTO.java
对比新文件 @@ -0,0 +1,18 @@ package com.iailab.module.data.channel.common.dto; import lombok.Data; /** * @author PanZhibao * @Description * @createTime 2024年10月31日 */ @Data public class ChannelSourceDTO { private String sourceType; private String sourceName; private String sourceId; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/common/service/ChannelSourceService.java
对比新文件 @@ -0,0 +1,88 @@ package com.iailab.module.data.channel.common.service; import com.iailab.module.data.channel.http.entity.HttpApiEntity; import com.iailab.module.data.channel.http.service.HttpApiService; import com.iailab.module.data.channel.kio.entity.ChannelKioDeviceEntity; import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService; import com.iailab.module.data.channel.modbus.dto.ChannelModBusDeviceDTO; import com.iailab.module.data.channel.modbus.entity.ChannelModBusDeviceEntity; import com.iailab.module.data.channel.modbus.service.ChannelModbusDeviceService; import com.iailab.module.data.channel.opcda.dto.ChannelOPCDADeviceDTO; import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; import com.iailab.module.data.channel.opcda.service.ChannelOPCDADeviceService; import com.iailab.module.data.channel.opcua.dto.ChannelOPCUADeviceDTO; import com.iailab.module.data.channel.opcua.entity.ChannelOPCUADeviceEntity; import com.iailab.module.data.channel.opcua.service.ChannelOPCUADeviceService; import com.iailab.module.data.common.enums.DataSourceType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author PanZhibao * @Description * @createTime 2024年10月31日 */ @Component public class ChannelSourceService { @Autowired private ChannelOPCDADeviceService channelOPCDADeviceService; @Autowired private ChannelOPCUADeviceService channelOPCUADeviceService; @Autowired private ChannelModbusDeviceService channelModbusDeviceService; @Autowired private ChannelKioDeviceService channelKioDeviceService; @Autowired private HttpApiService httpApiService; public Map<String, Map<String, String>> getSourcesId() { Map<String, Map<String, String>> result = new HashMap<>(); Map<String, String> opcdaMap = new HashMap<>(); List<ChannelOPCDADeviceEntity> opcdaList = channelOPCDADeviceService.list(new HashMap<>()); opcdaList.forEach(opcda -> { opcdaMap.put(opcda.getServerName(), opcda.getId()); }); result.put(DataSourceType.OPCDA.getCode(), opcdaMap); Map<String, String> opcuaMap = new HashMap<>(); List<ChannelOPCUADeviceEntity> opcuaList = channelOPCUADeviceService.list(new HashMap<>()); opcuaList.forEach(opcUa -> { opcuaMap.put(opcUa.getServerName(), opcUa.getId()); }); result.put(DataSourceType.OPCUA.getCode(), opcuaMap); Map<String, String> modbusMap = new HashMap<>(); List<ChannelModBusDeviceEntity> modbusList = channelModbusDeviceService.list(new HashMap<>()); modbusList.forEach(modbus -> { modbusMap.put(modbus.getName(), modbus.getId()); }); result.put(DataSourceType.ModBus.getCode(), modbusMap); Map<String, String> kioMap = new HashMap<>(); List<ChannelKioDeviceEntity> kioList = channelKioDeviceService.list(new HashMap<>()); kioList.forEach(kio -> { kioMap.put(kio.getInstanceName(), kio.getId()); }); result.put(DataSourceType.KIO.getCode(), kioMap); Map<String, String> httpMap = new HashMap<>(); List<HttpApiEntity> httpList = httpApiService.list(); httpList.forEach(http -> { httpMap.put(http.getCode(), http.getId()); }); result.put(DataSourceType.HTTP.getCode(), httpMap); return result; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/service/impl/ChannelKioDeviceServiceImpl.java
@@ -64,6 +64,9 @@ @Override public List<ChannelKioDeviceEntity> list(Map<String, Object> params) { return channelKioDeviceDao.selectList(new QueryWrapper<ChannelKioDeviceEntity>().orderByAsc("instance_name")); QueryWrapper<ChannelKioDeviceEntity> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByAsc("instance_name"); return channelKioDeviceDao.selectList(queryWrapper); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDADeviceService.java
@@ -18,6 +18,8 @@ List<ChannelOPCDADeviceDTO> selectAll(); List<ChannelOPCDADeviceEntity> list(Map<String, Object> params); PageResult<ChannelOPCDADeviceEntity> queryPage(OpcDaDevicePageReqVO reqVO); ChannelOPCDADeviceEntity info(String id); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDADeviceServiceImpl.java
@@ -40,6 +40,13 @@ } @Override public List<ChannelOPCDADeviceEntity> list(Map<String, Object> params) { QueryWrapper<ChannelOPCDADeviceEntity> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByDesc("create_time"); return channelOPCDADeviceDao.selectList(queryWrapper); } @Override public ChannelOPCDADeviceEntity info(String id) { return channelOPCDADeviceDao.selectById(id); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/common/PointTypeEnum.java
@@ -1,37 +1,33 @@ package com.iailab.module.data.point.common; import lombok.AllArgsConstructor; import lombok.Getter; /** * @author PanZhibao * @date 2021年04月25日 11:41 */ @Getter @AllArgsConstructor public enum PointTypeEnum { MEASURE_POINT("MEASURE", "MEASURE"), CALCULATE_POINT("CALCULATE", "CALCULATE"), CONSTANT("CONSTANT", "CONSTANT"); MEASURE_POINT("MEASURE", "测量点"), CALCULATE_POINT("CALCULATE", "计算点"), CONSTANT("CONSTANT", "常量点"); private String code; private String name; private String desc; PointTypeEnum(String code, String name){ this.code = code; this.name = name; } public static PointTypeEnum getEumByCode(String code) { if (code == null) { return null; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; for (PointTypeEnum statusEnum : PointTypeEnum.values()) { if (statusEnum.getCode().equals(code)) { return statusEnum; } } return null; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java
@@ -8,6 +8,8 @@ import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.excel.core.util.ExcelUtils; import com.iailab.module.data.api.dto.ApiPointValueQueryDTO; import com.iailab.module.data.channel.common.service.ChannelSourceService; import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.influxdb.service.InfluxDBService; import com.iailab.module.data.point.dto.DaPointDTO; import com.iailab.module.data.point.entity.DaPointEntity; @@ -180,11 +182,12 @@ List<PointImportExcelVO> list = Arrays.asList( PointImportExcelVO.builder().pointName("测点1").pointType("MEASURE").dataType("float").valueType("SIMULATE") .storeType(null).unit("t(非必填)").unittransfactor(new BigDecimal(1)).defaultValue(new BigDecimal(0)).maxValue(new BigDecimal(10000000.000000)).minValue(new BigDecimal(0)) .minfreqid("NET10").remark("备注(非必填)").sourceType("HTTP").sourceId("b9d0f670-2135-458f-9494-0cda4f35ec09").tagNo("SARD1200G00102RC001") .minfreqid("1min").remark("备注(非必填)").sourceType(DataSourceType.HTTP.getCode()) .sourceName("").tagNo("SARD1200G00102RC001") .build() ); // 输出 ExcelUtils.write(response, "测点导入模板.xls", "测点列表", PointImportExcelVO.class, list); ExcelUtils.write(response, "测点导入模板.xlsx", "测点列表", PointImportExcelVO.class, list); } @PostMapping("/import") iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dto/DaPointDTO.java
@@ -47,9 +47,6 @@ @DictFormat("data_type") private String dataTypeName; @Schema(description = "值类型", required = true) private String valueType; @Schema(description = "存储类型", required = true) private String storeType; @@ -101,8 +98,12 @@ @Schema(description = "测点Tag", required = true) private String tagNo; @Schema(description = "平滑尺度") private Integer dimension; @Schema(description = "值类型") private String valueType; @Schema(description = "计算公式", required = true) private String expression; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaMathPointService.java
@@ -13,6 +13,8 @@ void add(DaMathPointDTO dto, String pointId); void add(String expression, String pointId); DaMathPointDTO getByPoint(String pointId); void update(DaMathPointDTO dto); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaMathPointServiceImpl.java
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.UUID; /** * @author PanZhibao @@ -27,6 +28,15 @@ } @Override public void add(String expression, String pointId) { DaMathPointEntity entity = new DaMathPointEntity(); entity.setId(UUID.randomUUID().toString()); entity.setPointId(pointId); entity.setExpression(expression); baseDao.insert(entity); } @Override public DaMathPointDTO getByPoint(String pointId) { QueryWrapper<DaMathPointEntity> wrapper = new QueryWrapper<>(); wrapper.eq("point_id", pointId); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
@@ -14,6 +14,7 @@ import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.framework.datapermission.core.util.DataPermissionUtils; import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; import com.iailab.module.data.channel.common.service.ChannelSourceService; import com.iailab.module.data.common.enums.CommonConstant; import com.iailab.module.data.common.enums.IsEnableEnum; import com.iailab.module.data.point.common.IncreaseCodeEnum; @@ -65,6 +66,9 @@ @Resource private ConfigApi configApi; @Resource private ChannelSourceService channelSourceService; @Override public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) { @@ -129,18 +133,24 @@ public void add(DaPointDTO dataPoint) { DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class); daPointEntity.setId(UUID.randomUUID().toString()); if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) { DaMeasurePointDTO measurePoint = new DaMeasurePointDTO(); measurePoint.setSourceType(dataPoint.getSourceOption().get(0)); measurePoint.setSourceId(dataPoint.getSourceOption().get(1)); measurePoint.setTagNo(dataPoint.getSourceOption().get(2)); daMeasurePointService.add(measurePoint, daPointEntity.getId()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name())); } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) { daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name())); } else if (PointTypeEnum.CONSTANT.getName().equals(dataPoint.getPointType())) { daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name())); switch (PointTypeEnum.getEumByCode(dataPoint.getPointType())) { case MEASURE_POINT: DaMeasurePointDTO measurePoint = new DaMeasurePointDTO(); measurePoint.setSourceType(dataPoint.getSourceOption().get(0)); measurePoint.setSourceId(dataPoint.getSourceOption().get(1)); measurePoint.setTagNo(dataPoint.getSourceOption().get(2)); daMeasurePointService.add(measurePoint, daPointEntity.getId()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name())); break; case CALCULATE_POINT: daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name())); break; case CONSTANT: daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name())); break; default: break; } daPointEntity.setIsEnable(CommonConstant.IS_ENABLE); daPointEntity.setCreateTime(new Date()); @@ -153,14 +163,19 @@ DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class); daPointEntity.setUpdateTime(new Date()); daPointDao.updateById(daPointEntity); if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) { DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint(); measurePoint.setSourceType(dataPoint.getSourceOption().get(0)); measurePoint.setSourceId(dataPoint.getSourceOption().get(1)); measurePoint.setTagNo(dataPoint.getSourceOption().get(2)); daMeasurePointService.update(measurePoint); } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) { daMathPointService.update(dataPoint.getMathPoint()); switch (PointTypeEnum.getEumByCode(dataPoint.getPointType())) { case MEASURE_POINT: DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint(); measurePoint.setSourceType(dataPoint.getSourceOption().get(0)); measurePoint.setSourceId(dataPoint.getSourceOption().get(1)); measurePoint.setTagNo(dataPoint.getSourceOption().get(2)); daMeasurePointService.update(measurePoint); break; case CALCULATE_POINT: daMathPointService.update(dataPoint.getMathPoint()); break; default: break; } } @@ -298,7 +313,8 @@ if (CollUtil.isEmpty(importPoints)) { throw exception(POINT_IMPORT_LIST_IS_EMPTY); } Map<String, Map<String, String>> sourcesIdMap = channelSourceService.getSourcesId(); // 2. 遍历,逐个创建 or 更新 PointImportRespVO respVO = PointImportRespVO.builder().createPointnames(new ArrayList<>()) .updatePointnames(new ArrayList<>()).failurePointnames(new LinkedHashMap<>()).build(); @@ -307,20 +323,33 @@ // 判断如果不存在,再进行插入 DaPointEntity existPoint = baseMapper.selectByPointName(importPoint.getPointName()); if (existPoint == null) { DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(importPoint, DaPointEntity.class); daPointEntity.setId(UUID.randomUUID().toString()); DaMeasurePointDTO measurePoint = new DaMeasurePointDTO(); measurePoint.setSourceType(importPoint.getSourceType()); measurePoint.setSourceId(importPoint.getSourceId()); measurePoint.setTagNo(importPoint.getTagNo()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name())); daPointEntity.setIsEnable(CommonConstant.IS_ENABLE); daPointEntity.setCreateTime(new Date()); switch (PointTypeEnum.getEumByCode(daPointEntity.getPointType())) { case MEASURE_POINT: DaMeasurePointDTO measurePoint = new DaMeasurePointDTO(); measurePoint.setSourceType(importPoint.getSourceType()); measurePoint.setSourceId(sourcesIdMap.get(importPoint.getSourceType()).get(importPoint.getSourceName())); measurePoint.setTagNo(importPoint.getTagNo()); measurePoint.setValueType(importPoint.getValueType()); measurePoint.setDimension(importPoint.getDimension()); daMeasurePointService.add(measurePoint, daPointEntity.getId()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name())); break; case CALCULATE_POINT: daMathPointService.add(importPoint.getExpression(), daPointEntity.getId()); daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name())); break; case CONSTANT: daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name())); break; default: break; } daMeasurePointService.add(measurePoint, daPointEntity.getId()); daPointDao.insert(daPointEntity); respVO.getCreatePointnames().add(importPoint.getPointName()); return; } @@ -336,9 +365,12 @@ baseMapper.updateById(updatePoint); DaMeasurePointEntity measurePoint = new DaMeasurePointEntity(); measurePoint.setSourceType(importPoint.getSourceType()); measurePoint.setSourceId(importPoint.getSourceId()); measurePoint.setSourceId(sourcesIdMap.get(importPoint.getSourceType()).get(importPoint.getSourceName())); measurePoint.setTagNo(importPoint.getTagNo()); daMeasurePointService.update(measurePoint, new QueryWrapper<DaMeasurePointEntity>().eq("point_id",updatePoint.getId())); respVO.getUpdatePointnames().add(importPoint.getPointName()); }); return respVO; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/DaPointExcelVO.java
@@ -29,10 +29,6 @@ @ExcelProperty("数据类型") private String dataType; @Schema(description = "值类型") @ExcelProperty("值类型") private String valueType; @Schema(description = "存储类型") @ExcelProperty("存储类型") private String storeType; @@ -77,6 +73,14 @@ @ExcelProperty("测点Tag") private String tagNo; @Schema(description = "平滑尺度") @ExcelProperty("平滑尺度") private Integer dimension; @Schema(description = "值类型") @ExcelProperty("值类型") private String valueType; @Schema(description = "计算公式") @ExcelProperty("计算公式") private String expression; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportExcelVO.java
@@ -1,9 +1,6 @@ package com.iailab.module.data.point.vo; import com.alibaba.excel.annotation.ExcelProperty; import com.iailab.framework.excel.core.annotations.DictFormat; import com.iailab.framework.excel.core.convert.DictConvert; import com.iailab.module.system.enums.DictTypeConstants; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -23,6 +20,9 @@ @Accessors(chain = false) // 设置 chain = false,避免用户导入有问题 public class PointImportExcelVO { @ExcelProperty("测点编码") private String pointNo; @ExcelProperty("测点名称") private String pointName; @@ -31,9 +31,6 @@ @ExcelProperty("数据类型") private String dataType; @ExcelProperty("值类型") private String valueType; @ExcelProperty("存储类型") private String storeType; @@ -56,16 +53,26 @@ @ExcelProperty("采集频率") private String minfreqid; @Schema(description = "备注") @ExcelProperty("备注") private String remark; @ExcelProperty("数据源类型") private String sourceType; @ExcelProperty("数据源ID") private String sourceId; @ExcelProperty("数据源名称") private String sourceName; @ExcelProperty("测点Tag") private String tagNo; @ExcelProperty("平滑尺度") private Integer dimension; @ExcelProperty("值类型") private String valueType; @ExcelProperty("计算公式") private String expression; }