|
|
package com.yoho.unions.server.task;
|
|
|
|
|
|
import java.net.InetAddress;
|
|
|
import java.net.UnknownHostException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
...
|
...
|
@@ -9,6 +11,7 @@ import java.util.Map; |
|
|
import java.util.concurrent.locks.Lock;
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -38,11 +41,24 @@ public class UnionClickCountDayTask { |
|
|
// 防止交错执行
|
|
|
private Lock lock = new ReentrantLock();
|
|
|
|
|
|
// 每天00:05分执行
|
|
|
@Scheduled(cron = "* 05 0 * * ?")
|
|
|
// 每天01:30分执行
|
|
|
@Scheduled(cron = "* 30 1 * * ?")
|
|
|
//@Scheduled(cron = "* 0/2 * * * ?")
|
|
|
public void run() {
|
|
|
|
|
|
try {
|
|
|
InetAddress addr = InetAddress.getLocalHost();
|
|
|
String ip = addr.getHostAddress();
|
|
|
logger.info("当前ip是:{}", ip);
|
|
|
if (!StringUtils.equals("172.31.70.253", ip)) {
|
|
|
logger.info("当前环境不是目标环境,不执行操作!");
|
|
|
return;
|
|
|
}
|
|
|
} catch (UnknownHostException e1) {
|
|
|
logger.error("获取ip地址出错!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Calendar time = Calendar.getInstance();
|
|
|
time.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
time.set(Calendar.MINUTE, 0);
|
...
|
...
|
@@ -139,7 +155,7 @@ public class UnionClickCountDayTask { |
|
|
}
|
|
|
// 把统计结果放到表里
|
|
|
logger.info("UnionClickCountDayTask run start to insert map.size={}", map.size());
|
|
|
String dayId = formatDay.format(new Date(begin * 1000L));
|
|
|
String dayId = formatDay.format(new Date(end * 1000L - 1));
|
|
|
int successCount = 0;
|
|
|
int failedCount = 0;
|
|
|
for (Map.Entry<String, UnionClickCount> entry : map.entrySet()) {
|
...
|
...
|
@@ -154,7 +170,8 @@ public class UnionClickCountDayTask { |
|
|
bean.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
bean.setComb(dayId + "_" + bean.getUnionType() + "_" + bean.getClientType());
|
|
|
|
|
|
logger.info("UnionClickCountDayTask insert bean={}", bean);
|
|
|
logger.info("UnionClickCountDayTask insert bean={}", bean.getComb() + " : " + bean.getNum());
|
|
|
|
|
|
unionClickCountDayMapper.insert(bean);
|
|
|
successCount++;
|
|
|
count += info.getNum();
|
...
|
...
|
|