懒羊羊
2023-11-25 9bd5461a1387becd4da03158061a1ed17ddf6a6c
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.modular.cm.passingStationCollection.service.impl;
2
3 import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
4 import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
5 import cn.stylefeng.guns.modular.bs.equipmentInfo.model.params.EquipmentInfoParam;
6 import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult;
7 import cn.stylefeng.guns.modular.cm.passingStationCollection.entity.PassingStationCollection;
8 import cn.stylefeng.guns.modular.cm.passingStationCollection.mapper.PassingStationCollectionMapper;
9 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
10 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult;
11 import  cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
12 import cn.stylefeng.roses.core.util.ToolUtil;
13 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
14 import com.baomidou.mybatisplus.core.metadata.IPage;
15 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
16 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service;
19
20 import java.io.Serializable;
21 import java.text.DecimalFormat;
22 import java.text.NumberFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.*;
25 import java.util.concurrent.TimeUnit;
26
27 /**
28  * <p>
29  * 产品过站采集 服务实现类
30  * </p>
31  *
32  * @author zrm
33  * @since 2023-02-11
34  */
35 @Service
36 public class PassingStationCollectionServiceImpl extends ServiceImpl<PassingStationCollectionMapper, PassingStationCollection> implements PassingStationCollectionService {
37     @Autowired
38     private PassingStationCollectionService passingService;
39
40     private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
41     @Override
42     public void add(PassingStationCollectionParam param){
43         PassingStationCollection entity = getEntity(param);
44 //        try{
45 //            String beatTime = getDistanceTime(df.format(param.getOutboundTime()), df.format(param.getInboundTime()));
46 //            entity.setBeatTime(beatTime);
47 //        }catch (Exception e){
48 //            e.printStackTrace();
49 //        }
50         this.save(entity);
51     }
52
53     @Override
54     public void delete(PassingStationCollectionParam param){
55         this.removeById(getKey(param));
56     }
57
58     @Override
59     public void update(PassingStationCollectionParam param){
60         PassingStationCollection oldEntity = getOldEntity(param);
61         PassingStationCollection newEntity = getEntity(param);
62         ToolUtil.copyProperties(newEntity, oldEntity);
63         this.updateById(newEntity);
64     }
65
66     @Override
67     public PassingStationCollectionResult findBySpec(PassingStationCollectionParam param){
68         return null;
69     }
70
71     @Override
72     public List<PassingStationCollectionResult> findListBySpec(PassingStationCollectionParam param){
73         return null;
74     }
75
76     @Override
77     public LayuiPageInfo findPageBySpec(PassingStationCollectionParam param){
78         Page pageContext = getPageContext();
79         IPage page = this.baseMapper.customPageList(pageContext, param);
80         List<PassingStationCollectionResult> result = page.getRecords();
81         for (PassingStationCollectionResult passingStationCollectionResult : result) {
82             try {
83                 String beatTime = getDistanceTime(df.format(passingStationCollectionResult.getOutboundTime()), df.format(passingStationCollectionResult.getInboundTime()));
84                 if(beatTime.contains("-")){
85                     passingStationCollectionResult.setBeatTime("数据异常");
86                 }else {
87                     passingStationCollectionResult.setBeatTime(beatTime);
88                 }
89             }catch (Exception e){
90
91             }
92         }
93         return LayuiPageFactory.createPageInfo(page);
94     }
95
96     @Override
97     public LayuiPageInfo PassRate(PassingStationCollectionParam param) {
98         Page pageContext = getPageContext();
99         IPage page = this.baseMapper.PassRate(pageContext, param);
100         return LayuiPageFactory.createPageInfo(page);
101     }
102
103     @Override
9bd546 104     public int bigCenterRightTable(String startTime, String endTime,String qualifiedFlag,String workOrderNo) {
105         return this.baseMapper.bigCenterRightTable(startTime,endTime,qualifiedFlag,workOrderNo);
106     }
107
108     @Override
71e81e 109     public Integer getRepairQty() {
110         return baseMapper.getRepairQty();
111     }
112
113     @Override
114     public Integer getRepairQtyWeek() {
115         return baseMapper.getRepairQtyWeek();
116     }
117
118     @Override
119     public LayuiPageInfo passingPassRateList(PassingStationCollectionParam passingStationCollectionParam) {
120         List resultList = new ArrayList();
121         QueryWrapper<PassingStationCollection> wrapper = new QueryWrapper();
122         wrapper.select("location_code");
123         if(passingStationCollectionParam.getStartTime()!=null){
124             wrapper.between("collection_time",passingStationCollectionParam.getStartTime(),passingStationCollectionParam.getEndTime());
125         }
126         wrapper.groupBy("location_code");
127         List<PassingStationCollection> locationCode = passingService.list(wrapper);
128         for (PassingStationCollection passingStationCollection : locationCode) {
129             Map map = new HashMap();
130             int int1 = passingService.count(new QueryWrapper<PassingStationCollection>()
131                     .eq("location_code", passingStationCollection.getLocationCode())
132                     .eq("out_rs_sign", "1")
133             );
134             int int2 = passingService.count(new QueryWrapper<PassingStationCollection>()
135                     .eq("location_code", passingStationCollection.getLocationCode())
136                     .eq("out_rs_sign", "2")
137             );
138             map.put("locationCode",passingStationCollection.getLocationCode());
139             map.put("qualified",int1);
140             map.put("unqualified",int2);
141             DecimalFormat df = new DecimalFormat("0.00%");
142             if(int2 == 0){
143                 map.put("passRate","100%");
144             }else {
145                 Integer count = int1+int2;
146                 double c = (double)int1/count;
147                 map.put("passRate",df.format(c));
148             }
149             resultList.add(map);
150         }
151         LayuiPageInfo result = new LayuiPageInfo();
152         result.setCount(resultList.size());
153         result.setData(resultList);
154         return result;
155     }
156
157
158     private Serializable getKey(PassingStationCollectionParam param){
159         return param.getId();
160     }
161
162     private Page getPageContext() {
163         return LayuiPageFactory.defaultPage();
164     }
165
166     private PassingStationCollection getOldEntity(PassingStationCollectionParam param) {
167         return this.getById(getKey(param));
168     }
169
170     private PassingStationCollection getEntity(PassingStationCollectionParam param) {
171         PassingStationCollection entity = new PassingStationCollection();
172         ToolUtil.copyProperties(param, entity);
173         return entity;
174     }
175
176     public static String getDistanceTime(String str1, String str2) {
177         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
178         Date one;
179         Date two;
180         long day = 0;//天数差
181         long hour = 0;//小时数差
182         long min = 0;//分钟数差
183         long second=0;//秒数差
184         long diff=0 ;//毫秒差
185         String result = "";
186         try {
187             final Calendar c = Calendar.getInstance();
188             c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
189             one = df.parse(str1);
190             c.setTime(one);
191             two = df.parse(str2);
192             long time2 = one.getTime();
193             long time1 = two.getTime();
194             diff = time2 - time1;
195             day = diff / (24 * 60 * 60 * 1000);
196             hour = (diff / (60 * 60 * 1000) - day * 24);
197             min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
198             second = diff/1000;
199             System.out.println("day="+day+" hour="+hour+" min="+min+" ss="+second%60+" SSS="+diff%1000);
200             String daystr = day%30+"天";
201             String hourStr = hour%24+"小时";
202             String minStr = min%60+"分";
203             Integer intHourStr = Integer.valueOf(hourStr.substring(0,1))*60;
204             Integer intMinStr = Integer.valueOf(minStr.substring(0,1));
205             System.out.println(intHourStr+intMinStr);
206             String secondStr = second%60+"秒";
207             if (day!=0){
208                 result = result + daystr;
209             }
210             if (hour!=0){
211                 result = result + hourStr;
212             }
213             if (min!=0){
214                 result = result + minStr;
215             }
216             if (second!=0){
217                 result = result + secondStr;
218             }
219
220         } catch (Exception e) {
221             e.printStackTrace();
222         }
223         return String.valueOf(second);
224     }
225
226     @Override
227     public int updateSFC(String sfcCode, String childSfcCode) {
228         return this.baseMapper.updateSFC(sfcCode, childSfcCode);
229     }
230
231     @Override
232     public List<PassingStationCollectionResult> exportTable(PassingStationCollectionParam param) {
233         List<PassingStationCollectionResult> results = baseMapper.customList(param);
234         for (PassingStationCollectionResult result : results) {
235             if(result.getInboundTime()!=null&&result.getOutboundTime()!=null){
236                 String beatTime = getDistanceTime(df.format(result.getOutboundTime()), df.format(result.getInboundTime()));
237                 result.setBeatTime(beatTime);
238             }
239             if(result.getOutRsSign().equals("1")){
240                 result.setOutRsSign("合格");
241             }else {
242                 result.setOutRsSign("不合格");
243             }
244         }
245         return results;
246         
247     }
248
249
250
251 }