CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
package com.ld.igds.timer;
 
import com.bstek.dorado.annotation.Expose;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.es.dto.EsParam;
import com.ld.igds.es.manager.EsManager;
import com.ld.igds.es.service.CoreEsService;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.response.BaseResponse;
import com.ld.igds.models.DepotConf;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.DateUtil;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
import java.util.Date;
import java.util.List;
 
/**
 * 能耗数据获取,当前协议为自动调用,系统每间隔1个小时获取一次
 * <p>
 * 由于加载的优先级问题,这里直接用Resource引入,并且指定实现类
 */
@Slf4j
@Component(EsScheduled.BEAN_ID)
public class EsScheduled {
 
    public static final String BEAN_ID = "basic.esScheduled";
 
    @Resource(name = CoreCommonService.BEAN_ID)
    private CoreCommonService coreCommonService;
 
    @Resource(name = CoreEsService.BEAN_ID)
    private CoreEsService coreEsService;
 
 
    @Resource
    private EsManager esManager;
 
    /**
     * @Scheduled(cron = "1 0 * * * ?")
     * 能耗获取定时器,每小时执行一次,执行时间为每个小时的第一秒
     * @Scheduled(cron = "0 0 8,20 * * ?")
     * 每天的早上8点和晚上8点执行两次
     */
    @Scheduled(cron = "1 0 * * * ?")
    public void scheduled() {
        doExe(null);
    }
 
 
 
    /**
     * 大屏页面能耗信息推送,每天早上9点更新并推送
     */
    @Scheduled(cron = "0 0 9 * * ?")
    public void scheduled2() {
        log.info("===================系统定时推送能耗信息=======================");
        EsParam esParam = new EsParam();
        esParam.setCompanyId(ContextUtil.getDefaultCompanyId());
        esParam.setStart(DateUtil.getNewByDay(new Date(), -15));
 
        coreEsService.queryScreenEsChart(esParam, true);
    }
 
    public void doExe(String companyId) {
        log.info("===================系统定时能耗检测=======================");
        
        if(null == companyId){
            companyId = ContextUtil.getDefaultCompanyId();
        }
 
        List<DepotConf> list = coreCommonService.getCacheDepotConf(companyId);
 
        if (null == list || list.isEmpty()) return;
 
        BaseResponse response;
        for (DepotConf depotConf : list) {
 
            if(null == depotConf.getEsSer()) continue;
            response = esManager.checkEsByConf(depotConf);
 
            if (!OrderRespEnum.ORDER_SUCCESS.getCode().equals(response.getCode())) {
                log.error("----自动调用能耗执行失败,仓库={},失败原因={}", depotConf.getDepotName(), response.getMsg());
            }
        }
    }
    
    
    /**
     * 
     * basic.esScheduled#doExeByHand
     * 手动触发检测
     */
    @Expose
    public void doExeByHand() {
        
        log.info("----------------------手动触发能耗统一检测----------------{}",ContextUtil.getLoginUserName());
        String companyId = ContextUtil.getCompanyId();
        doExe(companyId);
    }
}