春风项目四线(合箱线、总装线)
wujian
2024-01-25 c6e06980cccbb86fa224633d3585f9164295bff1
提交 | 用户 | 时间
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<>();
78         List<DaPassingStationCollection> list = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
79         //筛除节拍为空的数据
80         list = list.stream().filter(x -> StringUtils.isNotEmpty(x.getBeatTime())).collect(Collectors.toList());
81         //做筛选操作
82         if (CollUtil.isNotEmpty(list)){
83             for (DaPassingStationCollection passingStationCollection : list) {
84                 if (StringUtils.isNotEmpty(passingStationCollection.getBeatTime())){
85                     Long aLong = Long.valueOf(passingStationCollection.getBeatTime());
86                     passingStationCollection.setBeatTimeLong(aLong);
87                 }else {
88                     passingStationCollection.setBeatTimeLong(0L);
89                 }
90             }
91             Map<String, Double> collect = list.stream().collect(Collectors.groupingBy(DaPassingStationCollection::getLocationCode, Collectors.averagingLong(DaPassingStationCollection::getBeatTimeLong)));
92             //排序
93             List<Map.Entry<String,Double>> entryList = new ArrayList<>(collect.entrySet());
94             Collections.sort(entryList, new Comparator<Map.Entry<String, Double>>() {
95                 @Override
96                 public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
97                     double v = o2.getValue() - o1.getValue();
98                     return (int) v;
99                 }
100             });
101             LinkedHashMap<String, Double> linkedHashMap = new LinkedHashMap<String, Double>();
102             int i = 1;
103             double sum =  0;
104             for (Map.Entry<String,Double> e : entryList
105             ) {
106                 if (i<6){
107                     sum = sum + e.getValue();
108                     linkedHashMap.put(e.getKey(),e.getValue());
109                     i++;
110                 }
111
112             }
113             //计算数据
114             if (CollUtil.isNotEmpty(linkedHashMap)){
115                 for (String s : linkedHashMap.keySet()) {
116                     DaPassingStationVO vo = new DaPassingStationVO();
117                     BigDecimal divide = BigDecimal.valueOf(linkedHashMap.get(s)).divide(BigDecimal.valueOf(sum),4, RoundingMode.HALF_UP);
118                     vo.setName(s);
119                     vo.setValue(divide);
120                     result.add(vo);
121                 }
122             }
123
124 //            Map<String, List<DaPassingStationCollection>> collect = list.stream().collect(Collectors.groupingBy(DaPassingStationCollection::getLocationCode));
125 //            for (String key:collect.keySet()){
126 //                List<DaPassingStationCollection> list1 = collect.get(key);
127 //                if (CollUtil.isNotEmpty(list1)) {
128 //                    Double collect1 = list1.stream().collect(Collectors.averagingLong(DaPassingStationCollection::getBeatTimeLong));
129 //                }
130 //            }
131         }
132         return result;
133     }
134
fd2207 135     /**
9ebb88 136      * 获取首页单日累计量产数据
W 137      * @param fieldName bs
138      * @return list
139      */
140     @Override
141     public Integer getProduceNumToday(String fieldName) {
142
143         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
144         bsOrderScheduling.setQueryField(fieldName);
145         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
146         LocalDateTime startTime = LocalDate.now().atStartOfDay();
147         LocalDateTime endTime = LocalDate.now().plusDays(1).atStartOfDay();
148         String s1 = startTime.format(formatter);
149         String s2 = endTime.format(formatter);
150         bsOrderScheduling.setStartTime(s1);
151         bsOrderScheduling.setEndTime(s2);
152         return bsOrderSchedulingMapper.getProduceNumToday(bsOrderScheduling);
153     }
154
155     /**
fd2207 156      * 新增产品过站采集
157      * 
158      * @param daPassingStationCollection 产品过站采集
159      * @return 结果
160      */
161     @Override
162     public int insertDaPassingStationCollection(DaPassingStationCollection daPassingStationCollection)
163     {
164         daPassingStationCollection.setCreateTime(DateUtils.getNowDate());
165         return daPassingStationCollectionMapper.insertDaPassingStationCollection(daPassingStationCollection);
166     }
167
168     /**
169      * 修改产品过站采集
170      * 
171      * @param daPassingStationCollection 产品过站采集
172      * @return 结果
173      */
174     @Override
175     public int updateDaPassingStationCollection(DaPassingStationCollection daPassingStationCollection)
176     {
177         daPassingStationCollection.setUpdateTime(DateUtils.getNowDate());
178         return daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollection);
179     }
180
181     /**
182      * 批量删除产品过站采集
183      * 
184      * @param ids 需要删除的产品过站采集主键
185      * @return 结果
186      */
187     @Override
188     public int deleteDaPassingStationCollectionByIds(Long[] ids)
189     {
190         return daPassingStationCollectionMapper.deleteDaPassingStationCollectionByIds(ids);
191     }
192
193     /**
194      * 删除产品过站采集信息
195      * 
196      * @param id 产品过站采集主键
197      * @return 结果
198      */
199     @Override
200     public int deleteDaPassingStationCollectionById(Long id)
201     {
202         return daPassingStationCollectionMapper.deleteDaPassingStationCollectionById(id);
203     }
ff985a 204
205     @Override
206     public void insertRepairRecordByIds(DaPassingStationCollection daPassingStationCollection) {
207         Long[] conditions = daPassingStationCollection.getIds();
208         for (int i = 0; i < conditions.length; i++) {
209             DaPassingStationCollection result = daPassingStationCollectionMapper.selectDaPassingStationCollectionById(conditions[i]);
210             RmRepairRecord rmRepairRecord = new RmRepairRecord();
211             rmRepairRecord.setBoxCode(result.getSfcCode());
212             rmRepairRecord.setProcessesCode(result.getLocationCode());
213             rmRepairRecord.setOriginalResult(result.getOutRsSign());
214             rmRepairRecordMapper.insertRmRepairRecord(rmRepairRecord);
215         }
216     }
fd2207 217 }