潘志宝
2024-10-04 b8b8cb26b0a13c8ca10ffa53cef2abbff4eb20de
DataPointApiImpl
已修改3个文件
96 ■■■■ 文件已修改
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java 79 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
@@ -1,13 +1,20 @@
package com.iailab.module.data.api.point;
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.point.collection.PointCollector;
import com.iailab.module.data.point.dto.DaPointDTO;
import com.iailab.module.data.point.dto.DaPointWriteValueDTO;
import com.iailab.module.data.point.service.DaPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @author PanZhibao
@@ -21,33 +28,81 @@
    @Autowired
    private DaPointService daPointService;
    @Override
    public ApiPointDTO getInfoByNo(String pointNo) {
        return null;
    }
    @Autowired
    private PointCollector pointCollector;
    @Autowired
    private InfluxDBService influxDBService;
    @Override
    public ApiPointDTO getInfoById(String pointId) {
        return null;
        return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoById(pointId), ApiPointDTO.class);
    }
    @Override
    public ApiPointDTO getInfoByNo(String pointNo) {
        return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoByNo(pointNo), ApiPointDTO.class);
    }
    @Override
    public Map<String, Object> queryPointsRealValue(List<String> pointNos) {
        return null;
        return pointCollector.getCurrentValue(pointNos);
    }
    @Override
    public Map<String, List<Map<String, Object>>> queryPointsHistoryValue(ApiPointsValueQueryDTO queryDto) {
        return null;
        Map<String, List<Map<String, Object>>> data = new HashMap<>();
        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 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 data;
    }
    @Override
    public List<ApiPointValueDTO> queryPointHistoryValue(ApiPointValueQueryDTO queryDto) {
        return null;
        DaPointDTO daPointDTO = daPointService.getByNo(queryDto.getPointNo());
        InfluxPointValuePOJO pojo = new InfluxPointValuePOJO();
        pojo.setPoint(queryDto.getPointNo());
        pojo.setType(daPointDTO.getDataType());
        Date startTime = queryDto.getStart();
        Date endTime = queryDto.getEnd();
        List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startTime, endTime);
        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")));
            pointValueList.add(pointValue);
        }
        return pointValueList;
    }
    @Override
    public Boolean writePointRealValue(ApiPointValueWriteDTO queryDto) {
        return null;
    public Boolean writePointRealValue(ApiPointValueWriteDTO writeDTO) {
        try {
            DaPointWriteValueDTO wr = new DaPointWriteValueDTO();
            wr.setPointNo(writeDTO.getPointNo());
            wr.setPointValue(writeDTO.getValue());
            pointCollector.setValue(wr);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java
@@ -18,12 +18,15 @@
    DaPointDTO info(String id);
    DaPointDTO getSimpleInfoById(String id);
    DaPointDTO getSimpleInfoByNo(String no);
    void add(DaPointDTO daPointDTO);
    void update(DaPointDTO daPointDTO);
    void delete(String[] id);
    List<DaPointDTO> list(Map<String, Object> params);
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
@@ -73,6 +73,18 @@
    }
    @Override
    public DaPointDTO getSimpleInfoById(String id) {
        return ConvertUtils.sourceToTarget(daPointDao.selectById(id), DaPointDTO.class);
    }
    @Override
    public DaPointDTO getSimpleInfoByNo(String no) {
        QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq("pointNo", no);
        return ConvertUtils.sourceToTarget(daPointDao.selectOne(queryWrapper), DaPointDTO.class);
    }
    @Override
    public List<DaPointDTO> list(Map<String, Object> params) {
        Object pointType = params.get("pointType");
        List<String> pointNos = new ArrayList<>();