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