[fix]调整到期提醒策略,新增已过期的设备可以关闭提醒的功能

This commit is contained in:
yunpeng.zhang 2024-01-17 13:33:43 +08:00
parent 934dae7c4c
commit 26a28178bb
4 changed files with 61 additions and 23 deletions

View File

@ -28,7 +28,8 @@
</head> </head>
<body style="padding: 10px;"> <body style="padding: 10px;">
Dear ${nickName} : Dear ${nickName} :
<p style="padding-left: 30px;">以下设备耗材即将到达使用效期,请及时处理!</p> <div style="padding-left: 20px;">
<p><strong>以下设备耗材即将到达使用效期或已过使用效期,请及时处理!</strong></p>
<table style="width:833pt"> <table style="width:833pt">
<thead> <thead>
<tr style="background:#3498db;"> <tr style="background:#3498db;">
@ -43,22 +44,43 @@ Dear ${nickName} :
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<#if dueConsumables ?? && (dueConsumables ?size > 0) > <#if overDueNotices ?? && (overDueNotices ?size > 0) >
<#list dueConsumables as consumable > <tr>
<tr> <th colspan="8" style="background:#f56c6c;text-align: center;">已过期</th>
<td>${consumable.consumableNo}</td> </tr>
<td>${consumable.consumableName}</td> <#list overDueNotices as consumable >
<td>${consumable.equipmentName}</td> <tr>
<td>${consumable.equipmentNo}</td> <td>${consumable.consumableNo}</td>
<td>${consumable.equipmentDept}</td> <td>${consumable.consumableName}</td>
<td>${consumable.equipmentLocation}</td> <td>${consumable.equipmentName}</td>
<td>${consumable.activationTime?string("yyyy-MM-dd")}</td> <td>${consumable.equipmentNo}</td>
<td style="background: #e74c3c">${consumable.dueTime?string("yyyy-MM-dd")}</td> <td>${consumable.equipmentDept}</td>
</tr> <td>${consumable.equipmentLocation}</td>
</#list> <td>${consumable.activationTime?string("yyyy-MM-dd")}</td>
</#if> <td style="background: #e74c3c">${consumable.dueTime?string("yyyy-MM-dd")}</td>
</tr>
</#list>
</#if>
<#if dueNotices ?? && (dueNotices ?size > 0) >
<tr>
<th colspan="8" style="background:#e6a23c;text-align: center;">即将到期</th>
</tr>
<#list dueNotices as consumable >
<tr>
<td>${consumable.consumableNo}</td>
<td>${consumable.consumableName}</td>
<td>${consumable.equipmentName}</td>
<td>${consumable.equipmentNo}</td>
<td>${consumable.equipmentDept}</td>
<td>${consumable.equipmentLocation}</td>
<td>${consumable.activationTime?string("yyyy-MM-dd")}</td>
<td style="background: #ebb768">${consumable.dueTime?string("yyyy-MM-dd")}</td>
</tr>
</#list>
</#if>
</tbody> </tbody>
</table> </table>
</div>
<hr> <hr>
<p style="font-size: 13px;"><i>该邮件为系统自动发送,请勿回复</i></p> <p style="font-size: 13px;"><i>该邮件为系统自动发送,请勿回复</i></p>
</body> </body>

View File

@ -18,10 +18,11 @@ import java.util.List;
public interface EquipmentConsumablesMapper extends BaseMapperPlus<EquipmentConsumablesMapper, EquipmentConsumables, EquipmentConsumablesVo> { public interface EquipmentConsumablesMapper extends BaseMapperPlus<EquipmentConsumablesMapper, EquipmentConsumables, EquipmentConsumablesVo> {
/** /**
* 获取即将到期需要提醒的耗材 * 获取即将到期需要提醒的耗材 到期时间处于 beginDate endDate 之间的耗材
* @param date 与到期时间相比较查询出距离到期时间还有一段时间的耗材 * @param beginDate
* @param endDate
* @return * @return
*/ */
List<ConsumableNoticeDto> selectNoticeList(@Param("date") Date date); List<ConsumableNoticeDto> selectNoticeList(@Param("beginDate") Date beginDate,@Param("endDate") Date endDate);
} }

View File

@ -1,6 +1,7 @@
package com.eqc.system.service.impl; package com.eqc.system.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.eqc.common.utils.DateUtils; import com.eqc.common.utils.DateUtils;
import com.eqc.common.utils.StreamUtils; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eqc.common.utils.email.MailUtils; 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.domain.dto.ConsumableNoticeDto;
import com.eqc.system.service.ISysConfigService;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
@ -163,14 +166,17 @@ public class EquipmentConsumablesServiceImpl implements IEquipmentConsumablesSer
} }
/** /**
* 设备到期提醒 提前七天开始提醒 * 设备即将到期提醒 提前七天开始提醒,已过期的不再提醒
*/ */
@Override @Override
public void dueNotice() { public void dueNotice() {
//获取到期的耗材是否继续提醒
boolean isOverDueNotice = Convert.toBool(SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.consumable.overDueNotices"));
//当前时间+7天 //当前时间+7天
String subject = "设备耗材即将到期提醒"; String subject = "设备耗材即将到期提醒";
Date date = DateUtils.addDays(DateUtils.beginOfDay(DateUtils.getNowDate()), 7); Date today = DateUtils.beginOfDay(DateUtils.getNowDate());
List<ConsumableNoticeDto> consumableNotices = baseMapper.selectNoticeList(date); Date afterSevenDays = DateUtils.addDays(today, 7);
List<ConsumableNoticeDto> consumableNotices = baseMapper.selectNoticeList(isOverDueNotice ? null : today, afterSevenDays);
if (consumableNotices.isEmpty()){ if (consumableNotices.isEmpty()){
log.warn("当前没有即将到期的耗材"); log.warn("当前没有即将到期的耗材");
return; return;
@ -180,10 +186,16 @@ public class EquipmentConsumablesServiceImpl implements IEquipmentConsumablesSer
ConsumableNoticeDto notice = notices.get(0); ConsumableNoticeDto notice = notices.get(0);
String email = notice.getChargeUserEmail(); String email = notice.getChargeUserEmail();
String chargeNickName = notice.getChargeNickName(); String chargeNickName = notice.getChargeNickName();
//拆分即将过期和已过期的
//已过期的
List<ConsumableNoticeDto> overDueNotices = StreamUtils.filter(notices, (n -> n.getDueTime().before(today)));
//即将过期的
List<ConsumableNoticeDto> dueNotices = StreamUtils.filter(notices, (n -> n.getDueTime().after(today)));
//构建html //构建html
Map<String, Object> root = new HashMap<>(); Map<String, Object> root = new HashMap<>();
root.put("nickName", chargeNickName); root.put("nickName", chargeNickName);
root.put("dueConsumables", notices); root.put("overDueNotices", overDueNotices);
root.put("dueNotices", dueNotices);
String content = buildMailContent(root, "consumableDueEmailTemp.ftl"); String content = buildMailContent(root, "consumableDueEmailTemp.ftl");
if (StringUtils.isEmpty(content)){ if (StringUtils.isEmpty(content)){
log.error("邮件内容构建失败,邮件未发送"); log.error("邮件内容构建失败,邮件未发送");

View File

@ -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_user u on u.user_id = c.charge_user
left join sys_dept dept on e.department = dept.dept_id left join sys_dept dept on e.department = dept.dept_id
where u.del_flag = '0' and dept.del_flag = '0' where u.del_flag = '0' and dept.del_flag = '0'
and c.status = '0' and c.due_time &lt;= #{date} and c.status = '0' and c.due_time &lt;= #{endDate}
<if test="beginDate != null">
and c.due_time &gt;= #{beginDate}
</if>
</select> </select>