提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.point.collection; |
H |
2 |
|
|
3 |
import com.iailab.module.data.common.enums.DataSourceType; |
|
4 |
import com.iailab.module.data.common.utils.R; |
|
5 |
import com.iailab.module.data.channel.kio.collector.KingIOCollector; |
|
6 |
import com.iailab.module.data.point.collection.handler.CalculateHandle; |
|
7 |
import com.iailab.module.data.point.common.PointTypeEnum; |
|
8 |
import com.iailab.module.data.point.dto.DaPointDTO; |
|
9 |
import com.iailab.module.data.point.service.DaPointService; |
|
10 |
import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; |
|
11 |
import com.iailab.module.data.channel.modbus.collector.ModBusCollector; |
|
12 |
import com.iailab.module.data.channel.opcua.collector.OpcUaCollector; |
|
13 |
import com.iailab.module.data.point.collection.handler.ConstantHandle; |
|
14 |
import com.iailab.module.data.point.collection.handler.MeasureHandle; |
|
15 |
import com.iailab.module.data.point.dto.DaPointWriteValueDTO; |
|
16 |
import com.iailab.module.data.influxdb.service.InfluxDBService; |
|
17 |
import lombok.extern.slf4j.Slf4j; |
|
18 |
import javax.annotation.Resource; |
|
19 |
import org.springframework.stereotype.Component; |
|
20 |
import org.springframework.util.CollectionUtils; |
|
21 |
|
|
22 |
import java.math.BigDecimal; |
|
23 |
import java.util.*; |
|
24 |
|
|
25 |
/** |
|
26 |
* @author PanZhibao |
|
27 |
* @Description |
|
28 |
* @createTime 2023年04月25日 16:16:00 |
|
29 |
*/ |
|
30 |
@Slf4j |
|
31 |
@Component |
|
32 |
public class PointCollector { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private DaPointService daPointService; |
|
36 |
|
|
37 |
@Resource |
|
38 |
private ConstantHandle constantHandle; |
|
39 |
|
|
40 |
@Resource |
|
41 |
private MeasureHandle measureHandle; |
|
42 |
|
|
43 |
@Resource |
|
44 |
private CalculateHandle calculateHandle; |
|
45 |
|
|
46 |
@Resource |
|
47 |
private KingIOCollector kingIOCollector; |
|
48 |
|
|
49 |
@Resource |
|
50 |
private InfluxDBService influxDBService; |
|
51 |
|
|
52 |
@Resource |
|
53 |
private ModBusCollector modBusCollector; |
|
54 |
|
|
55 |
@Resource |
|
56 |
private OpcUaCollector opcUaCollector; |
|
57 |
|
|
58 |
/** |
|
59 |
* 采集 |
|
60 |
* |
|
61 |
* @param collectTime |
|
62 |
* @param minfreq |
|
63 |
*/ |
|
64 |
public void collect(Date collectTime, String minfreq) { |
|
65 |
try { |
|
66 |
Map<String, Object> dataMap = new HashMap<>(); |
|
67 |
List<InfluxPointValuePOJO> pointValues = new ArrayList<>(); |
|
68 |
|
|
69 |
log.info("读取常量点"); |
|
70 |
List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(minfreq); |
|
71 |
pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap)); |
|
72 |
|
|
73 |
log.info("读取测量点"); |
|
74 |
List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq); |
|
75 |
pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap)); |
|
76 |
|
|
77 |
log.info("读取计算点"); |
|
78 |
List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq); |
|
79 |
pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap)); |
|
80 |
|
|
81 |
log.info("存入数据库"); |
|
82 |
influxDBService.asyncWritePointValues(pointValues); |
|
83 |
|
|
84 |
log.info("采集完成"); |
|
85 |
} catch (Exception ex) { |
|
86 |
log.info("采集异常!"); |
|
87 |
ex.printStackTrace(); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
public Map<String, Object> getCurrentValue(List<String> pointNos) { |
|
92 |
try { |
|
93 |
Map<String, Object> data = new HashMap<>(); |
|
94 |
if (CollectionUtils.isEmpty(pointNos)) { |
|
95 |
return data; |
|
96 |
} |
|
97 |
data.putAll(constantHandle.getCurrent(pointNos)); |
|
98 |
data.putAll(measureHandle.getCurrent(pointNos)); |
|
99 |
data.putAll(calculateHandle.getCurrent(pointNos)); |
|
100 |
return data; |
|
101 |
} catch (Exception ex) { |
|
102 |
return R.error(ex.getMessage()); |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
public void setValue(DaPointWriteValueDTO writeValue) throws Exception { |
|
108 |
DaPointDTO daPointDTO = daPointService.getByNo(writeValue.getPointNo()); |
|
109 |
if (daPointDTO == null) { |
|
110 |
throw new Exception("点位不存在"); |
|
111 |
} |
|
112 |
if (PointTypeEnum.CONSTANT.getCode().equals(daPointDTO.getPointType())) { |
|
113 |
daPointDTO.setDefaultValue(new BigDecimal(writeValue.getPointValue().toString())); |
|
114 |
daPointService.updateDefaultValue(daPointDTO); |
|
115 |
} else if (PointTypeEnum.MEASURE_POINT.getCode().equals(daPointDTO.getPointType())) { |
|
116 |
DaPointDTO mPoint = daPointService.getMeasurePointByNo(daPointDTO.getPointNo()); |
|
117 |
if (DataSourceType.OPCUA.getCode().equals(mPoint.getSourceType())) { |
|
118 |
opcUaCollector.setTagData(mPoint.getSourceId(), mPoint.getTagNo(), writeValue.getPointValue().toString(), mPoint.getDataType()); |
|
119 |
} else if (DataSourceType.ModBus.getCode().equals(mPoint.getSourceType())) { |
|
120 |
modBusCollector.setTagValue(mPoint.getSourceId(), mPoint.getTagNo(), writeValue.getPointValue().toString()); |
|
121 |
} else if (DataSourceType.KIO.getCode().equals(mPoint.getSourceType())) { |
|
122 |
kingIOCollector.setTagValue(mPoint.getSourceId(), mPoint.getTagNo(), writeValue.getPointValue().toString(), mPoint.getDataType()); |
|
123 |
} else { |
|
124 |
log.info("没有匹配的TagNo=" + mPoint.getTagNo()); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
} |
|
129 |
} |