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