From c0eabff28c4bd9212d2550162f28193daf9976fe Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期一, 23 三月 2026 14:25:40 +0800
Subject: [PATCH] feat: 新增巡检记录通知功能及查询条件优化
---
src/main/java/com/ruoyi/production/service/impl/ProductInspectionRecordServiceImpl.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 96 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductInspectionRecordServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductInspectionRecordServiceImpl.java
index 5320a0e..44acb36 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductInspectionRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductInspectionRecordServiceImpl.java
@@ -1,10 +1,21 @@
package com.ruoyi.production.service.impl;
-import com.ruoyi.production.pojo.ProductInspectionRecord;
+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;
/**
* <p>
@@ -14,7 +25,90 @@
* @author 鑺杞欢锛堟睙鑻忥級鏈夐檺鍏徃
* @since 2026-03-16 04:16:32
*/
+@Slf4j
@Service
-public class ProductInspectionRecordServiceImpl extends ServiceImpl<ProductInspectionRecordMapper, ProductInspectionRecord> implements ProductInspectionRecordService {
+public class ProductInspectionRecordServiceImpl extends ServiceImpl<ProductInspectionRecordMapper, ProductInspectionRecord>
+ 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<Long> ids) {
+ if (ids == null || ids.isEmpty()) {
+ return;
+ }
+
+ // 1. 鏌ヨ宸℃璁板綍
+ List<ProductInspectionRecord> records = listByIds(ids);
+ if (records == null || records.isEmpty()) {
+ log.warn("鏈壘鍒板搴旂殑宸℃璁板綍, ids={}", ids);
+ return;
+ }
+
+ // 2. 鏌ヨ宀椾綅涓簅p鐨勭敤鎴�
+ List<SysUser> 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<SysNotice> notices = new ArrayList<>();
+ for (ProductInspectionRecord record : records) {
+ // 杩囨护鍑轰笉鍚堟牸鐨勮褰�
+ if (!"no".equalsIgnoreCase(record.getJudgement())) {
+ continue;
+ }
+
+ // 鏋勫缓娑堟伅鍐呭锛歺xx鐢熶骇璁㈠崟锛寈x宸ュ簭锛寈x妫�楠岄」涓嶅悎鏍硷紝璇峰強鏃跺宸ヨ壓鍙婂弬鏁板仛璋冩暣锛�
+ 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();
+
+ // 涓烘瘡涓猳p宀椾綅鐢ㄦ埛鍒涘缓閫氱煡
+ 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("宸插彂閫亄}鏉″贰妫�涓嶅悎鏍奸�氱煡缁檣}涓猳p宀椾綅鐢ㄦ埛", notices.size(), opUsers.size());
+ }
+ }
}
--
Gitblit v1.9.3