package com.ruoyi.web.controller.api;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.model.*;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TBreedingAndPreservationDTO;
import com.ruoyi.system.dto.TTrainLibraryDTO;
import com.ruoyi.system.query.TBreedingAndPreservationQuery;
import com.ruoyi.system.query.TPedigreeChartConfirmQuery;
import com.ruoyi.system.query.TPedigreeChartQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TBreedingAndPreservationDetailVO;
import com.ruoyi.system.vo.TBreedingAndPreservationVO;
import com.ruoyi.system.vo.TPedigreeChartVO;
import com.ruoyi.system.vo.TProjectTeamVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.stream.Collectors;
/**
*
* 菌种选育保藏记录 前端控制器
*
*
* @author 无关风月
* @since 2025-04-12
*/
@RestController
@RequestMapping("")
@Api(tags = "菌种选育保藏记录")
public class TBreedingAndPreservationController {
@Resource
private TBreedingAndPreservationService breedingAndPreservationService;
@Resource
private TCulturePreservationService culturePreservationService;
@Resource
private TObservationOfPetriDishesService observationOfPetriDishesService;
@Resource
private TVaccinationSlopeService vaccinationSlopeService;
@Resource
private TSeparationOfCultureDishesService separationOfCultureDishesService;
@Resource
private TokenService tokenService;
@Resource
private ISysUserService sysUserService;
/**
* 菌种选育保藏记录分页列表
*/
//@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:list')")
@ApiOperation(value = "菌种选育保藏记录-获取菌种选育保藏记录分页列表",response = TBreedingAndPreservationQuery.class)
@PostMapping(value = "/api/t-breeding-and-preservation/pageList")
public R> 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);
return R.ok(breedingAndPreservationService.pageList(query));
}
/**
* 新增菌种库
*/
//@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:add')")
@Log(title = "菌种选育保藏记录-新增选育保藏记录", businessType = BusinessType.INSERT)
@ApiOperation(value = "菌种选育保藏记录-新增选育保藏记录",response = TBreedingAndPreservationDTO.class)
@PostMapping(value = "/api/t-breeding-and-preservation/add")
public R add(@RequestBody String param) {
if (tokenService.getLoginUser()==null){
return R.fail(401,"登陆失效");
}
TBreedingAndPreservationDTO dto = JSON.parseObject(param,TBreedingAndPreservationDTO.class);
if (dto.getStatus()==3){
dto.setIsDraft(1);
}
breedingAndPreservationService.save(dto);
List separationOfCultureDishesList = dto.getSeparationOfCultureDishesList();
for (TSeparationOfCultureDishes tSeparationOfCultureDishes : separationOfCultureDishesList) {
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
separationOfCultureDishesService.saveBatch(separationOfCultureDishesList);
List observationOfPetriDishes = dto.getObservationOfPetriDishes();
for (TObservationOfPetriDishes tSeparationOfCultureDishes : observationOfPetriDishes) {
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
observationOfPetriDishesService.saveBatch(observationOfPetriDishes);
List vaccinationSlopes = dto.getVaccinationSlopes();
for (TVaccinationSlope tSeparationOfCultureDishes : vaccinationSlopes) {
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
vaccinationSlopeService.saveBatch(vaccinationSlopes);
List culturePreservations = dto.getCulturePreservations();
for (TCulturePreservation tSeparationOfCultureDishes : culturePreservations) {
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
culturePreservationService.saveBatch(culturePreservations);
if (dto.getStatus()!=null&&dto.getStatus()==2){
// 新增消息
TNotice tNotice = new TNotice();
List 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);
}
return R.ok();
}
@Resource
private TProjectTeamService projectTeamService;
@Resource
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")
public R update(@RequestBody String param) {
if (tokenService.getLoginUser()==null){
return R.fail(401,"登陆失效");
}
TBreedingAndPreservationDTO dto = JSON.parseObject(param,TBreedingAndPreservationDTO.class);
if (dto.getStatus()==3){
dto.setIsDraft(1);
}else{
dto.setIsDraft(0);
}
breedingAndPreservationService.updateById(dto);
List separationOfCultureDishesList = dto.getSeparationOfCultureDishesList();
for (TSeparationOfCultureDishes tSeparationOfCultureDishes : separationOfCultureDishesList) {
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
separationOfCultureDishesService.remove(new LambdaQueryWrapper().eq(TSeparationOfCultureDishes::getBreedingPreserveId, dto.getId()));
separationOfCultureDishesService.saveBatch(separationOfCultureDishesList);
List observationOfPetriDishes = dto.getObservationOfPetriDishes();
for (TObservationOfPetriDishes observationOfPetriDish : observationOfPetriDishes) {
observationOfPetriDish.setBreedingPreserveId(dto.getId());
}
observationOfPetriDishesService.remove(new LambdaQueryWrapper().eq(TObservationOfPetriDishes::getBreedingPreserveId, dto.getId()));
observationOfPetriDishesService.saveBatch(observationOfPetriDishes);
List vaccinationSlopes = dto.getVaccinationSlopes();
for (TVaccinationSlope vaccinationSlope : vaccinationSlopes) {
vaccinationSlope.setBreedingPreserveId(dto.getId());
}
vaccinationSlopeService.remove(new LambdaQueryWrapper().eq(TVaccinationSlope::getBreedingPreserveId, dto.getId()));
vaccinationSlopeService.saveBatch(vaccinationSlopes);
List culturePreservations = dto.getCulturePreservations();
for (TCulturePreservation tSeparationOfCultureDishes : culturePreservations) {
tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
}
culturePreservationService.remove(new LambdaQueryWrapper().eq(TCulturePreservation::getBreedingPreserveId, dto.getId()));
culturePreservationService.saveBatch(culturePreservations);
if (dto.getStatus()==2){
// 新增消息
TNotice tNotice = new TNotice();
List 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);
}
return R.ok();
}
@Log(title = "接种斜面记录确认入库", businessType = BusinessType.UPDATE)
@ApiOperation(value = "接种斜面记录确认入库",response = TConfirmBreedingAndPreservationDTO.class)
@PostMapping(value = "/api/t-breeding-and-preservation/vaccinationSlopesConfirm")
public R vaccinationSlopesConfirm(@RequestBody String param) {
Long userId = tokenService.getLoginUser().getUserId();
TConfirmBreedingAndPreservationDTO dto = JSON.parseObject(param,TConfirmBreedingAndPreservationDTO.class);
TVaccinationSlope byId = vaccinationSlopeService.getById(dto.getId());
byId.setPreserveId(userId+"");
byId.setPreserveTime(LocalDateTime.now());
byId.setPreserveSignature(dto.getPreserveSignature());
vaccinationSlopeService.updateById(byId);
return R.ok();
}
@Log(title = "菌种保藏记录确认入库", businessType = BusinessType.UPDATE)
@ApiOperation(value = "菌种保藏记录确认入库",response = TConfirmBreedingAndPreservationDTO.class)
@PostMapping(value = "/api/t-breeding-and-preservation/culturePreservationsConfirm")
public R culturePreservationsConfirm(@RequestBody String param) {
Long userId = tokenService.getLoginUser().getUserId();
TConfirmBreedingAndPreservationDTO dto = JSON.parseObject(param,TConfirmBreedingAndPreservationDTO.class);
TCulturePreservation byId = culturePreservationService.getById(dto.getId());
byId.setPreserveId(userId+"");
byId.setPreserveTime(LocalDateTime.now());
byId.setPreserveSignature(dto.getPreserveSignature());
culturePreservationService.updateById(byId);
return R.ok();
}
//@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:detail')")
@ApiOperation(value = "选育保藏记录详情")
@GetMapping(value = "/open/t-breeding-and-preservation/getDetailById")
public R getDetailById(@RequestParam String id) {
TBreedingAndPreservationDetailVO res = new TBreedingAndPreservationDetailVO();
TBreedingAndPreservation breedingAndPreservation = breedingAndPreservationService.getById(id);
BeanUtils.copyProperties(breedingAndPreservation, res);
List separationOfCultureDishesList = separationOfCultureDishesService.lambdaQuery().eq(TSeparationOfCultureDishes::getBreedingPreserveId, id).list();
List observationOfPetriDishes = observationOfPetriDishesService.lambdaQuery().eq(TObservationOfPetriDishes::getBreedingPreserveId, id).list();
List vaccinationSlopes = vaccinationSlopeService.lambdaQuery().eq(TVaccinationSlope::getBreedingPreserveId, id).list();
List culturePreservations = culturePreservationService.lambdaQuery().eq(TCulturePreservation::getBreedingPreserveId, id).list();
res.setSeparationOfCultureDishesList(separationOfCultureDishesList);
res.setObservationOfPetriDishes(observationOfPetriDishes);
res.setVaccinationSlopes(vaccinationSlopes);
res.setCulturePreservations(culturePreservations);
return R.ok(res);
}
//
// @Log(title = "培养皿分离记录删除", businessType = BusinessType.DELETE)
// @ApiOperation(value = "培养皿分离记录删除")
// @DeleteMapping(value = "/open/t_project_team/deleteSeparationOfCultureDishes")
// public R deleteSeparationOfCultureDishes(@RequestParam String id) {
// return R.ok(separationOfCultureDishesService.removeById(id));
// }
// @Log(title = "培养皿生物学形态观察记录", businessType = BusinessType.DELETE)
// @ApiOperation(value = "培养皿生物学形态观察记录删除")
// @DeleteMapping(value = "/open/t_project_team/deleteObservationOfPetriDishes")
// public R deleteObservationOfPetriDishes(@RequestParam String id) {
//
// return R.ok(observationOfPetriDishesService.removeById(id));
// }
// @Log(title = "接种斜面记录删除", businessType = BusinessType.DELETE)
// @ApiOperation(value = "接种斜面记录删除")
// @DeleteMapping(value = "/open/t_project_team/deleteVaccinationSlope")
// public R deleteVaccinationSlope(@RequestParam String id) {
// TVaccinationSlope byId = vaccinationSlopeService.getById(id);
// if (byId.getPreserveSignature()!=null){
// return R.fail("菌种保藏人签字确认之后,不可删除");
// }
// return R.ok(vaccinationSlopeService.removeById(id));
// }
// @Log(title = "菌种保藏记录删除", businessType = BusinessType.DELETE)
// @ApiOperation(value = "菌种保藏记录删除")
// @DeleteMapping(value = "/open/t_project_team/deleteCulturePreservation")
// public R deleteCulturePreservation(@RequestParam String id) {
// TCulturePreservation byId = culturePreservationService.getById(id);
// if (byId.getPreserveSignature()!=null){
// return R.fail("菌种保藏人签字确认之后,不可删除");
// }
// return R.ok(culturePreservationService.removeById(id));
// }
@Log(title = "菌种保藏记录删除", businessType = BusinessType.DELETE)
@ApiOperation(value = "菌种保藏记录删除")
@DeleteMapping(value = "/open/t_project_team/deleteBreedingAndPreservation")
public R deleteCulturePreservation(@RequestParam String id) {
return R.ok(breedingAndPreservationService.removeById(id));
}
}