提交 | 用户 | 时间
|
60201e
|
1 |
package com.iailab.module.data.api.point; |
潘 |
2 |
|
48c064
|
3 |
import com.iailab.framework.common.pojo.PageResult; |
a2aa90
|
4 |
import com.iailab.framework.common.util.date.DateUtils; |
b8b8cb
|
5 |
import com.iailab.framework.common.util.object.ConvertUtils; |
60201e
|
6 |
import com.iailab.module.data.api.point.dto.*; |
b8b8cb
|
7 |
import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; |
潘 |
8 |
import com.iailab.module.data.influxdb.service.InfluxDBService; |
a2aa90
|
9 |
import com.iailab.module.data.influxdb.service.impl.InfluxDBServiceImpl; |
b8b8cb
|
10 |
import com.iailab.module.data.point.collection.PointCollector; |
48c064
|
11 |
import com.iailab.module.data.point.dto.DaMathPointDTO; |
b8b8cb
|
12 |
import com.iailab.module.data.point.dto.DaPointDTO; |
潘 |
13 |
import com.iailab.module.data.point.dto.DaPointWriteValueDTO; |
48c064
|
14 |
import com.iailab.module.data.point.service.DaMathPointService; |
1c3121
|
15 |
import com.iailab.module.data.point.service.DaPointService; |
潘 |
16 |
import org.springframework.beans.factory.annotation.Autowired; |
b8b8cb
|
17 |
import org.springframework.util.CollectionUtils; |
60201e
|
18 |
import org.springframework.validation.annotation.Validated; |
潘 |
19 |
import org.springframework.web.bind.annotation.RestController; |
|
20 |
|
b8b8cb
|
21 |
import java.util.*; |
潘 |
22 |
import java.util.stream.Collectors; |
48c064
|
23 |
import java.util.stream.IntStream; |
60201e
|
24 |
|
潘 |
25 |
/** |
|
26 |
* @author PanZhibao |
|
27 |
* @Description |
|
28 |
* @createTime 2024年09月02日 |
|
29 |
*/ |
|
30 |
@RestController // 提供 RESTful API 接口,给 Feign 调用 |
|
31 |
@Validated |
|
32 |
public class DataPointApiImpl implements DataPointApi { |
|
33 |
|
1c3121
|
34 |
@Autowired |
潘 |
35 |
private DaPointService daPointService; |
|
36 |
|
b8b8cb
|
37 |
@Autowired |
潘 |
38 |
private PointCollector pointCollector; |
|
39 |
|
|
40 |
@Autowired |
|
41 |
private InfluxDBService influxDBService; |
48c064
|
42 |
|
L |
43 |
@Autowired |
|
44 |
private DaMathPointService daMathPointService; |
60201e
|
45 |
|
潘 |
46 |
@Override |
73ed35
|
47 |
public ApiPointDTO getInfoById(String pointId) { |
07890e
|
48 |
return daPointService.getSimpleInfoById(pointId); |
D |
49 |
} |
|
50 |
|
|
51 |
@Override |
50084d
|
52 |
public List<ApiPointDTO> getInfoByIds(Set<String> pointIds) { |
07890e
|
53 |
List<ApiPointDTO> result = new ArrayList<>(pointIds.size()); |
D |
54 |
for (String pointId : pointIds) { |
|
55 |
result.add(daPointService.getSimpleInfoById(pointId)); |
|
56 |
} |
|
57 |
return result; |
b8b8cb
|
58 |
} |
潘 |
59 |
|
|
60 |
@Override |
|
61 |
public ApiPointDTO getInfoByNo(String pointNo) { |
|
62 |
return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoByNo(pointNo), ApiPointDTO.class); |
60201e
|
63 |
} |
潘 |
64 |
|
|
65 |
@Override |
73ed35
|
66 |
public Map<String, Object> queryPointsRealValue(List<String> pointNos) { |
b8b8cb
|
67 |
return pointCollector.getCurrentValue(pointNos); |
60201e
|
68 |
} |
潘 |
69 |
|
|
70 |
@Override |
73ed35
|
71 |
public Map<String, List<Map<String, Object>>> queryPointsHistoryValue(ApiPointsValueQueryDTO queryDto) { |
b8b8cb
|
72 |
Map<String, List<Map<String, Object>>> data = new HashMap<>(); |
34ba73
|
73 |
Calendar calendar = Calendar.getInstance(); |
潘 |
74 |
calendar.set(Calendar.MILLISECOND, 0); |
b8b8cb
|
75 |
if (queryDto.getEnd() == null) { |
34ba73
|
76 |
queryDto.setEnd(calendar.getTime()); |
b8b8cb
|
77 |
} |
34ba73
|
78 |
if (queryDto.getStart() == null) { |
潘 |
79 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
80 |
queryDto.setStart(calendar.getTime()); |
|
81 |
} |
|
82 |
|
b8b8cb
|
83 |
Map<String, Object> params = new HashMap<>(1); |
潘 |
84 |
params.put("pointNos", queryDto.getPointNos()); |
|
85 |
List<DaPointDTO> pointList = daPointService.list(params); |
|
86 |
if (CollectionUtils.isEmpty(pointList)) { |
|
87 |
return data; |
|
88 |
} |
|
89 |
List<InfluxPointValuePOJO> influxParams = pointList.stream().map(item -> { |
|
90 |
InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); |
|
91 |
pojo.setPoint(item.getPointNo()); |
|
92 |
pojo.setType(item.getDataType()); |
|
93 |
return pojo; |
|
94 |
}).collect(Collectors.toList()); |
|
95 |
data = influxDBService.queryPointsValues(influxParams, queryDto.getStart(), queryDto.getEnd()); |
|
96 |
return data; |
60201e
|
97 |
} |
潘 |
98 |
|
|
99 |
@Override |
73ed35
|
100 |
public List<ApiPointValueDTO> queryPointHistoryValue(ApiPointValueQueryDTO queryDto) { |
b8b8cb
|
101 |
DaPointDTO daPointDTO = daPointService.getByNo(queryDto.getPointNo()); |
潘 |
102 |
InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); |
|
103 |
pojo.setPoint(queryDto.getPointNo()); |
|
104 |
pojo.setType(daPointDTO.getDataType()); |
|
105 |
Date startTime = queryDto.getStart(); |
|
106 |
Date endTime = queryDto.getEnd(); |
34ba73
|
107 |
Calendar calendar = Calendar.getInstance(); |
潘 |
108 |
calendar.set(Calendar.MILLISECOND, 0); |
|
109 |
if (endTime == null) { |
|
110 |
endTime = calendar.getTime(); |
|
111 |
} |
|
112 |
if (startTime == null) { |
|
113 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
114 |
startTime = calendar.getTime(); |
|
115 |
} |
b8b8cb
|
116 |
List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startTime, endTime); |
潘 |
117 |
List<ApiPointValueDTO> pointValueList = new ArrayList<>(); |
|
118 |
for (int i = 0; list.size() - i >= 1; i++) { |
|
119 |
ApiPointValueDTO pointValue = new ApiPointValueDTO(); |
9df837
|
120 |
pointValue.setV(Double.parseDouble(list.get(i).get(InfluxDBServiceImpl.VALUE).toString())); |
潘 |
121 |
pointValue.setT(DateUtils.parse(list.get(i).get(InfluxDBServiceImpl.TIME).toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
b8b8cb
|
122 |
pointValueList.add(pointValue); |
潘 |
123 |
} |
|
124 |
return pointValueList; |
60201e
|
125 |
} |
潘 |
126 |
|
|
127 |
@Override |
b8b8cb
|
128 |
public Boolean writePointRealValue(ApiPointValueWriteDTO writeDTO) { |
潘 |
129 |
try { |
|
130 |
DaPointWriteValueDTO wr = new DaPointWriteValueDTO(); |
|
131 |
wr.setPointNo(writeDTO.getPointNo()); |
|
132 |
wr.setPointValue(writeDTO.getValue()); |
|
133 |
pointCollector.setValue(wr); |
|
134 |
return true; |
|
135 |
} catch (Exception ex) { |
2780e6
|
136 |
ex.printStackTrace(); |
b8b8cb
|
137 |
return false; |
潘 |
138 |
} |
60201e
|
139 |
} |
48c064
|
140 |
|
L |
141 |
@Override |
116db5
|
142 |
public PageResult<ApiPointDTO> getPageByNo(ApiPointPageReqVO reqVO) { |
L |
143 |
DaPointDTO daPointDTO = daPointService.getSimpleInfoByNo(reqVO.getPointNo()); |
48c064
|
144 |
DaMathPointDTO daMathPointDTO = daMathPointService.getByPoint(daPointDTO.getId()); |
L |
145 |
String[] pointNos = daMathPointDTO.getExpression().split("[-+]+"); |
|
146 |
HashMap<Integer, String> map = new HashMap<>(); |
|
147 |
IntStream.range(0, pointNos.length).forEach(i -> map.put(i, pointNos[i])); |
|
148 |
List<String> pointNosL = new ArrayList<>(); |
|
149 |
for (String value : map.values()) { |
|
150 |
pointNosL.add(value); |
|
151 |
} |
|
152 |
PageResult<ApiPointDTO> pageResult = daPointService.getPointPage(map); |
|
153 |
Map<String, Object> CurrentValueMap = pointCollector.getCurrentValue(pointNosL); |
|
154 |
pageResult.getList().stream().map(item -> { |
|
155 |
item.setCurrentValue(CurrentValueMap.get(item.getPointNo())); |
|
156 |
return item; |
|
157 |
}).collect(Collectors.toList()); |
|
158 |
return pageResult; |
|
159 |
} |
60201e
|
160 |
} |