Merge branch 'FSHJOB1.2' into 'master'

Fshjob1.2

See merge request !27
This commit is contained in:
虞继恩
2018-06-04 11:26:36 +08:00
4 changed files with 77 additions and 29 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,30 +103,32 @@ 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();
}
}
});
}
}
}
}
@@ -27,11 +27,12 @@ public class NewsPushJob implements SimpleJob {
@Override
public void execute(ShardingContext shardingContext) {
try {
String time = DateUtils.date2Str(new Date(), "yyyy-MM-dd HH");
time = time + ":00:00";
String time = DateUtils.date2Str(new Date(), "yyyy-MM-dd HH:mm");
time = time + ":00";
logger.info("开始执行新闻定时发布:"+ time);
newsService.pushNews(time);
newsService.offlineNews(time);
logger.info("结束执行新闻定时发布:"+ time);
} catch (Exception e) {
logger.error("新闻定时发布和下架任务异常", e);
DingDingMessageUtil.sendTextMessage("新闻定时发布和下架任务异常:" + e.getMessage());
@@ -103,14 +103,12 @@
</job:simple>
<!-- 有房小新闻定时发布 每小时执行一次 -->
<!-- 有房小新闻定时发布 每分钟执行一次 -->
<job:simple id="newsPushJob" class="com.fangjia.job.youfang.job.NewsPushJob" registry-center-ref="regCenter"
sharding-total-count="1" cron="0 0 * * * ?" sharding-item-parameters=""
failover="true" description="【有房】 有房小新闻定时发布 每小时执行一次"
sharding-total-count="1" cron="0/60 * * * * ?" sharding-item-parameters=""
failover="true" description="【有房】 有房小新闻定时发布 每分钟执行一次"
overwrite="true" event-trace-rdb-data-source="elasticJobLog" job-exception-handler="com.fangjia.job.youfang.handler.CustomJobExceptionHandler">
<job:listener class="com.fangjia.job.youfang.listener.MessageElasticJobListener"></job:listener>
</job:simple>
<!-- 有房小区详情缓存刷新任务