From 0c989fbcca1cd4b53d59e8ba288227a5a68d92a4 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 27 六月 2025 18:08:25 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/laboratory

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java |  111 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 95 insertions(+), 16 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 26e8cca..3db12d7 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
@@ -22,13 +22,12 @@
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 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;
 
 /**
@@ -54,8 +53,10 @@
     private final TProjectTeamService projectTeamService;
     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) {
+    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;
@@ -66,6 +67,8 @@
         this.projectTeamService = projectTeamService;
         this.projectTeamStaffService = projectTeamStaffService;
         this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
+        this.noticeService = noticeService;
+        this.inspectionReportService = inspectionReportService;
     }
 
     /**
@@ -76,6 +79,61 @@
     @PostMapping(value = "/api/t-sampling-record/pageList")
     public R<PageInfo<TSamplingRecordVO>> pageList(@RequestBody String param) {
         TSamplingRecordQuery query = JSON.parseObject(param, TSamplingRecordQuery.class);
+        // 获取当前用户
+        Long userId = tokenService.getLoginUser().getUserId();
+        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+        query.setRoleType(roleType);
+        if (roleType != 1){
+            query.setUserId(userId);
+            if(roleType ==2){
+                // 查询项目组
+                TProjectTeamStaff projectTeamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
+                        .eq(TProjectTeamStaff::getUserId, userId));
+                // 查询项目的工艺工程师id
+                TProjectTeamStaff teamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
+                        .eq(TProjectTeamStaff::getTeamId, projectTeamStaff.getTeamId())
+                        .eq(TProjectTeamStaff::getRoleType, 3)
+                        .last("LIMIT 1"));
+                // 查询实验参与人员
+                List<TExperimentDispatchParticipants> experimentDispatchParticipants = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
+                        .eq(TExperimentDispatchParticipants::getUserId, teamStaff.getUserId()));
+                if(!CollectionUtils.isEmpty(experimentDispatchParticipants)){
+                    List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
+                    query.setDispatchIds(dispatchIds);
+                }
+            }else {
+                // 查询实验参与人员
+                List<TExperimentDispatchParticipants> experimentDispatchParticipants = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
+                        .eq(TExperimentDispatchParticipants::getUserId, userId));
+                if (!CollectionUtils.isEmpty(experimentDispatchParticipants)) {
+                    List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
+                    query.setDispatchIds(dispatchIds);
+                }
+            }
+            if(roleType == 4){
+                // 查询检验报告
+                List<TInspectionReport> inspectionReports = inspectionReportService.list(Wrappers.lambdaQuery(TInspectionReport.class)
+                        .eq(TInspectionReport::getStatus, 1));
+                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);
+                    }
+                }
+            }
+        }
         return R.ok(samplingRecordService.pageList(query));
     }
 
@@ -274,13 +332,30 @@
     public R<Boolean> batchSendSamples(@RequestBody String param) {
         BatchSendSamplesDTO batchSendSamplesDTO = JSON.parseObject(param, BatchSendSamplesDTO.class);
         Long userId = tokenService.getLoginUser().getUserId();
+        List<String> ids = batchSendSamplesDTO.getRecordOperationId();
         // 批量送样
-        samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class)
-                .eq(TSamplingRecordOperation::getId, batchSendSamplesDTO.getRecordOperationId())
-                .set(TSamplingRecordOperation::getStatus, 2)
-                .set(TSamplingRecordOperation::getSendSign, batchSendSamplesDTO.getSendSign())
-                .set(TSamplingRecordOperation::getSendTime, LocalDateTime.now())
-                .set(TSamplingRecordOperation::getSendPersonId, userId));
+        List<TSamplingRecordOperation> samplingRecordOperations = samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
+                .in(TSamplingRecordOperation::getId, ids));
+        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());
+        // 查询实验调度
+        TExperimentDispatch experimentDispatch = experimentDispatchService.getById(samplingRecord.getDispatchId());
+        // 查询实验调度参与人员
+        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);
+        });
         return R.ok();
     }
 
@@ -294,13 +369,17 @@
     public R<Boolean> batchCollectSamples(@RequestBody String param) {
         BatchCollectSamplesDTO batchCollectSamplesDTO = JSON.parseObject(param, BatchCollectSamplesDTO.class);
         Long userId = tokenService.getLoginUser().getUserId();
+        List<String> ids = batchCollectSamplesDTO.getRecordOperationId();
         // 批量送样
-        samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class)
-                .eq(TSamplingRecordOperation::getId, batchCollectSamplesDTO.getRecordOperationId())
-                .set(TSamplingRecordOperation::getStatus, 3)
-                .set(TSamplingRecordOperation::getReceiptsSign, batchCollectSamplesDTO.getReceiptsSign())
-                .set(TSamplingRecordOperation::getReceiptsTime, LocalDateTime.now())
-                .set(TSamplingRecordOperation::getReceiptsPersonId, userId));
+        List<TSamplingRecordOperation> samplingRecordOperations = samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
+                .in(TSamplingRecordOperation::getId, ids));
+        for (TSamplingRecordOperation samplingRecordOperation : samplingRecordOperations) {
+            samplingRecordOperation.setStatus(3);
+            samplingRecordOperation.setReceiptsPersonId(userId);
+            samplingRecordOperation.setReceiptsSign(samplingRecordOperation.getReceiptsSign());
+            samplingRecordOperation.setReceiptsTime(LocalDateTime.now());
+        }
+        samplingRecordOperationService.updateBatchById(samplingRecordOperations);
         return R.ok();
     }
 

--
Gitblit v1.7.1