package com.ruoyi.web.controller.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.*;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TPedigreeChartConfirmQuery;
import com.ruoyi.system.query.TPedigreeChartDetailConfirmCountDTO;
import com.ruoyi.system.query.TPedigreeChartDetailQuery;
import com.ruoyi.system.query.TPedigreeChartQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TPedigreeChartConfirmVO;
import com.ruoyi.system.vo.TPedigreeChartDetailVO;
import com.ruoyi.system.vo.TPedigreeChartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.C;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/**
*
* 谱系图 前端控制器
*
*
* @author 无关风月
* @since 2025-04-12
*/
@RestController
@RequestMapping("")
@Api(tags = "谱系图管理")
public class TPedigreeChartController {
@Resource
private TPedigreeChartDetailService pedigreeChartDetailService;
@Resource
private TPedigreeChartService pedigreeChartService;
@Resource
private TokenService tokenService;
@Resource
private ISysUserService sysUserService;
/**
* 获取谱系图分页列表
*/
//@PreAuthorize("@ss.hasPermi('system:pedigreeChart:list')")
@ApiOperation(value = "谱系图-获取谱系图分页列表",response = TPedigreeChartQuery.class)
@PostMapping(value = "/api/t-pedigree-chart/pageList")
public R> pageList(@RequestBody String param) {
TPedigreeChartQuery query = JSON.parseObject(param, TPedigreeChartQuery.class);
SysUser sysUser = sysUserService.selectUserById(tokenService.getLoginUser().getUserId());
if (sysUser.getRoleType().equals("2")){
query.setRoleType(2);
List allProjectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
.list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
if (!allProjectIds.isEmpty()){
List 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")){
query.setRoleType(3);
List allProjectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
.list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
if (!allProjectIds.isEmpty()){ List 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<>());
}
}else{
query.setRoleType(1);
}
return R.ok(pedigreeChartService.pageList(query));
}
/**
* 谱系图-新增谱系图、新增谱系图
*/
//@PreAuthorize("@ss.hasPermi('system:pedigreeChart:addProgenitor')")
@Log(title = "谱系图-新增谱系图-新增谱系图", businessType = BusinessType.INSERT)
@ApiOperation(value = "新增谱系图-新增谱系图",response = TPedigreeChartParentAllDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/addProgenitor")
public R addProgenitorAll(@RequestBody String param) {
LoginUser loginUser = tokenService.getLoginUser();
if (loginUser==null){
return R.fail("登录失效");
}
TPedigreeChartParentAllDTO dto = JSON.parseObject(param, TPedigreeChartParentAllDTO.class);
TPedigreeChart parent = dto.getParent();
if (!dto.getOne().isEmpty()){
String child = JSON.toJSONString(dto.getOne().get(0));
parent.setJson(child);
}
List 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();
parent.setProjectId(projectTeam.getId());
}
pedigreeChartService.save(parent);
if (!dto.getOne().isEmpty()){
TPedigreeChartParentOneDTO oneLevel = dto.getOne().get(0);
oneLevel.setParentId("0");
oneLevel.setType(1);
oneLevel.setStatus(oneLevel.getStatus());
oneLevel.setStorageTime(LocalDateTime.now());
oneLevel.setPedigreeChartId(parent.getId());
oneLevel.setVaccinateId(loginUser.getUserId()+"");
oneLevel.setVaccinateSignature(oneLevel.getVaccinateSignature());
oneLevel.setVaccinateTime(LocalDateTime.now());
oneLevel.setId(null);
if (parent.getStatus()==1){
oneLevel.setAuditStatus(0);
}else{
oneLevel.setAuditStatus(1);
}
oneLevel.setCodeStatus(parent.getStatus());
pedigreeChartDetailService.save(oneLevel);
List countList = oneLevel.getChildren();
if (!countList.isEmpty()){
TPedigreeChartParentOneCountDTO count = countList.get(0);
count.setParentId(oneLevel.getId());
count.setType(2);
count.setVaccinateId(loginUser.getUserId()+"");
count.setVaccinateTime(LocalDateTime.now());
count.setStatus(1);
count.setPedigreeChartId(parent.getId());
count.setId(null);
if (parent.getStatus()==1){
count.setAuditStatus(0);
}else{
count.setAuditStatus(1);
}
count.setCodeStatus(parent.getStatus());
pedigreeChartDetailService.save(count);
if (count.getChildren()!=null){
for (TPedigreeChartParentTwoDTO tPedigreeChartParentTwoDTO : count.getChildren()) {
tPedigreeChartParentTwoDTO.setParentId(oneLevel.getId());
tPedigreeChartParentTwoDTO.setPedigreeChartId(parent.getId());
tPedigreeChartParentTwoDTO.setType(1);
if (tPedigreeChartParentTwoDTO.getStatus()==null){
tPedigreeChartParentTwoDTO.setStatus(1);
}
tPedigreeChartParentTwoDTO.setVaccinateId(loginUser.getUserId()+"");
tPedigreeChartParentTwoDTO.setVaccinateSignature(tPedigreeChartParentTwoDTO.getVaccinateSignature());
tPedigreeChartParentTwoDTO.setVaccinateTime(LocalDateTime.now());
tPedigreeChartParentTwoDTO.setStorageTime(LocalDateTime.now());
tPedigreeChartParentTwoDTO.setParentId(count.getId());
tPedigreeChartParentTwoDTO.setId(null);
if (parent.getStatus()==1){
tPedigreeChartParentTwoDTO.setAuditStatus(0);
}else{
tPedigreeChartParentTwoDTO.setAuditStatus(1);
}
tPedigreeChartParentTwoDTO.setCodeStatus(parent.getStatus());
pedigreeChartDetailService.save(tPedigreeChartParentTwoDTO);
List count1List = tPedigreeChartParentTwoDTO.getChildren();
if (!count1List.isEmpty()){
// 传代数
TPedigreeChartParentTwoCountDTO childCount = count1List.get(0);
childCount.setType(2);
if (parent.getStatus()==1){
count.setAuditStatus(0);
}else{
count.setAuditStatus(1);
}
count.setVaccinateId(loginUser.getUserId()+"");
count.setVaccinateTime(LocalDateTime.now());
childCount.setParentId(tPedigreeChartParentTwoDTO.getId());
childCount.setPedigreeChartId(parent.getId());
childCount.setStatus(1);
childCount.setId(null);
childCount.setCodeStatus(parent.getStatus());
pedigreeChartDetailService.save(childCount);
if (childCount.getChildren()!=null){
for (TPedigreeChartParentThreeDTO tPedigreeChartParentThreeDTO : childCount.getChildren()) {
tPedigreeChartParentThreeDTO.setParentId(childCount.getId());
tPedigreeChartParentThreeDTO.setPedigreeChartId(parent.getId());
tPedigreeChartParentThreeDTO.setType(1);
tPedigreeChartParentThreeDTO.setVaccinateId(loginUser.getUserId()+"");
if (tPedigreeChartParentThreeDTO.getStatus()==null){
tPedigreeChartParentThreeDTO.setStatus(1);
}
tPedigreeChartParentThreeDTO.setVaccinateId(loginUser.getUserId()+"");
tPedigreeChartParentThreeDTO.setVaccinateSignature(tPedigreeChartParentTwoDTO.getVaccinateSignature());
tPedigreeChartParentThreeDTO.setVaccinateTime(LocalDateTime.now());
tPedigreeChartParentThreeDTO.setStorageTime(LocalDateTime.now());
tPedigreeChartParentThreeDTO.setPedigreeChartId(parent.getId());
tPedigreeChartParentThreeDTO.setId(null);
if (parent.getStatus()==1){
tPedigreeChartParentThreeDTO.setAuditStatus(0);
}else{
tPedigreeChartParentThreeDTO.setAuditStatus(1);
}
tPedigreeChartParentThreeDTO.setCodeStatus(parent.getStatus());
pedigreeChartDetailService.save(tPedigreeChartParentThreeDTO);
}
}
}
}
}
}
String child = JSON.toJSONString(oneLevel);
parent.setJson(child);
pedigreeChartService.updateById(parent);
}
// 新增消息
TNotice tNotice = new TNotice();
List allProjectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId,parent.getProjectId() )
.eq(TProjectTeamStaff::getRoleType, 2)
.list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
if (!allProjectIds.isEmpty()){
TProjectTeam team = projectTeamService.lambdaQuery().in(TProjectTeam::getId, allProjectIds)
.eq(TProjectTeam::getStatus, 1)
.orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
TProjectTeamStaff projectTeamStaff = projectTeamStaffService.lambdaQuery()
.eq(TProjectTeamStaff::getTeamId, team.getId()).eq(TProjectTeamStaff::getRoleType, 1).one();
tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
tNotice.setUserId(projectTeamStaff.getUserId());
tNotice.setStatus(1);
tNotice.setNoticeContent("菌种工程师新增【1】条【菌种传代生产谱系图】操作,等待您签字确认;");
tNotice.setDataId(parent.getId());
tNotice.setNoticeType(4);
noticeService.save(tNotice);
}
return R.ok();
}
@Resource
private TProjectTeamService projectTeamService;
@Resource
private TProjectTeamStaffService projectTeamStaffService;
@Resource
private TNoticeService noticeService;
/**
*/
@Log(title = "谱系图-编辑谱系图-编辑谱系图", businessType = BusinessType.UPDATE)
@ApiOperation(value = "编辑谱系图-编辑谱系图",response = TPedigreeChartParentAllDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/editProgenitor")
public R editProgenitor(@RequestBody String param) {
LoginUser loginUser = tokenService.getLoginUser();
if (loginUser==null){
return R.fail("登录失效");
}
TPedigreeChartParentAllDTO dto = JSON.parseObject(param, TPedigreeChartParentAllDTO.class);
TPedigreeChart parent = dto.getParent();
if (!dto.getOne().isEmpty()){
String child = JSON.toJSONString(dto.getOne().get(0));
parent.setJson(child);
}
List 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();
parent.setProjectId(projectTeam.getId());
}
Integer status = parent.getStatus();
TPedigreeChart pedigreeChart = pedigreeChartService.getById(parent.getId());
if (pedigreeChart.getStatus() == 2){
parent.setStatus(2);
}
pedigreeChartService.updateById(parent);
parent.setStatus( status);
if (!dto.getOne().isEmpty()){
TPedigreeChartParentOneDTO oneLevel = dto.getOne().get(0);
oneLevel.setParentId("0");
oneLevel.setType(1);
oneLevel.setStatus(oneLevel.getStatus());
oneLevel.setStorageTime(LocalDateTime.now());
oneLevel.setPedigreeChartId(parent.getId());
oneLevel.setVaccinateId(loginUser.getUserId()+"");
oneLevel.setVaccinateSignature(oneLevel.getVaccinateSignature());
oneLevel.setVaccinateTime(LocalDateTime.now());
oneLevel.setId(dto.getOne().get(0).getId());
if (oneLevel.getId()==null){
if (parent.getStatus()==1){
oneLevel.setAuditStatus(0);
oneLevel.setCodeStatus(parent.getStatus());
}else{
oneLevel.setAuditStatus(1);
oneLevel.setCodeStatus(parent.getStatus());
}
}else{
if (parent.getStatus()==2){
switch (oneLevel.getAuditStatus()){
case 0:
oneLevel.setAuditStatus(1);
oneLevel.setCodeStatus(parent.getStatus());
break;
case 1:
oneLevel.setAuditStatus(1);
oneLevel.setCodeStatus(parent.getStatus());
break;
case 2:
oneLevel.setAuditStatus(2);
oneLevel.setCodeStatus(parent.getStatus());
}
}
}
pedigreeChartDetailService.saveOrUpdate(oneLevel);
List countList = oneLevel.getChildren();
if (!countList.isEmpty()){
TPedigreeChartParentOneCountDTO count = countList.get(0);
count.setParentId(oneLevel.getId());
count.setType(2);
count.setVaccinateId(loginUser.getUserId()+"");
count.setVaccinateTime(LocalDateTime.now());
count.setStatus(1);
if (count.getId()==null){
if (parent.getStatus()==1){
count.setAuditStatus(0);
count.setCodeStatus(parent.getStatus());
}else{
count.setAuditStatus(1);
count.setCodeStatus(parent.getStatus());
}
}else{
if (parent.getStatus()==2){
switch (count.getAuditStatus()){
case 0:
count.setAuditStatus(1);
count.setCodeStatus(parent.getStatus());
break;
case 1:
count.setAuditStatus(1);
count.setCodeStatus(parent.getStatus());
break;
case 2:
count.setAuditStatus(2);
count.setCodeStatus(parent.getStatus());
}
}
}
count.setPedigreeChartId(parent.getId());
count.setId(countList.get(0).getId());
pedigreeChartDetailService.saveOrUpdate(count);
if (count.getChildren()!=null){
for (TPedigreeChartParentTwoDTO tPedigreeChartParentTwoDTO : count.getChildren()) {
tPedigreeChartParentTwoDTO.setParentId(oneLevel.getId());
tPedigreeChartParentTwoDTO.setPedigreeChartId(parent.getId());
tPedigreeChartParentTwoDTO.setType(1);
if (tPedigreeChartParentTwoDTO.getStatus()==null){
tPedigreeChartParentTwoDTO.setStatus(1);
}
tPedigreeChartParentTwoDTO.setVaccinateId(loginUser.getUserId()+"");
tPedigreeChartParentTwoDTO.setVaccinateSignature(tPedigreeChartParentTwoDTO.getVaccinateSignature());
tPedigreeChartParentTwoDTO.setVaccinateTime(LocalDateTime.now());
tPedigreeChartParentTwoDTO.setStorageTime(LocalDateTime.now());
tPedigreeChartParentTwoDTO.setParentId(count.getId());
tPedigreeChartParentTwoDTO.setId(tPedigreeChartParentTwoDTO.getId());
if (tPedigreeChartParentTwoDTO.getId()==null){
if (parent.getStatus()==1){
tPedigreeChartParentTwoDTO.setAuditStatus(0);
tPedigreeChartParentTwoDTO.setCodeStatus(parent.getStatus());
}else{
tPedigreeChartParentTwoDTO.setAuditStatus(1);
tPedigreeChartParentTwoDTO.setCodeStatus(parent.getStatus());
}
}else{
if (parent.getStatus()==2){
switch (tPedigreeChartParentTwoDTO.getAuditStatus()){
case 0:
tPedigreeChartParentTwoDTO.setAuditStatus(1);
tPedigreeChartParentTwoDTO.setCodeStatus(parent.getStatus());
break;
case 1:
tPedigreeChartParentTwoDTO.setAuditStatus(1);
tPedigreeChartParentTwoDTO.setCodeStatus(parent.getStatus());
break;
case 2:
tPedigreeChartParentTwoDTO.setAuditStatus(2);
tPedigreeChartParentTwoDTO.setCodeStatus(parent.getStatus());
}
}
}
pedigreeChartDetailService.saveOrUpdate(tPedigreeChartParentTwoDTO);
List count1List = tPedigreeChartParentTwoDTO.getChildren();
if (!count1List.isEmpty()){
// 传代数
TPedigreeChartParentTwoCountDTO childCount = count1List.get(0);
childCount.setType(2);
if (childCount.getId()==null){
if (parent.getStatus()==1){
childCount.setAuditStatus(0);
childCount.setCodeStatus(parent.getStatus());
}else{
childCount.setAuditStatus(1);
childCount.setCodeStatus(parent.getStatus());
}
}else{
if (parent.getStatus()==2){
switch (childCount.getAuditStatus()){
case 0:
childCount.setAuditStatus(1);
childCount.setCodeStatus(parent.getStatus());
break;
case 1:
childCount.setAuditStatus(1);
childCount.setCodeStatus(parent.getStatus());
break;
case 2:
childCount.setAuditStatus(2);
childCount.setCodeStatus(parent.getStatus());
}
}
}
count.setVaccinateId(loginUser.getUserId()+"");
count.setVaccinateTime(LocalDateTime.now());
childCount.setParentId(tPedigreeChartParentTwoDTO.getId());
childCount.setPedigreeChartId(parent.getId());
childCount.setStatus(1);
childCount.setId(childCount.getId());
pedigreeChartDetailService.saveOrUpdate(childCount);
if (childCount.getChildren()!=null){
for (TPedigreeChartParentThreeDTO tPedigreeChartParentThreeDTO : childCount.getChildren()) {
tPedigreeChartParentThreeDTO.setParentId(childCount.getId());
tPedigreeChartParentThreeDTO.setPedigreeChartId(parent.getId());
tPedigreeChartParentThreeDTO.setType(1);
tPedigreeChartParentThreeDTO.setVaccinateId(loginUser.getUserId()+"");
if (tPedigreeChartParentThreeDTO.getStatus()==null){
tPedigreeChartParentThreeDTO.setStatus(1);
}
tPedigreeChartParentThreeDTO.setVaccinateId(loginUser.getUserId()+"");
tPedigreeChartParentThreeDTO.setVaccinateSignature(tPedigreeChartParentTwoDTO.getVaccinateSignature());
tPedigreeChartParentThreeDTO.setVaccinateTime(LocalDateTime.now());
tPedigreeChartParentThreeDTO.setStorageTime(LocalDateTime.now());
tPedigreeChartParentThreeDTO.setPedigreeChartId(parent.getId());
tPedigreeChartParentThreeDTO.setId(tPedigreeChartParentThreeDTO.getId());
if (tPedigreeChartParentThreeDTO.getId()==null){
if (parent.getStatus()==1){
tPedigreeChartParentThreeDTO.setAuditStatus(0);
tPedigreeChartParentThreeDTO.setCodeStatus(parent.getStatus());
}else{
tPedigreeChartParentThreeDTO.setAuditStatus(1);
tPedigreeChartParentThreeDTO.setCodeStatus(parent.getStatus());
}
}else{
if (parent.getStatus()==2){
switch (tPedigreeChartParentThreeDTO.getAuditStatus()){
case 0:
tPedigreeChartParentThreeDTO.setAuditStatus(1);
tPedigreeChartParentThreeDTO.setCodeStatus(parent.getStatus());
break;
case 1:
tPedigreeChartParentThreeDTO.setAuditStatus(1);
tPedigreeChartParentThreeDTO.setCodeStatus(parent.getStatus());
break;
case 2:
tPedigreeChartParentThreeDTO.setAuditStatus(2);
tPedigreeChartParentThreeDTO.setCodeStatus(parent.getStatus());
}
}
}
pedigreeChartDetailService.saveOrUpdate(tPedigreeChartParentThreeDTO);
}
}
}
}
}
}
String child = JSON.toJSONString(oneLevel);
parent.setJson(child);
parent.setStatus(null);
pedigreeChartService.updateById(parent);
}
// 新增消息
TNotice tNotice = new TNotice();
List allProjectIds = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId,parent.getProjectId() )
.eq(TProjectTeamStaff::getRoleType, 2)
.list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
if (!allProjectIds.isEmpty()){
TProjectTeam team = projectTeamService.lambdaQuery().in(TProjectTeam::getId, allProjectIds)
.eq(TProjectTeam::getStatus, 1)
.orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
TProjectTeamStaff projectTeamStaff = projectTeamStaffService.lambdaQuery()
.eq(TProjectTeamStaff::getTeamId, team.getId()).eq(TProjectTeamStaff::getRoleType, 1).one();
tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
tNotice.setUserId(projectTeamStaff.getUserId());
tNotice.setStatus(1);
tNotice.setNoticeContent("菌种工程师新增【1】条【菌种传代生产谱系图】操作,等待您签字确认;");
tNotice.setDataId(parent.getId());
tNotice.setNoticeType(4);
noticeService.save(tNotice);
}
return R.ok();
}
@Log(title = "谱系图-谱系图-删除谱系图", businessType = BusinessType.DELETE)
@ApiOperation(value = "谱系图-删除谱系图")
@Transactional
@DeleteMapping(value = "/open/t-pedigree-chart/deleteProgenitor")
public R deleteProgenitor(@RequestParam String id) {
pedigreeChartService.removeById(id);
return R.ok();
}
@Log(title = "谱系图-谱系图-删除菌种传代项", businessType = BusinessType.DELETE)
@ApiOperation(value = "谱系图-删除菌种传代项",response = TPedigreeChartParentDTO.class)
@DeleteMapping(value = "/open/t-pedigree-chart/deleteProgenitorChild")
public R deleteProgenitorChild(@RequestParam String id) {
List children = pedigreeChartDetailService.lambdaQuery().eq(TPedigreeChartDetail::getParentId, id)
.list();
if (!children.isEmpty()){
return R.fail("请先删除子项");
}
pedigreeChartDetailService.removeById(id);
return R.ok();
}
@Log(title = "谱系图-谱系图-编辑菌种传代/传代数项", businessType = BusinessType.UPDATE)
@ApiOperation(value = "谱系图-编辑菌种传代/传代数项",response = TPedigreeChartParentDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/updateChild")
public R updateChild(@RequestBody String param) {
TPedigreeChartDetailUpdateDTO dto = JSON.parseObject(param, TPedigreeChartDetailUpdateDTO.class);
pedigreeChartDetailService.updateById(dto);
return R.ok();
}
/**
* 谱系图-祖代新增菌种传代项
*/
//@PreAuthorize("@ss.hasPermi('system:pedigreeChart:addChild')")
@Log(title = "谱系图-祖代/母代新增菌种传代项", businessType = BusinessType.INSERT)
@ApiOperation(value = "祖代/母代新增菌种传代项",response = TPedigreeChartDetailDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/addProgenitorChild")
@Transactional
public R addProgenitorChild(@RequestBody String param) {
LoginUser loginUser = tokenService.getLoginUser();
if (loginUser==null){
return R.fail("登录失效");
}
TPedigreeChartDetailDTO dto = JSON.parseObject(param, TPedigreeChartDetailDTO.class);
if (dto.getParentId().equals("0")){
// 新增祖/母代
dto.setParentId("0");
pedigreeChartDetailService.save(dto);
}else{
String parentId = dto.getParentId();
TPedigreeChartDetail parent = pedigreeChartDetailService.getById(parentId);
if (parent.getType()==2){
if (parent.getAuditStatus()==1){
return R.fail("传代计划数未审核");
}
if (parent.getAuditStatus()==3){
return R.fail("传代计划数审核被驳回");
}
}
Long count = pedigreeChartDetailService.lambdaQuery().eq(TPedigreeChartDetail::getParentId, parentId).count();
if (count>=parent.getGenerationCount()){
return R.fail("该谱系图已满");
}
String pedigreeChartId = pedigreeChartDetailService.getById(parentId).getPedigreeChartId();
TPedigreeChart pedigreeChart = pedigreeChartService.getById(pedigreeChartId);
TPedigreeChartDetail tPedigreeChartDetail = new TPedigreeChartDetail();
BeanUtils.copyProperties(dto,tPedigreeChartDetail);
tPedigreeChartDetail.setStrainSource(dto.getStrainSource());
tPedigreeChartDetail.setParentId(parentId);
tPedigreeChartDetail.setPedigreeChartId(pedigreeChartId);
tPedigreeChartDetail.setStatus(dto.getStatus());
tPedigreeChartDetail.setStorageTime(LocalDateTime.now());
tPedigreeChartDetail.setRemark(dto.getRemark());
tPedigreeChartDetail.setType(1);
tPedigreeChartDetail.setPedigreeChartId(pedigreeChart.getId());
tPedigreeChartDetail.setVaccinateId(loginUser.getUserId()+"");
tPedigreeChartDetail.setVaccinateTime(LocalDateTime.now());
tPedigreeChartDetail.setCodeStatus(dto.getCodeStatus());
if (dto.getStatus() ==2){
tPedigreeChartDetail.setDiscardTime(LocalDateTime.now());
}
if (dto.getCodeStatus()==2){
tPedigreeChartDetail.setAuditStatus(1);
}else{
tPedigreeChartDetail.setAuditStatus(0);
}
tPedigreeChartDetail.setVaccinateSignature(dto.getVaccinateSignature());
pedigreeChartDetailService.save(tPedigreeChartDetail);
}
return R.ok();
}
/**
* 0获取谱系图详情待确认传代计划数分页列表
*/
@ApiOperation(value = "谱系图-2.0获取谱系图详情待确认传代计划数分页列表",response = TPedigreeChartDetailQuery.class)
@PostMapping(value = "/api/t-pedigree-chart/pageListCountDetail")
public R> pageListCountDetail(@RequestBody String param) {
TPedigreeChartDetailQuery query = JSON.parseObject(param, TPedigreeChartDetailQuery.class);
return R.ok(pedigreeChartService.pageListCountDetail(query));
}
@ApiOperation(value = "谱系图-2.0审批人确认传代计划数",response = TPedigreeChartDetailConfirmCountDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/confirmCount")
public R confirmCount(@RequestBody String param) {
TPedigreeChartDetailConfirmCountDTO query = JSON.parseObject(param, TPedigreeChartDetailConfirmCountDTO.class);
TPedigreeChartDetail pedigreeChartDetailServiceById = pedigreeChartDetailService.getById(query.getId());
pedigreeChartDetailServiceById.setAuditStatus(2);
pedigreeChartDetailServiceById.setPreserveSignature(query.getPreserveSignature());
pedigreeChartDetailService.updateById(pedigreeChartDetailServiceById);
return R.ok();
}
/**
* 获取谱系图详情待入库菌种分页列表
*/
@ApiOperation(value = "谱系图-获取谱系图详情待入库菌种分页列表",response = TPedigreeChartDetailQuery.class)
@PostMapping(value = "/api/t-pedigree-chart/pageListDetail")
public R> pageListDetail(@RequestBody String param) {
TPedigreeChartDetailQuery query = JSON.parseObject(param, TPedigreeChartDetailQuery.class);
return R.ok(pedigreeChartService.pageListDetail(query));
}
/**
* 谱系图-菌种传代生产谱系图详情
*/
//@PreAuthorize("@ss.hasPermi('system:pedigreeChart:detailInfo')")
@ApiOperation(value = "谱系图-谱系图详情")
@GetMapping(value = "/open/t-pedigree-chart/getDetailInfoById")
public R getDetailInfoById(@RequestParam String id) {
List tPedigreeChartParentOneDTOS = new ArrayList<>();
TPedigreeChart pedigreeChart = pedigreeChartService.getById(id);
List details = pedigreeChartDetailService.lambdaQuery().eq(TPedigreeChartDetail::getPedigreeChartId, id).list();
TPedigreeChartParentAllDetailDTO tPedigreeChartParentAllDetailDTO = new TPedigreeChartParentAllDetailDTO();
// 祖代
TPedigreeChartDetail pedigreeChartDetail = details.stream().filter(e -> e.getParentId().equals("0")
&& e.getType()==1).findFirst().orElse(null);
if (pedigreeChartDetail!=null){
// 祖代/母代
TPedigreeChartParentOneDTO tPedigreeChartParentOneDTO = new TPedigreeChartParentOneDTO();
BeanUtils.copyProperties(pedigreeChartDetail,tPedigreeChartParentOneDTO);
TPedigreeChartDetail childCount = details.stream().filter(e -> e.getParentId().equals(tPedigreeChartParentOneDTO.getId())
&& e.getType() == 2).findFirst().orElse(null);
// 传代计划数
if (childCount!=null){
TPedigreeChartParentOneCountDTO tPedigreeChartParentOneCountDTO = new TPedigreeChartParentOneCountDTO();
List tPedigreeChartParentOneCountDTOS = new ArrayList<>();
BeanUtils.copyProperties(childCount,tPedigreeChartParentOneCountDTO);
tPedigreeChartParentOneCountDTO.setParent(pedigreeChartDetail);
// 祖代母代传代数
List childs = details.stream().filter(e -> e.getParentId().equals(tPedigreeChartParentOneCountDTO.getId())
&& e.getType() == 1).collect(Collectors.toList());
List tPedigreeChartParentTwoDTOS = new ArrayList<>();
List tPedigreeChartParentThreeDTOS = new ArrayList<>();
for (TPedigreeChartDetail tPedigreeChartDetail : childs) {
TPedigreeChartParentTwoDTO tPedigreeChartParentTwoDTO = new TPedigreeChartParentTwoDTO();
BeanUtils.copyProperties(tPedigreeChartDetail,tPedigreeChartParentTwoDTO);
tPedigreeChartParentTwoDTO.setParent(childCount);
TPedigreeChartDetail childCountChild = details.stream().filter(e -> e.getParentId().equals(tPedigreeChartParentTwoDTO.getId())
&& e.getType() == 2).findFirst().orElse(null);
if (childCountChild!=null){
ArrayList tPedigreeChartParentTwoCountDTOS = new ArrayList<>();
TPedigreeChartParentTwoCountDTO tPedigreeChartParentTwoCountDTO = new TPedigreeChartParentTwoCountDTO();
BeanUtils.copyProperties(childCountChild,tPedigreeChartParentTwoCountDTO);
List childChilds = details.stream().filter(e -> e.getParentId().equals(tPedigreeChartParentTwoCountDTO.getId())
&& e.getType() == 1).collect(Collectors.toList());
for (TPedigreeChartDetail chartDetail : childChilds) {
TPedigreeChartParentThreeDTO tPedigreeChartParentThreeDTO = new TPedigreeChartParentThreeDTO();
BeanUtils.copyProperties(chartDetail,tPedigreeChartParentThreeDTO);
tPedigreeChartParentThreeDTO.setParent(childCountChild);
tPedigreeChartParentThreeDTOS.add(tPedigreeChartParentThreeDTO);
}
tPedigreeChartParentTwoCountDTO.setChildren(tPedigreeChartParentThreeDTOS);
tPedigreeChartParentTwoCountDTOS.add(tPedigreeChartParentTwoCountDTO);
tPedigreeChartParentTwoDTO.setChildren(tPedigreeChartParentTwoCountDTOS);
}
tPedigreeChartParentTwoDTOS.add(tPedigreeChartParentTwoDTO);
}
tPedigreeChartParentOneCountDTO.setChildren(tPedigreeChartParentTwoDTOS);
tPedigreeChartParentOneCountDTOS.add(tPedigreeChartParentOneCountDTO);
tPedigreeChartParentOneDTO.setChildren(tPedigreeChartParentOneCountDTOS);
}
tPedigreeChartParentOneDTOS.add(tPedigreeChartParentOneDTO);
tPedigreeChartParentAllDetailDTO.setOne(tPedigreeChartParentOneDTOS);
}
pedigreeChart.setPedigreeChartParentAllDetailDTO(tPedigreeChartParentAllDetailDTO);
return R.ok(pedigreeChart);
}
/**
* 谱系图-菌种传代生产谱系图详情-菌种详情
*/
@ApiOperation(value = "谱系图-菌种传代生产谱系图详情-菌种详情")
@GetMapping(value = "/api/t-pedigree-chart/strainInfo")
public R strainInfo(@RequestParam String id) {
TPedigreeChartDetail tPedigreeChartDetail = pedigreeChartDetailService.getById(id);
if (!tPedigreeChartDetail.getParentId().equals("0")){
TPedigreeChartDetail tPedigreeChartDetail1 = pedigreeChartDetailService.getById(tPedigreeChartDetail.getParentId());
tPedigreeChartDetail.setParent(tPedigreeChartDetail1);
}
return R.ok(tPedigreeChartDetail);
}
/**
* 谱系图-设置传代数
*/
//@PreAuthorize("@ss.hasPermi('system:pedigreeChart:updateCount')")
@ApiOperation(value = "谱系图-设置传代数",response = TPedigreeChartDetailCountDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/updateCount")
public R updateCount(@RequestBody String param) {
TPedigreeChartDetailCountDTO dto = JSON.parseObject(param, TPedigreeChartDetailCountDTO.class);
TPedigreeChartDetail count = pedigreeChartDetailService.getById(dto.getId());
count.setGenerationCount(dto.getGenerationCount());
// 待审核状态
count.setAuditStatus(1);
count.setVaccinateId(tokenService.getLoginUser().getUserId()+"");
count.setVaccinateTime(LocalDateTime.now());
count.setVaccinateSignature(dto.getVaccinateSignature());
pedigreeChartDetailService.updateById(count);
return R.ok();
}
@ApiOperation(value = "谱系图-设置传代数",response = TPedigreeChartDetailCountDTO.class)
@PostMapping(value = "/api/t-pedigree-chart/addCount")
public R addCount(@RequestBody String param) {
TPedigreeChartDetailCountDTO dto = JSON.parseObject(param, TPedigreeChartDetailCountDTO.class);
TPedigreeChartDetail pedigreeChartDetail1 = new TPedigreeChartDetail();
pedigreeChartDetail1.setParentId(dto.getParentId());
pedigreeChartDetail1.setVaccinateId(tokenService.getLoginUser().getUserId()+"");
pedigreeChartDetail1.setVaccinateTime(LocalDateTime.now());
pedigreeChartDetail1.setVaccinateSignature(dto.getVaccinateSignature());
TPedigreeChartDetail tPedigreeChartDetail = pedigreeChartDetailService.getById(dto.getParentId());
pedigreeChartDetail1.setGenerationCount(dto.getGenerationCount());
pedigreeChartDetail1.setPedigreeChartId(tPedigreeChartDetail.getPedigreeChartId());
pedigreeChartDetail1.setType(2);
pedigreeChartDetail1.setCodeStatus(dto.getCodeStatus());
if (dto.getCodeStatus()==1){
pedigreeChartDetail1.setAuditStatus(0);
}else{
pedigreeChartDetail1.setAuditStatus(1);
}
pedigreeChartDetailService.save(pedigreeChartDetail1);
return R.ok();
}
/**
* 谱系图-菌种工程师确认入库
*/
//@PreAuthorize("@ss.hasPermi('system:pedigreeChart:confirm')")
@ApiOperation(value = "谱系图-菌种工程师确认入库",response = TTrainLibraryDetailConfirmDto.class)
@Log(title = "谱系图-菌种工程师确认入库", businessType = BusinessType.UPDATE)
@PostMapping(value = "/api/t-pedigree-chart/confirm")
public R confirm(@RequestBody String param) {
if (tokenService.getLoginUser()==null){
return R.fail("登录失效");
}
TTrainLibraryDetailConfirmDto dto = JSON.parseObject(param, TTrainLibraryDetailConfirmDto.class);
TPedigreeChartDetail pedigreeChartDetail = pedigreeChartDetailService.getById(dto.getId());
pedigreeChartDetail.setPreserveId(String.valueOf(tokenService.getLoginUser().getUserId()));
pedigreeChartDetail.setPreserveSignature(dto.getPreserveSignature());
pedigreeChartDetail.setConfirmTime(LocalDateTime.now());
pedigreeChartDetail.setAuditStatus(2);
pedigreeChartDetailService.updateById(pedigreeChartDetail);
return R.ok();
}
}