发表于: 2017-10-31 22:11:37
1 811
一.今天完成的主要事情
1.完成批量任务中的其他三个功能的实现
第一个,投资到期提醒,process方法如下:
public void process() throws InterruptedException {
while (true) {
try {
//获取数据
List<UserProductRelation> userProductRelations = getUserProductRelationData();
if (CollectionUtils.isNotEmpty(userProductRelations)) {
//执行对数据的操作,操作完毕之后继续获取数据
processForData(userProductRelations);
continue;
}
log.info("InvestRemindEtl not get any data, sleep " + SLEEP_MILLISECOND + "ms");
Thread.sleep(SLEEP_MILLISECOND);
} catch (Throwable t) {
t.printStackTrace();
log.error(t.getMessage());
log.error("InvestRemindEtl process() error!");
Thread.sleep(SLEEP_MILLISECOND);
}
}
}
主要就是先获取数据,然后再执行对数据的操作,如果获取不到数据了,就将线程置为休眠
获取数据的代码为:
private List<UserProductRelation> getUserProductRelationData() throws ServiceException, ServiceDaoException, ParseException {
List<UserProductRelation> userProductRelations = null;
//获取投资到期提醒天数,并计算出应该提醒的时间范围
Long constantId = constantService.getConstantIdByStatus(0);
if (DataUtils.isNullOrEmpty(constantId)){
return userProductRelations;
}
Constant constant = constantService.getObjectById(constantId);
if (DataUtils.isNullOrEmpty(constant)){
return userProductRelations;
}
long remindTime = System.currentTimeMillis() + constant.getInvestRemindDays()*OtherUtil.MILLISECOND_OF_ONE_DAY;
//根据条件查询user_product_relation表中应该提醒的产品List返回
Map<String, Object> map = DynamicUtil.getUserProductRelationListByStatusAndHasSendMsgAndDueDate(remindTime,
UserProductRelation.STATUS_INVESTING,
UserProductRelation.SEND_MESSAGE_NOT, false);
List<Long> userProductRelationIds = userProductRelationService.getIdsByDynamicCondition(UserProductRelation.class,
map, 0, TASK_LEN);
if (CollectionUtils.isNotEmpty(userProductRelationIds)){
userProductRelations = userProductRelationService.getObjectsByIds(userProductRelationIds);
}
return userProductRelations;
}
主要逻辑是先从常量表中获取投资到期提醒天数,然后计算时间戳,接着根据时间戳和状态,以及是否发送消息等字段动态查询userProductRelation表,最后返回
然后是对数据的处理,该方法只对数据做处理,所以没有返回值
private void processForData(List<UserProductRelation> userProductRelations) throws ServiceException, ServiceDaoException{
for (UserProductRelation userProductRelation: userProductRelations) {
Long productId = userProductRelation.getProductId();
Long userId = userProductRelation.getUserId();
//获取产品对象和用户对象
Product product = productService.getObjectById(productId);
User user = userService.getObjectById(userId);
//新增一条消息
Message message = OtherUtil.createAutoMessage(userId, userProductRelation.getId(), product, "即将到期",
Message.AUTOMESSAGE_INVEST_EXPIRING);
messageService.insert(message);
//设置userproductRelation对象的hasSendMsg字段为已发送
userProductRelation.setHasSendMsg(UserProductRelation.SEND_MESSAGE_ALREADY);
userProductRelationService.update(userProductRelation);
//设置用户的未读消息数加1
user.setMessageChecked(user.getMessageChecked() +1);
userService.update(user);
}
}
主要逻辑是先获取产品对象和用户对象,然后根据这两个对象新增一条消息,接着更新用户表
2.完成了债权到期提醒和总债券匹配提醒
债权到期提醒和总债券匹配提醒和投资到期提醒有所区别,这两个功能要求每天执行,而且只执行一次,而投资到期提醒则是每隔一段时间就执行,一天之中可能会执行很多次,所以有一定的区别
因为这两个功能基本类似,所以将这两个功能都放在一个类中
首先是process()方法
public void process() throws InterruptedException {
try {
//获取数据
long count = getCreditData();
//如果不为0,则执行单个债权匹配情况
if (count != 0) {
processForSingle(count);
}
//执行总债券匹配情况
processForAll();
} catch (Throwable t) {
t.printStackTrace();
log.error(t.getMessage());
log.error("CreditRemindEtl process() error!");
}
}
该方法中不再有循环,每天就执行一次,不论成功或者失败
至于processForSingle和processForAll方法,都是涉及到一些逻辑实现,这里就不再贴出了,只是需要注意的是实现这种功能,在配置文件中要配置不同的定时任务执行器
如图:
3.对昨天的到期回款功能进行了拆分重构,具体是将该功能拆分为两个类
具体的代码就不贴了
二.明天计划完成的事情
1.完成最后一个跑批任务
2.对整个跑批任务进行进一步的优化
3.如果有时间,继续实现上传文件功能接口
三.遇到的问题
暂无
四.收获
又明白了一种定时任务的用法
五,项目进度情况
自己负责的任务应该能够在规定的时间内完成,项目已经延期到了11月5号,但愿不会再继续延期
评论