houzhongjian
2024-10-30 a28ca3f36d0ace05966a8c0fac1e4b5fe921f882
Merge remote-tracking branch 'origin/master'
已修改24个文件
已删除1个文件
已重命名3个文件
已添加7个文件
1071 ■■■■ 文件已修改
iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/mapper/BaseMapperX.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/constant/Constant.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/ErrorCodeConstants.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiDataController.java 208 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java 178 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/ApiPointValueQueryDTO.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/tag/controller/admin/TagController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/MeasureValueType.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/InfluxDBService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java 98 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/dao/DaPointDao.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/DaPointExcelVO.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportExcelVO.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointImportRespVO.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/vo/PointValueExportVO.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yaml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-system/iailab-module-system-biz/src/main/resources/application-dev.yaml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
/**
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";
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;
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;
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, "测点配置已经存在");
}
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
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/ApiDataController.java
文件已删除
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;
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/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;
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;
}
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;
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;
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("应用未授权");
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.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 + "]");
    }
}
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);
                });
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";
}
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;
    }
}
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)");
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());
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);
}
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);
                }
            }
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 {
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);
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<>();
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());
                        }
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));
    }
}
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);
    };
}
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);
}
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;
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;
}
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;
}
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;
}
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;
}
iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yaml
文件名从 iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yml 修改
@@ -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
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