提交 | 用户 | 时间
|
fd2207
|
1 |
package com.jcdm.main.da.passingStationCollection.service.impl; |
懒 |
2 |
|
c6e069
|
3 |
import java.math.BigDecimal; |
W |
4 |
import java.math.RoundingMode; |
9ebb88
|
5 |
import java.time.LocalDate; |
W |
6 |
import java.time.LocalDateTime; |
|
7 |
import java.time.format.DateTimeFormatter; |
c6e069
|
8 |
import java.util.*; |
W |
9 |
import java.util.stream.Collectors; |
9ebb88
|
10 |
|
c6e069
|
11 |
import cn.hutool.core.collection.CollUtil; |
9ebb88
|
12 |
import com.jcdm.common.constant.Constants; |
fd2207
|
13 |
import com.jcdm.common.utils.DateUtils; |
c6e069
|
14 |
import com.jcdm.common.utils.StringUtils; |
9ebb88
|
15 |
import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling; |
W |
16 |
import com.jcdm.main.bs.orderScheduling.mapper.BsOrderSchedulingMapper; |
|
17 |
import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService; |
fd2207
|
18 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
懒 |
19 |
import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper; |
|
20 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
c6e069
|
21 |
import com.jcdm.main.da.passingStationCollection.vo.DaPassingStationVO; |
ff985a
|
22 |
import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord; |
懒 |
23 |
import com.jcdm.main.rm.repairRecord.mapper.RmRepairRecordMapper; |
fd2207
|
24 |
import org.springframework.beans.factory.annotation.Autowired; |
9ebb88
|
25 |
import org.springframework.format.annotation.DateTimeFormat; |
fd2207
|
26 |
import org.springframework.stereotype.Service; |
懒 |
27 |
|
|
28 |
/** |
|
29 |
* 产品过站采集Service业务层处理 |
|
30 |
* |
|
31 |
* @author yyt |
|
32 |
* @date 2023-12-12 |
|
33 |
*/ |
|
34 |
@Service |
|
35 |
public class DaPassingStationCollectionServiceImpl implements IDaPassingStationCollectionService |
|
36 |
{ |
|
37 |
@Autowired |
|
38 |
private DaPassingStationCollectionMapper daPassingStationCollectionMapper; |
ff985a
|
39 |
|
懒 |
40 |
@Autowired |
|
41 |
private RmRepairRecordMapper rmRepairRecordMapper; |
9ebb88
|
42 |
|
W |
43 |
@Autowired |
|
44 |
private BsOrderSchedulingMapper bsOrderSchedulingMapper; |
|
45 |
|
|
46 |
@Autowired |
|
47 |
private IBsOrderSchedulingService bsOrderSchedulingService; |
fd2207
|
48 |
|
懒 |
49 |
/** |
|
50 |
* 查询产品过站采集 |
|
51 |
* |
|
52 |
* @param id 产品过站采集主键 |
|
53 |
* @return 产品过站采集 |
|
54 |
*/ |
|
55 |
@Override |
|
56 |
public DaPassingStationCollection selectDaPassingStationCollectionById(Long id) |
|
57 |
{ |
|
58 |
return daPassingStationCollectionMapper.selectDaPassingStationCollectionById(id); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* 查询产品过站采集列表 |
|
63 |
* |
|
64 |
* @param daPassingStationCollection 产品过站采集 |
|
65 |
* @return 产品过站采集 |
|
66 |
*/ |
|
67 |
@Override |
|
68 |
public List<DaPassingStationCollection> selectDaPassingStationCollectionList(DaPassingStationCollection daPassingStationCollection) |
|
69 |
{ |
|
70 |
return daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection); |
|
71 |
} |
|
72 |
|
c6e069
|
73 |
@Override |
W |
74 |
public List<DaPassingStationVO> getTopProcess(DaPassingStationCollection daPassingStationCollection) |
|
75 |
{ |
|
76 |
|
|
77 |
List<DaPassingStationVO> result = new ArrayList<>(); |
020295
|
78 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
W |
79 |
|
|
80 |
LocalDateTime startTime = LocalDate.now().atStartOfDay(); |
|
81 |
LocalDateTime endTime = LocalDate.now().plusDays(1).atStartOfDay(); |
|
82 |
String s1 = startTime.format(formatter); |
|
83 |
String s2 = endTime.format(formatter); |
|
84 |
daPassingStationCollection.setStartTime(s1); |
|
85 |
daPassingStationCollection.setEndTime(s2); |
c6e069
|
86 |
List<DaPassingStationCollection> list = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection); |
W |
87 |
//筛除节拍为空的数据 |
|
88 |
list = list.stream().filter(x -> StringUtils.isNotEmpty(x.getBeatTime())).collect(Collectors.toList()); |
|
89 |
//做筛选操作 |
|
90 |
if (CollUtil.isNotEmpty(list)){ |
|
91 |
for (DaPassingStationCollection passingStationCollection : list) { |
|
92 |
if (StringUtils.isNotEmpty(passingStationCollection.getBeatTime())){ |
|
93 |
Long aLong = Long.valueOf(passingStationCollection.getBeatTime()); |
|
94 |
passingStationCollection.setBeatTimeLong(aLong); |
|
95 |
}else { |
|
96 |
passingStationCollection.setBeatTimeLong(0L); |
|
97 |
} |
|
98 |
} |
|
99 |
Map<String, Double> collect = list.stream().collect(Collectors.groupingBy(DaPassingStationCollection::getLocationCode, Collectors.averagingLong(DaPassingStationCollection::getBeatTimeLong))); |
|
100 |
//排序 |
|
101 |
List<Map.Entry<String,Double>> entryList = new ArrayList<>(collect.entrySet()); |
|
102 |
Collections.sort(entryList, new Comparator<Map.Entry<String, Double>>() { |
|
103 |
@Override |
|
104 |
public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) { |
|
105 |
double v = o2.getValue() - o1.getValue(); |
|
106 |
return (int) v; |
|
107 |
} |
|
108 |
}); |
|
109 |
LinkedHashMap<String, Double> linkedHashMap = new LinkedHashMap<String, Double>(); |
|
110 |
int i = 1; |
|
111 |
double sum = 0; |
|
112 |
for (Map.Entry<String,Double> e : entryList |
|
113 |
) { |
|
114 |
if (i<6){ |
|
115 |
sum = sum + e.getValue(); |
|
116 |
linkedHashMap.put(e.getKey(),e.getValue()); |
|
117 |
i++; |
|
118 |
} |
|
119 |
|
|
120 |
} |
|
121 |
//计算数据 |
|
122 |
if (CollUtil.isNotEmpty(linkedHashMap)){ |
|
123 |
for (String s : linkedHashMap.keySet()) { |
|
124 |
DaPassingStationVO vo = new DaPassingStationVO(); |
|
125 |
BigDecimal divide = BigDecimal.valueOf(linkedHashMap.get(s)).divide(BigDecimal.valueOf(sum),4, RoundingMode.HALF_UP); |
|
126 |
vo.setName(s); |
|
127 |
vo.setValue(divide); |
|
128 |
result.add(vo); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
// Map<String, List<DaPassingStationCollection>> collect = list.stream().collect(Collectors.groupingBy(DaPassingStationCollection::getLocationCode)); |
|
133 |
// for (String key:collect.keySet()){ |
|
134 |
// List<DaPassingStationCollection> list1 = collect.get(key); |
|
135 |
// if (CollUtil.isNotEmpty(list1)) { |
|
136 |
// Double collect1 = list1.stream().collect(Collectors.averagingLong(DaPassingStationCollection::getBeatTimeLong)); |
|
137 |
// } |
|
138 |
// } |
|
139 |
} |
|
140 |
return result; |
|
141 |
} |
|
142 |
|
fd2207
|
143 |
/** |
9ebb88
|
144 |
* 获取首页单日累计量产数据 |
W |
145 |
* @param fieldName bs |
|
146 |
* @return list |
|
147 |
*/ |
|
148 |
@Override |
|
149 |
public Integer getProduceNumToday(String fieldName) { |
|
150 |
|
|
151 |
BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
|
152 |
bsOrderScheduling.setQueryField(fieldName); |
|
153 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
154 |
LocalDateTime startTime = LocalDate.now().atStartOfDay(); |
|
155 |
LocalDateTime endTime = LocalDate.now().plusDays(1).atStartOfDay(); |
|
156 |
String s1 = startTime.format(formatter); |
|
157 |
String s2 = endTime.format(formatter); |
|
158 |
bsOrderScheduling.setStartTime(s1); |
|
159 |
bsOrderScheduling.setEndTime(s2); |
|
160 |
return bsOrderSchedulingMapper.getProduceNumToday(bsOrderScheduling); |
|
161 |
} |
|
162 |
|
|
163 |
/** |
fd2207
|
164 |
* 新增产品过站采集 |
懒 |
165 |
* |
|
166 |
* @param daPassingStationCollection 产品过站采集 |
|
167 |
* @return 结果 |
|
168 |
*/ |
|
169 |
@Override |
|
170 |
public int insertDaPassingStationCollection(DaPassingStationCollection daPassingStationCollection) |
|
171 |
{ |
|
172 |
daPassingStationCollection.setCreateTime(DateUtils.getNowDate()); |
|
173 |
return daPassingStationCollectionMapper.insertDaPassingStationCollection(daPassingStationCollection); |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* 修改产品过站采集 |
|
178 |
* |
|
179 |
* @param daPassingStationCollection 产品过站采集 |
|
180 |
* @return 结果 |
|
181 |
*/ |
|
182 |
@Override |
|
183 |
public int updateDaPassingStationCollection(DaPassingStationCollection daPassingStationCollection) |
|
184 |
{ |
|
185 |
daPassingStationCollection.setUpdateTime(DateUtils.getNowDate()); |
|
186 |
return daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollection); |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* 批量删除产品过站采集 |
|
191 |
* |
|
192 |
* @param ids 需要删除的产品过站采集主键 |
|
193 |
* @return 结果 |
|
194 |
*/ |
|
195 |
@Override |
|
196 |
public int deleteDaPassingStationCollectionByIds(Long[] ids) |
|
197 |
{ |
|
198 |
return daPassingStationCollectionMapper.deleteDaPassingStationCollectionByIds(ids); |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* 删除产品过站采集信息 |
|
203 |
* |
|
204 |
* @param id 产品过站采集主键 |
|
205 |
* @return 结果 |
|
206 |
*/ |
|
207 |
@Override |
|
208 |
public int deleteDaPassingStationCollectionById(Long id) |
|
209 |
{ |
|
210 |
return daPassingStationCollectionMapper.deleteDaPassingStationCollectionById(id); |
|
211 |
} |
ff985a
|
212 |
|
懒 |
213 |
@Override |
|
214 |
public void insertRepairRecordByIds(DaPassingStationCollection daPassingStationCollection) { |
|
215 |
Long[] conditions = daPassingStationCollection.getIds(); |
|
216 |
for (int i = 0; i < conditions.length; i++) { |
|
217 |
DaPassingStationCollection result = daPassingStationCollectionMapper.selectDaPassingStationCollectionById(conditions[i]); |
|
218 |
RmRepairRecord rmRepairRecord = new RmRepairRecord(); |
|
219 |
rmRepairRecord.setBoxCode(result.getSfcCode()); |
|
220 |
rmRepairRecord.setProcessesCode(result.getLocationCode()); |
|
221 |
rmRepairRecord.setOriginalResult(result.getOutRsSign()); |
|
222 |
rmRepairRecordMapper.insertRmRepairRecord(rmRepairRecord); |
|
223 |
} |
|
224 |
} |
fd2207
|
225 |
} |