diff --git a/admin/src/main/resources/templates/consumableDueEmailTemp.ftl b/admin/src/main/resources/templates/consumableDueEmailTemp.ftl index 4387be1..e5512ee 100644 --- a/admin/src/main/resources/templates/consumableDueEmailTemp.ftl +++ b/admin/src/main/resources/templates/consumableDueEmailTemp.ftl @@ -28,7 +28,8 @@ Dear ${nickName} : -

以下设备耗材即将到达使用效期,请及时处理!

+
+

以下设备耗材即将到达使用效期或已过使用效期,请及时处理!

@@ -43,22 +44,43 @@ Dear ${nickName} : - <#if dueConsumables ?? && (dueConsumables ?size > 0) > - <#list dueConsumables as consumable > - - - - - - - - - - - - + <#if overDueNotices ?? && (overDueNotices ?size > 0) > + + + + <#list overDueNotices as consumable > + + + + + + + + + + + + + <#if dueNotices ?? && (dueNotices ?size > 0) > + + + + <#list dueNotices as consumable > + + + + + + + + + + + +
${consumable.consumableNo}${consumable.consumableName}${consumable.equipmentName}${consumable.equipmentNo}${consumable.equipmentDept}${consumable.equipmentLocation}${consumable.activationTime?string("yyyy-MM-dd")}${consumable.dueTime?string("yyyy-MM-dd")}
已过期
${consumable.consumableNo}${consumable.consumableName}${consumable.equipmentName}${consumable.equipmentNo}${consumable.equipmentDept}${consumable.equipmentLocation}${consumable.activationTime?string("yyyy-MM-dd")}${consumable.dueTime?string("yyyy-MM-dd")}
即将到期
${consumable.consumableNo}${consumable.consumableName}${consumable.equipmentName}${consumable.equipmentNo}${consumable.equipmentDept}${consumable.equipmentLocation}${consumable.activationTime?string("yyyy-MM-dd")}${consumable.dueTime?string("yyyy-MM-dd")}
+

该邮件为系统自动发送,请勿回复

diff --git a/system/src/main/java/com/eqc/system/mapper/EquipmentConsumablesMapper.java b/system/src/main/java/com/eqc/system/mapper/EquipmentConsumablesMapper.java index d60df26..e4fa4bb 100644 --- a/system/src/main/java/com/eqc/system/mapper/EquipmentConsumablesMapper.java +++ b/system/src/main/java/com/eqc/system/mapper/EquipmentConsumablesMapper.java @@ -18,10 +18,11 @@ import java.util.List; public interface EquipmentConsumablesMapper extends BaseMapperPlus { /** - * 获取即将到期需要提醒的耗材 - * @param date 与到期时间相比较,查询出距离到期时间还有一段时间的耗材 + * 获取即将到期需要提醒的耗材 到期时间处于 beginDate 和 endDate 之间的耗材 + * @param beginDate + * @param endDate * @return */ - List selectNoticeList(@Param("date") Date date); + List selectNoticeList(@Param("beginDate") Date beginDate,@Param("endDate") Date endDate); } diff --git a/system/src/main/java/com/eqc/system/service/impl/EquipmentConsumablesServiceImpl.java b/system/src/main/java/com/eqc/system/service/impl/EquipmentConsumablesServiceImpl.java index 59703d5..dc9013b 100644 --- a/system/src/main/java/com/eqc/system/service/impl/EquipmentConsumablesServiceImpl.java +++ b/system/src/main/java/com/eqc/system/service/impl/EquipmentConsumablesServiceImpl.java @@ -1,6 +1,7 @@ package com.eqc.system.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import com.eqc.common.utils.DateUtils; import com.eqc.common.utils.StreamUtils; @@ -11,7 +12,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.eqc.common.utils.email.MailUtils; +import com.eqc.common.utils.spring.SpringUtils; import com.eqc.system.domain.dto.ConsumableNoticeDto; +import com.eqc.system.service.ISysConfigService; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -163,14 +166,17 @@ public class EquipmentConsumablesServiceImpl implements IEquipmentConsumablesSer } /** - * 设备到期提醒 提前七天开始提醒 + * 设备即将到期提醒 提前七天开始提醒,已过期的不再提醒 */ @Override public void dueNotice() { + //获取到期的耗材是否继续提醒 + boolean isOverDueNotice = Convert.toBool(SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.consumable.overDueNotices")); //当前时间+7天 String subject = "设备耗材即将到期提醒"; - Date date = DateUtils.addDays(DateUtils.beginOfDay(DateUtils.getNowDate()), 7); - List consumableNotices = baseMapper.selectNoticeList(date); + Date today = DateUtils.beginOfDay(DateUtils.getNowDate()); + Date afterSevenDays = DateUtils.addDays(today, 7); + List consumableNotices = baseMapper.selectNoticeList(isOverDueNotice ? null : today, afterSevenDays); if (consumableNotices.isEmpty()){ log.warn("当前没有即将到期的耗材"); return; @@ -180,10 +186,16 @@ public class EquipmentConsumablesServiceImpl implements IEquipmentConsumablesSer ConsumableNoticeDto notice = notices.get(0); String email = notice.getChargeUserEmail(); String chargeNickName = notice.getChargeNickName(); + //拆分即将过期和已过期的 + //已过期的 + List overDueNotices = StreamUtils.filter(notices, (n -> n.getDueTime().before(today))); + //即将过期的 + List dueNotices = StreamUtils.filter(notices, (n -> n.getDueTime().after(today))); //构建html Map root = new HashMap<>(); root.put("nickName", chargeNickName); - root.put("dueConsumables", notices); + root.put("overDueNotices", overDueNotices); + root.put("dueNotices", dueNotices); String content = buildMailContent(root, "consumableDueEmailTemp.ftl"); if (StringUtils.isEmpty(content)){ log.error("邮件内容构建失败,邮件未发送"); diff --git a/system/src/main/resources/mapper/system/EquipmentConsumablesMapper.xml b/system/src/main/resources/mapper/system/EquipmentConsumablesMapper.xml index 21173f1..bc345b3 100644 --- a/system/src/main/resources/mapper/system/EquipmentConsumablesMapper.xml +++ b/system/src/main/resources/mapper/system/EquipmentConsumablesMapper.xml @@ -45,7 +45,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join sys_user u on u.user_id = c.charge_user left join sys_dept dept on e.department = dept.dept_id where u.del_flag = '0' and dept.del_flag = '0' - and c.status = '0' and c.due_time <= #{date} + and c.status = '0' and c.due_time <= #{endDate} + + and c.due_time >= #{beginDate} +