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