add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
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
package com.dobbinsoft.fw.support.quartz;
 
import com.dobbinsoft.fw.support.component.open.OpenPlatform;
import com.dobbinsoft.fw.support.component.open.OpenPlatformStorageStrategy;
import com.dobbinsoft.fw.support.component.open.model.OPNotify;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
 
import java.util.Date;
import java.util.List;
 
/**
 * ClassName: OPQuartz
 * Description: 开放平台通知定时任务
 *
 * @author: e-weichaozheng
 * @date: 2021-04-25
 */
@EnableScheduling
@Slf4j
public class OPNotifyQuartz {
 
    @Autowired
    private OpenPlatformStorageStrategy openPlatformStorageStrategy;
 
    @Autowired
    private OpenPlatform openPlatform;
 
    /**
     * 每秒执行一次的最大努力通知
     */
    @Scheduled(fixedRate = 1)
    public void tryNotify() {
        if (!openPlatformStorageStrategy.customTryNotify()) {
            List<OPNotify> needNotify = openPlatformStorageStrategy.getNeedNotify();
            for (OPNotify notify : needNotify) {
                try {
                    int res = openPlatform.sendNotify(notify);
                    OPNotify opNotify = new OPNotify();
                    opNotify.setNextNotify(new Date(System.currentTimeMillis() + 1000L * 60 * (long) Math.pow(2, notify.getTimes())));
                    opNotify.setTimes(notify.getTimes() + 1);
                    opNotify.setStatus(res);
                    opNotify.setId(notify.getId());
                    openPlatformStorageStrategy.updateNotify(opNotify);
                } catch (Exception e) {
                    log.error("[最大努力通知 定时任务] Item异常", e);
                }
            }
        }
    }
 
}