xuhy
2025-12-09 9f480a6addb804f667041224b5d527584a690c9b
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;
    }
    /**
@@ -82,12 +83,16 @@
        // 获取当前用户
        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));
                if(Objects.isNull(projectTeamStaff)){
                    return R.fail("当前用户未加入项目组,无法进行操作");
                }
                // 查询项目的工艺工程师id
                TProjectTeamStaff teamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                        .eq(TProjectTeamStaff::getTeamId, projectTeamStaff.getTeamId())
@@ -107,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);
                                //                    }
                            }
                        }
                    }
                }
            }
        }
@@ -225,8 +270,16 @@
        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());
@@ -234,17 +287,26 @@
        userIds.addAll(sendUserIds);
        userIds.addAll(receiptsUserIds);
        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
        samplingRecordOperations.forEach(samplingRecordOperation -> {
        for (TSamplingRecordOperation samplingRecordOperation : samplingRecordOperations) {
            if(Objects.nonNull(samplingRecordOperation.getHandlePersonId())){
                samplingRecordOperation.setHandlePersonName(Objects.requireNonNull(sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getHandlePersonId())).findFirst().orElse(null)).getNickName());
                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())){
                samplingRecordOperation.setSendPersonName(Objects.requireNonNull(sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getSendPersonId())).findFirst().orElse(null)).getNickName());
                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())){
                samplingRecordOperation.setReceiptsPersonName(Objects.requireNonNull(sysUsers.stream().filter(user -> user.getUserId().equals(samplingRecordOperation.getReceiptsPersonId())).findFirst().orElse(null)).getNickName());
                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());
                }
            }
        });
        }
        samplingRecordVO.setSamplingRecordOperations(samplingRecordOperations);
        // 查询实验调度信息
@@ -262,6 +324,11 @@
            });
            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)){
@@ -308,29 +375,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();
    }
@@ -344,18 +408,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.setSendPersonId(userId);
            samplingRecordOperation.setSendSign(samplingRecordOperation.getReceiptsSign());
            samplingRecordOperation.setSendTime(LocalDateTime.now());
//            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();
    }