优化用户统计,对已没有合作的企业不进行数据统计

This commit is contained in:
尹吉欢
2018-06-04 11:26:08 +08:00
parent 8cd3b0cfe6
commit 4739773fa9
2 changed files with 71 additions and 22 deletions
@@ -154,6 +154,32 @@ public class DateUtilCustom {
}
}
/**
* 判断time是否在from,to之内
*
* @param time 指定日期
* @param from 开始日期
* @param to 结束日期
* @return
*/
public static boolean belongCalendar(Date time, Date from, Date to) {
Calendar date = Calendar.getInstance();
date.setTime(time);
Calendar after = Calendar.getInstance();
after.setTime(from);
Calendar before = Calendar.getInstance();
before.setTime(to);
if (date.after(after) && date.before(before)) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
System.err.println(JsonUtils.toJson(getLatelyDate(3)));
}
@@ -2,8 +2,11 @@ package com.fangjia.job.fsh.job;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,14 +16,17 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.fangjia.job.common.core.FangjiaThreadPoolExecutor;
import com.fangjia.job.common.util.DataUtil;
import com.fangjia.job.common.util.DateUtilCustom;
import com.fangjia.job.common.util.DingDingMessageUtil;
import com.fangjia.job.fsh.document.UserStat;
import com.fangjia.job.fsh.po.Enterprise;
import com.fangjia.job.fsh.po.EnterpriseProductUser;
import com.fangjia.job.fsh.po.FinancialCustomersConfig;
import com.fangjia.job.fsh.po.LoanCustomersConfig;
import com.fangjia.job.fsh.po.PotentialCustomersFilterConfig;
import com.fangjia.job.fsh.service.CustomerStatService;
import com.fangjia.job.fsh.service.EnterpriseProductUserService;
import com.fangjia.job.fsh.service.EnterpriseService;
import com.fangjia.job.fsh.service.FinancialCustomersConfigService;
import com.fangjia.job.fsh.service.HouseInfoService;
import com.fangjia.job.fsh.service.HouseSubstitutionService;
@@ -64,6 +70,9 @@ public class UserStatJob implements SimpleJob {
@Autowired
private LoanCustomersConfigService loanCustomersConfigService;
@Autowired
private EnterpriseService enterpriseService;
@Override
public void execute(ShardingContext shardingContext) {
logger.info("开始执行UserStatJob" + shardingContext.getShardingParameter());
@@ -75,6 +84,18 @@ public class UserStatJob implements SimpleJob {
final List<FinancialCustomersConfig> financialCustomersList = financialCustomersConfigService.queryAll();
// 贷款潜客分析条件
final List<LoanCustomersConfig> LoanCustomersConfigList = loanCustomersConfigService.queryAll();
// 存储企业的状态,是否需要处理企业下的用户数据
Map<Long,Boolean> checkMap = new ConcurrentHashMap<Long,Boolean>();
List<Enterprise> enList = enterpriseService.queryByPage(1, 2000);
for (Enterprise enterprise : enList) {
//有效期
if (enterprise.getStatus() == 1 && DateUtilCustom.belongCalendar(new Date(), enterprise.getStartDate(), DateUtils.addDays(enterprise.getEndDate(), 1))) {
checkMap.put(enterprise.getId(), true);
} else {
checkMap.put(enterprise.getId(), false);
}
}
long total = enterpriseProductUserService.queryCount();
int pages = PageBean.calcPages(total, 1000);
final Semaphore semaphore = new Semaphore(10);
@@ -82,31 +103,33 @@ public class UserStatJob implements SimpleJob {
List<EnterpriseProductUser> users = enterpriseProductUserService.queryByPage(i, 1000);
for (EnterpriseProductUser user : users) {
final EnterpriseProductUser u = user;
if (u.getEid() %2 == Integer.parseInt(shardingContext.getShardingParameter())) {
try {
semaphore.acquire();
} catch (InterruptedException e1) {
}
FangjiaThreadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
try {
processStat(u);
// 理财和贷款潜客统计
customerStatService.customerStat(u, financiaFilterConfig, loanFilterConfig, financialCustomersList, LoanCustomersConfigList);
} catch (Exception e) {
logger.error("用户维度统计任务异常", e);
DingDingMessageUtil.sendTextMessage("用户维度统计任务异常:" + e.getMessage());
} finally {
semaphore.release();
}
// 启用状态,有效期内才计算数据
if (checkMap.get(u.getEid())) {
if (u.getEid() %2 == Integer.parseInt(shardingContext.getShardingParameter())) {
try {
semaphore.acquire();
} catch (InterruptedException e1) {
}
});
FangjiaThreadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
try {
processStat(u);
// 理财和贷款潜客统计
customerStatService.customerStat(u, financiaFilterConfig, loanFilterConfig, financialCustomersList, LoanCustomersConfigList);
} catch (Exception e) {
logger.error("用户维度统计任务异常", e);
DingDingMessageUtil.sendTextMessage("用户维度统计任务异常:" + e.getMessage());
} finally {
semaphore.release();
}
}
});
}
}
}
}
logger.info("UserStatJob执行结束");