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();
|
}
|
|
|
|
}
|