From 082bddee7df8a05ca95f473ec2643701d41a5213 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 08 十月 2026 11:09:01 +0800
Subject: [PATCH] 更新代码
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBreedingAndPreservationController.java | 302 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 256 insertions(+), 46 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBreedingAndPreservationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBreedingAndPreservationController.java
index dbb9ec1..ef97301 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBreedingAndPreservationController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBreedingAndPreservationController.java
@@ -4,8 +4,11 @@
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.system.dto.TConfirmBreedingAndPreservationDTO;
+import com.ruoyi.system.mapper.TProjectTeamMapper;
import com.ruoyi.system.model.*;
+import java.util.ArrayList;
import java.util.List;
@@ -29,6 +32,7 @@
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -70,12 +74,40 @@
@ApiOperation(value = "菌种选育保藏记录-获取菌种选育保藏记录分页列表",response = TBreedingAndPreservationQuery.class)
@PostMapping(value = "/api/t-breeding-and-preservation/pageList")
public R<PageInfo<TBreedingAndPreservationVO>> pageList(@RequestBody String param) {
- LoginUser loginUser = tokenService.getLoginUser();
- if (loginUser==null){
- return R.fail(401,"登录失效");
- }
- SysUser sysUser = sysUserService.selectUserById(loginUser.getUserId());
+
TBreedingAndPreservationQuery query = JSON.parseObject(param, TBreedingAndPreservationQuery.class);
+ SysUser sysUser = sysUserService.selectUserById(tokenService.getLoginUser().getUserId());
+ if (sysUser.getRoleType().equals("2")){
+ List<String> allProjectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
+ .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
+ if (!allProjectIds.isEmpty()){ List<String> projectIds = projectTeamService.lambdaQuery().in(TProjectTeam::getId, allProjectIds)
+ .list().stream().map(TProjectTeam::getId).collect(Collectors.toList());
+
+ if (projectIds.isEmpty()){
+ return R.ok(new PageInfo<>());
+ }
+ query.setProjectIds(projectIds);
+ }else {
+ return R.ok(new PageInfo<>());
+ }
+ }else if (!sysUser.getRoleType().equals("1")){
+ if (query.getProjectIds() == null || query.getProjectIds().isEmpty()){
+ List<String> allProjectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
+ .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
+ if (!allProjectIds.isEmpty()){
+ List<String> projectIds = projectTeamService.lambdaQuery().in(TProjectTeam::getId, allProjectIds)
+ .eq(TProjectTeam::getStatus, 1).list().stream().map(TProjectTeam::getId).collect(Collectors.toList());
+
+ if (projectIds.isEmpty()){
+ return R.ok(new PageInfo<>());
+ }
+ query.setProjectIds(projectIds);
+ }else {
+ return R.ok(new PageInfo<>());
+ }
+ }
+ }
+
return R.ok(breedingAndPreservationService.pageList(query));
}
/**
@@ -90,6 +122,22 @@
return R.fail(401,"登陆失效");
}
TBreedingAndPreservationDTO dto = JSON.parseObject(param,TBreedingAndPreservationDTO.class);
+ if (dto.getStatus()==1){
+ return R.fail("有菌种待确认,无法提交");
+ }
+
+ if (dto.getStatus()==3){
+ dto.setIsDraft(1);
+ }
+ List<String> projectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
+ .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
+ if (!projectIds.isEmpty()){
+ TProjectTeam projectTeam = projectTeamService.lambdaQuery().in(TProjectTeam::getId, projectIds)
+ .eq(TProjectTeam::getStatus, 1)
+ .orderByDesc(BaseModel::getCreateTime)
+ .last("limit 1").one();
+ dto.setProjectId(projectTeam.getId());
+ }
breedingAndPreservationService.save(dto);
List<TSeparationOfCultureDishes> separationOfCultureDishesList = dto.getSeparationOfCultureDishesList();
for (TSeparationOfCultureDishes tSeparationOfCultureDishes : separationOfCultureDishesList) {
@@ -103,33 +151,20 @@
observationOfPetriDishesService.saveBatch(observationOfPetriDishes);
List<TVaccinationSlope> vaccinationSlopes = dto.getVaccinationSlopes();
for (TVaccinationSlope tSeparationOfCultureDishes : vaccinationSlopes) {
+ tSeparationOfCultureDishes.setHandleId(tokenService.getLoginUser().getUserId()+"");
+ tSeparationOfCultureDishes.setHandleTime(LocalDateTime.now());
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
vaccinationSlopeService.saveBatch(vaccinationSlopes);
List<TCulturePreservation> culturePreservations = dto.getCulturePreservations();
for (TCulturePreservation tSeparationOfCultureDishes : culturePreservations) {
+ tSeparationOfCultureDishes.setHandleId(tokenService.getLoginUser().getUserId()+"");
+ tSeparationOfCultureDishes.setHandleTime(LocalDateTime.now());
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
culturePreservationService.saveBatch(culturePreservations);
- if (dto.getStatus()==2){
- // 新增消息
- TNotice tNotice = new TNotice();
- List<String> collect = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
- .eq(TProjectTeamStaff::getRoleType, 2)
- .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
- TProjectTeam one = projectTeamService.lambdaQuery().in(TProjectTeam::getId, collect)
- .eq(TProjectTeam::getStatus, 1)
- .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
- TProjectTeamStaff one1 = projectTeamStaffService.lambdaQuery()
- .eq(TProjectTeamStaff::getTeamId, one.getId()).eq(TProjectTeamStaff::getRoleType, 2).one();
- tNotice.setUserId(one1.getUserId());
-
- tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
- tNotice.setStatus(1);
- tNotice.setNoticeContent("您有【1】条【菌种选育保藏记录】等待签字入库确认;");
- tNotice.setDataId(dto.getId());
- tNotice.setNoticeType(5);
- noticeService.save(tNotice);
+ if (dto.getStatus()!=null&&dto.getStatus()==2){
+ notifyProjectEngineers(dto.getProjectId(), dto.getId(), 5);
}
return R.ok();
}
@@ -139,7 +174,6 @@
private TProjectTeamStaffService projectTeamStaffService;
@Resource
private TNoticeService noticeService;
- //@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:update')")
@Log(title = "菌种选育保藏记录-编辑选育保藏记录", businessType = BusinessType.UPDATE)
@ApiOperation(value = "菌种选育保藏记录-编辑选育保藏记录",response = TBreedingAndPreservationDTO.class)
@PostMapping(value = "/api/t-breeding-and-preservation/update")
@@ -148,6 +182,40 @@
return R.fail(401,"登陆失效");
}
TBreedingAndPreservationDTO dto = JSON.parseObject(param,TBreedingAndPreservationDTO.class);
+ if (dto.getStatus()==3){
+ dto.setIsDraft(1);
+ }else{
+ dto.setIsDraft(0);
+ }
+ TBreedingAndPreservation breedingAndPreservationServiceById = breedingAndPreservationService.getById(dto.getId());
+ if (breedingAndPreservationServiceById == null) {
+ return R.fail("记录不存在");
+ }
+ if (breedingAndPreservationServiceById.getStatus()==1){
+ return R.fail("该记录已提交,不可编辑!");
+ }
+ SysUser currentUser = sysUserService.selectUserById(tokenService.getLoginUser().getUserId());
+ if ("3".equals(currentUser.getRoleType())) {
+ return R.fail("菌种工程师只能进行入库确认,不能编辑记录");
+ }
+ List<TVaccinationSlope> vaccinationSlopes = dto.getVaccinationSlopes();
+ List<TCulturePreservation> culturePreservations = dto.getCulturePreservations();
+ if (vaccinationSlopes == null || culturePreservations == null) {
+ return R.fail("接种斜面记录和菌种保藏记录不能为空");
+ }
+ if (dto.getStatus() != null && dto.getStatus() == 1) {
+ if (breedingAndPreservationServiceById.getStatus() == null
+ || breedingAndPreservationServiceById.getStatus() != 2) {
+ return R.fail("请先同步给保藏人并完成入库确认");
+ }
+ boolean slopeUnconfirmed = vaccinationSlopes.stream().anyMatch(item ->
+ !StringUtils.hasLength(item.getPreserveId()) || !StringUtils.hasLength(item.getPreserveSignature()));
+ boolean preservationUnconfirmed = culturePreservations.stream().anyMatch(item ->
+ !StringUtils.hasLength(item.getPreserveId()) || !StringUtils.hasLength(item.getPreserveSignature()));
+ if (slopeUnconfirmed || preservationUnconfirmed) {
+ return R.fail("存在未确认的接种斜面或菌种保藏记录,不能提交");
+ }
+ }
breedingAndPreservationService.updateById(dto);
List<TSeparationOfCultureDishes> separationOfCultureDishesList = dto.getSeparationOfCultureDishesList();
for (TSeparationOfCultureDishes tSeparationOfCultureDishes : separationOfCultureDishesList) {
@@ -161,57 +229,192 @@
}
observationOfPetriDishesService.remove(new LambdaQueryWrapper<TObservationOfPetriDishes>().eq(TObservationOfPetriDishes::getBreedingPreserveId, dto.getId()));
observationOfPetriDishesService.saveBatch(observationOfPetriDishes);
- List<TVaccinationSlope> vaccinationSlopes = dto.getVaccinationSlopes();
for (TVaccinationSlope vaccinationSlope : vaccinationSlopes) {
vaccinationSlope.setBreedingPreserveId(dto.getId());
}
vaccinationSlopeService.remove(new LambdaQueryWrapper<TVaccinationSlope>().eq(TVaccinationSlope::getBreedingPreserveId, dto.getId()));
vaccinationSlopeService.saveBatch(vaccinationSlopes);
- List<TCulturePreservation> culturePreservations = dto.getCulturePreservations();
for (TCulturePreservation tSeparationOfCultureDishes : culturePreservations) {
+
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
culturePreservationService.remove(new LambdaQueryWrapper<TCulturePreservation>().eq(TCulturePreservation::getBreedingPreserveId, dto.getId()));
+ for (TCulturePreservation culturePreservation : culturePreservations) {
+ culturePreservation.setBreedingPreserveId(dto.getId());
+ }
culturePreservationService.saveBatch(culturePreservations);
if (dto.getStatus()==2){
- // 新增消息
- TNotice tNotice = new TNotice();
- List<String> collect = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
- .eq(TProjectTeamStaff::getRoleType, 2)
- .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
- TProjectTeam one = projectTeamService.lambdaQuery().in(TProjectTeam::getId, collect)
- .eq(TProjectTeam::getStatus, 1)
- .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
- TProjectTeamStaff one1 = projectTeamStaffService.lambdaQuery()
- .eq(TProjectTeamStaff::getTeamId, one.getId()).eq(TProjectTeamStaff::getRoleType, 2).one();
- tNotice.setUserId(one1.getUserId());
-
- tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
- tNotice.setStatus(1);
- tNotice.setNoticeContent("您有【1】条【菌种选育保藏记录】等待签字入库确认;");
- tNotice.setDataId(dto.getId());
- tNotice.setNoticeType(6);
- noticeService.save(tNotice);
+ notifyProjectEngineers(dto.getProjectId(), dto.getId(), 6);
}
return R.ok();
+ }
+
+ private void notifyProjectEngineers(String projectId, String dataId, int noticeType) {
+ List<TProjectTeamStaff> engineers = projectTeamStaffService.lambdaQuery()
+ .eq(TProjectTeamStaff::getTeamId, projectId)
+ .eq(TProjectTeamStaff::getRoleType, 3)
+ .list();
+ for (TProjectTeamStaff engineer : engineers) {
+ TNotice notice = new TNotice();
+ notice.setUserId(engineer.getUserId());
+ notice.setCommitId(tokenService.getLoginUser().getUserId() + "");
+ notice.setStatus(1);
+ notice.setNoticeContent("您有【1】条【菌种选育保藏记录】等待签字入库确认;");
+ notice.setDataId(dataId);
+ notice.setNoticeType(noticeType);
+ noticeService.save(notice);
+ }
+ }
+
+ @Log(title = "接种斜面记录确认入库", businessType = BusinessType.UPDATE)
+ @ApiOperation(value = "接种斜面记录确认入库",response = TConfirmBreedingAndPreservationDTO.class)
+ @PostMapping(value = "/api/t-breeding-and-preservation/vaccinationSlopesConfirm")
+ public R<Boolean> vaccinationSlopesConfirm(@RequestBody String param) {
+ if (tokenService.getLoginUser() == null) {
+ return R.fail(401, "登陆失效");
+ }
+ Long userId = tokenService.getLoginUser().getUserId();
+
+ TConfirmBreedingAndPreservationDTO dto = JSON.parseObject(param,TConfirmBreedingAndPreservationDTO.class);
+ TVaccinationSlope vaccinationSlope = vaccinationSlopeService.getById(dto.getId());
+ if (vaccinationSlope == null) {
+ return R.fail("接种斜面记录不存在");
+ }
+ R<Boolean> validation = validatePreservationConfirmation(vaccinationSlope.getBreedingPreserveId(), userId,
+ vaccinationSlope.getPreserveSignature());
+ if (validation != null) {
+ return validation;
+ }
+ vaccinationSlope.setPreserveId(userId+"");
+ vaccinationSlope.setPreserveTime(LocalDateTime.now());
+ vaccinationSlope.setPreserveSignature(dto.getPreserveSignature());
+ vaccinationSlopeService.updateById(vaccinationSlope);
+ return R.ok();
+ }
+ @Log(title = "菌种保藏记录确认入库", businessType = BusinessType.UPDATE)
+ @ApiOperation(value = "菌种保藏记录确认入库",response = TConfirmBreedingAndPreservationDTO.class)
+ @PostMapping(value = "/api/t-breeding-and-preservation/culturePreservationsConfirm")
+ public R<Boolean> culturePreservationsConfirm(@RequestBody String param) {
+ if (tokenService.getLoginUser() == null) {
+ return R.fail(401, "登陆失效");
+ }
+ Long userId = tokenService.getLoginUser().getUserId();
+ TConfirmBreedingAndPreservationDTO dto = JSON.parseObject(param,TConfirmBreedingAndPreservationDTO.class);
+ TCulturePreservation culturePreservation = culturePreservationService.getById(dto.getId());
+ if (culturePreservation == null) {
+ return R.fail("菌种保藏记录不存在");
+ }
+ R<Boolean> validation = validatePreservationConfirmation(culturePreservation.getBreedingPreserveId(), userId,
+ culturePreservation.getPreserveSignature());
+ if (validation != null) {
+ return validation;
+ }
+ culturePreservation.setPreserveId(userId+"");
+ culturePreservation.setPreserveTime(LocalDateTime.now());
+ culturePreservation.setPreserveSignature(dto.getPreserveSignature());
+ culturePreservationService.updateById(culturePreservation);
+ return R.ok();
+ }
+
+ @Resource
+ private TProjectTeamMapper tProjectTeamMapper;
+
+ private R<Boolean> validatePreservationConfirmation(String breedingPreserveId, Long userId,
+ String existingSignature) {
+ if (StringUtils.hasLength(existingSignature)) {
+ return R.fail("该记录已经确认,不能重复签字");
+ }
+ TBreedingAndPreservation record = breedingAndPreservationService.getById(breedingPreserveId);
+ if (record == null || record.getStatus() == null || record.getStatus() != 2) {
+ return R.fail("仅已同步且未提交的记录可以确认入库");
+ }
+ boolean isProjectEngineer = projectTeamStaffService.lambdaQuery()
+ .eq(TProjectTeamStaff::getTeamId, record.getProjectId())
+ .eq(TProjectTeamStaff::getUserId, userId)
+ .count() > 0;
+
+ SysUser sysUser = sysUserService.selectUserById(userId);
+
+ if (isProjectEngineer) {
+ if (!sysUser.getRoleType().equals("3")) {
+ return R.fail("仅当前项目的菌种工程师可以确认入库");
+ }
+ }
+ return null;
}
//@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:detail')")
@ApiOperation(value = "选育保藏记录详情")
@GetMapping(value = "/open/t-breeding-and-preservation/getDetailById")
public R<TBreedingAndPreservationDetailVO> getDetailById(@RequestParam String id) {
- TBreedingAndPreservationDetailVO res = new TBreedingAndPreservationDetailVO();
+ if (!StringUtils.hasText(id)) {
+ return R.fail("记录ID不能为空");
+ }
TBreedingAndPreservation breedingAndPreservation = breedingAndPreservationService.getById(id);
+ if (breedingAndPreservation == null) {
+ return R.fail("菌种选育保藏记录不存在或已删除");
+ }
+ List<SysUser> sysUsers = sysUserService.selectAllList();
+ TBreedingAndPreservationDetailVO res = new TBreedingAndPreservationDetailVO();
BeanUtils.copyProperties(breedingAndPreservation, res);
List<TSeparationOfCultureDishes> separationOfCultureDishesList = separationOfCultureDishesService.lambdaQuery().eq(TSeparationOfCultureDishes::getBreedingPreserveId, id).list();
List<TObservationOfPetriDishes> observationOfPetriDishes = observationOfPetriDishesService.lambdaQuery().eq(TObservationOfPetriDishes::getBreedingPreserveId, id).list();
List<TVaccinationSlope> vaccinationSlopes = vaccinationSlopeService.lambdaQuery().eq(TVaccinationSlope::getBreedingPreserveId, id).list();
List<TCulturePreservation> culturePreservations = culturePreservationService.lambdaQuery().eq(TCulturePreservation::getBreedingPreserveId, id).list();
+ for (TCulturePreservation culturePreservation : culturePreservations) {
+ SysUser sysUser = findUserById(sysUsers, culturePreservation.getHandleId());
+ if (sysUser!=null){
+ culturePreservation.setHandleName(sysUser.getNickName());
+ }
+ }
+ for (TVaccinationSlope vaccinationSlope : vaccinationSlopes) {
+ SysUser sysUser = findUserById(sysUsers, vaccinationSlope.getHandleId());
+ if (sysUser!=null){
+ vaccinationSlope.setHandleName(sysUser.getNickName());
+ }
+ }
+
+ if (com.ruoyi.common.utils.StringUtils.isNotEmpty(breedingAndPreservation.getProjectId())) {
+ TProjectTeam tProjectTeam = tProjectTeamMapper.selectById(breedingAndPreservation.getProjectId());
+ if (tProjectTeam != null) {
+ List<TProjectTeamStaff> list = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, tProjectTeam.getId()).list();
+ StringBuilder staffNames = new StringBuilder();
+ for (TProjectTeamStaff tProjectTeamStaff : list) {
+ SysUser sysUser = sysUserService.selectUserById(Long.valueOf(tProjectTeamStaff.getUserId()));
+ if (sysUser!=null){
+ staffNames.append(sysUser.getNickName()).append(",");
+ }
+ }
+ if (StringUtils.hasLength(staffNames.toString())){
+ tProjectTeam.setStaff(staffNames.substring(0, staffNames.toString().length() - 1));
+ }
+
+ List<TProjectTeam> tProjectTeamList = new ArrayList<>();
+ tProjectTeamList.add(tProjectTeam);
+ res.setTProjectTeamList(tProjectTeamList);
+ }
+ }
+
res.setSeparationOfCultureDishesList(separationOfCultureDishesList);
res.setObservationOfPetriDishes(observationOfPetriDishes);
res.setVaccinationSlopes(vaccinationSlopes);
res.setCulturePreservations(culturePreservations);
return R.ok(res);
+ }
+
+ private SysUser findUserById(List<SysUser> sysUsers, String userId) {
+ if (!StringUtils.hasText(userId)) {
+ return null;
+ }
+ try {
+ Long parsedUserId = Long.valueOf(userId);
+ return sysUsers.stream()
+ .filter(user -> user.getUserId() != null && user.getUserId().equals(parsedUserId))
+ .findFirst()
+ .orElse(null);
+ } catch (NumberFormatException exception) {
+ return null;
+ }
}
//
// @Log(title = "培养皿分离记录删除", businessType = BusinessType.DELETE)
@@ -251,6 +454,13 @@
@ApiOperation(value = "菌种保藏记录删除")
@DeleteMapping(value = "/open/t_project_team/deleteBreedingAndPreservation")
public R<Boolean> deleteCulturePreservation(@RequestParam String id) {
+ TBreedingAndPreservation record = breedingAndPreservationService.getById(id);
+ if (record == null) {
+ return R.fail("记录不存在");
+ }
+ if (record.getStatus() != null && record.getStatus() == 1) {
+ return R.fail("该记录已提交,不可删除");
+ }
return R.ok(breedingAndPreservationService.removeById(id));
}
}
--
Gitblit v1.7.1