|
|
|
@@ -40,18 +40,18 @@ public class InvestSchedule { |
|
|
|
@Autowired |
|
|
|
Environment environment; |
|
|
|
|
|
|
|
private static final String PREFIX = "招商定时任务"; |
|
|
|
private static final String SCHEDULE_TAG = "招商定时任务"; |
|
|
|
|
|
|
|
|
|
|
|
//@Scheduled(cron = "0 0 14 * * ?") // 每天下午两点执行定时任务 |
|
|
|
@Scheduled(cron = "0 */30 * * * *?") // 测试,每5分钟执行 |
|
|
|
public void messageSchedule() { |
|
|
|
log.info("{}: 开始", PREFIX); |
|
|
|
log.info("{}: 开始", SCHEDULE_TAG); |
|
|
|
//一个月内未完成提醒 |
|
|
|
taskMonthMessage(); |
|
|
|
//一周内未跟踪提醒 |
|
|
|
demandWeekMessage(); |
|
|
|
log.info("{}: 结束", PREFIX); |
|
|
|
log.info("{}: 结束", SCHEDULE_TAG); |
|
|
|
} |
|
|
|
|
|
|
|
private void taskMonthMessage() { |
|
|
|
@@ -69,14 +69,14 @@ public class InvestSchedule { |
|
|
|
} |
|
|
|
//查询满足条件 |
|
|
|
List<InvestTaskEntity> tasks = taskService.listByStatusAndTime(Arrays.asList(EnumTaskStatus.INTENTION, EnumTaskStatus.NEGOTIATING), start.getTime(), end.getTime()); |
|
|
|
log.info("{}:{} - {} 的任务数 :{}", PREFIX, start, end, tasks.size()); |
|
|
|
log.info("{}:{} - {} 的任务数 :{}", SCHEDULE_TAG, start, end, tasks.size()); |
|
|
|
if (tasks.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
for (InvestTaskEntity task : tasks) { |
|
|
|
String owner = task.getOwner(); |
|
|
|
if (StringUtils.isEmpty(owner)) { |
|
|
|
log.warn("{}:taskID:{} owner不存在:{}, 跳过", PREFIX, task.getId(), task.getOwner()); |
|
|
|
log.warn("{}:taskID:{} owner不存在:{}, 跳过", SCHEDULE_TAG, task.getId(), task.getOwner()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
List<Long> ownerArray = JSONArray.parseArray(owner, Long.class); |
|
|
|
@@ -85,7 +85,7 @@ public class InvestSchedule { |
|
|
|
if (CollectionUtils.isNotEmpty(messageList)) { |
|
|
|
for (InvestMessageEntity messageEntity : messageList) { |
|
|
|
if (messageEntity.getTid().equals(task.getId())) { |
|
|
|
log.info("{}:taskID:{} 提醒已存在:{}, 跳过", PREFIX, task.getId(), messageEntity.getId()); |
|
|
|
log.info("{}:taskID:{} 提醒已存在:{}, 跳过", SCHEDULE_TAG, task.getId(), messageEntity.getId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
addTaskMessage(task, ownerArray); |
|
|
|
@@ -100,7 +100,7 @@ public class InvestSchedule { |
|
|
|
private void addTaskMessage(InvestTaskEntity task, List<Long> ownerArray) { |
|
|
|
String message = String.format(EnumInvestMessageType.TASK_REMIND.getInfo(), task.getId(), DateUtils.format(task.getLastTime())); |
|
|
|
messageService.saveBatchMessage(ownerArray, message, EnumInvestMessageTag.TASK_MONTH, EnumFollowType.TASK, task.getId(),task.getTenantId()); |
|
|
|
log.info("{}:taskID:{} 为用户{}创建消息提醒", PREFIX, task.getId(), task.getOwner()); |
|
|
|
log.info("{}:taskID:{} 为用户{}创建消息提醒", SCHEDULE_TAG, task.getId(), task.getOwner()); |
|
|
|
} |
|
|
|
|
|
|
|
private void demandWeekMessage() { |
|
|
|
@@ -111,9 +111,9 @@ public class InvestSchedule { |
|
|
|
//初始化时间条件 |
|
|
|
Calendar start = Calendar.getInstance(); |
|
|
|
if (environment.acceptsProfiles(ENV_STR)) { |
|
|
|
start.add(Calendar.DAY_OF_YEAR, 1); //测试 |
|
|
|
start.add(Calendar.DAY_OF_YEAR, -1); //测试 |
|
|
|
} else { |
|
|
|
start.add(Calendar.DAY_OF_YEAR, 7); |
|
|
|
start.add(Calendar.DAY_OF_YEAR, -7); |
|
|
|
} |
|
|
|
|
|
|
|
//查询跟踪列表 |
|
|
|
@@ -122,14 +122,12 @@ public class InvestSchedule { |
|
|
|
List<InvestCustomerVo> demands = customerService.listByIds(InvestHelper.getIds(follows, InvestFollowRecordEntity::getFollowId), |
|
|
|
Arrays.asList(EnumCustomerType.INTENTIONAL, EnumCustomerType.POTENTIAL)); |
|
|
|
|
|
|
|
/** |
|
|
|
* 已经已经提醒过的用户 |
|
|
|
*/ |
|
|
|
// 已经提醒过的用户 |
|
|
|
List<String> userDemandFlag = new ArrayList<>(); |
|
|
|
for (InvestCustomerVo customerVo : demands) { |
|
|
|
Long owner = customerVo.getDemandOwner(); |
|
|
|
if (Objects.isNull(owner)) { |
|
|
|
log.warn("{}:customerID:{} owner不存在:{}, 跳过", PREFIX, customerVo.getId(), customerVo.getDemandOwner()); |
|
|
|
log.warn("{}:customerID:{} owner不存在:{}, 跳过", SCHEDULE_TAG, customerVo.getId(), customerVo.getDemandOwner()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
List<InvestMessageEntity> messageList = demandMessageUserIdMap.get(owner); |
|
|
|
@@ -138,13 +136,13 @@ public class InvestSchedule { |
|
|
|
} |
|
|
|
for (InvestMessageEntity messageEntity : messageList) { |
|
|
|
if (messageEntity.getTid().equals(messageEntity.getId())) { |
|
|
|
log.info("{}:taskID:{} 提醒已存在:{}, 跳过", PREFIX, customerVo.getId(), messageEntity.getId()); |
|
|
|
log.info("{}:taskID:{} 提醒已存在:{}, 跳过", SCHEDULE_TAG, customerVo.getId(), messageEntity.getId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
String userDemandFlagItem = StringUtils.join(messageEntity.getOwner(), messageEntity.getId()); |
|
|
|
//已经提醒过的用户不在提醒 |
|
|
|
if (userDemandFlag.contains(userDemandFlagItem)) { |
|
|
|
log.info("{}:taskID:{} 提醒已存在:{}, 跳过", PREFIX, customerVo.getId(), userDemandFlagItem); |
|
|
|
log.info("{}:taskID:{} 提醒已存在:{}, 跳过", SCHEDULE_TAG, customerVo.getId(), userDemandFlagItem); |
|
|
|
continue; |
|
|
|
} |
|
|
|
addCustomerMessage(customerVo, owner); |
|
|
|
@@ -156,6 +154,6 @@ public class InvestSchedule { |
|
|
|
private void addCustomerMessage(InvestCustomerVo customerVo, Long owner) { |
|
|
|
String message = String.format(EnumInvestMessageType.COSTOMER_REMIND.getInfo(), customerVo.getId()); |
|
|
|
messageService.saveBatchMessage(Arrays.asList(owner), message, EnumInvestMessageTag.CUSTOMER_WEEK, EnumFollowType.DEMAND, customerVo.getId(),customerVo.getTenantId()); |
|
|
|
log.info("{}:customerID:{} 为用户{}创建消息提醒", PREFIX, customerVo.getId(), customerVo.getDemandOwner()); |
|
|
|
log.info("{}:customerID:{} 为用户{}创建消息提醒", SCHEDULE_TAG, customerVo.getId(), customerVo.getDemandOwner()); |
|
|
|
} |
|
|
|
} |