From 8ad863082097ffdcab4a8e7f426d344a1fe6f892 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期六, 07 十一月 2026 00:27:02 +0800
Subject: [PATCH] 修复人员管理接口校验与导出,完善设备保养计划与文件受控功能

---
 cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java |  207 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 144 insertions(+), 63 deletions(-)

diff --git a/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java b/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java
index 8a6bd95..09d26e6 100644
--- a/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java
+++ b/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java
@@ -33,6 +33,7 @@
 import com.ruoyi.personnel.pojo.PersonTraining;
 import com.ruoyi.personnel.pojo.PersonTrainingDetailed;
 import com.ruoyi.personnel.pojo.PersonTrainingDetailedFile;
+import com.ruoyi.personnel.pojo.PersonTrainingRecord;
 import com.ruoyi.personnel.service.PersonTrainingDetailedService;
 import com.ruoyi.personnel.service.PersonTrainingService;
 import com.ruoyi.system.mapper.UserMapper;
@@ -57,6 +58,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -98,50 +100,32 @@
 
     @Override
     public void personTrainingImport(MultipartFile file, PersonTraining training) {
+        if (file == null || file.isEmpty()) {
+            throw new ErrorException("璇烽�夋嫨瀵煎叆鏂囦欢");
+        }
+        if (training == null || StringUtils.isBlank(training.getPlanYear())) {
+            throw new ErrorException("璇烽�夋嫨璁″垝骞翠唤");
+        }
+        if (training.getReviewerId() == null) {
+            throw new ErrorException("璇烽�夋嫨瀹℃牳浜�");
+        }
+        String originalFilename = file.getOriginalFilename();
+        if (StringUtils.isBlank(originalFilename)) {
+            throw new ErrorException("鏂囦欢鍚嶄笉鑳戒负绌�");
+        }
 
         Integer userId = SecurityUtils.getUserId().intValue();
         // 骞村害璁″垝鐖剁骇鏂板鏁版嵁
         PersonTraining personSupervisePlan = new PersonTraining();
-        String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
+        String fileName = originalFilename.contains(".")
+                ? originalFilename.substring(0, originalFilename.lastIndexOf("."))
+                : originalFilename;
         personSupervisePlan.setFileName(fileName);
         personSupervisePlan.setPlanYear(training.getPlanYear());
         personSupervisePlan.setCompilerId(userId);
         personSupervisePlan.setReviewerId(training.getReviewerId());
         personSupervisePlan.setCompilationDate(LocalDateTime.now());
         baseMapper.insert(personSupervisePlan);
-        User user = userMapper.selectById(userId);
-        // 娑堟伅鍙戦��
-        InformationNotification info = new InformationNotification();
-        // 鍙戦�佷汉
-        info.setCreateUser(user.getName());
-        info.setMessageType("6");
-        info.setTheme("CNAS鍩硅璁″垝瀹℃牳閫氱煡");
-        info.setContent("鎮ㄦ湁涓�鏉″煿璁鍒掑緟瀹℃牳");
-        info.setSenderId(userId);
-        // 鎺ユ敹浜�
-        info.setConsigneeId(training.getApproverId());
-        info.setJumpPath(MenuJumpPathConstants.PERSONNEL);
-        informationNotificationService.addInformationNotification(info);
-
-        // 鍙戦�佷紒涓氬井淇¢�氱煡
-        threadPoolTaskExecutor.execute(() -> {
-            // 鏌ヨ鎺ユ敹浜�
-            User personnel = userMapper.selectById(training.getApproverId());
-
-            String message = "";
-            message += "CNAS鍩硅璁″垝瀹℃牳閫氱煡";
-            message += "\n璇峰幓璧勬簮绠$悊-浜哄憳-鍩硅璁″垝濉啓";
-            message += "\n" + fileName + "鐨勫煿璁鍒掑緟瀹℃牳";
-            //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡锛堟帴鏀朵汉涓嶅瓨鍦ㄦ垨鍙戦�佸け璐ヤ笉褰卞搷瀵煎叆娴佺▼锛�
-            if (personnel == null || StringUtils.isBlank(personnel.getAccount())) {
-                return;
-            }
-            try {
-                WxCpUtils.inform(personnel.getAccount(), message, null);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        });
 
         // 骞村害璁″垝璇︽儏 鏂板
         try {
@@ -149,65 +133,138 @@
             personSupervisePlanDetailsListener.setPlanId(personSupervisePlan.getId());
             EasyExcel.read(file.getInputStream(), PersonTrainingDetailedUpload.class, personSupervisePlanDetailsListener).sheet().doRead();
         } catch (IOException e) {
-            e.printStackTrace();
+            throw new ErrorException("璇诲彇瀵煎叆鏂囦欢澶辫触锛岃妫�鏌ユ枃浠舵牸寮�");
         }
+
+        User user = userMapper.selectById(userId);
+        // 娑堟伅鍙戦�侊紙鎺ユ敹浜轰负閫夊畾鐨勫鏍镐汉锛�
+        InformationNotification info = new InformationNotification();
+        info.setCreateUser(user != null ? user.getName() : "");
+        info.setMessageType("6");
+        info.setTheme("CNAS鍩硅璁″垝瀹℃牳閫氱煡");
+        info.setContent("鎮ㄦ湁涓�鏉″煿璁鍒掑緟瀹℃牳");
+        info.setSenderId(userId);
+        info.setConsigneeId(training.getReviewerId());
+        info.setJumpPath(MenuJumpPathConstants.PERSONNEL);
+        informationNotificationService.addInformationNotification(info);
+
+        // 鍙戦�佷紒涓氬井淇¢�氱煡锛堟帴鏀朵汉涓嶅瓨鍦ㄦ垨鍙戦�佸け璐ヤ笉褰卞搷瀵煎叆娴佺▼锛�
+        threadPoolTaskExecutor.execute(() -> {
+            User personnel = userMapper.selectById(training.getReviewerId());
+            if (personnel == null || StringUtils.isBlank(personnel.getAccount())) {
+                return;
+            }
+            String message = "";
+            message += "CNAS鍩硅璁″垝瀹℃牳閫氱煡";
+            message += "\n璇峰幓璧勬簮绠$悊-浜哄憳-鍩硅璁″垝濉啓";
+            message += "\n" + fileName + "鐨勫煿璁鍒掑緟瀹℃牳";
+            try {
+                WxCpUtils.inform(personnel.getAccount(), message, null);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        });
     }
 
     @Override
     public void personTrainingDelete(Integer id) {
-        personTrainingDetailedService.remove(Wrappers.<PersonTrainingDetailed>lambdaQuery()
+        if (id == null) {
+            throw new ErrorException("缂哄皯璁″垝id");
+        }
+        List<PersonTrainingDetailed> details = personTrainingDetailedService.list(Wrappers.<PersonTrainingDetailed>lambdaQuery()
                 .eq(PersonTrainingDetailed::getPlanId, id));
+        if (!details.isEmpty()) {
+            List<Integer> detailIds = details.stream().map(PersonTrainingDetailed::getId).collect(Collectors.toList());
+            // 杩炲悓鏄庣粏涓嬬殑鍩硅璁板綍銆侀檮浠朵竴璧峰垹闄わ紝閬垮厤鐣欎笅瀛ゅ効鏁版嵁
+            personTrainingRecordMapper.delete(Wrappers.<PersonTrainingRecord>lambdaQuery()
+                    .in(PersonTrainingRecord::getCourseId, detailIds));
+            personTrainingDetailedFileMapper.delete(Wrappers.<PersonTrainingDetailedFile>lambdaQuery()
+                    .in(PersonTrainingDetailedFile::getTrainingDetailedId, detailIds));
+            personTrainingDetailedService.remove(Wrappers.<PersonTrainingDetailed>lambdaQuery()
+                    .eq(PersonTrainingDetailed::getPlanId, id));
+        }
         baseMapper.deleteById(id);
     }
 
     @Override
     public void reviewAnnualPersonnelTraining(PersonTraining training) {
-        PersonTraining personTraining = new PersonTraining();
-        personTraining.setId(training.getId());
-        personTraining.setApproverId(training.getApproverId());// 娣诲姞鎵瑰噯浜�
-        personTraining.setAuditDate(LocalDateTime.now());
-        personTraining.setAuditRemarks(training.getAuditRemarks());
-        personTraining.setReviewerStatus(training.getReviewerStatus());
-
+        if (training == null || training.getId() == null) {
+            throw new ErrorException("缂哄皯璁″垝id");
+        }
+        if (!Integer.valueOf(1).equals(training.getReviewerStatus()) && !Integer.valueOf(2).equals(training.getReviewerStatus())) {
+            throw new ErrorException("瀹℃牳缁撴灉涓嶆纭�");
+        }
         PersonTraining old = baseMapper.selectById(training.getId());
+        if (old == null) {
+            throw new ErrorException("鍩硅璁″垝涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎");
+        }
+        if (Integer.valueOf(1).equals(old.getReviewerStatus())) {
+            throw new ErrorException("璇ヨ鍒掑凡瀹℃牳閫氳繃锛岃鍕块噸澶嶅鏍�");
+        }
+        boolean passed = Integer.valueOf(1).equals(training.getReviewerStatus());
+        if (passed && training.getApproverId() == null) {
+            throw new ErrorException("璇烽�夋嫨鎵瑰噯浜�");
+        }
 
-        // 娑堟伅鍙戦��
+        baseMapper.update(null, Wrappers.<PersonTraining>lambdaUpdate()
+                .eq(PersonTraining::getId, training.getId())
+                .set(PersonTraining::getApproverId, passed ? training.getApproverId() : null)
+                .set(PersonTraining::getAuditDate, LocalDateTime.now())
+                .set(PersonTraining::getAuditRemarks, training.getAuditRemarks())
+                .set(PersonTraining::getReviewerStatus, training.getReviewerStatus()));
+
+        // 鍙湁瀹℃牳閫氳繃鎵嶉�氱煡鎵瑰噯浜�
+        if (!passed) {
+            return;
+        }
         Integer userId = SecurityUtils.getUserId().intValue();
         User user = userMapper.selectById(userId);
         InformationNotification info = new InformationNotification();
-        // 鍙戦�佷汉
-        info.setCreateUser(user.getName());
+        info.setCreateUser(user != null ? user.getName() : "");
         info.setMessageType("6");
         info.setTheme("CNAS鍩硅璁″垝瀹℃牳閫氱煡");
         info.setContent("鎮ㄦ湁涓�鏉″煿璁鍒掑緟鎵瑰噯");
         info.setSenderId(userId);
-        // 鎺ユ敹浜�
         info.setConsigneeId(training.getApproverId());
         info.setJumpPath(MenuJumpPathConstants.PERSONNEL);
         informationNotificationService.addInformationNotification(info);
 
         // 鍙戦�佷紒涓氬井淇¢�氱煡
         threadPoolTaskExecutor.execute(() -> {
-            // 鏌ヨ鎺ユ敹浜�
             User personnel = userMapper.selectById(training.getApproverId());
-
+            if (personnel == null || StringUtils.isBlank(personnel.getAccount())) {
+                return;
+            }
             String message = "";
             message += "CNAS鍩硅璁″垝鎵瑰噯閫氱煡";
             message += "\n璇峰幓璧勬簮绠$悊-浜哄憳-鍩硅璁″垝濉啓";
             message += "\n" + old.getFileName() + "鐨勫煿璁鍒掑緟鎵瑰噯";
-            //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡
             try {
                 WxCpUtils.inform(personnel.getAccount(), message, null);
             } catch (Exception e) {
-                throw new RuntimeException(e);
+                e.printStackTrace();
             }
         });
-
-        baseMapper.updateById(personTraining);
     }
 
     @Override
     public void approveAnnualPersonnelTraining(PersonTraining training) {
+        if (training == null || training.getId() == null) {
+            throw new ErrorException("缂哄皯璁″垝id");
+        }
+        if (!Integer.valueOf(1).equals(training.getApprovalStatus()) && !Integer.valueOf(2).equals(training.getApprovalStatus())) {
+            throw new ErrorException("鎵瑰噯缁撴灉涓嶆纭�");
+        }
+        PersonTraining old = baseMapper.selectById(training.getId());
+        if (old == null) {
+            throw new ErrorException("鍩硅璁″垝涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎");
+        }
+        if (!Integer.valueOf(1).equals(old.getReviewerStatus())) {
+            throw new ErrorException("璇ヨ鍒掑皻鏈鏍搁�氳繃锛屼笉鑳芥壒鍑�");
+        }
+        if (Integer.valueOf(1).equals(old.getApprovalStatus())) {
+            throw new ErrorException("璇ヨ鍒掑凡鎵瑰噯锛岃鍕块噸澶嶆搷浣�");
+        }
         LambdaUpdateWrapper<PersonTraining> wrapper = Wrappers.<PersonTraining>lambdaUpdate()
                 .eq(PersonTraining::getId, training.getId())
                 .set(PersonTraining::getApprovalDate, LocalDateTime.now())
@@ -224,30 +281,48 @@
     @Override
     public void exportPersonTraining(Integer id, HttpServletResponse response) {
 
+        if (id == null) {
+            throw new ErrorException("缂哄皯璁″垝id");
+        }
         // 鏌ヨ璇︽儏
         PersonTraining personTraining = baseMapper.selectById(id);
-
-        //鑾峰彇鎻愪氦浜虹殑绛惧悕鍦板潃
-        String writeUrl = userMapper.selectById(personTraining.getCompilerId()).getSignatureUrl();
-        if (ObjectUtils.isEmpty(writeUrl) || writeUrl.equals("")) {
-            throw new ErrorException("鎵句笉鍒版楠屼汉鐨勭鍚�");
+        if (personTraining == null) {
+            throw new ErrorException("鍩硅璁″垝涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎");
         }
 
-        //鑾峰彇澶嶆牳浜虹殑绛惧悕鍦板潃
+        //鑾峰彇缂栧埗浜虹殑绛惧悕鍦板潃
+        User compiler = userMapper.selectById(personTraining.getCompilerId());
+        String writeUrl = compiler != null ? compiler.getSignatureUrl() : null;
+        if (StringUtils.isBlank(writeUrl)) {
+            throw new ErrorException("缂栧埗浜烘湭涓婁紶绛惧悕锛屾殏鏃犳硶瀵煎嚭");
+        }
+        if (!new File(imgUrl + "/" + writeUrl).exists()) {
+            throw new ErrorException("缂栧埗浜虹殑绛惧悕鍥剧墖涓嶅瓨鍦紝璇烽噸鏂颁笂浼犵鍚�");
+        }
+
+        //鑾峰彇瀹℃牳浜虹殑绛惧悕鍦板潃
         String examineUrl = null;
         if (personTraining.getReviewerId() != null) {
-            examineUrl = userMapper.selectById(personTraining.getReviewerId()).getSignatureUrl();
+            User reviewer = userMapper.selectById(personTraining.getReviewerId());
+            examineUrl = reviewer != null ? reviewer.getSignatureUrl() : null;
             if (StringUtils.isBlank(examineUrl)) {
-                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+                throw new ErrorException("瀹℃牳浜烘湭涓婁紶绛惧悕锛屾殏鏃犳硶瀵煎嚭");
+            }
+            if (!new File(imgUrl + "/" + examineUrl).exists()) {
+                throw new ErrorException("瀹℃牳浜虹殑绛惧悕鍥剧墖涓嶅瓨鍦紝璇烽噸鏂颁笂浼犵鍚�");
             }
         }
 
         //鑾峰彇鎵瑰噯浜虹殑绛惧悕鍦板潃
         String ratifyUrl = null;
         if (personTraining.getApproverId() != null) {
-            ratifyUrl = userMapper.selectById(personTraining.getApproverId()).getSignatureUrl();
+            User approver = userMapper.selectById(personTraining.getApproverId());
+            ratifyUrl = approver != null ? approver.getSignatureUrl() : null;
             if (StringUtils.isBlank(ratifyUrl)) {
-                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+                throw new ErrorException("鎵瑰噯浜烘湭涓婁紶绛惧悕锛屾殏鏃犳硶瀵煎嚭");
+            }
+            if (!new File(imgUrl + "/" + ratifyUrl).exists()) {
+                throw new ErrorException("鎵瑰噯浜虹殑绛惧悕鍥剧墖涓嶅瓨鍦紝璇烽噸鏂颁笂浼犵鍚�");
             }
         }
 
@@ -307,8 +382,14 @@
      */
     @Override
     public void exportPersonTrainingRecord(Integer id, HttpServletResponse response) {
+        if (id == null) {
+            throw new ErrorException("缂哄皯鍩硅鏄庣粏id");
+        }
         // 鏌ヨ浜哄憳鍩硅鏄庣粏
         PersonTrainingDetailedDto detailedDto = personTrainingDetailedMapper.selectTrainingDetail(id);
+        if (detailedDto == null) {
+            throw new ErrorException("鍩硅璁板綍涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎");
+        }
 
         // 鐢熸垚鍩硅鑰佸笀绛惧悕锛堟湭閰嶇疆绛惧悕鏃剁敤閫忔槑鍥剧墖鍏滃簳锛屾ā鏉块噷鐨勫浘鐗囧崰浣嶄笉鑳戒负 null锛�
         detailedDto.setTrainingLecturerRender(UserUtils.orTransparentPicture(

--
Gitblit v1.9.3