定时推送优化!

This commit is contained in:
易焱 2019-06-09 19:11:05 +08:00
parent cbfa434a27
commit 25058a6be9
1 changed files with 31 additions and 24 deletions

View File

@ -56,7 +56,7 @@ public class RemindJobImpl implements RemindJob {
@Autowired
private ITblDeviceService deviceService;
private final String pushContent = "【换水提醒】您的水族箱需要换水啦~您可以在水箱设置中更改提醒设置";
private final String pushContent = "【换水提醒】您的水族箱\"%s\"需要换水啦~您可以在水箱设置中更改提醒设置";
@Scheduled(cron = "0 0 10 * * ?")
@Override
@ -67,20 +67,19 @@ public class RemindJobImpl implements RemindJob {
.eq(TblTmpPushRemind::getRemindDate, LocalDate.now()));
final PushList pushList = new PushList();
list.forEach(tblTmpPushRemind -> {
pushList.setUserId(tblTmpPushRemind.getUserId());
pushList.setDeviceId(tblTmpPushRemind.getDeviceId());
pushList.setPhoneType("ALL");
pushList.setShowName(tblTmpPushRemind.getShowName());
pushList.setPushType(PushTypeEnum.remind_water.getKey());
pushList.setPushTitle(PushTypeEnum.remind_water.getValue());
pushList.setPushContext(pushContent);
sendPushQueueMessage(pushList);
//更新换水提醒下次时间
Date nextRemindDate = nextRemindDate(tblTmpPushRemind.getRemindCycle());
Instant instant = nextRemindDate.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
tblTmpPushRemind.setRemindDate(instant.atZone(zoneId).toLocalDate());
tmpPushRemindService.saveOrUpdate(tblTmpPushRemind);
//查询出设备对应的名称
TblDeviceUser deviceUser = deviceUserService.getOne(new QueryWrapper<TblDeviceUser>().lambda()
.eq(TblDeviceUser::getDeviceId, tblTmpPushRemind.getDeviceId())
.eq(TblDeviceUser::getUserId, tblTmpPushRemind.getUserId()));
if (deviceUser != null) {
setPushList(pushList, deviceUser);
//更新换水提醒下次时间
Date nextRemindDate = nextRemindDate(tblTmpPushRemind.getRemindCycle());
Instant instant = nextRemindDate.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
tblTmpPushRemind.setRemindDate(instant.atZone(zoneId).toLocalDate());
tmpPushRemindService.saveOrUpdate(tblTmpPushRemind);
}
});
log.info("RemindJobImpl - commDeviceChangeWater --> end");
}
@ -102,14 +101,7 @@ public class RemindJobImpl implements RemindJob {
List<TblDeviceUser> deviceUsers = deviceUserService.list(new QueryWrapper<TblDeviceUser>().lambda()
.eq(TblDeviceUser::getDeviceId, device.getDeviceId()));
deviceUsers.forEach(deviceUser -> {
pushList.setUserId(deviceUser.getUserId());
pushList.setDeviceId(deviceUser.getDeviceId());
pushList.setPhoneType("ALL");
pushList.setShowName(deviceUser.getShowName());
pushList.setPushType(PushTypeEnum.remind_water.getKey());
pushList.setPushTitle(PushTypeEnum.remind_water.getValue());
pushList.setPushContext(pushContent);
sendPushQueueMessage(pushList);
setPushList(pushList, deviceUser);
});
Date date = nextRemindDate(Integer.parseInt(tblDeviceHeaterDetail.getHeaterCycle()));
String nextRemindDate = IfishTaskUtil.format(date);
@ -117,10 +109,25 @@ public class RemindJobImpl implements RemindJob {
tblDeviceHeaterDetail.setHerterRemindDate(nextRemindDate);
deviceHeaterDetailService.updateById(tblDeviceHeaterDetail);
});
log.info("RemindJobImpl - heaterDeviceChangeWater --> end");
}
/**
* 设置pushList 推送对象
* @param pushList
* @param deviceUser
*/
private void setPushList(PushList pushList, TblDeviceUser deviceUser) {
pushList.setUserId(deviceUser.getUserId());
pushList.setDeviceId(deviceUser.getDeviceId());
pushList.setPhoneType("ALL");
pushList.setShowName(deviceUser.getShowName());
pushList.setPushType(PushTypeEnum.remind_water.getKey());
pushList.setPushTitle(PushTypeEnum.remind_water.getValue());
pushList.setPushContext(String.format(pushContent, deviceUser.getShowName()));
sendPushQueueMessage(pushList);
}
/**
* 设置下次提醒日期
* @param remindCycle