From a28ca3f36d0ace05966a8c0fac1e4b5fe921f882 Mon Sep 17 00:00:00 2001 From: houzhongjian <houzhongyi@126.com> Date: 星期三, 30 十月 2024 16:25:12 +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-data/iailab-module-data-biz/db/mysql/tenant.sql | 3 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/channel/http/collector/ihdb/HttpCollectorForIhd.java | 44 - iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.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-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java | 8 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/resources/application-dev.yaml | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java | 1 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java | 16 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java | 12 iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java | 7 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/point/collection/handler/CalculateHandle.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/MeasureValueType.java | 36 ++ iailab-module-system/iailab-module-system-biz/src/main/resources/application-dev.yaml | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/tag/controller/admin/TagController.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java | 178 +++++++++ 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-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java | 2 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/common/enums/CommonConstant.java | 2 /dev/null | 208 ----------- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java | 16 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/influxdb/common/config/InfluxDBInstance.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java | 1 iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java | 7 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/influxdb/service/impl/InfluxDBServiceImpl.java | 98 ++++ 35 files changed, 771 insertions(+), 300 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..0d530d5 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 @@ -81,6 +81,11 @@ String TENANT_ID = "tenantId"; /** + * tenantId + */ + String HEAD_TENANT_ID = "tenant-id"; + + /** * 云存储配置KEY */ String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY"; diff --git a/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java b/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java index cb47d49..bb8f25c 100644 --- a/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java +++ b/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java @@ -198,7 +198,7 @@ Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate); while (calendar.getTime().compareTo(endDate) <= 0) { - days.add(DateUtils.format(calendar.getTime(), FORMAT_YEAR_MONTH_DAY)); + days.add(DateUtils.format(calendar.getTime(), FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); calendar.add(Calendar.SECOND, seconds); } return days; diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java index 24398c3..fc12d2d 100644 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java @@ -1,5 +1,6 @@ package com.iailab.module.data.api.point.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.io.Serializable; @@ -14,6 +15,7 @@ public class ApiPointValueDTO implements Serializable { private static final long serialVersionUID = 1L; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date dataTime; private double dataValue; 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/db/mysql/tenant.sql b/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql index 9a3d454..f6e6d3c 100644 --- a/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql +++ b/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql @@ -159,7 +159,8 @@ `source_type` VARCHAR(10) COMMENT '数据源类型', `source_id` VARCHAR(36) COMMENT '数据源ID', `tag_no` VARCHAR(64) COMMENT '测点Tag', - `dimension` INT COMMENT '尺度' , + `dimension` INT COMMENT '平滑尺度(min)' , + `value_type` VARCHAR(36) COMMENT '值类型(数字量,模拟量)', PRIMARY KEY (id) USING BTREE, UNIQUE KEY `uk_point_id` (`point_id`) USING BTREE, KEY `uk_tag_no` (`tag_no`) USING BTREE 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/ApiDataController.java deleted file mode 100644 index 4072571..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiDataController.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.iailab.module.data.api.controller; - -import com.iailab.framework.common.pojo.CommonResult; -import com.iailab.framework.common.util.date.DateUtils; -import com.iailab.module.data.api.dto.IndexQueryDTO; -import com.iailab.module.data.api.dto.echarts.BarLineDTO; -import com.iailab.module.data.api.dto.echarts.SeriesItem; -import com.iailab.module.data.api.dto.ApiPointValueQueryDTO; -import com.iailab.module.data.point.collection.PointCollector; -import com.iailab.module.data.point.common.PointDataTypeEnum; -import com.iailab.module.data.point.dto.DaPointDTO; -import com.iailab.module.data.point.service.DaPointService; -import com.iailab.module.data.point.service.DaPointValueService; -import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; -import com.iailab.module.data.influxdb.service.InfluxDBService; -import com.iailab.module.data.api.dto.DeviceValueDTO; -import com.iailab.module.data.api.utils.ApiSecurityUtils; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.extern.slf4j.Slf4j; -import javax.annotation.Resource; -import org.springframework.util.CollectionUtils; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.security.PermitAll; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.math.BigDecimal; -import java.util.*; -import java.util.stream.Collectors; - -import static com.iailab.framework.common.pojo.CommonResult.success; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年05月02日 10:58:00 - */ -@Slf4j -@RestController -@RequestMapping("/api/data") -@Tag(name = "数据") -public class ApiDataController { - - @Resource - private DaPointService daPointService; - - @Resource - private ApiSecurityUtils apiSecurityUtils; - - @Resource - private DaPointValueService daPointValueService; - - @Resource - private InfluxDBService influxDBService; - - @Resource - private PointCollector pointCollector; - - @PermitAll - @PostMapping("/point/history") - @Operation(summary = "point历史数据") - public CommonResult<Map<String, List<Map<String, Object>>>> pointHistory(HttpServletResponse response, HttpServletRequest - request, @RequestBody ApiPointValueQueryDTO queryDto) { - try { - apiSecurityUtils.validate(request); - Map<String, List<Map<String, Object>>> data = new HashMap<>(); - if (CollectionUtils.isEmpty(queryDto.getPointNos())) { - return success(data); - } - if (queryDto.getStart() == null) { - queryDto.setStart(new Date()); - } - if (queryDto.getEnd() == null) { - queryDto.setEnd(new Date()); - } - Map<String, Object> params = new HashMap<>(1); - params.put("pointNos", queryDto.getPointNos()); - List<DaPointDTO> pointList = daPointService.list(params); - if (CollectionUtils.isEmpty(pointList)) { - return success(data); - } - List<InfluxPointValuePOJO> influxParams = pointList.stream().map(item -> { - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(item.getPointNo()); - pojo.setType(item.getDataType()); - return pojo; - }).collect(Collectors.toList()); - data = influxDBService.queryPointsValues(influxParams, queryDto.getStart(), queryDto.getEnd()); - return success(data); - - } catch (Exception ex) { - return new CommonResult<Map<String, List<Map<String, Object>>>>().setMsg(ex.getMessage()); - } - } - - @PostMapping("/point/current") - @Operation(summary = "point当前实时数据") - public CommonResult<Map<String, Object>> pointCurrent(HttpServletResponse response, HttpServletRequest - request, @RequestBody List<String> pointNos) { - try { - // apiSecurityUtils.validate(request); - Map<String, Object> data = pointCollector.getCurrentValue(pointNos); - return success(data); - } catch (Exception ex) { - return new CommonResult<Map<String, Object>>().setMsg(ex.getMessage()); - } - } - - @PostMapping("/point/chart") - public CommonResult<BarLineDTO> pointChart(@RequestBody IndexQueryDTO dto) { - BarLineDTO CommonResult = new BarLineDTO(); - try { - List<String> legend = new ArrayList<>(); - List<SeriesItem> series = new ArrayList<>(); - String endDateStr = dto.getEndDate() == null ? DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") : DateUtils.format(dto.getEndDate(), "yyyy-MM-dd HH:mm:ss"); - Date endDate = DateUtils.parse(endDateStr, "yyyy-MM-dd HH:mm"); - Date startDate = dto.getStartDate() == null ? DateUtils.addDateHours(endDate, -2) : dto.getStartDate(); - List<String> categories = DateUtils.getTimeScale(startDate, endDate, dto.getGranularity() == null ? 10 : dto.getGranularity()); - if (CollectionUtils.isEmpty(dto.getCodes())) { - return new CommonResult<BarLineDTO>().setData(CommonResult); - } - List<DaPointDTO> pointList = new ArrayList<>(); - dto.getCodes().forEach(item -> { - pointList.add(daPointService.getByNo(item)); - }); - pointList.forEach(item -> { - legend.add(item.getPointName()); - SeriesItem seriesItem = new SeriesItem(); - seriesItem.setName(item.getPointName()); - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(item.getPointNo()); - pojo.setType(item.getDataType()); - List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startDate, endDate); - List<Object[]> sData = list.stream().map(dataItem -> { - Object[] valueArray = new Object[]{dataItem.get("time"), - getFormatValue(item.getDataType(), dataItem.get("value"))}; - return valueArray; - }).collect(Collectors.toList()); - seriesItem.setData(sData); - series.add(seriesItem); - }); - CommonResult.setLegend(legend); - CommonResult.setCategories(categories); - CommonResult.setSeries(series); - } catch (Exception ex) { - ex.printStackTrace(); - } - return new CommonResult<BarLineDTO>().setData(CommonResult); - } - - private Object getFormatValue(String dataType, Object value) { - if (!PointDataTypeEnum.BOOLEAN.getCode().equals(dataType)) { - BigDecimal decValue = new BigDecimal(value.toString()); - if (PointDataTypeEnum.FLOAT.getCode().equals(dataType)) { - return decValue.setScale(2, BigDecimal.ROUND_HALF_UP); - } else if (PointDataTypeEnum.INT.getCode().equals(dataType)) { - decValue = decValue.setScale(0, BigDecimal.ROUND_HALF_UP); - } - } - return value; - } - - - @PostMapping("/pointRelation/history") - @Operation(summary = "pointRelation历史数据") - public CommonResult<Map<String, List<Map<String, Object>>>> pointRelationHistory(HttpServletResponse response, HttpServletRequest - request, @RequestBody ApiPointValueQueryDTO queryDto) { - try { - Map<String, List<Map<String, Object>>> data = new HashMap<>(); - if (CollectionUtils.isEmpty(queryDto.getPointNos())) { - return success(data); - } - if (queryDto.getStart() == null) { - queryDto.setStart(new Date()); - } - if (queryDto.getEnd() == null) { - queryDto.setEnd(new Date()); - } - data = daPointValueService.getHistoryList(queryDto); - if (CollectionUtils.isEmpty(data)) { - return success(data); - } - return success(data); - } catch (Exception ex) { - return new CommonResult<Map<String, List<Map<String, Object>>>>().setMsg(ex.getMessage()); - } - } - - @GetMapping("/device-value") - public List<DeviceValueDTO> getDeviceValue(@RequestParam Map<String, Object> params) { - List<DeviceValueDTO> CommonResult = new ArrayList<>(); - if (params.get("pointNos") == null) { - return CommonResult; - } - List<String> pointNos = Arrays.asList(params.get("pointNos").toString().split(",")); - Map<String, Object> data = pointCollector.getCurrentValue(pointNos); - if (!CollectionUtils.isEmpty(data)) { - data.forEach((k, v) -> { - DeviceValueDTO dto = new DeviceValueDTO(); - dto.setDataId(k); - dto.setValue(new BigDecimal(v.toString())); - CommonResult.add(dto); - }); - } - return CommonResult; - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java new file mode 100644 index 0000000..a1c2d64 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java @@ -0,0 +1,178 @@ +package com.iailab.module.data.api.controller.admin; + +import com.iailab.framework.common.pojo.CommonResult; +import com.iailab.framework.common.util.date.DateUtils; +import com.iailab.module.data.api.dto.IndexQueryDTO; +import com.iailab.module.data.api.dto.echarts.BarLineDTO; +import com.iailab.module.data.api.dto.echarts.SeriesItem; +import com.iailab.module.data.api.point.DataPointApi; +import com.iailab.module.data.api.point.dto.ApiPointValueDTO; +import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; +import com.iailab.module.data.api.point.dto.ApiPointsValueQueryDTO; +import com.iailab.module.data.point.common.PointDataTypeEnum; +import com.iailab.module.data.point.dto.DaPointDTO; +import com.iailab.module.data.point.service.DaPointService; +import com.iailab.module.data.api.dto.DeviceValueDTO; +import com.iailab.module.data.api.utils.ApiSecurityUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.security.PermitAll; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +import static com.iailab.framework.common.pojo.CommonResult.success; + +/** + * @author PanZhibao + * @Description + * @createTime 2023年05月02日 10:58:00 + */ +@Slf4j +@RestController +@RequestMapping("/data/api") +@Tag(name = "数据") +public class ApiDataController { + + @Resource + private DaPointService daPointService; + + @Resource + private ApiSecurityUtils apiSecurityUtils; + + @Autowired + private DataPointApi dataPointApi; + + @PermitAll + @PostMapping("/query-points/history-value") + @Operation(summary = "查询多个测点历史值") + public CommonResult<Map<String, List<Map<String, Object>>>> queryPointsRealValue(HttpServletResponse response, HttpServletRequest + request, @RequestBody ApiPointsValueQueryDTO queryDto) { + Map<String, List<Map<String, Object>>> data = new HashMap<>(); + try { + apiSecurityUtils.validate(request); + data = dataPointApi.queryPointsHistoryValue(queryDto); + return success(data); + + } catch (Exception ex) { + return new CommonResult<Map<String, List<Map<String, Object>>>>().setMsg(ex.getMessage()); + } + } + + @PermitAll + @PostMapping("/query-point/history-value") + @Operation(summary = "查询单个测点历史值") + public CommonResult<List<ApiPointValueDTO>> queryPointHistoryValue(HttpServletResponse response, HttpServletRequest + request, @RequestBody ApiPointValueQueryDTO queryDto) { + List<ApiPointValueDTO> pointValueList = new ArrayList<>(); + try { + apiSecurityUtils.validate(request); + pointValueList = dataPointApi.queryPointHistoryValue(queryDto); + return success(pointValueList); + + } catch (Exception ex) { + return new CommonResult<List<ApiPointValueDTO>>().setMsg(ex.getMessage()); + } + } + + @PostMapping("/query-points/real-value") + @Operation(summary = "查询多个测点当前值") + public CommonResult<Map<String, Object>> queryPointsRealValue(HttpServletResponse response, HttpServletRequest + request, @RequestBody List<String> pointNos) { + Map<String, Object> data = new HashMap<>(); + try { + apiSecurityUtils.validate(request); + data = dataPointApi.queryPointsRealValue(pointNos); + return success(data); + } catch (Exception ex) { + return new CommonResult<Map<String, Object>>().setMsg(ex.getMessage()); + } + } + + @PostMapping("/query-points/chart") + public CommonResult<BarLineDTO> queryPointsChart(HttpServletResponse response, HttpServletRequest + request, @RequestBody IndexQueryDTO dto) { + BarLineDTO CommonResult = new BarLineDTO(); + try { + apiSecurityUtils.validate(request); + List<String> legend = new ArrayList<>(); + List<SeriesItem> series = new ArrayList<>(); + String endDateStr = dto.getEndDate() == null ? DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") : DateUtils.format(dto.getEndDate(), "yyyy-MM-dd HH:mm:ss"); + Date endDate = DateUtils.parse(endDateStr, "yyyy-MM-dd HH:mm"); + Date startDate = dto.getStartDate() == null ? DateUtils.addDateHours(endDate, -2) : dto.getStartDate(); + List<String> categories = DateUtils.getTimeScale(startDate, endDate, dto.getGranularity() == null ? 60 : dto.getGranularity()); + if (CollectionUtils.isEmpty(dto.getCodes())) { + return new CommonResult<BarLineDTO>().setData(CommonResult); + } + List<DaPointDTO> pointList = new ArrayList<>(); + dto.getCodes().forEach(item -> { + pointList.add(daPointService.getByNo(item)); + }); + pointList.forEach(item -> { + legend.add(item.getPointName()); + SeriesItem seriesItem = new SeriesItem(); + seriesItem.setName(item.getPointName()); + ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); + queryDto.setStart(startDate); + queryDto.setEnd(endDate); + queryDto.setPointNo(item.getPointNo()); + List<ApiPointValueDTO> list = dataPointApi.queryPointHistoryValue(queryDto); + List<Object[]> sData = list.stream().map(dataItem -> { + Object[] valueArray = new Object[]{DateUtils.format(dataItem.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), + getFormatValue(item.getDataType(), dataItem.getDataValue())}; + return valueArray; + }).collect(Collectors.toList()); + seriesItem.setData(sData); + series.add(seriesItem); + }); + CommonResult.setLegend(legend); + CommonResult.setCategories(categories); + CommonResult.setSeries(series); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new CommonResult<BarLineDTO>().setData(CommonResult); + } + + private Object getFormatValue(String dataType, Object value) { + if (!PointDataTypeEnum.BOOLEAN.getCode().equals(dataType)) { + BigDecimal decValue = new BigDecimal(value.toString()); + if (PointDataTypeEnum.FLOAT.getCode().equals(dataType)) { + return decValue.setScale(2, BigDecimal.ROUND_HALF_UP); + } else if (PointDataTypeEnum.INT.getCode().equals(dataType)) { + decValue = decValue.setScale(0, BigDecimal.ROUND_HALF_UP); + } + } + return value; + } + + + @GetMapping("/device-value") + public List<DeviceValueDTO> getDeviceValue(@RequestParam Map<String, Object> params) { + List<DeviceValueDTO> CommonResult = new ArrayList<>(); + if (params.get("pointNos") == null) { + return CommonResult; + } + List<String> pointNos = Arrays.asList(params.get("pointNos").toString().split(",")); + Map<String, Object> data = dataPointApi.queryPointsRealValue(pointNos); + if (!CollectionUtils.isEmpty(data)) { + data.forEach((k, v) -> { + DeviceValueDTO dto = new DeviceValueDTO(); + dto.setDataId(k); + dto.setValue(new BigDecimal(v.toString())); + CommonResult.add(dto); + }); + } + return CommonResult; + } +} 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/api/dto/IndexQueryDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java index 3014e37..ede287d 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java @@ -1,5 +1,6 @@ package com.iailab.module.data.api.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.util.Date; @@ -7,9 +8,11 @@ @Data public class IndexQueryDTO { - + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startDate; - + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endDate; private String code; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java index c62c369..64cc9a6 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java @@ -1,9 +1,11 @@ package com.iailab.module.data.api.point; +import com.iailab.framework.common.util.date.DateUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.data.api.point.dto.*; import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; import com.iailab.module.data.influxdb.service.InfluxDBService; +import com.iailab.module.data.influxdb.service.impl.InfluxDBServiceImpl; import com.iailab.module.data.point.collection.PointCollector; import com.iailab.module.data.point.dto.DaPointDTO; import com.iailab.module.data.point.dto.DaPointWriteValueDTO; @@ -86,8 +88,8 @@ List<ApiPointValueDTO> pointValueList = new ArrayList<>(); for (int i = 0; list.size() - i >= 1; i++) { ApiPointValueDTO pointValue = new ApiPointValueDTO(); - pointValue.setDataValue(Double.parseDouble(list.get(i).get("value").toString())); - pointValue.setDataTime((Date) (list.get(i).get("time"))); + pointValue.setDataValue(Double.parseDouble(list.get(i).get(InfluxDBServiceImpl.VALUE).toString())); + pointValue.setDataTime(DateUtils.parse(list.get(i).get(InfluxDBServiceImpl.TIME).toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); pointValueList.add(pointValue); } return pointValueList; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java index 774c1e4..016cb99 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java @@ -5,10 +5,13 @@ import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.security.core.LoginUser; import com.iailab.framework.security.core.util.SecurityFrameworkUtils; +import com.iailab.framework.tenant.core.context.TenantContextHolder; import com.iailab.module.system.api.user.AdminUserApi; import com.iailab.module.system.api.user.dto.AdminUserRespDTO; import org.apache.commons.lang3.StringUtils; + import javax.annotation.Resource; + import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; @@ -43,9 +46,18 @@ return token; } + private void setTenantId(HttpServletRequest httpRequest) { + String tenantId = httpRequest.getHeader(Constant.HEAD_TENANT_ID); + + if (StringUtils.isBlank(tenantId)) { + TenantContextHolder.setTenantId(Long.parseLong(tenantId)); + } + } + public void validate(HttpServletRequest httpRequest) throws Exception { - String token = getRequestToken(httpRequest); + setTenantId(httpRequest); + /*String token = getRequestToken(httpRequest); if (StringUtils.isBlank(token)) { throw new Exception("token 不能为空!"); } @@ -58,7 +70,7 @@ throw new RuntimeException("用户不存在"); } AdminUserRespDTO userData = user.getData(); - String username = userData.getUsername(); + String username = userData.getUsername();*/ /*ApiAppEntity appInfo = apiAppService.getInfoByAppKey(username); if (appInfo == null) { throw new RuntimeException("应用未授权"); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java similarity index 76% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java index 51c6bae..8b1ad12 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java @@ -1,6 +1,5 @@ package com.iailab.module.data.channel.http.collector.ihdb; -import cn.hutool.core.util.ArrayUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -9,7 +8,7 @@ import com.iailab.module.data.channel.http.service.HttpApiService; import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.common.utils.DateUtils; -import com.iailab.module.data.common.utils.HttpsRequest; +import com.iailab.module.data.common.utils.HttpRequest; import com.iailab.module.data.common.utils.TagUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -17,30 +16,26 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; -import java.sql.Array; import java.util.*; /** * iHyperDB采集 + * * @author lirm * @Description * @createTime 2024年10月16日 */ @Slf4j @Component -public class HttpCollectorForSS { +public class HttpCollectorForIhd { private Map<String, HttpApiEntity> apiMap = new HashMap<>(); @Autowired private HttpApiService httpApiService; - @Autowired - HttpsRequest httpsRequest; + private static final String STA_TRUE = "true"; - private final String STA_TRUE = "true"; - - private final int GROUP_MAX_COUNT = 50; - + private static final int GROUP_MAX_COUNT = 50; private HttpApiEntity getHttpApi(String id) { if (apiMap.containsKey(id)) { @@ -60,12 +55,12 @@ queryParams.put("datatype", valueType); queryParams.put("dimension", dimension); queryParams.put("tagname", tagNo); - String jsonString = JSON.toJSONString(queryParams); + String jsonString = JSON.toJSONString(queryParams); tagSb.append(jsonString); tagSb.append("]"); log.info("body=====" + tagSb.toString()); - String currentDate = DateUtils.format(new Date(),"yyyyMMddHHmmss"); - String responseStr = httpsRequest.doPost(httpApi.getUrl(), tagSb.toString(), currentDate, "utf-8"); + String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); + String responseStr = HttpRequest.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); JSONObject responseObj = JSON.parseObject(responseStr); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { JSONArray tagValueList = responseObj.getJSONArray("data"); @@ -86,7 +81,7 @@ Map<Integer, List<Object[]>> measurePointsCountGroup = new HashMap<>(); int pointListSize = params.size(); - int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); + int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); log.info("groupCount=" + groupCount); for (int i = 0; i < groupCount; i++) { int end = (i + 1) * GROUP_MAX_COUNT; @@ -96,7 +91,7 @@ measurePointsCountGroup.put(i, params.subList(i * GROUP_MAX_COUNT, end)); } Map<String, Object> result = new HashMap<>(params.size()); - for(Map.Entry<Integer, List<Object[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { + for (Map.Entry<Integer, List<Object[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { try { getByHtp(result, measurePointsItem.getValue()); } catch (Exception ex) { @@ -110,12 +105,12 @@ HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0].toString()); StringBuilder tagSb = new StringBuilder(); tagSb.append("["); - for (int i = 0; i < params.size(); i ++) { + for (int i = 0; i < params.size(); i++) { Map<String, Object> queryParams = new HashMap<>(); queryParams.put("tagname", params.get(i)[1]); queryParams.put("dimension", params.get(i)[2]); queryParams.put("datatype", params.get(i)[3]); - String jsonString = JSON.toJSONString(queryParams); + String jsonString = JSON.toJSONString(queryParams); tagSb.append(jsonString); if (i < params.size() - 1) { tagSb.append(","); @@ -123,8 +118,8 @@ } tagSb.append("]"); log.info("body=====" + tagSb.toString()); - String currentDate = DateUtils.format(new Date(),"yyyyMMddHHmmss"); - String responseStr = httpsRequest.doPost(httpApi.getUrl(), tagSb.toString(),currentDate, "utf-8"); + String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); + String responseStr = HttpRequest.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); JSONObject responseObj = JSON.parseObject(responseStr); log.info("responseObj=====" + responseObj.toJSONString()); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { @@ -136,16 +131,5 @@ } } } - - } - - public static void main(String[] args) { - Map<String, Object> queryParams = new HashMap<>(); - queryParams.put("tagname", "11"); - queryParams.put("dimension", 1); - queryParams.put("datatype", "22"); - String jsonString = JSONObject.toJSONString(queryParams); - System.out.println(jsonString); - System.out.println("[" + jsonString + "]"); } } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/tag/controller/admin/TagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/tag/controller/admin/TagController.java index bda6560..cad7f29 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/tag/controller/admin/TagController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/tag/controller/admin/TagController.java @@ -157,7 +157,7 @@ List<TagOptionDTO> op2 = new ArrayList<>(); tags.forEach(item1 -> { TagOptionDTO op3 = new TagOptionDTO(); - op3.setValue(item1.getTagDesc()); + op3.setValue(item1.getTagName()); op3.setLabel(item1.getTagName()); op2.add(op3); }); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java index 55b95f5..45047bb 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java @@ -14,5 +14,5 @@ BigDecimal ZERO_VALUE = new BigDecimal("0"); - String HTTP_API_SHASTEEL_IH = "SHASTEEL_IH"; + String iHyperDB = "iHyperDB"; } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/MeasureValueType.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/MeasureValueType.java new file mode 100644 index 0000000..64f29b5 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/MeasureValueType.java @@ -0,0 +1,36 @@ +package com.iailab.module.data.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 测量值类型 + * + * @author PanZhibao + * @Description + * @createTime 2024年10月28日 + */ +@Getter +@AllArgsConstructor +public enum MeasureValueType { + + SIMULATE("SIMULATE", "模拟量"), + + DIGITAL("DIGITAL", "数字量"); + + private String code; + private String desc; + + public static MeasureValueType getEumByCode(String code) { + if (code == null) { + return null; + } + + for (MeasureValueType statusEnum : MeasureValueType.values()) { + if (statusEnum.getCode().equals(code)) { + return statusEnum; + } + } + return null; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java index 3588186..c0f580d 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java @@ -142,6 +142,7 @@ // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 + conn.setRequestProperty("content-type", "application/json"); conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java index b427907..69ef90b 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java @@ -19,8 +19,8 @@ @Value("${influx-db.org}") public String org; - @Value("${influx-db.bucket}") - public String bucket; + /*@Value("${influx-db.bucket}") + public String bucket;*/ @Value("${influx-db.token}") public String token; @@ -28,7 +28,7 @@ @Value("${influx-db.url}") public String url; - private final static String BUCKET_NAME = "tenant_"; + private final static String BUCKET_NAME = "bucket_"; private Logger logger = LoggerFactory.getLogger(getClass()); 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 17514d0..9a96695 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操作类 @@ -43,19 +53,27 @@ private WriteApi writeApi; + @Autowired + private DaPointService daPointService; + private WriteApiBlocking writeApiBlocking; private QueryApi queryApi; private InfluxQLQueryApi influxQLQueryApi; - private String VALUE = "value"; + public static final String VALUE = "value"; - private String TIME = "time"; + public static final String TIME = "time"; 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) { @@ -100,7 +118,8 @@ } if (!CollectionUtils.isEmpty(pointValues)) { pointValues.forEach(item -> { - writeApi.writeMeasurement(influxDBInstance.bucket, influxDBInstance.org, WritePrecision.MS, item); + String bucket = influxDBInstance.getBucket(); + writeApi.writeMeasurement(bucket, influxDBInstance.org, WritePrecision.MS, item); }); } writeApi.flush(); @@ -113,6 +132,7 @@ } if (!CollectionUtils.isEmpty(tagValues)) { tagValues.forEach(item -> { + log.info("bucket==="+ influxDBInstance.getBucket() + ",org===" + influxDBInstance.org); writeApi.writeMeasurement(influxDBInstance.getBucket(), influxDBInstance.org, WritePrecision.MS, item); }); } @@ -201,21 +221,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) { @@ -306,7 +384,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/job/task/PointCollectTaskNet60.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java index 26eed3f..9770ce1 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java @@ -3,7 +3,9 @@ import com.iailab.module.data.point.collection.PointCollector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import javax.annotation.Resource; + import org.springframework.stereotype.Component; import java.time.LocalDateTime; @@ -19,15 +21,15 @@ */ @Component("pointCollectTaskNet60") public class PointCollectTaskNet60 implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); + private final Logger logger = LoggerFactory.getLogger(getClass()); - private final String NET = "NET60"; + private static final String NET = "1min"; @Resource private PointCollector pointCollector; @Override - public void run(String params){ + public void run(String params) { // 0 0/1 * * * ? logger.debug("CollectTaskNet60定时任务正在执行,参数为:{}", params); try { diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java index dc4c0be..203492c 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java @@ -66,22 +66,18 @@ Map<String, Object> dataMap = new HashMap<>(); List<InfluxPointValuePOJO> pointValues = new ArrayList<>(); - // 读取常量点 log.info("读取常量点"); List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(minfreq); pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap)); - // 读取测量点 log.info("读取测量点"); List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq); pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap)); - // 读取计算点 log.info("读取计算点"); List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq); pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap)); - // 存入数据库 log.info("存入数据库"); influxDBService.asyncWritePointValues(pointValues); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java index 5fe035d..c45c633 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java @@ -39,7 +39,7 @@ @Resource private JavaScriptHandler javaScriptHandler; - public static final String regex = "[+\\-\\*\\/\\(\\)\\&\\|\\>\\<]"; + public static final String regex = "[+\\-\\*/()\\&\\|\\>\\<]"; public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) { List<InfluxPointValuePOJO> result = new ArrayList<>(); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java index cd4f668..41299ec 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java @@ -1,6 +1,6 @@ package com.iailab.module.data.point.collection.handler; -import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForSS; +import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; import com.iailab.module.data.channel.opcda.collector.OpcDACollector; import com.iailab.module.data.common.enums.CommonConstant; import com.iailab.module.data.common.enums.DataSourceType; @@ -52,7 +52,7 @@ private OpcDACollector opcDACollector; @Autowired - private HttpCollectorForSS httpCollectorForSS; + private HttpCollectorForIhd httpCollectorForIhd; @Resource private DaPointService daPointService; @@ -68,7 +68,7 @@ List<String[]> opcDaTagIds = new ArrayList<>(); List<String[]> modbusTagIds = new ArrayList<>(); List<String[]> kioTagIds = new ArrayList<>(); - List<Object[]> httpTagSS = new ArrayList<>(); + List<Object[]> httpTagIhd = new ArrayList<>(); dtos.stream().forEach(item -> { @@ -81,8 +81,8 @@ } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { kioTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { - if (CommonConstant.HTTP_API_SHASTEEL_IH.equals(item.getSourceName())) { - httpTagSS.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); + if (CommonConstant.iHyperDB.equals(item.getSourceName())) { + httpTagIhd.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); } } }); @@ -100,8 +100,8 @@ if (!CollectionUtils.isEmpty(kioTagIds)) { tagValues.putAll(kingIOCollector.getTagValues(kioTagIds)); } - if (!CollectionUtils.isEmpty(httpTagSS)) { - tagValues.putAll(httpCollectorForSS.getTagValues(httpTagSS)); + if (!CollectionUtils.isEmpty(httpTagIhd)) { + tagValues.putAll(httpCollectorForIhd.getTagValues(httpTagIhd)); } this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); log.info("测量点处理结束"); @@ -178,7 +178,7 @@ } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { - value = httpCollectorForSS.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()); + value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()); } else { log.info("没有匹配的TagNo=" + item.getTagNo()); } 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-data/iailab-module-data-biz/src/main/resources/application-dev.yml b/iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yaml similarity index 93% rename from iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yml rename to iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yaml index f528d97..52e059a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yml +++ b/iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yaml @@ -44,15 +44,15 @@ # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 127.0.0.1 # 地址 + host: 172.16.8.100 # 地址 port: 6379 # 端口 database: 0 # 数据库索引 password: 123456 # 密码,建议生产环境开启 influx-db: org: iailab - bucket: iailab_data - token: 2_wr57sVbZQx2QHhN3wWNGOCOtPan_NdCu06NsCGcB8G7rjhjK3yHcLf3uTXE9xkjHHSQwo37E1Mxa0367qXgg== + bucket: buk_shasteel + token: Q2qsriQG3FEfZ35lik1KSkFToma3bsgfQLwJrNQfSK06MC569sZ9mrQ0vLtsVYn70HMfQcC9gf_yUG16JQtm8w== url: http://172.16.8.200:8086 username: root password: iailab12345678 diff --git a/iailab-module-system/iailab-module-system-biz/src/main/resources/application-dev.yaml b/iailab-module-system/iailab-module-system-biz/src/main/resources/application-dev.yaml index 8ae216b..969d720 100644 --- a/iailab-module-system/iailab-module-system-biz/src/main/resources/application-dev.yaml +++ b/iailab-module-system/iailab-module-system-biz/src/main/resources/application-dev.yaml @@ -146,6 +146,8 @@ - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求 - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 demo: false # 开启演示模式 + captcha: + enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试 justauth: enabled: true -- Gitblit v1.9.3