CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
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
package com.ld.igds.timer;
 
import com.ld.igds.constant.Constant;
import com.ld.igds.gas.dto.GasParam;
import com.ld.igds.gas.manager.GasManager;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.response.GasResponse;
import com.ld.igds.models.Depot;
import com.ld.igds.models.TimingDepot;
import com.ld.igds.timer.service.ITimerService;
import com.ld.igds.view.service.HDepotService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 气体定时检测
 */
@Slf4j
@Service(Constant.JOB_BEAN_GAS)
public class JobGasService implements Job {
 
    @Autowired
    private ITimerService timerService;
    @Autowired
    private HDepotService depotService;
    @Autowired
    private GasManager gasManager;
 
    @Override
    public void execute(JobExecutionContext context) {
        log.info("=======================开始执行定时气体检测=============================");
        try {
            // 获取JOB的ID
            String key = context.getTrigger().getKey().getName();
            String jobId = key.substring(7);
 
            //根据当前JOB获取设备列表
            List<TimingDepot> list = timerService.getDepotByTimerId(jobId);
            if (null == list || list.isEmpty()) {
                log.info(context.getJobDetail().getDescription() + "该方案下没有配置需要执行的仓库,定时检测失败……");
                return;
            }
 
            // 获取到需要操作的仓库列表
            List<Depot> depots = depotService.getDepotByTimer(list);
            if (null == depots || depots.isEmpty()) {
                log.info(context.getJobDetail().getDescription() + "该方案下没有获取到仓库信息,定时检测失败……");
                return;
            }
 
            GasParam param;
            GasResponse tempResp;
            Map<String, String> mapError = new HashMap<String, String>();
            for (Depot depot : depots) {
                param = new GasParam();
                param.setCompanyId(depot.getCompanyId());
                param.setDepotId(depot.getId());
                tempResp = gasManager.checkGas(param);
 
                if (!OrderRespEnum.ORDER_SUCCESS.getCode().equals(
                        tempResp.getCode())) {
                    mapError.put(depot.getName(), tempResp.getMsg());
                }
                Thread.sleep(3 * 1000);
            }
 
            if (mapError.isEmpty()) {
                log.info("气体定时检测命令发送成功,请等待终端响应……");
            } else {
                String errorMsg = "";
                for (String str : mapError.keySet()) {
                    errorMsg = "仓库:" + str + "采集失败,异常:" + mapError.get(str);
                    log.error("气体定时检测-" + errorMsg);
                }
            }
        } catch (Exception e) {
            log.error("定时气体采集异常:{}", e);
        }
    }
}