春风项目四线(合箱线、总装线)
yyt
2024-05-06 bbc5784cc34d65e64d639d949e75b978fe07bdb3
提交 | 用户 | 时间
fd2207 1 package com.jcdm.main.da.passingStationCollection.service.impl;
2
c6e069 3 import cn.hutool.core.collection.CollUtil;
059083 4 import com.alibaba.fastjson2.JSONObject;
fd2207 5 import com.jcdm.common.utils.DateUtils;
c6e069 6 import com.jcdm.common.utils.StringUtils;
9ebb88 7 import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
W 8 import com.jcdm.main.bs.orderScheduling.mapper.BsOrderSchedulingMapper;
9 import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
fd2207 10 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
11 import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
12 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
c6e069 13 import com.jcdm.main.da.passingStationCollection.vo.DaPassingStationVO;
ff985a 14 import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord;
15 import com.jcdm.main.rm.repairRecord.mapper.RmRepairRecordMapper;
059083 16 import com.jcdm.main.websocket.WebSocketServer;
fd2207 17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service;
059083 19
W 20 import java.math.BigDecimal;
21 import java.math.RoundingMode;
22 import java.time.LocalDate;
23 import java.time.LocalDateTime;
24 import java.time.format.DateTimeFormatter;
25 import java.util.*;
26 import java.util.stream.Collectors;
fd2207 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     }
f7a995 225     @Override
059083 226     public String SelectSN(String SNcode,String node) {
W 227         try {
228             Map<String, Object> params = new HashMap<>();
9e6d86 229             params.put("SN_CODE",SNcode);
W 230             params.put("Node",node);
059083 231             params.put("Success","");
W 232             daPassingStationCollectionMapper.SelectSN(params);
233             return (String)params.get("Success");
234         } catch (Exception e) {
235             return "数据查询失败!";
236         }
237     }
f7a995 238
059083 239     public String sendMessage(String message) throws Exception{
W 240         Map<String,Object> map = new HashMap<>();
241
242         // 获取当前日期和时间
243         LocalDateTime nowDateTime = LocalDateTime.now();
244         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
245         System.out.println(dateTimeFormatter.format(nowDateTime));
246         map.put("server_time",dateTimeFormatter.format(nowDateTime));
247         map.put("server_code","200");
248
249         map.put("server_message",message);
250         JSONObject jsonObject =  new JSONObject(map);
251         WebSocketServer.sendAllMessage(jsonObject.toString());
252         return jsonObject.toString();
f7a995 253     }
fd2207 254 }