diff --git a/src/main/java/com/ifish7/tasks/job/impl/RemindJobImpl.java b/src/main/java/com/ifish7/tasks/job/impl/RemindJobImpl.java index 40d7d4d..157804d 100644 --- a/src/main/java/com/ifish7/tasks/job/impl/RemindJobImpl.java +++ b/src/main/java/com/ifish7/tasks/job/impl/RemindJobImpl.java @@ -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().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 deviceUsers = deviceUserService.list(new QueryWrapper().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