xuhy
1 天以前 8586161442cbe058fae93bfd35a468485b9b505e
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java
@@ -27,9 +27,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 +54,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 +68,7 @@
        this.projectTeamStaffService = projectTeamStaffService;
        this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
        this.noticeService = noticeService;
        this.inspectionReportService = inspectionReportService;
    }
    /**
@@ -110,6 +110,46 @@
                    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);
                                //                    }
                            }
                        }
                    }
                }
            }
        }
        return R.ok(samplingRecordService.pageList(query));
    }