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