From 0220811fbcffd4bd4df334502a2af272ae29f1e3 Mon Sep 17 00:00:00 2001
From: wenminjie <1036699586@qq.com>
Date: 星期一, 13 七月 2026 10:14:30 +0800
Subject: [PATCH] 修复了已知BUG

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java |  137 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 106 insertions(+), 31 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java
index 472321a..3afd72c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java
@@ -2,6 +2,7 @@
 
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.basic.PageInfo;
@@ -27,9 +28,7 @@
 
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -56,8 +55,9 @@
     private final TProjectTeamStaffService projectTeamStaffService;
     private final TExperimentDispatchParticipantsService experimentDispatchParticipantsService;
     private final TNoticeService noticeService;
+    private final TInspectionReportService inspectionReportService;
     @Autowired
-    public TSamplingRecordController(TSamplingRecordService samplingRecordService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TSamplingRecordOperationService samplingRecordOperationService, TExperimentDispatchService experimentDispatchService, TProjectProposalService projectProposalService, TProjectTeamService projectTeamService, TProjectTeamStaffService projectTeamStaffService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService, TNoticeService noticeService) {
+    public TSamplingRecordController(TSamplingRecordService samplingRecordService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TSamplingRecordOperationService samplingRecordOperationService, TExperimentDispatchService experimentDispatchService, TProjectProposalService projectProposalService, TProjectTeamService projectTeamService, TProjectTeamStaffService projectTeamStaffService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService, TNoticeService noticeService, TInspectionReportService inspectionReportService) {
         this.samplingRecordService = samplingRecordService;
         this.tokenService = tokenService;
         this.sysUserService = sysUserService;
@@ -69,6 +69,7 @@
         this.projectTeamStaffService = projectTeamStaffService;
         this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
         this.noticeService = noticeService;
+        this.inspectionReportService = inspectionReportService;
     }
 
     /**
@@ -89,6 +90,9 @@
                 // 查询项目组
                 TProjectTeamStaff projectTeamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                         .eq(TProjectTeamStaff::getUserId, userId));
+                if(Objects.isNull(projectTeamStaff)){
+                    return R.fail("当前用户未加入项目组,无法进行操作");
+                }
                 // 查询项目的工艺工程师id
                 TProjectTeamStaff teamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                         .eq(TProjectTeamStaff::getTeamId, projectTeamStaff.getTeamId())
@@ -108,6 +112,46 @@
                 if (!CollectionUtils.isEmpty(experimentDispatchParticipants)) {
                     List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
                     query.setDispatchIds(dispatchIds);
+                }
+            }
+            if(roleType == 4){
+                // 查询当前用户所在的项目组
+                List<TProjectTeamStaff> projectTeamStaffs = projectTeamStaffService.list(Wrappers.lambdaQuery(TProjectTeamStaff.class)
+                        .eq(TProjectTeamStaff::getUserId, userId));
+                if (!CollectionUtils.isEmpty(projectTeamStaffs)) {
+                    List<String> teamIds = projectTeamStaffs.stream().map(TProjectTeamStaff::getTeamId).distinct().collect(Collectors.toList());
+                    List<TProjectProposal> projectProposals = projectProposalService.list(Wrappers.lambdaQuery(TProjectProposal.class)
+                            .in(TProjectProposal::getTeamId, teamIds));
+                    if (!CollectionUtils.isEmpty(projectProposals)) {
+                        List<String> projectIds = projectProposals.stream().map(TProjectProposal::getId).collect(Collectors.toList());
+                        List<TExperimentDispatch> experimentDispatches = experimentDispatchService.list(Wrappers.lambdaQuery(TExperimentDispatch.class)
+                                .in(TExperimentDispatch::getProposalId, projectIds));
+                        if (!CollectionUtils.isEmpty(experimentDispatches)) {
+                            List<String> dispatchIds2 = experimentDispatches.stream().map(TExperimentDispatch::getId).collect(Collectors.toList());
+                            // 查询检验报告
+                            List<TInspectionReport> inspectionReports = inspectionReportService.list(Wrappers.lambdaQuery(TInspectionReport.class)
+                                    .eq(TInspectionReport::getStatus, 2)
+                                    .in(TInspectionReport::getDispatchId, dispatchIds2));
+                            if (!CollectionUtils.isEmpty(inspectionReports)) {
+                                List<String> dispatchIds = inspectionReports.stream().map(TInspectionReport::getDispatchId).distinct().collect(Collectors.toList());
+                                List<String> dispatchIds1 = query.getDispatchIds();
+                                Iterator<String> iterator = dispatchIds1.iterator();
+                                while (iterator.hasNext()) {
+                                    String next = iterator.next();
+                                    if (dispatchIds.contains(next)) {
+                                        iterator.remove();
+                                    }
+                                }
+                                //                    if(CollectionUtils.isEmpty(dispatchIds1)){
+                                //                        List<String> id = new ArrayList<>();
+                                //                        id.add("-1");
+                                //                        query.setDispatchIds(id);
+                                //                    }else {
+                                query.setDispatchIds(dispatchIds1);
+                                //                    }
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -226,26 +270,45 @@
         TSamplingRecordVO samplingRecordVO = new TSamplingRecordVO();
         BeanUtils.copyProperties(samplingRecord, samplingRecordVO);
 
+        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+        Long userId = tokenService.getLoginUser().getUserId();
+        LambdaQueryWrapper<TSamplingRecordOperation> wrapper = new LambdaQueryWrapper<>();
+        if(roleType == 4){
+            // 化验师只查看自己接收得数据
+            wrapper.eq(TSamplingRecordOperation::getReceiptsPersonId,userId );
+        }
+        wrapper.eq(TSamplingRecordOperation::getSamplingId, id);
         // 查询取样操作记录
-        List<TSamplingRecordOperation> samplingRecordOperations = samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class).eq(TSamplingRecordOperation::getSamplingId, id));
+        List<TSamplingRecordOperation> samplingRecordOperations = samplingRecordOperationService.list(wrapper);
 
         List<Long> userIds = samplingRecordOperations.stream().map(TSamplingRecordOperation::getHandlePersonId).collect(Collectors.toList());
         List<Long> sendUserIds = samplingRecordOperations.stream().map(TSamplingRecordOperation::getSendPersonId).collect(Collectors.toList());
         List<Long> receiptsUserIds = samplingRecordOperations.stream().map(TSamplingRecordOperation::getReceiptsPersonId).collect(Collectors.toList());
         userIds.addAll(sendUserIds);
         userIds.addAll(receiptsUserIds);
-        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
-        samplingRecordOperations.forEach(samplingRecordOperation -> {
-            if(Objects.nonNull(samplingRecordOperation.getHandlePersonId())){
-                samplingRecordOperation.setHandlePersonName(Objects.requireNonNull(sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getHandlePersonId())).findFirst().orElse(null)).getNickName());
+        if(!CollectionUtils.isEmpty(userIds)){
+            List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
+            for (TSamplingRecordOperation samplingRecordOperation : samplingRecordOperations) {
+                if(Objects.nonNull(samplingRecordOperation.getHandlePersonId())){
+                    List<SysUser> users = sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getHandlePersonId())).collect(Collectors.toList());
+                    if(!CollectionUtils.isEmpty(users)){
+                        samplingRecordOperation.setHandlePersonName(users.get(0).getNickName());
+                    }
+                }
+                if(Objects.nonNull(samplingRecordOperation.getSendPersonId())){
+                    List<SysUser> users = sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getSendPersonId())).collect(Collectors.toList());
+                    if(!CollectionUtils.isEmpty(users)){
+                        samplingRecordOperation.setSendPersonName(users.get(0).getNickName());
+                    }
+                }
+                if(Objects.nonNull(samplingRecordOperation.getReceiptsPersonId())){
+                    List<SysUser> users = sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getReceiptsPersonId())).collect(Collectors.toList());
+                    if(!CollectionUtils.isEmpty(users)){
+                        samplingRecordOperation.setReceiptsPersonName(users.get(0).getNickName());
+                    }
+                }
             }
-            if(Objects.nonNull(samplingRecordOperation.getSendPersonId())){
-                samplingRecordOperation.setSendPersonName(Objects.requireNonNull(sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getSendPersonId())).findFirst().orElse(null)).getNickName());
-            }
-            if(Objects.nonNull(samplingRecordOperation.getReceiptsPersonId())){
-                samplingRecordOperation.setReceiptsPersonName(Objects.requireNonNull(sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getReceiptsPersonId())).findFirst().orElse(null)).getNickName());
-            }
-        });
+        }
 
         samplingRecordVO.setSamplingRecordOperations(samplingRecordOperations);
         // 查询实验调度信息
@@ -263,10 +326,16 @@
             });
             String participantsName = tExperimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(";"));
             experimentDispatch.setParticipantsName(participantsName);
+
+            // 返回化验师列表
+            List<TExperimentDispatchParticipants> experimentDispatchParticipantChemists = tExperimentDispatchParticipants.stream().
+                    filter(a -> a.getRoleType().equals(4)).collect(Collectors.toList());
+            experimentDispatch.setExperimentDispatchParticipantChemists(experimentDispatchParticipantChemists);
             // 查询课题方案名称
             TProjectProposal projectProposal = projectProposalService.getById(experimentDispatch.getProposalId());
             if(Objects.nonNull(projectProposal)){
                 experimentDispatch.setProjectName(projectProposal.getProjectName());
+                experimentDispatch.setProjectCode(projectProposal.getProjectCode());
             }
         }
         samplingRecordVO.setExperimentDispatch(experimentDispatch);
@@ -282,8 +351,8 @@
     @DeleteMapping(value = "/open/t-sampling-record/deleteById")
     public R<Boolean> deleteById(@RequestParam String id) {
         // 删除取样操作记录
-        samplingRecordOperationService.remove(Wrappers.lambdaQuery(TSamplingRecordOperation.class).eq(TSamplingRecordOperation::getSamplingId, id));
-        return R.ok(samplingRecordService.removeById(id));
+        samplingRecordOperationService.removeById(id);
+        return R.ok();
     }
 
     /**
@@ -309,29 +378,26 @@
     public R<Boolean> batchSendSamples(@RequestBody String param) {
         BatchSendSamplesDTO batchSendSamplesDTO = JSON.parseObject(param, BatchSendSamplesDTO.class);
         Long userId = tokenService.getLoginUser().getUserId();
-        List<String> ids = batchSendSamplesDTO.getRecordOperationId();
         // 批量送样
-        List<TSamplingRecordOperation> samplingRecordOperations = samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
-                .in(TSamplingRecordOperation::getId, ids));
+        List<TSamplingRecordOperation> samplingRecordOperations = batchSendSamplesDTO.getRecordOperationList();
         for (TSamplingRecordOperation samplingRecordOperation : samplingRecordOperations) {
             samplingRecordOperation.setStatus(2);
             samplingRecordOperation.setSendPersonId(userId);
-            samplingRecordOperation.setSendSign(samplingRecordOperation.getSendSign());
             samplingRecordOperation.setSendTime(LocalDateTime.now());
         }
         samplingRecordOperationService.updateBatchById(samplingRecordOperations);
 
         // 查询取样记录信息
-        TSamplingRecord samplingRecord = samplingRecordService.getById(samplingRecordOperations.get(0).getSamplingId());
+//        TSamplingRecord samplingRecord = samplingRecordService.getById(samplingRecordOperations.get(0).getSamplingId());
         // 查询实验调度
-        TExperimentDispatch experimentDispatch = experimentDispatchService.getById(samplingRecord.getDispatchId());
+//        TExperimentDispatch experimentDispatch = experimentDispatchService.getById(samplingRecord.getDispatchId());
         // 查询实验调度参与人员
-        List<TExperimentDispatchParticipants> teamStaffs = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
-                .eq(TExperimentDispatchParticipants::getDispatchId, experimentDispatch.getId())
-                .eq(TExperimentDispatchParticipants::getRoleType, 4));
+//        List<TExperimentDispatchParticipants> teamStaffs = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
+//                .eq(TExperimentDispatchParticipants::getDispatchId, experimentDispatch.getId())
+//                .eq(TExperimentDispatchParticipants::getRoleType, 4));
         // MESSAGE 添加消息
-        teamStaffs.forEach(teamStaff -> {
-            noticeService.saveNotice(teamStaff.getUserId(), "您有【1】条【送样单】等待确认接收样品", tokenService.getLoginUser().getUser().getNickName(),13);
+        samplingRecordOperations.forEach(samplingRecordOperation -> {
+            noticeService.saveNotice(samplingRecordOperation.getReceiptsPersonId(), "您有【1】条【送样单】等待确认接收样品", tokenService.getLoginUser().getUser().getNickName(),13);
         });
         return R.ok();
     }
@@ -345,18 +411,27 @@
     @PostMapping(value = "/open/t-sampling-record/batchCollectSamples")
     public R<Boolean> batchCollectSamples(@RequestBody String param) {
         BatchCollectSamplesDTO batchCollectSamplesDTO = JSON.parseObject(param, BatchCollectSamplesDTO.class);
-        Long userId = tokenService.getLoginUser().getUserId();
+//        Long userId = tokenService.getLoginUser().getUserId();
         List<String> ids = batchCollectSamplesDTO.getRecordOperationId();
         // 批量送样
         List<TSamplingRecordOperation> samplingRecordOperations = samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
                 .in(TSamplingRecordOperation::getId, ids));
         for (TSamplingRecordOperation samplingRecordOperation : samplingRecordOperations) {
             samplingRecordOperation.setStatus(3);
-            samplingRecordOperation.setReceiptsPersonId(userId);
+//            samplingRecordOperation.setReceiptsPersonId(userId);
             samplingRecordOperation.setReceiptsSign(samplingRecordOperation.getReceiptsSign());
             samplingRecordOperation.setReceiptsTime(LocalDateTime.now());
         }
         samplingRecordOperationService.updateBatchById(samplingRecordOperations);
+
+        // 判断是否所有取样记录都收样了
+        List<TSamplingRecordOperation> allRecordOperations = samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
+                .eq(TSamplingRecordOperation::getSamplingId, samplingRecordOperations.get(0).getSamplingId()));
+        if(allRecordOperations.stream().allMatch(e -> e.getStatus() == 3)){
+            samplingRecordService.update(Wrappers.lambdaUpdate(TSamplingRecord.class)
+                    .set(TSamplingRecord::getStatus, 4)
+                    .eq(TSamplingRecord::getId, samplingRecordOperations.get(0).getSamplingId()));
+        }
         return R.ok();
     }
 

--
Gitblit v1.7.1