|
|
@@ -0,0 +1,115 @@
|
|
|
+package cn.iocoder.yudao.module.pms.job.qhse;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
|
|
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|
|
+import cn.iocoder.yudao.module.pms.constant.PmsConstants;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.cert.vo.IotMeasureCertPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.stat.DeptUtil;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.cert.IotMeasureCertMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.measure.IotMeasureBookMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.message.PmsMessage;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.PostApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.permission.RoleApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class BookAndCertWeekJob implements JobHandler {
|
|
|
+ private final IotMeasureBookMapper iotMeasureBookMapper;
|
|
|
+ private final DeptApi deptApi;
|
|
|
+ private final DeptService deptService;
|
|
|
+ private final PmsMessage pmsMessage;
|
|
|
+ private final AdminUserApi adminUserApi;
|
|
|
+ private final PostApi postApi;
|
|
|
+ private final RoleApi roleApi;
|
|
|
+ private final RoleService roleService;
|
|
|
+ private final PermissionApi permissionApi;
|
|
|
+ private final IotMeasureCertMapper iotMeasureCertMapper;
|
|
|
+ private final DeptUtil deptUtil;
|
|
|
+
|
|
|
+ public BookAndCertWeekJob(IotMeasureBookMapper iotMeasureBookMapper, DeptApi deptApi, DeptService deptService, PmsMessage pmsMessage, AdminUserApi adminUserApi, PostApi postApi, RoleApi roleApi, RoleService roleService, PermissionApi permissionApi, IotMeasureCertMapper iotMeasureCertMapper, DeptUtil deptUtil) {
|
|
|
+ this.iotMeasureBookMapper = iotMeasureBookMapper;
|
|
|
+ this.deptApi = deptApi;
|
|
|
+ this.deptService = deptService;
|
|
|
+ this.pmsMessage = pmsMessage;
|
|
|
+ this.adminUserApi = adminUserApi;
|
|
|
+ this.postApi = postApi;
|
|
|
+ this.roleApi = roleApi;
|
|
|
+ this.roleService = roleService;
|
|
|
+ this.permissionApi = permissionApi;
|
|
|
+ this.iotMeasureCertMapper = iotMeasureCertMapper;
|
|
|
+ this.deptUtil = deptUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @TenantIgnore
|
|
|
+ public String execute(String param) throws Exception {
|
|
|
+ //获取项目部
|
|
|
+ List<DeptRespDTO> collect = deptApi.getDeptList().stream().filter(e -> "2".equals(e.getType())).collect(Collectors.toList());
|
|
|
+ collect.forEach(dept -> {
|
|
|
+ Set<Long> ids = new HashSet<>();
|
|
|
+ if (Objects.nonNull(dept.getId())) {
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(dept.getId());
|
|
|
+ ids.add(dept.getId());
|
|
|
+ }
|
|
|
+ IotMeasureBookPageReqVO reqVO = new IotMeasureBookPageReqVO();
|
|
|
+ reqVO.setAlertWarn(true);
|
|
|
+ //90天预警
|
|
|
+ long warn = iotMeasureBookMapper.selectCountByDeptAndExpireAndWarn(reqVO, ids);
|
|
|
+ reqVO.setExpired(true);
|
|
|
+ Long expired = iotMeasureBookMapper.selectCountByDeptAndExpireAndWarn(reqVO, ids);
|
|
|
+ //获取证书的预警及过期数量
|
|
|
+ IotMeasureCertPageReqVO reqVO1 = new IotMeasureCertPageReqVO();
|
|
|
+ reqVO1.setAlertWarn(true);
|
|
|
+ Long warnCert = iotMeasureCertMapper.selectCountByDeptAndExpireAndWarn(reqVO1, ids);
|
|
|
+ reqVO1.setExpired(true);
|
|
|
+ Long expiredCert = iotMeasureCertMapper.selectCountByDeptAndExpireAndWarn(reqVO1, ids);
|
|
|
+ if (warn>0||expired>0||warnCert>0||expiredCert>0) {
|
|
|
+ List<AdminUserRespDTO> userListByDeptId = adminUserApi.getUserListByDeptId(dept.getId());
|
|
|
+ List<Long> userIds = roleApi.getRoleUserIds("QHSE项目部");
|
|
|
+ //给项目部的角色为QHSE项目部的人员发送消息,项目部的过期及预警都要发送消息
|
|
|
+ userListByDeptId.stream().filter(e -> userIds.contains(e.getId())).forEach(adminUser -> {
|
|
|
+ pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
|
|
|
+ });
|
|
|
+ //发送给各公司的QHSE负责人
|
|
|
+ String companyCode = deptUtil.getCompanyCode(dept.getId());
|
|
|
+ if ("rh".equals(companyCode)){
|
|
|
+ List<AdminUserRespDTO> rh = adminUserApi.getUserListByDeptId(157L);
|
|
|
+ List<Long> rhIds = roleApi.getRoleUserIds("QHSE安全副总监");
|
|
|
+ rh.stream().filter(e -> rhIds.contains(e.getId())).forEach(adminUser -> {
|
|
|
+ pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
|
|
|
+ });
|
|
|
+ } else if ("ry".equals(companyCode)){
|
|
|
+ List<AdminUserRespDTO> ry = adminUserApi.getUserListByDeptId(158L);
|
|
|
+ List<Long> ryIds = roleApi.getRoleUserIds("QHSE安全副总监");
|
|
|
+ ry.stream().filter(e -> ryIds.contains(e.getId())).forEach(adminUser -> {
|
|
|
+ pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
|
|
|
+ });
|
|
|
+ } else if ("rd".equals(companyCode)){
|
|
|
+ List<AdminUserRespDTO> rd = adminUserApi.getUserListByDeptId(163L);
|
|
|
+ List<Long> rdIds = roleApi.getRoleUserIds("QHSE安全副总监");
|
|
|
+ rd.stream().filter(e -> rdIds.contains(e.getId())).forEach(adminUser -> {
|
|
|
+ pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //已过期的信息给藏总发消息
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+}
|