发表于: 2017-10-31 22:23:30

1 718


今天完成的事情:

1.完成另外的定时任务

债权投满警戒线

public void process() {
try {
/* 第一步、使用中的原始债权集合 */
       List<Credit> credits = getUseingCredit();
if (CollectionUtils.isEmpty(credits)) {
log.info("CreditMatchedPersentSendMsg not get any useing credits");
}
/* 第二步、处理逻辑 */
       processForUseingCredit(credits);
}
catch (Throwable t) {
log.error("CreditMatchedPersentSendMsg error", t);
}
}

private void processForUseingCredit(List<Credit> credits)
throws ServiceException, ServiceDaoException {
log.info("method processForCredits begin...");
List<CreditSplit> notMatchedCreditList = new ArrayList<>();
BigDecimal notMatchedAmount = BigDecimal.ZERO, totalMatchedPersent = BigDecimal.ZERO,
totalNotMatchedAmount = BigDecimal.ZERO, totalAmount = BigDecimal.ZERO;
for (Credit credit : credits) {
/* 第一步、累加各个原始债权未匹配的金额 */
       notMatchedCreditList = splitService.getNotMatchedCreditSplitList(credit.getId());
log.info("notMatchedCreditList size is: " + notMatchedCreditList.size());
notMatchedAmount = calcNotMatchedAmount(notMatchedCreditList);
log.info("notMatchedAmount is: " + notMatchedAmount);
totalNotMatchedAmount = totalNotMatchedAmount.add(notMatchedAmount);
totalAmount = totalAmount.add(credit.getAmount());
}
totalMatchedPersent = BigDecimal.ONE
           .subtract(totalNotMatchedAmount.divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP));
// totalMatchedPersent = new BigDecimal("0.71"); //测试用
   totalMatchedPersent = totalMatchedPersent.multiply(new BigDecimal("100"));
log.info("matchedPersent is: " + totalMatchedPersent + "%");
/* 第二步、如果大于设定值,则给相应人发短信 */
   if (totalMatchedPersent.compareTo(persent) >= 0) {
sendMsg();
}
log.info("method processForCredits end...");
}


投资到期提醒

主要逻辑先获取数据,然后再执行对数据的操作,如果获取不到数据了,就将线程置为休眠,再从常量表中获取投资到期提醒天数,然后计算时间戳,接着根据时间戳和状态,以及是否发送消息等字段动态查询invest表,最后返回。

public void process() throws InterruptedException {
while (true) {
try {
List<Invest> invests = getImmediateExpireInvests();
if (CollectionUtils.isEmpty(invests)) {
log.info("getImmediateExpireInvests no data, sleep " + SLEEP_MILLISECOND + " ms");
Thread.sleep(SLEEP_MILLISECOND);
}
processForData(invests);
}
catch (Throwable t) {
log.error("InvestEndPushMsg error", t);
Thread.sleep(SLEEP_MILLISECOND);
}
}
}

private void processForData(List<Invest> invests) throws ServiceException, ServiceDaoException {
for (Invest invest : invests) {
/* 第一步、推送消息 */
       pushMsg(invest);
/* 第二步、维护invest表的字段 */
       invest.setHasPushMsg(true);
investService.update(invest);
log.info("update invest hasPushMsg true success");
}
}

private void pushMsg(Invest invest) throws ServiceException, ServiceDaoException {
Long uid = invest.getUserId();
User user = userService.getObjectById(uid);
Orders orders = ordersService.getObjectById(invest.getOrdersId());
rMessage message = new Message();
message.setUid(uid);
message.setTitle("投资即将到期");
message.setSummary("您的" + orders.getProductName() + "投资还剩" + days + "天即将到期");
message.setInvestId(invest.getId());
message.setStatus(Message.UNREAD);
message.setType(Message.PERSON_TYPE);
Long messageId = messageService.insert(message);
log.info(" uid " + uid + " invest immediate expire msg push success ,messageId = " + messageId);
messageService.sendNoticeUnicast(message, user.getDeviceToken(), user.getOs());

}

private List<Invest> getImmediateExpireInvests() throws ServiceException, ServiceDaoException {
List<Invest> invests = new ArrayList<>();
days = getDays();
Map<String, Object> params = DynamicUtil.getImmediateExpireInvests(days);
List<Long> ids = investService.getIdsByDynamicCondition(Invest.class, params, 0, TASK_LEN);
if (CollectionUtils.isEmpty(ids)) {
log.info("getImmediateExpireInvests ids is empty");
}
else {
invests = investService.getObjectsByIds(ids);
log.info("getImmediateExpireInvests invests size: " + invests.size());
}
return invests;
}

private int getDays() throws ServiceException, ServiceDaoException {
Long constantId = constantService.getConstantIdByKey("investDeadlineDays");
Constant investDeadlineDays = constantService.getObjectById(constantId);
String value = investDeadlineDays.getValue();
log.info("days is: " + value);
return new Integer(value);
}

明天计划的事情:完成定时任务

遇到的问题:暂无

收获:学习定时任务


返回列表 返回列表
评论

    分享到