admin
2024-10-15 4995469ae28ce99f5e682895c0708d15f4dc63cd
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
package com.yeshi.fanli.service.manger;
 
import com.google.gson.Gson;
import com.yeshi.fanli.dto.push.PushContentDetailDTO;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.impl.JobThreadExecutorServiceImpl;
import com.yeshi.fanli.service.inter.lable.BoutiqueAutoRuleService;
import com.yeshi.fanli.service.inter.push.HWPushService;
import com.yeshi.fanli.util.mq.cmq.PushCMQManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
 
@Component
public class JobManager {
 
    Logger orderMoneyLog = LoggerFactory.getLogger("orderMoneyLog");
 
    @Resource
    private BoutiqueAutoRuleService boutiqueAutoRuleService;
 
 
    @Resource
    private HWPushService hwPushService;
 
    private Map<String, Long> latestRunTimeMap = new HashMap<>();
 
    class MyRunnable implements Runnable {
        private String method;
 
        public MyRunnable(String methodName) {
            this.method = methodName;
        }
 
        @Override
 
        public void run() {
            latestRunTimeMap.put(method, System.currentTimeMillis());
        }
    }
 
 
    /**
     * 开始任务
     */
    public void start() {
        initScheduler();// 启动商品更新定时任务
    }
 
    /**
     * 修复未运行的
     */
    public void repaire() {
        for (Iterator<String> its = latestRunTimeMap.keySet().iterator(); its.hasNext(); ) {
            String methodName = its.next();
            //15分钟以上的需要修复
            if (System.currentTimeMillis() - latestRunTimeMap.get(methodName).longValue() > 1000 * 60 * 15L) {
                try {
                    Method method = this.getClass().getMethod(methodName);
                    method.invoke(this);
                } catch (Exception e) {
                }
            }
        }
 
 
    }
 
    /**
     * 获取方法名称
     *
     * @param thread
     * @return
     */
    private String getMethodName(Thread thread) {
        return thread.getStackTrace()[2].getMethodName();
    }
 
    /**
     * 创建Scheduler()执行自动爬取
     */
    private void initScheduler() {
        boutiqueAutoRuleService.startScheduler();
    }
 
 
 
}