CZT
2024-03-02 3a7fd31b5beadda5b3c12450935db9913a52bd92
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
package com.fzzy.api.timer;
 
import com.fzzy.api.data.ApiParam;
import com.fzzy.api.entity.ApiConfs;
import com.fzzy.api.service.*;
import com.fzzy.api.utils.ContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
/**
 * @author: andy.jia
 * @description: 推送省平台数据定时任务
 * @version:
 */
@Slf4j
@Component(PushDataScheduled.BEAN_ID)
public class PushDataScheduled {
 
    public static final String BEAN_ID = "api.pushDataScheduled";
 
 
    @Autowired
    private ApiPushManager apiPushManager;
 
    @Autowired
    private ApiCommonService apiCommonService;
 
    /**
     * cron = "0 0,30 * * * ? "
     * <p>
     * 固定時間:0分鐘,30分鐘執行
     */
    @Scheduled(cron = "0 0,30 * * * ? ")
    public void scheduled() {
 
        log.info("------->>>>>>>>>>系统执行定时推送省平台接口");
 
        List<ApiConfs> list = apiCommonService.listCacheConf();
 
        if (null == list || list.isEmpty()) return;
 
        Date exeDate = new Date();
 
        for (ApiConfs conf : list) {
 
            exeByConf11(conf, exeDate);
 
            exeByConf99(conf, exeDate);
        }
 
    }
 
 
    /**
     * 同步义务数据
     *
     * @param conf
     * @param exeDate
     */
    private void exeByConf99(ApiConfs conf, Date exeDate) {
        if (null == conf.getPushType99() || conf.getPushType99().equals(ApiConfs.SYNC_PUSH_HAND)) {
 
            log.info("------->>>>>>>>>> 业务接口数据,系统配置为手动模式,取消自动执行");
            return;
        }
 
 
        Date start = exeDate;
 
        //是否执行
        boolean isExecute = false;
        boolean isUpdateStart = false;
        //核对天是否匹配
        if (conf.getPushDay99().equals(ApiConfs.TIME_ALL)) {
            isExecute = true;
        } else {
            int dayOfWeek = ContextUtil.getDayOfWeek(exeDate);
            if (String.valueOf(dayOfWeek).equals(conf.getPushDay11())) {
                isExecute = true;
 
                //开始时间提前7天
                start = DateUtils.addDays(start, -7);
                isUpdateStart = true;
            } else {
                isExecute = false;
            }
        }
 
        if (!isExecute) {
            log.debug("------->>>>>>>>>> 业务数据推送---时间配置天不匹配");
            return;
        }
 
        log.info("------->>>>>>>>>> 业务数据推送---开始查询相关业务数据进行推送");
        ApiParam param = new ApiParam();
        param.setPushProtocol(conf.getPushProtocol());
        param.setKqdm(conf.getKqdm());
        param.setStart(start);
        param.setEnd(exeDate);
        param.setDeptId(conf.getDeptId());
 
 
        PushService12 pushService12 = apiPushManager.getPushService12(conf.getPushProtocol());
        pushService12.pushData(param);
 
        PushService13 pushService13 = apiPushManager.getPushService13(conf.getPushProtocol());
        pushService13.pushData(param);
 
        PushService14 pushService14 = apiPushManager.getPushService14(conf.getPushProtocol());
        pushService14.pushData(param);
    }
 
    /**
     * 推送基础信息
     *
     * @param conf
     * @param exeDate
     */
    private void exeByConf11(ApiConfs conf, Date exeDate) {
 
        if (null == conf.getPushType11() || conf.getPushType11().equals(ApiConfs.SYNC_PUSH_HAND)) {
            log.info("------->>>>>>>>>> 基础数据推送,系统配置为手动模式,取消自动执行");
            return;
        }
 
 
        Date start = exeDate;
 
        //是否执行
        boolean isExecute;
        boolean isUpdateStart = false;
        //核对天是否匹配
        if (conf.getPushDay11().equals(ApiConfs.TIME_ALL)) {
            isExecute = true;
        } else {
            int dayOfWeek = ContextUtil.getDayOfWeek(exeDate);
            if (String.valueOf(dayOfWeek).equals(conf.getPushDay11())) {
                isExecute = true;
 
                //开始时间提前7天
                start = DateUtils.addDays(start, -7);
                isUpdateStart = true;
            } else {
                isExecute = false;
            }
        }
 
        if (!isExecute) {
            log.debug("------->>>>>>>>>> 基础数据推送---时间配置天不匹配");
            return;
        }
 
        //核对时间是否匹配
        if (conf.getPushHour11().equals(ApiConfs.TIME_ALL)) {
            isExecute = true;
        } else {
            int hourOfDay = ContextUtil.getHourOfDay(exeDate);
            if (String.valueOf(hourOfDay).equals(conf.getPushHour11())) {
                isExecute = true;
 
                if (!isUpdateStart) {
                    start = DateUtils.addDays(start, -1);
                    isUpdateStart = true;
                }
            } else {
                isExecute = false;
            }
        }
        if (!isExecute) {
            log.debug("------->>>>>>>>>> 基础数据推送---时间配置小时不匹配");
            return;
        }
 
        //核对时间分钟是否匹配
        int minute = ContextUtil.getMinuteOfHour(exeDate);
        if (String.valueOf(minute).equals(conf.getPushMinute11())) {
            isExecute = true;
            if (!isUpdateStart) {
                start = DateUtils.addHours(start, -1);
            }
        } else {
            isExecute = false;
        }
 
        if (!isExecute) {
            log.debug("------->>>>>>>>>> 基础数据推送---时间配置分钟不匹配");
            return;
        }
 
        log.info("------->>>>>>>>>> 基础数据推送---开始查询相关基础数据进行推送");
 
        ApiParam param = new ApiParam();
        param.setPushProtocol(conf.getPushProtocol());
        param.setKqdm(conf.getKqdm());
        param.setStart(start);
        param.setEnd(exeDate);
        param.setDeptId(conf.getDeptId());
 
 
        PushService11 pushService11 = apiPushManager.getPushService11(conf.getPushProtocol());
        pushService11.pushData(param);
    }
}