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.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.setContent(msg);
|
messageDTO.setCategory("技术状态鉴定消息");
|
messageDTO.setFromUser("admin");
|
messageDTO.setToUser(sysUser.getUsername());
|
if(needAlerts.size()!=0){
|
sysBaseApi.sendSysAnnouncement(messageDTO);
|
}
|
}
|
}
|
}
|