hyingbo
2025-05-27 3a740faa161ec976986c0735ba18837f570a525f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.jeecg.modules.eam.job;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.constant.enums.MessageSplitTypeEnum;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.modules.eam.entity.Equipment;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.service.*;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
 
public class TechnologyStatusAlart implements Job {
 
    @Resource
    private IEamEquipmentService equipmentService;
    @Resource
    private ISysBaseAPI sysBaseApi;
    @Resource
    private ISysRoleService sysRoleService;
    @Resource
    private ISysDictService sysDictService;
    @Resource
    private ISysDictItemService sysDictItemService;
    @Resource
    private ISysUserRoleService sysUserRoleService;
    @Resource
    private ISysUserService sysUserService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        LocalDateTime currentDateTime = LocalDateTime.now();
        LocalDateTime dateBefore2Months = currentDateTime.plusMonths(2);
        Date result = Date.from(dateBefore2Months.atZone(ZoneId.systemDefault()).toInstant());
        List<Equipment> needAlerts = equipmentService.list(
                new QueryWrapper<Equipment>()
                .lt("next_technology_status_qualification_time",result)
                .eq("property_status","normal")
                .eq("del_flag",0));
        SysDict sysDict = sysDictService.getOne(new QueryWrapper<SysDict>().eq("dict_code","info_type"),false);
        SysDictItem sysDictItem = sysDictItemService.getOne(
                new QueryWrapper<SysDictItem>()
                .eq("item_text","技术状态鉴定提醒")
                .eq("dict_id",sysDict.getId()),false);
        String roleCode = sysDictItem.getItemValue();
        SysRole sysRole = sysRoleService.getOne(new QueryWrapper<SysRole>().eq("role_code",roleCode),false);
        List<SysUserRole> sysUserRoles = sysUserRoleService.list(new QueryWrapper<SysUserRole>()
                .eq("role_id",sysRole.getId()));
        for(SysUserRole sysUserRole:sysUserRoles){
            SysUser sysUser = sysUserService.getById(sysUserRole.getUserId());
            String title = "设备技术状态鉴定到期提醒!";
            String msg = "统一编码为:";
            for(Equipment equipment:needAlerts){
                msg = msg+"【"+equipment.getNum()+"】";
            }
            msg = msg+"的设备技术状态鉴定的日期不足两个月,请及时处理";
            MessageDTO messageDTO = new MessageDTO();
            messageDTO.setTitle(title);
            messageDTO.setMessageType(MessageSplitTypeEnum.untilMaintenancePeriod.getType());
            messageDTO.setContent(msg);
            messageDTO.setCategory("技术状态鉴定消息");
            messageDTO.setFromUser("admin");
            messageDTO.setToUser(sysUser.getUsername());
            if(needAlerts.size()!=0){
                sysBaseApi.sendSysAnnouncement(messageDTO);
            }
        }
    }
}