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