From 2fa7f761cf80802f54f727381b282d3b264501a7 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 08 十月 2026 11:11:26 +0800
Subject: [PATCH] 提交最新代码
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSamplingRecordController.java | 200 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 169 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 26e8cca..f8a83a9 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;
@@ -22,13 +23,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 +54,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 +68,8 @@
this.projectTeamService = projectTeamService;
this.projectTeamStaffService = projectTeamStaffService;
this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
+ this.noticeService = noticeService;
+ this.inspectionReportService = inspectionReportService;
}
/**
@@ -76,6 +80,81 @@
@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));
+ if(Objects.isNull(projectTeamStaff)){
+ return R.fail("当前用户未加入项目组,无法进行操作");
+ }
+ // 查询项目的工艺工程师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<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));
}
@@ -191,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);
// 查询实验调度信息
@@ -228,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);
@@ -247,8 +351,15 @@
@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));
+ TSamplingRecord samplingRecord = samplingRecordService.getById(id);
+ if (Objects.nonNull(samplingRecord)) {
+ samplingRecordOperationService.remove(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
+ .eq(TSamplingRecordOperation::getSamplingId, id));
+ samplingRecordService.removeById(id);
+ } else {
+ samplingRecordOperationService.removeById(id);
+ }
+ return R.ok();
}
/**
@@ -275,12 +386,26 @@
BatchSendSamplesDTO batchSendSamplesDTO = JSON.parseObject(param, BatchSendSamplesDTO.class);
Long userId = tokenService.getLoginUser().getUserId();
// 批量送样
- 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 = batchSendSamplesDTO.getRecordOperationList();
+ for (TSamplingRecordOperation samplingRecordOperation : samplingRecordOperations) {
+ samplingRecordOperation.setStatus(2);
+ samplingRecordOperation.setSendPersonId(userId);
+ 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 添加消息
+ samplingRecordOperations.forEach(samplingRecordOperation -> {
+ noticeService.saveNotice(samplingRecordOperation.getReceiptsPersonId(), "您有【1】条【送样单】等待确认接收样品", tokenService.getLoginUser().getUser().getNickName(),13);
+ });
return R.ok();
}
@@ -293,14 +418,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();
// 批量送样
- 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);
+
+ // 判断是否所有取样记录都收样了
+ 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