优化用户统计,对已没有合作的企业不进行数据统计
This commit is contained in:
+26
@@ -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) {
|
public static void main(String[] args) {
|
||||||
System.err.println(JsonUtils.toJson(getLatelyDate(3)));
|
System.err.println(JsonUtils.toJson(getLatelyDate(3)));
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-22
@@ -2,8 +2,11 @@ package com.fangjia.job.fsh.job;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.dangdang.ddframe.job.api.simple.SimpleJob;
|
||||||
import com.fangjia.job.common.core.FangjiaThreadPoolExecutor;
|
import com.fangjia.job.common.core.FangjiaThreadPoolExecutor;
|
||||||
import com.fangjia.job.common.util.DataUtil;
|
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.common.util.DingDingMessageUtil;
|
||||||
import com.fangjia.job.fsh.document.UserStat;
|
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.EnterpriseProductUser;
|
||||||
import com.fangjia.job.fsh.po.FinancialCustomersConfig;
|
import com.fangjia.job.fsh.po.FinancialCustomersConfig;
|
||||||
import com.fangjia.job.fsh.po.LoanCustomersConfig;
|
import com.fangjia.job.fsh.po.LoanCustomersConfig;
|
||||||
import com.fangjia.job.fsh.po.PotentialCustomersFilterConfig;
|
import com.fangjia.job.fsh.po.PotentialCustomersFilterConfig;
|
||||||
import com.fangjia.job.fsh.service.CustomerStatService;
|
import com.fangjia.job.fsh.service.CustomerStatService;
|
||||||
import com.fangjia.job.fsh.service.EnterpriseProductUserService;
|
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.FinancialCustomersConfigService;
|
||||||
import com.fangjia.job.fsh.service.HouseInfoService;
|
import com.fangjia.job.fsh.service.HouseInfoService;
|
||||||
import com.fangjia.job.fsh.service.HouseSubstitutionService;
|
import com.fangjia.job.fsh.service.HouseSubstitutionService;
|
||||||
@@ -64,6 +70,9 @@ public class UserStatJob implements SimpleJob {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LoanCustomersConfigService loanCustomersConfigService;
|
private LoanCustomersConfigService loanCustomersConfigService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EnterpriseService enterpriseService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(ShardingContext shardingContext) {
|
public void execute(ShardingContext shardingContext) {
|
||||||
logger.info("开始执行UserStatJob" + shardingContext.getShardingParameter());
|
logger.info("开始执行UserStatJob" + shardingContext.getShardingParameter());
|
||||||
@@ -75,6 +84,18 @@ public class UserStatJob implements SimpleJob {
|
|||||||
final List<FinancialCustomersConfig> financialCustomersList = financialCustomersConfigService.queryAll();
|
final List<FinancialCustomersConfig> financialCustomersList = financialCustomersConfigService.queryAll();
|
||||||
// 贷款潜客分析条件
|
// 贷款潜客分析条件
|
||||||
final List<LoanCustomersConfig> LoanCustomersConfigList = loanCustomersConfigService.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();
|
long total = enterpriseProductUserService.queryCount();
|
||||||
int pages = PageBean.calcPages(total, 1000);
|
int pages = PageBean.calcPages(total, 1000);
|
||||||
final Semaphore semaphore = new Semaphore(10);
|
final Semaphore semaphore = new Semaphore(10);
|
||||||
@@ -82,30 +103,32 @@ public class UserStatJob implements SimpleJob {
|
|||||||
List<EnterpriseProductUser> users = enterpriseProductUserService.queryByPage(i, 1000);
|
List<EnterpriseProductUser> users = enterpriseProductUserService.queryByPage(i, 1000);
|
||||||
for (EnterpriseProductUser user : users) {
|
for (EnterpriseProductUser user : users) {
|
||||||
final EnterpriseProductUser u = user;
|
final EnterpriseProductUser u = user;
|
||||||
if (u.getEid() %2 == Integer.parseInt(shardingContext.getShardingParameter())) {
|
// 启用状态,有效期内才计算数据
|
||||||
try {
|
if (checkMap.get(u.getEid())) {
|
||||||
semaphore.acquire();
|
if (u.getEid() %2 == Integer.parseInt(shardingContext.getShardingParameter())) {
|
||||||
} catch (InterruptedException e1) {
|
try {
|
||||||
}
|
semaphore.acquire();
|
||||||
FangjiaThreadPoolExecutor.execute(new Runnable() {
|
} catch (InterruptedException e1) {
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user