|
|
@@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.pms.constant.PmsConstants;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotattachment.vo.IotAttachmentSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdailyreportfuel.vo.IotDailyReportFuelSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceassociate.vo.IotDeviceAssociatePageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotproductionexception.vo.IotProductionExceptionPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojectinfo.vo.IotProjectInfoPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.*;
|
|
|
@@ -26,6 +27,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotattachment.IotAttachmentDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdailyreportfuel.IotDailyReportFuelDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceassociate.IotDeviceAssociateDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotproductionexception.IotProductionExceptionDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojectinfo.IotProjectInfoDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttask.IotProjectTaskDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttaskattrs.IotTaskAttrModelProperty;
|
|
|
@@ -36,6 +38,7 @@ import cn.iocoder.yudao.module.pms.dal.mysql.IotProductClassifyMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotattachment.IotAttachmentMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdailyreportfuel.IotDailyReportFuelMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdeviceassociate.IotDeviceAssociateMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotproductionexception.IotProductionExceptionMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotprojectinfo.IotProjectInfoMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotprojecttask.IotProjectTaskMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotrddailyreport.IotRdDailyReportMapper;
|
|
|
@@ -129,6 +132,8 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
|
|
|
private IotRdDailyReportDetailMapper iotRdDailyReportDetailMapper;
|
|
|
@Resource
|
|
|
private IotDeviceAssociateMapper iotDeviceAssociateMapper;
|
|
|
+ @Resource
|
|
|
+ private IotProductionExceptionMapper iotProductionExceptionMapper;
|
|
|
|
|
|
@Override
|
|
|
public Long createIotRdDailyReport(IotRdDailyReportSaveReqVO createReqVO) {
|
|
|
@@ -256,6 +261,8 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
|
|
|
|
|
|
Long deptId = dailyReport.getDeptId();
|
|
|
Long taskId = dailyReport.getTaskId();
|
|
|
+ // 日报所属日期
|
|
|
+ LocalDateTime reportDate = dailyReport.getCreateTime();
|
|
|
|
|
|
// 如果是修改 非生产时间 ,则不必再发起审批 生产运营部 维护 时效
|
|
|
if (StrUtil.isBlank(updateReqVO.getNonProduct())) {
|
|
|
@@ -272,110 +279,143 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
|
|
|
// 审核同意 将生产异常情况 (npt 工程质量) 发送到拥有 生产异常通知 角色的人员
|
|
|
BigDecimal accidentTime = dailyReport.getAccidentTime();
|
|
|
if (ObjUtil.isNotEmpty(accidentTime) && accidentTime.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- String companyName = "四川瑞都";
|
|
|
- BigDecimal day = accidentTime.divide(new BigDecimal("24"), 2, RoundingMode.HALF_UP);
|
|
|
- String accidentDay = day + "T";
|
|
|
- // 异常情况
|
|
|
- String malfunction = StrUtil.blankToDefault(dailyReport.getMalfunction(), "无");
|
|
|
- DeptDO dept = deptService.getDept(deptId);
|
|
|
|
|
|
- List<String> projectDeptNames = new ArrayList<>();
|
|
|
- // 查询瑞鹰 163l 下具有以上角色的人员 查询集团(科瑞石油技术) 拥有以上角色的人员
|
|
|
- Set<Long> userIds = new HashSet<>();
|
|
|
- Set<Long> deptIds = new HashSet<>();
|
|
|
- DataPermissionUtils.executeIgnore(() -> {
|
|
|
- // 封装以上消息内容 发送到公司 角色 (生产异常通知)
|
|
|
- // 查询瑞恒 157l 下具有以上角色的人员 查询集团(科瑞石油技术) 拥有以上角色的人员
|
|
|
- deptIds.add(163l);
|
|
|
- List<AdminUserDO> companyUsers = adminUserService.getUserListByDeptIds(deptIds);
|
|
|
- if (CollUtil.isNotEmpty(companyUsers)) {
|
|
|
- companyUsers.forEach(user -> {
|
|
|
- userIds.add(user.getId());
|
|
|
- });
|
|
|
- }
|
|
|
- deptIds.clear();
|
|
|
- deptIds.add(156l);
|
|
|
- List<AdminUserDO> groupUsers = adminUserService.getUserListByDeptIds(deptIds);
|
|
|
- if (CollUtil.isNotEmpty(groupUsers)) {
|
|
|
- groupUsers.forEach(user -> {
|
|
|
- userIds.add(user.getId());
|
|
|
- });
|
|
|
- }
|
|
|
- // 查询当前队伍的上级项目部 过滤掉数据权限
|
|
|
- DeptDO projectDept = deptService.getDept(dept.getParentId());
|
|
|
- if (ObjUtil.isNotEmpty(projectDept)) {
|
|
|
- projectDeptNames.add(projectDept.getName());
|
|
|
- }
|
|
|
- });
|
|
|
+ // 查询表 rq_iot_production_exception 判断是否需要发送生产异常消息提醒
|
|
|
+ // 当前公司 taskId deptId reportId reportDate
|
|
|
+ // 查询表中相同 taskId 是否存在记录 记录日期yyyy-MM-dd如果与当前日期相关 <= 1天则不发送通知
|
|
|
+ IotProductionExceptionPageReqVO reqVO = new IotProductionExceptionPageReqVO();
|
|
|
+ reqVO.setTaskId(taskId);
|
|
|
+ IotProductionExceptionDO productionException = iotProductionExceptionMapper.selectMaxIdOne(reqVO);
|
|
|
+ boolean skipExceptionNotify = false;
|
|
|
+ if (ObjUtil.isEmpty(productionException)) {
|
|
|
+ // 没有当前任务关联的异常记录 直接保存发送消息提醒
|
|
|
|
|
|
- // 队伍名称
|
|
|
- String deptName = ObjUtil.isNotEmpty(dept) ? dept.getName() : StrUtil.EMPTY;
|
|
|
- // 项目部名称
|
|
|
- String projectDeptName = CollUtil.isNotEmpty(projectDeptNames) ? projectDeptNames.get(0) : StrUtil.EMPTY;
|
|
|
- String wellName = "无";
|
|
|
- if (ObjUtil.isNotEmpty(taskId)) {
|
|
|
- IotProjectTaskDO task = iotProjectTaskMapper.selectById(taskId);
|
|
|
- if (ObjUtil.isNotEmpty(task)) {
|
|
|
- wellName = task.getWellName();
|
|
|
+ } else {
|
|
|
+ // 存在当前任务的异常记录 记录日期 yyyy-MM-dd 与日报日期比较 如果相关 <= 1天 则不发送通知
|
|
|
+ LocalDateTime occurrenceDate = productionException.getOccurrenceDate();
|
|
|
+ if (ObjUtil.isNotEmpty(occurrenceDate)) {
|
|
|
+ LocalDate occurDay = productionException.getOccurrenceDate().toLocalDate();
|
|
|
+ LocalDate reportDay = reportDate.toLocalDate();
|
|
|
+ long dayDiff = Math.abs(ChronoUnit.DAYS.between(occurDay, reportDay));
|
|
|
+ skipExceptionNotify = dayDiff <= 1;
|
|
|
}
|
|
|
}
|
|
|
- // 当前处理进度 当日施工简报
|
|
|
- String brief = StrUtil.blankToDefault(dailyReport.getConstructionBrief(), "无");
|
|
|
- // 下步计划
|
|
|
- String nextPlan = StrUtil.blankToDefault(dailyReport.getNextPlan(), "无");
|
|
|
- // 故障误工时间 accidentTime H
|
|
|
-
|
|
|
- String PRODUCTION_EXCEPTION_MSG_TEMPLATE =
|
|
|
- "[**公司**]:{} \n" +
|
|
|
- "[**项目部**]:{} \n" +
|
|
|
- "[**队伍**]:{} \n" +
|
|
|
- "[**井号**]:{} \n" +
|
|
|
- "[**故障描述**]:{} \n" +
|
|
|
- "[**当前处理进度**]:{} \n" +
|
|
|
- "[**下步处理计划**]:{} \n" +
|
|
|
- "[**累计误工时间**]:{} \n";
|
|
|
-
|
|
|
- String finalMsgTitle = StrUtil.format(PRODUCTION_EXCEPTION_MSG_TEMPLATE,
|
|
|
- companyName, projectDeptName, deptName, wellName,
|
|
|
- malfunction, brief, nextPlan, accidentDay
|
|
|
- );
|
|
|
-
|
|
|
- RoleDO role = roleService.getRoleByCode("生产异常通知");
|
|
|
- if (ObjUtil.isNotEmpty(role)) {
|
|
|
- Set<Long> roleIds = new HashSet<>();
|
|
|
- roleIds.add(role.getId());
|
|
|
- List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
|
|
|
- if (CollUtil.isNotEmpty(userRoles)) {
|
|
|
- // 提取有审批角色的所有用户ID(去重+空值过滤)
|
|
|
- Set<Long> roleUserIds = userRoles.stream()
|
|
|
- .map(UserRoleDO::getUserId)
|
|
|
- .filter(Objects::nonNull) // 过滤空userId
|
|
|
- .collect(Collectors.toSet());
|
|
|
- // 计算两个集合的交集,得到最终目标用户ID
|
|
|
- Set<Long> targetUserIds = userIds.stream()
|
|
|
- .filter(roleUserIds::contains)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- // 异步发送 站内信 钉钉消息
|
|
|
- if (CollUtil.isNotEmpty(targetUserIds)) {
|
|
|
- Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
|
|
|
- // 给多个用户发送 相同 的 提醒消息
|
|
|
- if (CollUtil.isNotEmpty(users)) {
|
|
|
- // 生成消息提醒 标题内容
|
|
|
- CountDownLatch latch = new CountDownLatch(users.size());
|
|
|
- users.forEach((userId, user) -> {
|
|
|
- pmsThreadPoolTaskExecutor.execute(() -> {
|
|
|
- try {
|
|
|
- String mobile = user.getMobile();
|
|
|
- // 没有手机号也发送站内信消息
|
|
|
- if (StrUtil.isNotBlank(finalMsgTitle)) {
|
|
|
- pmsMessage.sendMessage(dailyReport.getId(), finalMsgTitle, PmsConstants.PRODUCTION_EXCEPTION,
|
|
|
- userId, mobile);
|
|
|
+
|
|
|
+ // 保存生产异常记录日志
|
|
|
+ IotProductionExceptionDO tobeAddedException = new IotProductionExceptionDO();
|
|
|
+ tobeAddedException.setCompanyId(163l);
|
|
|
+ tobeAddedException.setTaskId(taskId);
|
|
|
+ tobeAddedException.setReportId(dailyReport.getId());
|
|
|
+ tobeAddedException.setDeptId(dailyReport.getDeptId());
|
|
|
+ tobeAddedException.setOccurrenceDate(dailyReport.getCreateTime());
|
|
|
+ Integer num = iotProductionExceptionMapper.insert(tobeAddedException);
|
|
|
+
|
|
|
+ if (!skipExceptionNotify) {
|
|
|
+ String companyName = "四川瑞都";
|
|
|
+ BigDecimal day = accidentTime.divide(new BigDecimal("24"), 2, RoundingMode.HALF_UP);
|
|
|
+ String accidentDay = day + "T";
|
|
|
+ // 异常情况
|
|
|
+ String malfunction = StrUtil.blankToDefault(dailyReport.getMalfunction(), "无");
|
|
|
+ DeptDO dept = deptService.getDept(deptId);
|
|
|
+
|
|
|
+ List<String> projectDeptNames = new ArrayList<>();
|
|
|
+ // 查询瑞鹰 163l 下具有以上角色的人员 查询集团(科瑞石油技术) 拥有以上角色的人员
|
|
|
+ Set<Long> userIds = new HashSet<>();
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
+ DataPermissionUtils.executeIgnore(() -> {
|
|
|
+ // 封装以上消息内容 发送到公司 角色 (生产异常通知)
|
|
|
+ // 查询瑞恒 157l 下具有以上角色的人员 查询集团(科瑞石油技术) 拥有以上角色的人员
|
|
|
+ deptIds.add(163l);
|
|
|
+ List<AdminUserDO> companyUsers = adminUserService.getUserListByDeptIds(deptIds);
|
|
|
+ if (CollUtil.isNotEmpty(companyUsers)) {
|
|
|
+ companyUsers.forEach(user -> {
|
|
|
+ userIds.add(user.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ deptIds.clear();
|
|
|
+ deptIds.add(156l);
|
|
|
+ List<AdminUserDO> groupUsers = adminUserService.getUserListByDeptIds(deptIds);
|
|
|
+ if (CollUtil.isNotEmpty(groupUsers)) {
|
|
|
+ groupUsers.forEach(user -> {
|
|
|
+ userIds.add(user.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 查询当前队伍的上级项目部 过滤掉数据权限
|
|
|
+ DeptDO projectDept = deptService.getDept(dept.getParentId());
|
|
|
+ if (ObjUtil.isNotEmpty(projectDept)) {
|
|
|
+ projectDeptNames.add(projectDept.getName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 队伍名称
|
|
|
+ String deptName = ObjUtil.isNotEmpty(dept) ? dept.getName() : StrUtil.EMPTY;
|
|
|
+ // 项目部名称
|
|
|
+ String projectDeptName = CollUtil.isNotEmpty(projectDeptNames) ? projectDeptNames.get(0) : StrUtil.EMPTY;
|
|
|
+ String wellName = "无";
|
|
|
+ if (ObjUtil.isNotEmpty(taskId)) {
|
|
|
+ IotProjectTaskDO task = iotProjectTaskMapper.selectById(taskId);
|
|
|
+ if (ObjUtil.isNotEmpty(task)) {
|
|
|
+ wellName = task.getWellName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 当前处理进度 当日施工简报
|
|
|
+ String brief = StrUtil.blankToDefault(dailyReport.getConstructionBrief(), "无");
|
|
|
+ // 下步计划
|
|
|
+ String nextPlan = StrUtil.blankToDefault(dailyReport.getNextPlan(), "无");
|
|
|
+ // 故障误工时间 accidentTime H
|
|
|
+
|
|
|
+ String PRODUCTION_EXCEPTION_MSG_TEMPLATE =
|
|
|
+ "[**公司**]:{} \n" +
|
|
|
+ "[**项目部**]:{} \n" +
|
|
|
+ "[**队伍**]:{} \n" +
|
|
|
+ "[**井号**]:{} \n" +
|
|
|
+ "[**故障描述**]:{} \n" +
|
|
|
+ "[**当前处理进度**]:{} \n" +
|
|
|
+ "[**下步处理计划**]:{} \n" +
|
|
|
+ "[**累计误工时间**]:{} \n";
|
|
|
+
|
|
|
+ String finalMsgTitle = StrUtil.format(PRODUCTION_EXCEPTION_MSG_TEMPLATE,
|
|
|
+ companyName, projectDeptName, deptName, wellName,
|
|
|
+ malfunction, brief, nextPlan, accidentDay
|
|
|
+ );
|
|
|
+
|
|
|
+ RoleDO role = roleService.getRoleByCode("生产异常通知");
|
|
|
+ if (ObjUtil.isNotEmpty(role)) {
|
|
|
+ Set<Long> roleIds = new HashSet<>();
|
|
|
+ roleIds.add(role.getId());
|
|
|
+ List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
|
|
|
+ if (CollUtil.isNotEmpty(userRoles)) {
|
|
|
+ // 提取有审批角色的所有用户ID(去重+空值过滤)
|
|
|
+ Set<Long> roleUserIds = userRoles.stream()
|
|
|
+ .map(UserRoleDO::getUserId)
|
|
|
+ .filter(Objects::nonNull) // 过滤空userId
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ // 计算两个集合的交集,得到最终目标用户ID
|
|
|
+ Set<Long> targetUserIds = userIds.stream()
|
|
|
+ .filter(roleUserIds::contains)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ // 异步发送 站内信 钉钉消息
|
|
|
+ if (CollUtil.isNotEmpty(targetUserIds)) {
|
|
|
+ Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
|
|
|
+ // 给多个用户发送 相同 的 提醒消息
|
|
|
+ if (CollUtil.isNotEmpty(users)) {
|
|
|
+ // 生成消息提醒 标题内容
|
|
|
+ CountDownLatch latch = new CountDownLatch(users.size());
|
|
|
+ users.forEach((userId, user) -> {
|
|
|
+ pmsThreadPoolTaskExecutor.execute(() -> {
|
|
|
+ try {
|
|
|
+ String mobile = user.getMobile();
|
|
|
+ // 没有手机号也发送站内信消息
|
|
|
+ if (StrUtil.isNotBlank(finalMsgTitle)) {
|
|
|
+ pmsMessage.sendMessage(dailyReport.getId(), finalMsgTitle, PmsConstants.PRODUCTION_EXCEPTION,
|
|
|
+ userId, mobile);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ latch.countDown();
|
|
|
}
|
|
|
- } finally {
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|