houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.iailab.module.data.point.collection.handler;
 
import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils;
import com.iailab.module.data.point.dto.DaPointDTO;
import com.iailab.module.data.point.service.DaPointService;
import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
 
/**
 * 常量点处理
 *
 * @author PanZhibao
 * @Description
 * @createTime 2023年05月03日 22:28:00
 */
@Slf4j
@Component
public class ConstantHandle {
 
    @Resource
    private DaPointService daPointService;
 
    public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) {
        log.info("常量点处理开始");
        List<InfluxPointValuePOJO> result = new ArrayList<>();
        if (CollectionUtils.isEmpty(dtos)) {
            return result;
        }
        dtos.forEach(dto -> {
            InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto);
            pojo.setTimestamp(collectTime.toInstant());
            dataMap.put(dto.getPointNo(), dto.getDefaultValue());
            result.add(pojo);
        });
        log.info("常量点处理结束");
        return result;
    }
 
    public Map<String, Object> getCurrent(List<String> pointNos) {
        Map<String, Object> data = new HashMap<>();
 
        List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(pointNos);
        if (!CollectionUtils.isEmpty(pointConstantList)) {
            pointConstantList.forEach(item -> {
                data.put(item.getPointNo(), item.getDefaultValue());
            });
        }
        return data;
    }
 
}