懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
提交 | 用户 | 时间
8286c6 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
104     public List<PassingStationCollectionResult> snCodeSize(String str) {
105         return this.baseMapper.snCodeSize(str);
106     }
107
108     @Override
109     public PassingStationCollectionResult getMaxSnCode() {
110         return this.baseMapper.getMaxSnCode();
111     }
112
113     @Override
114     public List<PassingStationCollectionResult> getBeatTimeList(String sfcCode) {
115         return this.baseMapper.getBeatTimeList(sfcCode);
116     }
117
118     @Override
119     public List<PassingStationCollectionResult> bottomLeftChart2() {
120         return this.baseMapper.bottomLeftChart2();
121     }
122
123     @Override
124     public Integer getRepairQty() {
125         return baseMapper.getRepairQty();
126     }
127
128     @Override
129     public Integer getRepairQtyWeek() {
130         return baseMapper.getRepairQtyWeek();
131     }
132
133     @Override
134     public LayuiPageInfo passingPassRateList(PassingStationCollectionParam passingStationCollectionParam) {
135         List resultList = new ArrayList();
136         QueryWrapper<PassingStationCollection> wrapper = new QueryWrapper();
137         wrapper.select("location_code");
138         if(passingStationCollectionParam.getStartTime()!=null){
139             wrapper.between("collection_time",passingStationCollectionParam.getStartTime(),passingStationCollectionParam.getEndTime());
140         }
141         wrapper.groupBy("location_code");
142         List<PassingStationCollection> locationCode = passingService.list(wrapper);
143         for (PassingStationCollection passingStationCollection : locationCode) {
144             Map map = new HashMap();
145             int int1 = passingService.count(new QueryWrapper<PassingStationCollection>()
146                     .eq("location_code", passingStationCollection.getLocationCode())
147                     .eq("out_rs_sign", "1")
148             );
149             int int2 = passingService.count(new QueryWrapper<PassingStationCollection>()
150                     .eq("location_code", passingStationCollection.getLocationCode())
151                     .eq("out_rs_sign", "2")
152             );
153             map.put("locationCode",passingStationCollection.getLocationCode());
154             map.put("qualified",int1);
155             map.put("unqualified",int2);
156             DecimalFormat df = new DecimalFormat("0.00%");
157             if(int2 == 0){
158                 map.put("passRate","100%");
159             }else {
160                 Integer count = int1+int2;
161                 double c = (double)int1/count;
162                 map.put("passRate",df.format(c));
163             }
164             resultList.add(map);
165         }
166         LayuiPageInfo result = new LayuiPageInfo();
167         result.setCount(resultList.size());
168         result.setData(resultList);
169         return result;
170     }
171
172
173     private Serializable getKey(PassingStationCollectionParam param){
174         return param.getId();
175     }
176
177     private Page getPageContext() {
178         return LayuiPageFactory.defaultPage();
179     }
180
181     private PassingStationCollection getOldEntity(PassingStationCollectionParam param) {
182         return this.getById(getKey(param));
183     }
184
185     private PassingStationCollection getEntity(PassingStationCollectionParam param) {
186         PassingStationCollection entity = new PassingStationCollection();
187         ToolUtil.copyProperties(param, entity);
188         return entity;
189     }
190
191     public static String getDistanceTime(String str1, String str2) {
192         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
193         Date one;
194         Date two;
195         long day = 0;//天数差
196         long hour = 0;//小时数差
197         long min = 0;//分钟数差
198         long second=0;//秒数差
199         long diff=0 ;//毫秒差
200         String result = "";
201         try {
202             final Calendar c = Calendar.getInstance();
203             c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
204             one = df.parse(str1);
205             c.setTime(one);
206             two = df.parse(str2);
207             long time2 = one.getTime();
208             long time1 = two.getTime();
209             diff = time2 - time1;
210             day = diff / (24 * 60 * 60 * 1000);
211             hour = (diff / (60 * 60 * 1000) - day * 24);
212             min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
213             second = diff/1000;
214             System.out.println("day="+day+" hour="+hour+" min="+min+" ss="+second%60+" SSS="+diff%1000);
215             String daystr = day%30+"天";
216             String hourStr = hour%24+"小时";
217             String minStr = min%60+"分";
218             Integer intHourStr = Integer.valueOf(hourStr.substring(0,1))*60;
219             Integer intMinStr = Integer.valueOf(minStr.substring(0,1));
220             System.out.println(intHourStr+intMinStr);
221             String secondStr = second%60+"秒";
222             if (day!=0){
223                 result = result + daystr;
224             }
225             if (hour!=0){
226                 result = result + hourStr;
227             }
228             if (min!=0){
229                 result = result + minStr;
230             }
231             if (second!=0){
232                 result = result + secondStr;
233             }
234
235         } catch (Exception e) {
236             e.printStackTrace();
237         }
238         return String.valueOf(second);
239     }
240
241     @Override
242     public int updateSFC(String sfcCode, String childSfcCode) {
243         return this.baseMapper.updateSFC(sfcCode, childSfcCode);
244     }
245
246     @Override
247     public List<PassingStationCollectionResult> exportTable(PassingStationCollectionParam param) {
248         List<PassingStationCollectionResult> results = baseMapper.customList(param);
249         for (PassingStationCollectionResult result : results) {
250             if(result.getInboundTime()!=null&&result.getOutboundTime()!=null){
251                 String beatTime = getDistanceTime(df.format(result.getOutboundTime()), df.format(result.getInboundTime()));
252                 result.setBeatTime(beatTime);
253             }
254             if(result.getOutRsSign().equals("1")){
255                 result.setOutRsSign("合格");
256             }else {
257                 result.setOutRsSign("不合格");
258             }
259         }
260         return results;
261         
262     }
263
264
265
266 }