自动化立体仓库 - WMS系统
zyh
12 小时以前 701542ac0a90cf0e3a0a81ec2bb8066b5de68e75
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
package com.zy.asrs.task;
 
import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.BasErrLog;
import com.zy.asrs.entity.mes.MesReturn;
import com.zy.asrs.service.BasErrLogService;
import com.zy.asrs.service.impl.RcsServiceImpl;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.task.handler.ErrorStockHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
/**
 * Created by vincent on 2020/7/7
 */
@Component
public class ErrorStockScheduler {
 
    @Value("${mes.url}")
    public String MES_URL;
 
    @Autowired
    private BasErrLogService basErrLogService;
 
    private static final Logger log = LoggerFactory.getLogger(ErrorStockScheduler.class);
 
    @Autowired
    private ErrorStockHandler errorStockHandler;
 
    @Scheduled(cron = "0/3 * * * * ? ")
    private void execute(){
        ReturnT<String> returnT = errorStockHandler.start();
        if (!returnT.isSuccess()) {
            log.error(returnT.getMsg());
        }
    }
 
 
 
    /**
     * 每日故障信息上报
     */
    @Scheduled(cron = "0 0 20 * * ? ")
    public void faultReport() {
        // 获取今天的开始时间
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date todayStart = calendar.getTime();
 
        // 获取今天的结束时间
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        Date todayEnd = calendar.getTime();
 
        List<BasErrLog> basErrLogs = basErrLogService.selectList(
                new EntityWrapper<BasErrLog>()
                        .between("create_time", todayStart, todayEnd)
                        .orderBy("create_time", false)
        );
 
        int totalCount = basErrLogs.size();
        long totalTime = 0;
 
        for (BasErrLog basErrLog : basErrLogs) {
            if (basErrLog.getStartTime() != null && basErrLog.getEndTime() != null) {
                totalTime += basErrLog.getEndTime().getTime() - basErrLog.getStartTime().getTime();
            }
        }
 
        JSONObject params = new JSONObject();
        params.put("totalCount", totalCount);
        params.put("totalTime", totalTime / 1000);
 
        String url = "ErrorLogReport";
        String URL = MES_URL + url;
        String response = RcsServiceImpl.sendPost(URL, JSONObject.toJSONString(params));
        if (!StringUtils.isEmpty(response) && response.contains("Success")){
            MesReturn mesReturn = JSONObject.parseObject(response, MesReturn.class);
            if("1".equals(mesReturn.getSuccess())) {
                log.info("上报完成 ==> 故障次数:{}, 总时长:{}", totalCount, totalTime);
            }else {
                log.error("上报失败 ==> 故障次数:{}, 总时长:{}", totalCount, totalTime);
            }
        }
 
    }
 
}