提交 | 用户 | 时间
|
fd2207
|
1 |
package com.jcdm.main.da.passingStationCollection.service.impl; |
懒 |
2 |
|
c6e069
|
3 |
import cn.hutool.core.collection.CollUtil; |
59e228
|
4 |
import cn.hutool.core.util.ObjectUtil; |
059083
|
5 |
import com.alibaba.fastjson2.JSONObject; |
2c65c3
|
6 |
import com.jcdm.common.core.domain.R; |
fd2207
|
7 |
import com.jcdm.common.utils.DateUtils; |
c6e069
|
8 |
import com.jcdm.common.utils.StringUtils; |
9ebb88
|
9 |
import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling; |
W |
10 |
import com.jcdm.main.bs.orderScheduling.mapper.BsOrderSchedulingMapper; |
|
11 |
import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService; |
fd2207
|
12 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
2c65c3
|
13 |
import com.jcdm.main.da.passingStationCollection.domain.ProductNumVO; |
fd2207
|
14 |
import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper; |
懒 |
15 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
c6e069
|
16 |
import com.jcdm.main.da.passingStationCollection.vo.DaPassingStationVO; |
ff985a
|
17 |
import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord; |
懒 |
18 |
import com.jcdm.main.rm.repairRecord.mapper.RmRepairRecordMapper; |
059083
|
19 |
import com.jcdm.main.websocket.WebSocketServer; |
fd2207
|
20 |
import org.springframework.beans.factory.annotation.Autowired; |
懒 |
21 |
import org.springframework.stereotype.Service; |
059083
|
22 |
|
W |
23 |
import java.math.BigDecimal; |
|
24 |
import java.math.RoundingMode; |
|
25 |
import java.time.LocalDate; |
|
26 |
import java.time.LocalDateTime; |
|
27 |
import java.time.format.DateTimeFormatter; |
|
28 |
import java.util.*; |
|
29 |
import java.util.stream.Collectors; |
fd2207
|
30 |
|
懒 |
31 |
/** |
|
32 |
* 产品过站采集Service业务层处理 |
|
33 |
* |
|
34 |
* @author yyt |
|
35 |
* @date 2023-12-12 |
|
36 |
*/ |
|
37 |
@Service |
|
38 |
public class DaPassingStationCollectionServiceImpl implements IDaPassingStationCollectionService |
|
39 |
{ |
|
40 |
@Autowired |
|
41 |
private DaPassingStationCollectionMapper daPassingStationCollectionMapper; |
ff985a
|
42 |
|
懒 |
43 |
@Autowired |
|
44 |
private RmRepairRecordMapper rmRepairRecordMapper; |
9ebb88
|
45 |
|
W |
46 |
@Autowired |
|
47 |
private BsOrderSchedulingMapper bsOrderSchedulingMapper; |
|
48 |
|
|
49 |
@Autowired |
|
50 |
private IBsOrderSchedulingService bsOrderSchedulingService; |
fd2207
|
51 |
|
懒 |
52 |
/** |
|
53 |
* 查询产品过站采集 |
|
54 |
* |
|
55 |
* @param id 产品过站采集主键 |
|
56 |
* @return 产品过站采集 |
|
57 |
*/ |
|
58 |
@Override |
|
59 |
public DaPassingStationCollection selectDaPassingStationCollectionById(Long id) |
|
60 |
{ |
|
61 |
return daPassingStationCollectionMapper.selectDaPassingStationCollectionById(id); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* 查询产品过站采集列表 |
|
66 |
* |
|
67 |
* @param daPassingStationCollection 产品过站采集 |
|
68 |
* @return 产品过站采集 |
|
69 |
*/ |
|
70 |
@Override |
|
71 |
public List<DaPassingStationCollection> selectDaPassingStationCollectionList(DaPassingStationCollection daPassingStationCollection) |
|
72 |
{ |
|
73 |
return daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection); |
2c65c3
|
74 |
} |
W |
75 |
|
|
76 |
@Override |
|
77 |
public List<DaPassingStationCollection> selectDaPassingStationCollectionForSearch(DaPassingStationCollection daPassingStationCollection) { |
|
78 |
return daPassingStationCollectionMapper.selectDaPassingStationCollectionForSearch(daPassingStationCollection); |
fd2207
|
79 |
} |
懒 |
80 |
|
c6e069
|
81 |
@Override |
W |
82 |
public List<DaPassingStationVO> getTopProcess(DaPassingStationCollection daPassingStationCollection) |
|
83 |
{ |
|
84 |
|
|
85 |
List<DaPassingStationVO> result = new ArrayList<>(); |
020295
|
86 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
W |
87 |
|
|
88 |
LocalDateTime startTime = LocalDate.now().atStartOfDay(); |
|
89 |
LocalDateTime endTime = LocalDate.now().plusDays(1).atStartOfDay(); |
|
90 |
String s1 = startTime.format(formatter); |
|
91 |
String s2 = endTime.format(formatter); |
|
92 |
daPassingStationCollection.setStartTime(s1); |
|
93 |
daPassingStationCollection.setEndTime(s2); |
c6e069
|
94 |
List<DaPassingStationCollection> list = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection); |
W |
95 |
//筛除节拍为空的数据 |
|
96 |
list = list.stream().filter(x -> StringUtils.isNotEmpty(x.getBeatTime())).collect(Collectors.toList()); |
|
97 |
//做筛选操作 |
|
98 |
if (CollUtil.isNotEmpty(list)){ |
|
99 |
for (DaPassingStationCollection passingStationCollection : list) { |
|
100 |
if (StringUtils.isNotEmpty(passingStationCollection.getBeatTime())){ |
|
101 |
Long aLong = Long.valueOf(passingStationCollection.getBeatTime()); |
|
102 |
passingStationCollection.setBeatTimeLong(aLong); |
|
103 |
}else { |
|
104 |
passingStationCollection.setBeatTimeLong(0L); |
|
105 |
} |
|
106 |
} |
|
107 |
Map<String, Double> collect = list.stream().collect(Collectors.groupingBy(DaPassingStationCollection::getLocationCode, Collectors.averagingLong(DaPassingStationCollection::getBeatTimeLong))); |
|
108 |
//排序 |
|
109 |
List<Map.Entry<String,Double>> entryList = new ArrayList<>(collect.entrySet()); |
|
110 |
Collections.sort(entryList, new Comparator<Map.Entry<String, Double>>() { |
|
111 |
@Override |
|
112 |
public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) { |
|
113 |
double v = o2.getValue() - o1.getValue(); |
|
114 |
return (int) v; |
|
115 |
} |
|
116 |
}); |
|
117 |
LinkedHashMap<String, Double> linkedHashMap = new LinkedHashMap<String, Double>(); |
|
118 |
int i = 1; |
|
119 |
double sum = 0; |
|
120 |
for (Map.Entry<String,Double> e : entryList |
|
121 |
) { |
|
122 |
if (i<6){ |
|
123 |
sum = sum + e.getValue(); |
|
124 |
linkedHashMap.put(e.getKey(),e.getValue()); |
|
125 |
i++; |
|
126 |
} |
|
127 |
|
|
128 |
} |
|
129 |
//计算数据 |
|
130 |
if (CollUtil.isNotEmpty(linkedHashMap)){ |
|
131 |
for (String s : linkedHashMap.keySet()) { |
|
132 |
DaPassingStationVO vo = new DaPassingStationVO(); |
|
133 |
BigDecimal divide = BigDecimal.valueOf(linkedHashMap.get(s)).divide(BigDecimal.valueOf(sum),4, RoundingMode.HALF_UP); |
|
134 |
vo.setName(s); |
|
135 |
vo.setValue(divide); |
|
136 |
result.add(vo); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
// Map<String, List<DaPassingStationCollection>> collect = list.stream().collect(Collectors.groupingBy(DaPassingStationCollection::getLocationCode)); |
|
141 |
// for (String key:collect.keySet()){ |
|
142 |
// List<DaPassingStationCollection> list1 = collect.get(key); |
|
143 |
// if (CollUtil.isNotEmpty(list1)) { |
|
144 |
// Double collect1 = list1.stream().collect(Collectors.averagingLong(DaPassingStationCollection::getBeatTimeLong)); |
|
145 |
// } |
|
146 |
// } |
|
147 |
} |
|
148 |
return result; |
|
149 |
} |
|
150 |
|
fd2207
|
151 |
/** |
9ebb88
|
152 |
* 获取首页单日累计量产数据 |
W |
153 |
* @param fieldName bs |
|
154 |
* @return list |
|
155 |
*/ |
|
156 |
@Override |
|
157 |
public Integer getProduceNumToday(String fieldName) { |
|
158 |
|
|
159 |
BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
|
160 |
bsOrderScheduling.setQueryField(fieldName); |
|
161 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
162 |
LocalDateTime startTime = LocalDate.now().atStartOfDay(); |
|
163 |
LocalDateTime endTime = LocalDate.now().plusDays(1).atStartOfDay(); |
|
164 |
String s1 = startTime.format(formatter); |
|
165 |
String s2 = endTime.format(formatter); |
|
166 |
bsOrderScheduling.setStartTime(s1); |
|
167 |
bsOrderScheduling.setEndTime(s2); |
|
168 |
return bsOrderSchedulingMapper.getProduceNumToday(bsOrderScheduling); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
fd2207
|
172 |
* 新增产品过站采集 |
懒 |
173 |
* |
|
174 |
* @param daPassingStationCollection 产品过站采集 |
|
175 |
* @return 结果 |
|
176 |
*/ |
|
177 |
@Override |
|
178 |
public int insertDaPassingStationCollection(DaPassingStationCollection daPassingStationCollection) |
|
179 |
{ |
|
180 |
daPassingStationCollection.setCreateTime(DateUtils.getNowDate()); |
|
181 |
return daPassingStationCollectionMapper.insertDaPassingStationCollection(daPassingStationCollection); |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* 修改产品过站采集 |
|
186 |
* |
|
187 |
* @param daPassingStationCollection 产品过站采集 |
|
188 |
* @return 结果 |
|
189 |
*/ |
|
190 |
@Override |
|
191 |
public int updateDaPassingStationCollection(DaPassingStationCollection daPassingStationCollection) |
|
192 |
{ |
|
193 |
daPassingStationCollection.setUpdateTime(DateUtils.getNowDate()); |
|
194 |
return daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollection); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* 批量删除产品过站采集 |
|
199 |
* |
|
200 |
* @param ids 需要删除的产品过站采集主键 |
|
201 |
* @return 结果 |
|
202 |
*/ |
|
203 |
@Override |
|
204 |
public int deleteDaPassingStationCollectionByIds(Long[] ids) |
|
205 |
{ |
|
206 |
return daPassingStationCollectionMapper.deleteDaPassingStationCollectionByIds(ids); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* 删除产品过站采集信息 |
|
211 |
* |
|
212 |
* @param id 产品过站采集主键 |
|
213 |
* @return 结果 |
|
214 |
*/ |
|
215 |
@Override |
|
216 |
public int deleteDaPassingStationCollectionById(Long id) |
|
217 |
{ |
|
218 |
return daPassingStationCollectionMapper.deleteDaPassingStationCollectionById(id); |
|
219 |
} |
ff985a
|
220 |
|
懒 |
221 |
@Override |
|
222 |
public void insertRepairRecordByIds(DaPassingStationCollection daPassingStationCollection) { |
|
223 |
Long[] conditions = daPassingStationCollection.getIds(); |
59e228
|
224 |
String sfcCode = ""; |
W |
225 |
List<RmRepairRecord> save = new ArrayList<>(); |
|
226 |
|
ff985a
|
227 |
for (int i = 0; i < conditions.length; i++) { |
懒 |
228 |
DaPassingStationCollection result = daPassingStationCollectionMapper.selectDaPassingStationCollectionById(conditions[i]); |
59e228
|
229 |
if (i==0){ |
W |
230 |
if (ObjectUtil.isNotEmpty(result)){ |
|
231 |
sfcCode = result.getSfcCode(); |
|
232 |
rmRepairRecordMapper.deleteRmRepairRecordByCode(sfcCode); |
|
233 |
} |
|
234 |
} |
51b05b
|
235 |
if (ObjectUtil.isNotEmpty(result)){ |
W |
236 |
RmRepairRecord rmRepairRecord = new RmRepairRecord(); |
|
237 |
rmRepairRecord.setBoxCode(result.getSfcCode()); |
|
238 |
rmRepairRecord.setProcessesCode(result.getLocationCode()); |
|
239 |
rmRepairRecord.setOriginalResult(result.getOutRsSign()); |
|
240 |
rmRepairRecord.setCreateTime(new Date()); |
|
241 |
rmRepairRecordMapper.insertRmRepairRecord(rmRepairRecord); |
|
242 |
daPassingStationCollectionMapper.deleteDaPassingStationCollectionById(result.getId()); |
|
243 |
} |
ff985a
|
244 |
} |
59e228
|
245 |
|
ff985a
|
246 |
} |
f7a995
|
247 |
@Override |
059083
|
248 |
public String SelectSN(String SNcode,String node) { |
W |
249 |
try { |
|
250 |
Map<String, Object> params = new HashMap<>(); |
9e6d86
|
251 |
params.put("SN_CODE",SNcode); |
W |
252 |
params.put("Node",node); |
059083
|
253 |
params.put("Success",""); |
W |
254 |
daPassingStationCollectionMapper.SelectSN(params); |
|
255 |
return (String)params.get("Success"); |
|
256 |
} catch (Exception e) { |
|
257 |
return "数据查询失败!"; |
|
258 |
} |
|
259 |
} |
f7a995
|
260 |
|
2c65c3
|
261 |
@Override |
W |
262 |
public List<ProductNumVO> getProductNum(DaPassingStationCollection daPassingStationCollection) { |
|
263 |
String queryMonth = daPassingStationCollection.getQueryMonth(); |
|
264 |
LocalDate queryLocalDate = daPassingStationCollection.getQueryDate(); |
|
265 |
if (ObjectUtil.isNotEmpty(queryLocalDate)){ |
|
266 |
LocalDate addQueryLocalDate = queryLocalDate.plusDays(1); |
|
267 |
String queryDate = queryLocalDate.toString(); |
|
268 |
String addQueryDate = addQueryLocalDate.toString(); |
|
269 |
List<ProductNumVO> productNum = bsOrderSchedulingMapper.getProductNum(queryDate, addQueryDate); |
|
270 |
if (CollUtil.isNotEmpty(productNum)){ |
|
271 |
productNum.forEach(x -> { |
|
272 |
x.setQueryDate(queryDate); |
|
273 |
}); |
|
274 |
} |
|
275 |
return productNum; |
|
276 |
} else if (ObjectUtil.isNull(queryLocalDate) && ObjectUtil.isNotNull(queryMonth)){ |
|
277 |
//按月份查询 |
|
278 |
String s = queryMonth + "-01"; |
|
279 |
LocalDate parse = LocalDate.parse(s); |
|
280 |
LocalDate localDate = parse.plusMonths(1); |
|
281 |
String queryDate = parse.toString(); |
|
282 |
String addQueryDate = localDate.toString(); |
|
283 |
List<ProductNumVO> productNum = bsOrderSchedulingMapper.getProductNum(queryDate, addQueryDate); |
|
284 |
if (CollUtil.isNotEmpty(productNum)){ |
|
285 |
productNum.forEach(x -> { |
|
286 |
x.setQueryDate(queryMonth); |
|
287 |
}); |
|
288 |
} |
|
289 |
return productNum; |
|
290 |
} |
|
291 |
return new ArrayList<ProductNumVO>(); |
|
292 |
} |
|
293 |
|
1c7036
|
294 |
// public String sendMessage(String message) throws Exception{ |
Y |
295 |
// Map<String,Object> map = new HashMap<>(); |
|
296 |
// |
|
297 |
// // 获取当前日期和时间 |
|
298 |
// LocalDateTime nowDateTime = LocalDateTime.now(); |
|
299 |
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
300 |
// System.out.println(dateTimeFormatter.format(nowDateTime)); |
|
301 |
// map.put("server_time",dateTimeFormatter.format(nowDateTime)); |
|
302 |
// map.put("server_code","200"); |
|
303 |
// |
|
304 |
// map.put("server_message",message); |
|
305 |
// JSONObject jsonObject = new JSONObject(map); |
|
306 |
// WebSocketServer.sendAllMessage(jsonObject.toString()); |
|
307 |
// return jsonObject.toString(); |
|
308 |
// } |
|
309 |
|
|
310 |
public String sendMessage(String message,String userid) throws Exception{ |
059083
|
311 |
Map<String,Object> map = new HashMap<>(); |
W |
312 |
|
|
313 |
// 获取当前日期和时间 |
|
314 |
LocalDateTime nowDateTime = LocalDateTime.now(); |
|
315 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
316 |
System.out.println(dateTimeFormatter.format(nowDateTime)); |
|
317 |
map.put("server_time",dateTimeFormatter.format(nowDateTime)); |
|
318 |
map.put("server_code","200"); |
|
319 |
|
|
320 |
map.put("server_message",message); |
|
321 |
JSONObject jsonObject = new JSONObject(map); |
1c7036
|
322 |
WebSocketServer.sendInfo(jsonObject.toString(),userid); |
059083
|
323 |
return jsonObject.toString(); |
f7a995
|
324 |
} |
fd2207
|
325 |
} |