From a9b8f1075a8200acb1d6b35b1b88041a60bedabd Mon Sep 17 00:00:00 2001 From: liriming <1343021927@qq.com> Date: 星期二, 29 十月 2024 09:13:52 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportExcelVO.java | 71 +++++++ iailab-module-model/iailab-module-model-biz/src/main/resources/application-test_bak.yml | 5 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java | 8 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/DaPointExcelVO.java | 79 ++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java | 82 ++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/dev/hikvision/utils/MessageCode.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointValueExportVO.java | 20 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportRespVO.java | 23 ++ iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/mapper/BaseMapperX.java | 4 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/ErrorCodeConstants.java | 10 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java | 1 iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java | 98 ++++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java | 12 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/InfluxDBService.java | 7 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java | 92 +++++++++ 18 files changed, 489 insertions(+), 37 deletions(-) diff --git a/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/mapper/BaseMapperX.java b/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/mapper/BaseMapperX.java index 080477b..ccf2c77 100644 --- a/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/mapper/BaseMapperX.java +++ b/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/mapper/BaseMapperX.java @@ -1,10 +1,7 @@ package com.iailab.framework.mybatis.core.mapper; import cn.hutool.core.collection.CollUtil; -import com.baomidou.mybatisplus.core.metadata.OrderItem; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.iailab.framework.common.constant.Constant; import com.iailab.framework.common.pojo.PageParam; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.pojo.SortablePageParam; @@ -26,7 +23,6 @@ import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Objects; /** diff --git a/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java b/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java index 20a59fa..9f7ecc6 100644 --- a/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java +++ b/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java @@ -68,7 +68,7 @@ /** * token header */ - String TOKEN_HEADER = "token"; + String TOKEN_HEADER = "authorization"; /** * tenantCode diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/ErrorCodeConstants.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/ErrorCodeConstants.java new file mode 100644 index 0000000..59b3717 --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/ErrorCodeConstants.java @@ -0,0 +1,10 @@ +package com.iailab.module.data.enums; + +import com.iailab.framework.common.exception.ErrorCode; + +public interface ErrorCodeConstants { + // ========== 测点管理模块 ========== + ErrorCode POINT_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_001_001_001, "导入测点数据不能为空!"); + ErrorCode POINT_NOT_EXISTS = new ErrorCode(1_002_001_000, "测点配置不存在"); + ErrorCode POINT_EXISTS = new ErrorCode(1_002_002_000, "测点配置已经存在"); +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiDataController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java similarity index 96% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiDataController.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java index 4072571..125fedb 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiDataController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java @@ -1,4 +1,4 @@ -package com.iailab.module.data.api.controller; +package com.iailab.module.data.api.controller.admin; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.date.DateUtils; @@ -38,7 +38,7 @@ */ @Slf4j @RestController -@RequestMapping("/api/data") +@RequestMapping("/data/api/data") @Tag(name = "数据") public class ApiDataController { @@ -60,10 +60,8 @@ @PermitAll @PostMapping("/point/history") @Operation(summary = "point历史数据") - public CommonResult<Map<String, List<Map<String, Object>>>> pointHistory(HttpServletResponse response, HttpServletRequest - request, @RequestBody ApiPointValueQueryDTO queryDto) { + public CommonResult<Map<String, List<Map<String, Object>>>> pointHistory(@RequestBody ApiPointValueQueryDTO queryDto) { try { - apiSecurityUtils.validate(request); Map<String, List<Map<String, Object>>> data = new HashMap<>(); if (CollectionUtils.isEmpty(queryDto.getPointNos())) { return success(data); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiIndItemController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java similarity index 97% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiIndItemController.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java index 3fd5980..13957c8 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiIndItemController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java @@ -1,4 +1,4 @@ -package com.iailab.module.data.api.controller; +package com.iailab.module.data.api.controller.admin; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.object.ConvertUtils; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java index d3878fd..d48849a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java @@ -27,7 +27,6 @@ private Date start; @Schema(description = "结束时间") - @NotNull(message="end不能为空") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date end; } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/dev/hikvision/utils/MessageCode.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/dev/hikvision/utils/MessageCode.java index 32b80f2..a3e0bca 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/dev/hikvision/utils/MessageCode.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/dev/hikvision/utils/MessageCode.java @@ -9,8 +9,8 @@ public static final String JsonSavePath = "D:/hk-project/json";//海康威视抓取图片上传路径 // public static final String JsonSavePath = "D:/DLUT/json";//海康威视抓取图片上传路径 - public static final String HIK_WIN_PATH = "hikvision/win64/HCNetSDK.dll"; -// public static final String HIK_WIN_PATH = "D:\\DLUT\\lib\\HCNetSDK.dll"; +// public static final String HIK_WIN_PATH = "hikvision/win64/HCNetSDK.dll"; + public static final String HIK_WIN_PATH = "D:\\DLUT\\lib\\HCNetSDK.dll"; public static final String ModelCode = "Image_feature";//模型代码 diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/InfluxDBService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/InfluxDBService.java index bb9f207..dc4dbbd 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/InfluxDBService.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/InfluxDBService.java @@ -1,11 +1,10 @@ package com.iailab.module.data.influxdb.service; -import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; +import com.iailab.module.data.api.dto.ApiPointValueQueryDTO; import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; import com.iailab.module.data.api.dto.ApiTagValueQueryDTO; -import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; import com.iailab.module.data.influxdb.pojo.InfluxTagValuePOJO; -import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; +import com.iailab.module.data.point.vo.PointValueExportVO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -41,4 +40,6 @@ boolean exportTagValue(HttpServletResponse response, HttpServletRequest request, ApiTagValueQueryDTO params); Object queryPointMaxValue(InfluxPointValuePOJO point, Date startTime); + + List<PointValueExportVO> exportPointValue(ApiPointValueQueryDTO queryDto); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java index cc1dedc..cd88006 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java @@ -1,5 +1,6 @@ package com.iailab.module.data.influxdb.service.impl; +import com.iailab.module.data.api.dto.ApiPointValueQueryDTO; import com.iailab.module.data.common.utils.ExcelUtil; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.data.api.dto.ApiExportValueDTO; @@ -11,6 +12,9 @@ import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; import com.iailab.module.data.influxdb.pojo.InfluxTagValuePOJO; import com.iailab.module.data.influxdb.service.InfluxDBService; +import com.iailab.module.data.point.dto.DaPointDTO; +import com.iailab.module.data.point.service.DaPointService; +import com.iailab.module.data.point.vo.PointValueExportVO; import com.influxdb.client.InfluxQLQueryApi; import com.influxdb.client.QueryApi; import com.influxdb.client.WriteApi; @@ -23,13 +27,19 @@ import com.influxdb.query.InfluxQLQueryResult; import lombok.extern.slf4j.Slf4j; import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; + +import static com.iailab.framework.common.pojo.CommonResult.success; /** * InfluxDB操作类 @@ -42,6 +52,9 @@ private InfluxDBInstance influxDBInstance; private WriteApi writeApi; + + @Autowired + private DaPointService daPointService; private WriteApiBlocking writeApiBlocking; @@ -56,6 +69,11 @@ private int rawOffset = TimeZone.getDefault().getRawOffset(); private int pas_ms = 1000; + + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Resource + private InfluxDBService influxDBService; @Override public void syncWriteFloatValue(String pointNo, String dataValue, long time) { @@ -202,21 +220,79 @@ } @Override - public boolean exportTagValue(HttpServletResponse response, HttpServletRequest request, ApiTagValueQueryDTO params) { - InfluxTagValuePOJO tag = new InfluxTagValuePOJO(); - tag.setId(params.getTagId()); - tag.setType(params.getDataType()); - List<ApiExportValueDTO> valueList = getExportValue(tag, params.getStart(), params.getEnd()); + public boolean exportTagValue(HttpServletResponse response, HttpServletRequest request, ApiTagValueQueryDTO queryDto) { + //构建参数 + Map<String, Object> params = new HashMap<>(1); + params.put("pointNos", queryDto.getTagIds()); + + //查询point列表 + List<DaPointDTO> pointList = daPointService.list(params); + if (CollectionUtils.isEmpty(pointList)) { + return true; + } + + //插入pointType + List<InfluxPointValuePOJO> influxParams = pointList.stream().map(item -> { + InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); + pojo.setPoint(item.getTagNo()); + pojo.setType(item.getDataType()); + return pojo; + }).collect(Collectors.toList()); + + //查询 + Map<String, List<Map<String, Object>>> data = queryPointsValues(influxParams, queryDto.getStart(), queryDto.getEnd()); + + //提取list + List<Map<String, Object>> list = data.get(queryDto.getTagIds().get(0)); + + //导出 try{ String sheetTitle = "采集数据"; String[] title = new String[]{"值", "时间"}; - ExcelUtil.exportPointValue(sheetTitle, title, new ArrayList<>(valueList), response); + ExcelUtil.exportPointValue(sheetTitle, title, new ArrayList<>(list), response); } catch (Exception ex) { return false; } return true; } + @Override + public List<PointValueExportVO> exportPointValue(ApiPointValueQueryDTO queryDto) { + + List<PointValueExportVO> pointValueExportList = new ArrayList<>(); + + //构建参数 + Map<String, Object> params = new HashMap<>(1); + params.put("pointNos", queryDto.getPointNos()); + + //查询point列表 + List<DaPointDTO> pointList = daPointService.list(params); + if (CollectionUtils.isEmpty(pointList)) { + return pointValueExportList; + } + + //插入pointType + List<InfluxPointValuePOJO> influxParams = pointList.stream().map(item -> { + InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); + pojo.setPoint(item.getPointNo()); + pojo.setType(item.getDataType()); + return pojo; + }).collect(Collectors.toList()); + + //查询 + Map<String, List<Map<String, Object>>> data = queryPointsValues(influxParams, queryDto.getStart(), queryDto.getEnd()); + + //提取list + List<Map<String, Object>> list = data.get(queryDto.getPointNos().get(0)); + for(Map<String, Object> map : list){ + PointValueExportVO dto = new PointValueExportVO(); + dto.setDatatime(map.get("time").toString()); + dto.setDatavalue(map.get("value").toString()); + pointValueExportList.add(dto); + } + + return pointValueExportList; + } @Override public Map<String, Object> queryPointsLastValue(List<InfluxPointValuePOJO> influxParams) { @@ -292,7 +368,7 @@ InfluxPointValuePOJO point = influxParams.get(i); String measurement = PointValueUtils.getMeasurement(point.getType()); StringBuilder sb = new StringBuilder(); - sb.append("from(bucket:\"" + influxDBInstance.getBucket() + "\") "); + sb.append("from(bucket:\"" + influxDBInstance.bucket + "\") "); sb.append("|> range(start: ").append(start).append(", stop: ").append(stop).append(") "); sb.append("|> filter(fn: (r) => r[\"_measurement\"] == \"" + measurement + "\")"); sb.append("|> filter(fn: (r) => r[\"_field\"] == \"value\")"); @@ -307,7 +383,7 @@ for (FluxRecord record : records) { Map<String, Object> dataIem = new HashMap<>(2); dataIem.put(VALUE, record.getValueByKey("_value")); - dataIem.put(TIME, Date.from(record.getTime())); + dataIem.put(TIME, sdf.format(Date.from(record.getTime()))); dataList.add(dataIem); } } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java index 53a5e34..f4d16b2 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java @@ -1,27 +1,39 @@ package com.iailab.module.data.point.controller.admin; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.iailab.framework.apilog.core.annotation.ApiAccessLog; import com.iailab.framework.common.pojo.CommonResult; +import com.iailab.framework.common.pojo.PageParam; import com.iailab.framework.common.pojo.PageResult; -import com.iailab.framework.common.util.object.BeanUtils; +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.influxdb.service.InfluxDBService; import com.iailab.module.data.point.dto.DaPointDTO; import com.iailab.module.data.point.entity.DaPointEntity; import com.iailab.module.data.point.service.DaPointService; -import com.iailab.module.data.point.vo.DaPointPageReqVO; -import com.iailab.module.data.point.vo.DaPointRespVO; +import com.iailab.module.data.point.vo.*; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.io.IOException; +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; import static com.iailab.framework.common.pojo.CommonResult.success; +import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; /** @@ -37,6 +49,9 @@ @Resource private DaPointService daPointService; + + @Resource + private InfluxDBService influxDBService; @PreAuthorize("@ss.hasPermission('data:point:query')") @GetMapping("page") @@ -109,4 +124,75 @@ return success(true); } + @GetMapping("/export") + @Operation(summary = "导出测点列表") + @PreAuthorize("@ss.hasPermission('data:point:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportPointList(@Validated DaPointPageReqVO exportReqVO, + HttpServletResponse response) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List<DaPointEntity> list = daPointService.queryExcelList(exportReqVO).getList(); + List<DaPointExcelVO> daPointExcelVOlist = ConvertUtils.sourceToTarget(list,DaPointExcelVO.class); + ExcelUtils.write(response, "测点列表.xls", "数据", DaPointExcelVO.class, daPointExcelVOlist); + } + + @GetMapping("/exportValue") + @Operation(summary = "导出测点数据") + @PreAuthorize("@ss.hasPermission('data:point:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportPointValue(@RequestParam("pointNo") String pointNo, + @RequestParam("start") String start, + @RequestParam("end") String end, + HttpServletResponse response) throws IOException { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); + List<String> pointNos = new ArrayList<>(); + pointNos.add(pointNo); + queryDto.setPointNos(pointNos); + try{ + if (start == null) { + queryDto.setStart(new Date()); + }else{ + queryDto.setStart(formatter.parse(start)); + + } + if (end == null) { + queryDto.setEnd(new Date()); + }else{ + queryDto.setStart(formatter.parse(end)); + } + } catch (ParseException e) { + e.printStackTrace(); + } + List<PointValueExportVO> dointValueExportlist = influxDBService.exportPointValue(queryDto); + ExcelUtils.write(response, "测点数据.xls", "数据", PointValueExportVO.class, dointValueExportlist); + } + + @GetMapping("/get-import-template") + @Operation(summary = "获得导入测点模板") + public void importTemplate(HttpServletResponse response) throws IOException { + // 手动创建导出 demo + 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") + .build() + ); + // 输出 + ExcelUtils.write(response, "测点导入模板.xls", "测点列表", PointImportExcelVO.class, list); + } + + @PostMapping("/import") + @Operation(summary = "导入测点") + @Parameters({ + @Parameter(name = "file", description = "Excel 文件", required = true), + @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") + }) +// @PreAuthorize("@ss.hasPermission('data:point:import')") + public CommonResult<PointImportRespVO> importExcel(@RequestParam("file") MultipartFile file, + @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { + List<PointImportExcelVO> list = ExcelUtils.read(file, PointImportExcelVO.class); + return success(daPointService.importPointList(list, updateSupport)); + } + } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java index ce73d04..fc14b78 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java @@ -1,5 +1,6 @@ package com.iailab.module.data.point.dao; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.mybatis.core.mapper.BaseMapperX; @@ -11,6 +12,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -31,7 +33,15 @@ List<DaPointDTO> getMathPoint(Map<String, Object> params); - default IPage<DaPointDTO> selectPage(DaPointPageReqVO reqVO) { + default IPage<DaPointDTO> selectPageList(DaPointPageReqVO reqVO) { return getPageList(getPage(reqVO), reqVO); + }; + + default PageResult<DaPointEntity> selectExcelList(DaPointPageReqVO reqVO) { + return selectPage(reqVO,new QueryWrapper<>()); } + + default DaPointEntity selectByPointName(String pointName){ + return selectOne("point_name", pointName); + }; } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java index de84219..02a487f 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java @@ -1,9 +1,10 @@ package com.iailab.module.data.point.service; import com.iailab.framework.common.pojo.PageResult; +import com.iailab.module.data.common.utils.PageUtils; import com.iailab.module.data.point.dto.DaPointDTO; import com.iailab.module.data.point.entity.DaPointEntity; -import com.iailab.module.data.point.vo.DaPointPageReqVO; +import com.iailab.module.data.point.vo.*; import java.util.List; import java.util.Map; @@ -54,4 +55,7 @@ void updateDefaultValue(DaPointDTO dto); + PointImportRespVO importPointList(List<PointImportExcelVO> importPoints, boolean isUpdateSupport); + + PageResult<DaPointEntity> queryExcelList(DaPointPageReqVO exportReqVO); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java index 4f28365..fee2663 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java @@ -1,12 +1,19 @@ package com.iailab.module.data.point.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.annotations.VisibleForTesting; +import com.iailab.framework.common.exception.ServiceException; import com.iailab.framework.common.pojo.PageResult; +import com.iailab.framework.common.util.object.BeanUtils; 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.common.enums.CommonConstant; import com.iailab.module.data.common.enums.IsEnableEnum; import com.iailab.module.data.point.common.IncreaseCodeEnum; @@ -14,18 +21,27 @@ import com.iailab.module.data.point.dao.DaPointDao; import com.iailab.module.data.point.dto.DaMeasurePointDTO; import com.iailab.module.data.point.dto.DaPointDTO; +import com.iailab.module.data.point.entity.DaMeasurePointEntity; import com.iailab.module.data.point.entity.DaPointEntity; import com.iailab.module.data.point.service.DaMathPointService; import com.iailab.module.data.point.service.DaMeasurePointService; import com.iailab.module.data.point.service.DaPointService; import com.iailab.module.data.point.service.DaSequenceNumService; -import com.iailab.module.data.point.vo.DaPointPageReqVO; +import com.iailab.module.data.point.vo.*; +import com.iailab.module.infra.api.config.ConfigApi; import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; + import javax.annotation.Resource; import java.util.*; + +import com.iailab.module.data.enums.ErrorCodeConstants; + +import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; +import static com.iailab.module.data.enums.ErrorCodeConstants.*; /** * @author lirm @@ -47,10 +63,12 @@ @Resource private DaPointDao daPointDao; + @Resource + private ConfigApi configApi; @Override public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) { - IPage<DaPointDTO> page = daPointDao.selectPage(reqVO); + IPage<DaPointDTO> page = daPointDao.selectPageList(reqVO); return new PageResult<DaPointDTO>(page.getRecords(), page.getTotal()); } @@ -240,6 +258,66 @@ } @Override + @DSTransactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入 + public PointImportRespVO importPointList(List<PointImportExcelVO> importPoints, boolean isUpdateSupport) { + // 1.1 参数校验 + if (CollUtil.isEmpty(importPoints)) { + throw exception(POINT_IMPORT_LIST_IS_EMPTY); + } + + // 2. 遍历,逐个创建 or 更新 + PointImportRespVO respVO = PointImportRespVO.builder().createPointnames(new ArrayList<>()) + .updatePointnames(new ArrayList<>()).failurePointnames(new LinkedHashMap<>()).build(); + importPoints.forEach(importPoint -> { + + // 判断如果不存在,再进行插入 + 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()); + + daMeasurePointService.add(measurePoint, daPointEntity.getId()); + daPointDao.insert(daPointEntity); + + respVO.getCreatePointnames().add(importPoint.getPointName()); + return; + } + + // 如果存在,判断是否允许更新 + if (!isUpdateSupport) { + respVO.getFailurePointnames().put(importPoint.getPointName(), POINT_EXISTS.getMsg()); + return; + } + + DaPointEntity updatePoint = BeanUtils.toBean(importPoint, DaPointEntity.class); + updatePoint.setId(existPoint.getId()); + baseMapper.updateById(updatePoint); + DaMeasurePointEntity measurePoint = new DaMeasurePointEntity(); + measurePoint.setSourceType(importPoint.getSourceType()); + measurePoint.setSourceId(importPoint.getSourceId()); + measurePoint.setTagNo(importPoint.getTagNo()); + daMeasurePointService.update(measurePoint, new QueryWrapper<DaMeasurePointEntity>().eq("point_id",updatePoint.getId())); + respVO.getUpdatePointnames().add(importPoint.getPointName()); + }); + return respVO; + } + + @Override + public PageResult<DaPointEntity> queryExcelList(DaPointPageReqVO exportReqVO) { + + return daPointDao.selectExcelList(exportReqVO); + + } + + @Override public void enableByIds(String[] ids) { if (CollectionUtils.isEmpty(Arrays.asList(ids))) { return; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/DaPointExcelVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/DaPointExcelVO.java new file mode 100644 index 0000000..bb08cac --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/DaPointExcelVO.java @@ -0,0 +1,79 @@ +package com.iailab.module.data.point.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; + + +@Schema(description = "导出 - 测点信息 Response VO") +@Data +@ExcelIgnoreUnannotated +public class DaPointExcelVO { + + @Schema(description = "测点编码") + @ExcelProperty("测点编码") + private String pointNo; + + @Schema(description = "测点名称") + @ExcelProperty("测点名称") + private String pointName; + + @Schema(description = "测点类型") + @ExcelProperty("测点类型") + private String pointType; + + @Schema(description = "数据类型") + @ExcelProperty("数据类型") + private String dataType; + + @Schema(description = "值类型") + @ExcelProperty("值类型") + private String valueType; + + @Schema(description = "存储类型") + @ExcelProperty("存储类型") + private String storeType; + + @Schema(description = "测量单位") + @ExcelProperty("测量单位") + private String unit; + + @Schema(description = "单位转换") + @ExcelProperty("单位转换") + private BigDecimal unittransfactor; + + @Schema(description = "默认值") + @ExcelProperty("默认值") + private BigDecimal defaultValue; + + @Schema(description = "最大值") + @ExcelProperty("最大值") + private BigDecimal maxValue; + + @Schema(description = "最小值") + @ExcelProperty("最小值") + private BigDecimal minValue; + + @Schema(description = "采集频率") + @ExcelProperty("采集频率") + private String minfreqid; + + @Schema(description = "备注") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "数据源类型") + @ExcelProperty("数据源类型") + private String sourceType; + + @Schema(description = "数据源ID") + @ExcelProperty("数据源ID") + private String sourceId; + + @Schema(description = "测点Tag") + @ExcelProperty("测点Tag") + private String tagNo; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportExcelVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportExcelVO.java new file mode 100644 index 0000000..c8fe449 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportExcelVO.java @@ -0,0 +1,71 @@ +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; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; + +/** + * 用户 Excel 导入 VO + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题 +public class PointImportExcelVO { + + @ExcelProperty("测点名称") + private String pointName; + + @ExcelProperty("测点类型") + private String pointType; + + @ExcelProperty("数据类型") + private String dataType; + + @ExcelProperty("值类型") + private String valueType; + + @ExcelProperty("存储类型") + private String storeType; + + @ExcelProperty("测量单位") + private String unit; + + @ExcelProperty("单位转换") + private BigDecimal unittransfactor; + + @ExcelProperty("默认值") + private BigDecimal defaultValue; + + @ExcelProperty("最大值") + private BigDecimal maxValue; + + @ExcelProperty("最小值") + private BigDecimal minValue; + + @ExcelProperty("采集频率") + private String minfreqid; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("数据源类型") + private String sourceType; + + @ExcelProperty("数据源ID") + private String sourceId; + + @ExcelProperty("测点Tag") + private String tagNo; + +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportRespVO.java new file mode 100644 index 0000000..509df86 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportRespVO.java @@ -0,0 +1,23 @@ +package com.iailab.module.data.point.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Schema(description = "管理后台 - 用户导入 Response VO") +@Data +@Builder +public class PointImportRespVO { + + @Schema(description = "创建成功的测点名数组", requiredMode = Schema.RequiredMode.REQUIRED) + private List<String> createPointnames; + + @Schema(description = "更新成功的测点名数组", requiredMode = Schema.RequiredMode.REQUIRED) + private List<String> updatePointnames; + + @Schema(description = "导入失败的测点集合,key 为测点名,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED) + private Map<String, String> failurePointnames; +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointValueExportVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointValueExportVO.java new file mode 100644 index 0000000..dc39763 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointValueExportVO.java @@ -0,0 +1,20 @@ +package com.iailab.module.data.point.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "导出 - 测点数据 Response VO") +@Data +@ExcelIgnoreUnannotated +public class PointValueExportVO { + + @Schema(description = "采集值") + @ExcelProperty("采集值") + private String datavalue; + + @Schema(description = "采集时间") + @ExcelProperty("采集时间") + private String datatime; +} diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/application-test.yml b/iailab-module-model/iailab-module-model-biz/src/main/resources/application-test_bak.yml similarity index 94% rename from iailab-module-model/iailab-module-model-biz/src/main/resources/application-test.yml rename to iailab-module-model/iailab-module-model-biz/src/main/resources/application-test_bak.yml index d155af7..39218cb 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/resources/application-test.yml +++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/application-test_bak.yml @@ -49,5 +49,6 @@ password: 123456 mpk: - bakFilePath: D:\DLUT\mpkBakFile - model-file-path: D:\DLUT\MDK\Model\miail\ + bak-file-path: D:\DLUT\mpkBakFile + bak-resources: D:\DLUT\mpkResources + model-file-path: D:\DLUT\MDK\Model\miail\ \ No newline at end of file -- Gitblit v1.9.3