cnas-device/src/main/java/com/ruoyi/device/mapper/DeviceMapper.java
@@ -36,5 +36,11 @@ List<Map<String, Object>> treeDevice(@Param("deviceName") String deviceName); DeviceDto selectDeviceByCode(Integer id); /** * 查询到达校准有效期的设备-提前5天 * @return */ List<Device> selectOverdueDevice(); } cnas-device/src/main/java/com/ruoyi/device/task/DeviceRecordSchedule.java
@@ -3,7 +3,9 @@ import com.ruoyi.common.core.domain.entity.User; import com.ruoyi.common.utils.WxCpUtils; import com.ruoyi.device.dto.DeviceRecordDto; import com.ruoyi.device.mapper.DeviceMapper; import com.ruoyi.device.mapper.DeviceRecordMapper; import com.ruoyi.device.pojo.Device; import com.ruoyi.device.pojo.DeviceRecord; import com.ruoyi.system.mapper.UserMapper; import org.springframework.scheduling.annotation.Scheduled; @@ -20,6 +22,9 @@ */ @Component public class DeviceRecordSchedule { @Resource private DeviceMapper deviceMapper; @Resource private DeviceRecordMapper deviceRecordMapper; @Resource @@ -58,8 +63,41 @@ }); }); } /** * 每天9点执行一次 除了星期天 * 判断是否有设备到达校准有效期 */ // @Scheduled(cron = "0/5 * * * * *") @Scheduled(cron = "0 0 9 * * 1-6") // 每天9点执行一次 除了星期天 public void task2() { // 查询到达校准有效期的设备-提前5天 List<Device> deviceList = deviceMapper.selectOverdueDevice(); Map<Integer, List<Device>> userPersonIdMap = deviceList.stream().collect(Collectors.groupingBy(Device::getEquipmentManager)); userPersonIdMap.forEach((userId, recordList) -> { threadPoolTaskExecutor.execute(() -> { // 企业微信通知填写设备使用记录 User user = userMapper.selectById(userId); String message = ""; message += "设备使用记录未填写提醒通知"; for (Device deviceRecord : recordList) { message += "\n设备名称编号: " + deviceRecord.getDeviceName() + "-" + deviceRecord.getManagementNumber(); message += "\n委托编号: " + deviceRecord.getSampleCode(); message += "\n"; } message += "\n请去填写设备使用记录"; //发送企业微信消息通知 try { WxCpUtils.inform(user.getAccount(), message, null); } catch (Exception e) { throw new RuntimeException(e); } }); }); } } cnas-device/src/main/resources/mapper/DeviceMapper.xml
@@ -142,6 +142,7 @@ <resultMap id="deviceNameMap" type="map"> <result property="value" column="id"/> <result property="label" column="device_name"/> <result property="activationDate" column="activation_date"/> <result property="managementNumber" column="management_number"/> </resultMap> @@ -152,7 +153,8 @@ case when d.storage_point is null || d.storage_point ='' then '其他' else d.storage_point end as storage_point, d.device_name, d.management_number, null as value null as value, d.activation_date from device d LEFT JOIN laboratory l ON l.id = d.subordinate_departments_id <where> @@ -160,7 +162,6 @@ and device_name like concat('%',#{deviceName},'%') </if> </where> order by l.laboratory_name desc, d.storage_point desc </select> <select id="selectDeviceByCode" resultType="com.ruoyi.device.dto.DeviceDto"> @@ -181,4 +182,15 @@ u1.name, u2.name </select> <!-- 查询到达校准有效期的设备-提前5天 --> <select id="selectOverdueDevice" resultType="com.ruoyi.device.pojo.Device"> SELECT * FROM device WHERE -- 筛选出 activation_date 在当前日期前五天内的数据 activation_date BETWEEN now() AND now() + INTERVAL 5 DAY -- 筛选出 activation_date 已经超过当前日期的数据 OR activation_date < now() </select> </mapper> cnas-personnel/src/main/java/com/ruoyi/personnel/task/PersonTrainingSchedule.java
@@ -28,10 +28,10 @@ private ThreadPoolTaskExecutor threadPoolTaskExecutor; /** * 提醒填写设备使用记录 * 提醒填写人员培训记录 */ // @Scheduled(cron = "0/5 * * * * *") @Scheduled(cron = "0 0 9 1 * *") // 每月一号执行 @Scheduled(cron = "0 0 9 1,15 * *") // 每月一号执行 public void task1() { // 查询当月培训计划 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.M");