| | |
| | | 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; |
| | |
| | | */ |
| | | @Component |
| | | public class DeviceRecordSchedule { |
| | | |
| | | @Resource |
| | | private DeviceMapper deviceMapper; |
| | | @Resource |
| | | private DeviceRecordMapper deviceRecordMapper; |
| | | @Resource |
| | |
| | | |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 每天9点执行一次 除了星期天 |
| | | * 判断是否有设备到达校准有效期 |
| | | */ |
| | | // @Scheduled(cron = "0/10 * * * * *") |
| | | @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(); |
| | | message += "\n设备编号: " + deviceRecord.getManagementNumber(); |
| | | message += "\n校准有效期: " + deviceRecord.getActivationDate(); |
| | | message += "\n"; |
| | | } |
| | | message += "\n请去进行设备校准"; |
| | | |
| | | //发送企业微信消息通知 |
| | | try { |
| | | WxCpUtils.inform(user.getAccount(), message, null); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | } |