package com.ruoyi.production.service.impl; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.production.mapper.ProductInspectionRecordMapper; import com.ruoyi.production.pojo.ProductInspectionRecord; import com.ruoyi.production.service.ProductInspectionRecordService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.project.system.domain.SysNotice; import com.ruoyi.project.system.domain.SysUser; import com.ruoyi.project.system.mapper.SysUserMapper; import com.ruoyi.project.system.service.ISysNoticeService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; /** *

* 巡检记录表 服务实现类 *

* * @author 芯导软件(江苏)有限公司 * @since 2026-03-16 04:16:32 */ @Slf4j @Service public class ProductInspectionRecordServiceImpl extends ServiceImpl implements ProductInspectionRecordService { private static final String OP_POST_CODE = "op"; @Autowired private SysUserMapper userMapper; @Autowired private ISysNoticeService noticeService; @Override @Transactional(rollbackFor = Exception.class) public void notify(List ids) { if (ids == null || ids.isEmpty()) { return; } // 1. 查询巡检记录 List records = listByIds(ids); if (records == null || records.isEmpty()) { log.warn("未找到对应的巡检记录, ids={}", ids); return; } // 2. 查询岗位为op的用户 List opUsers = userMapper.selectUserListByPostCode(OP_POST_CODE); if (opUsers == null || opUsers.isEmpty()) { log.warn("未找到岗位编码为[{}]的用户", OP_POST_CODE); return; } // 3. 获取当前用户信息 Long currentUserId = SecurityUtils.getLoginUser().getUserId(); Long tenantId = SecurityUtils.getLoginUser().getTenantId(); // 4. 为每条巡检记录发送通知 List notices = new ArrayList<>(); for (ProductInspectionRecord record : records) { // 过滤出不合格的记录 if (!"no".equalsIgnoreCase(record.getJudgement())) { continue; } // 构建消息内容:xxx生产订单,xx工序,xx检验项不合格,请及时对工艺及参数做调整! String productionOrder = record.getUnqualifiedOrder(); String process = record.getProcess(); String inspectionItem = record.getInspectionItem(); StringBuilder messageBuilder = new StringBuilder(); if (productionOrder != null && !productionOrder.isEmpty()) { messageBuilder.append(productionOrder).append("生产订单,"); } if (process != null && !process.isEmpty()) { messageBuilder.append(process).append("工序,"); } if (inspectionItem != null && !inspectionItem.isEmpty()) { messageBuilder.append(inspectionItem).append("检验项不合格,"); } messageBuilder.append("请及时对工艺及参数做调整!"); String title = "巡检不合格通知"; String message = messageBuilder.toString(); // 为每个op岗位用户创建通知 for (SysUser opUser : opUsers) { SysNotice notice = new SysNotice(); notice.setNoticeType("1"); notice.setNoticeTitle(title); notice.setNoticeContent(message); notice.setStatus("0"); notice.setConsigneeId(opUser.getUserId()); notice.setSenderId(currentUserId); notice.setTenantId(tenantId); notices.add(notice); } } // 5. 批量保存通知 if (!notices.isEmpty()) { noticeService.saveBatch(notices); log.info("已发送{}条巡检不合格通知给{}个op岗位用户", notices.size(), opUsers.size()); } } }