package com.ruoyi.web.controller.api;
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;
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.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.TStrainReportProjectQuery;
import com.ruoyi.system.query.TStrainReportQuery;
import com.ruoyi.system.query.TTrainLibraryDetailQuery;
import com.ruoyi.system.query.TTrainLibraryQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.*;
import com.tencentcloudapi.tcaplusdb.v20190823.models.IdlFileInfo;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.parser.Token;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.Array;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* 菌种报告库 前端控制器
*
*
* @author 无关风月
* @since 2025-04-12
*/
@RestController
@RequestMapping("")
public class TStrainReportController {
@Resource
private TStrainReportService strainReportService;
@Resource
private TStrainReportDetailService strainReportDetailService;
@Resource
private ISysUserService sysUserService;
@Resource
private TokenService tokenService;
@Resource
private TProjectTeamService projectTeamService;
@Resource
private TProjectTeamStaffService projectTeamStaffService;
@ApiOperation(value = "菌种报告库分页列表查询",tags = "菌种报告库",response = TStrainReportQuery.class)
@PostMapping(value = "/api/t-strain-report/pageListAll")
public R> pageListAll(@RequestBody String param) {
LoginUser loginUser = tokenService.getLoginUser();
SysUser sysUser = sysUserService.selectUserById(loginUser.getUserId());
List projectIds = new ArrayList<>();
if (!sysUser.getRoleType().equals("1")){
// 查询和自己相关的项目组id
List collect = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, sysUser.getUserId()).list()
.stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
if (collect.isEmpty()){
collect.add("0");
}
projectIds = collect;
}
TStrainReportQuery query = JSON.parseObject(param, TStrainReportQuery.class);
if (StringUtils.hasLength(query.getTime())){
query.setStartTime(query.getTime().split(" - ")[0]);
query.setEndTime(query.getTime().split(" - ")[1]);
}
query.setProjectIds(projectIds);
return R.ok(strainReportService.pageListAll(query));
}
@ApiOperation(value = "获取菌种报告库操作评定分页列表",tags = "菌种报告库操作评定-菌种实验员",response = TStrainReportQuery.class)
@PostMapping(value = "/api/t-strain-report/pageList")
public R> pageList(@RequestBody String param) {
TStrainReportQuery query = JSON.parseObject(param, TStrainReportQuery.class);
if (StringUtils.hasLength(query.getTime())){
query.setStartTime(query.getTime().split(" - ")[0]);
query.setEndTime(query.getTime().split(" - ")[1]);
}
LoginUser loginUser = tokenService.getLoginUser();
SysUser sysUser = sysUserService.selectUserById(loginUser.getUserId());
query.setUserId(sysUser.getUserId()+"");
if (StringUtils.hasLength(query.getEvaluateName())){
List strings = new ArrayList<>();
List sysUser1 = sysUserService.selectUserByUserNameLike(query.getEvaluateName());
if (sysUser1.isEmpty()){
strings.add("0");
query.setEvaluateId(strings);
}else{
strings = sysUser1.stream().map(SysUser::getUserId).map(String::valueOf).collect(Collectors.toList());
query.setEvaluateId(strings);
}
}
query.setEvaluateHumanType(Integer.valueOf(sysUser.getRoleType()));
return R.ok(strainReportService.pageList(query));
}
//@PreAuthorize("@ss.hasPermi('system:strainReport:detail')")
@ApiOperation(value = "查看菌种库操作评定详情",tags = "菌种库操作评定-菌种实验员")
@GetMapping(value = "/open/t-strain-report/getDetailById")
public R getDetailById(@RequestParam String id) {
TStrainReportDetailVO tStrainReportDetailVO = new TStrainReportDetailVO();
TStrainReport strainReport = strainReportService.getById(id);
TStrainReportDetail strainReportDetail = strainReportDetailService.getOne(new LambdaQueryWrapper()
.eq(TStrainReportDetail::getReportId, strainReport.getId())
.eq(TStrainReportDetail::getEvaluateHumanType, 1)
.eq(TStrainReportDetail::getExperimentId, tokenService.getLoginUser().getUserId()));
if (strainReportDetail!=null){
tStrainReportDetailVO.setEvaluate(strainReportDetail.getEvaluate());
if (StringUtils.hasLength(strainReportDetail.getEvaluateId())){
SysUser sysUser = sysUserService.selectUserById(Long.valueOf(strainReportDetail.getEvaluateId()));
if (sysUser != null){
tStrainReportDetailVO.setEvaluateName(sysUser.getNickName());
}
}
}
BeanUtils.copyProperties(strainReport, tStrainReportDetailVO);
return R.ok(tStrainReportDetailVO);
}
//@PreAuthorize("@ss.hasPermi('system:strainReportProject:pageListProject')")
@ApiOperation(value = "获取菌种项目组评定分页列表",tags = "菌种项目组评定表",response = TStrainReportProjectQuery.class)
@PostMapping(value = "/api/t-strain-report/pageListProject")
public R> pageListProject(@RequestBody String param) {
TStrainReportProjectQuery query = JSON.parseObject(param, TStrainReportProjectQuery.class);
if (StringUtils.hasLength(query.getTime())){
query.setStartTime(query.getTime().split(" - ")[0]);
query.setEndTime(query.getTime().split(" - ")[1]);
}
SysUser sysUser = sysUserService.selectUserById(tokenService.getLoginUser().getUserId());
if (sysUser.getRoleType().equals("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 if (!sysUser.getRoleType().equals("1")){
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);
}
}
return R.ok(strainReportService.pageListProject(query));
}
@ApiOperation(value = "菌种项目组评定详情",tags = "菌种项目组评定表")
@GetMapping(value = "/open/t-strain-report/getDetailByIdProject")
public R getDetailByIdProject(@RequestParam String id) {
TProjectTeam byId = projectTeamService.getById(id);
TStrainReportDetailProjectVO tStrainReportDetailVO = new TStrainReportDetailProjectVO();
LoginUser loginUser = tokenService.getLoginUser();
SysUser sysUser = sysUserService.selectUserById(loginUser.getUserId());
List tStrainReports = strainReportService.list(new LambdaQueryWrapper()
.eq(TStrainReport::getStatus,3).eq(TStrainReport::getProjectId,id));
List strainReportIds = tStrainReports.stream().map(TStrainReport::getId).collect(Collectors.toList());
if (strainReportIds.isEmpty())strainReportIds.add("0");
List tStrainReportDetails = strainReportDetailService
.list(new LambdaQueryWrapper().in(TStrainReportDetail::getReportId,strainReportIds)
.orderByDesc(TStrainReportDetail::getCreateTime));
BigDecimal sum = new BigDecimal("0");
BigDecimal sum1 = new BigDecimal("0");
BigDecimal sum2 = new BigDecimal("0");
Integer temp = 0;
for (TStrainReport tStrainReport : tStrainReports) {
List tStrainReportDetails1 = tStrainReportDetails.stream()
.filter(e -> e.getReportId().equals(tStrainReport.getId())&&
e.getEvaluateHumanType()==1).collect(Collectors.toList());
List tStrainReportDetails2 = tStrainReportDetails.stream()
.filter(e -> e.getReportId().equals(tStrainReport.getId())&&
e.getEvaluateHumanType()==2).collect(Collectors.toList());
// 菌种工程积分
sum1 = tStrainReportDetails2.stream()
.filter(e -> e.getEvaluateHumanType().equals(1))
.map(TStrainReportDetail::getEvaluateTotal)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);
// 菌种实验员积分
sum2 = tStrainReportDetails1.stream()
.filter(e -> e.getEvaluateHumanType().equals(2))
.map(TStrainReportDetail::getEvaluateTotal)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);
List tStrainReportDetails3 = tStrainReportDetails.stream().filter(e -> e.getReportType() == 1).collect(Collectors.toList());
for (TStrainReportDetail tStrainReportDetail : tStrainReportDetails3) {
// 根据评定等级统计失败次数
if (StringUtils.hasLength(tStrainReportDetail.getEvaluate())&& tStrainReportDetail.getEvaluate().split(",").length>=5){
if (tStrainReportDetail.getEvaluate().split(",")[4].equals("2")){
temp++;
}
}
}
}
tStrainReportDetailVO.setTeamIntegral(sum);
tStrainReportDetailVO.setEngineerIntegral(sum1);
tStrainReportDetailVO.setExperimenterIntegral(sum2);
tStrainReportDetailVO.setFailCount(temp);
List strainReportIdsByProjectId = tStrainReports.stream().filter(e -> e.getProjectId().equals(byId.getId())).collect(Collectors.toList());
if (!strainReportIdsByProjectId.isEmpty()){
tStrainReportDetailVO.setEndTime(strainReportIdsByProjectId.get(0).getEvaluateTime());
}
tStrainReportDetailVO.setStartTime(byId.getCreateTime());
TProjectTeamStaff projectTeamStaff = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, byId.getId())
.eq(TProjectTeamStaff::getRoleType, 2).one();
List tStrainReportDetailExperimentVOS = new ArrayList<>();
if (sysUser.getRoleType().equals("4")){
TStrainReportDetailExperimentVO tStrainReportDetailExperimentVO = new TStrainReportDetailExperimentVO();
tStrainReportDetailExperimentVO.setUserName(sysUser.getNickName());
tStrainReportDetailExperimentVO.setHandleCount((int) tStrainReportDetails.stream().filter(e -> e.getExperimentId().equals(sysUser.getUserId() + "")).count());
BigDecimal handleIntegral = tStrainReportDetails.stream()
.filter(e -> e.getEvaluateHumanType().equals(1)&&e.getExperimentId().equals(sysUser.getUserId()+""))
.map(TStrainReportDetail::getEvaluateTotal)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);
tStrainReportDetailExperimentVO.setHandleIntegral(handleIntegral);
List strainReportDetails = tStrainReportDetails.stream().filter(e -> e.getExperimentId().equals(sysUser.getUserId() + "")).collect(Collectors.toList());
if (!strainReportDetails.isEmpty()){
tStrainReportDetailExperimentVO.setHandleStartTime(strainReportDetails.get(0).getCreateTime());
}
tStrainReportDetailExperimentVOS.add(tStrainReportDetailExperimentVO);
tStrainReportDetailVO.setDetailExperimentVOS(tStrainReportDetailExperimentVOS);
}else{
List strainReportDetails = tStrainReportDetails.stream()
.filter(e -> e.getEvaluateHumanType() == 2&&
e.getExperimentId().equals(projectTeamStaff.getUserId())).collect(Collectors.toList());
if (strainReportDetails.isEmpty()){
TStrainReportDetailEngineerVO tStrainReportDetailEngineerVO = new TStrainReportDetailEngineerVO();
tStrainReportDetailEngineerVO.setInnovateCount(0);
tStrainReportDetailEngineerVO.setInnovateIntegral(BigDecimal.ZERO);
tStrainReportDetailEngineerVO.setRegulationCount(0);
tStrainReportDetailEngineerVO.setRegulationIntegral(BigDecimal.ZERO);
tStrainReportDetailEngineerVO.setHandleCount(0);
tStrainReportDetailEngineerVO.setHandleIntegral(BigDecimal.ZERO);
tStrainReportDetailVO.setDetailEngineerVO(tStrainReportDetailEngineerVO);
List userIds = new ArrayList<>();
List tStrainReportDetailExperimentVOS1 = new ArrayList<>();
List collect = tStrainReportDetails.stream().filter(e -> e.getEvaluateHumanType().equals(1)).collect(Collectors.toList());
for (TStrainReportDetail tStrainReportDetail : collect) {
if (userIds.contains(tStrainReportDetail.getExperimentId())){
continue;
}
userIds.add(tStrainReportDetail.getExperimentId());
TStrainReportDetailExperimentVO tStrainReportDetailExperimentVO = new TStrainReportDetailExperimentVO();
tStrainReportDetailExperimentVO.setUserName(sysUserService.selectUserById(Long.valueOf(tStrainReportDetail.getExperimentId())).getNickName());
tStrainReportDetailExperimentVO.setHandleCount((int) collect.stream().filter(e -> e.getExperimentId().equals(tStrainReportDetail.getExperimentId())).count());
BigDecimal handleIntegral = collect.stream()
.filter(e -> e.getEvaluateHumanType().equals(1)&&e.getExperimentId().equals(sysUser.getUserId()+""))
.map(TStrainReportDetail::getEvaluateTotal)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);
tStrainReportDetailExperimentVO.setHandleIntegral(handleIntegral);
List collect9 = collect.stream().filter(e -> e.getExperimentId().equals(sysUser.getUserId()+"")).collect(Collectors.toList());
if (!collect9.isEmpty()){
tStrainReportDetailExperimentVO.setHandleEndTime(collect9.get(collect9.size()-1).getCreateTime());
}
tStrainReportDetailExperimentVO.setHandleStartTime(byId.getCreateTime());
tStrainReportDetailExperimentVOS1.add(tStrainReportDetailExperimentVO);
}
tStrainReportDetailVO.setDetailExperimentVOS(tStrainReportDetailExperimentVOS1);
}else{
List reportDetails = strainReportDetails.stream()
.filter(e -> e.getEvaluateHumanType().equals(2) && e.getExperimentId().equals(projectTeamStaff.getUserId())).collect(Collectors.toList());
TStrainReportDetailEngineerVO tStrainReportDetailEngineerVO = new TStrainReportDetailEngineerVO();
tStrainReportDetailEngineerVO.setInnovateCount((int)reportDetails.stream().filter(e->e.getEvaluateType()!=null&&e.getEvaluateType().equals(1)).count());
tStrainReportDetailEngineerVO.setInnovateIntegral(reportDetails.stream().filter(e->e.getEvaluateType()!=null&&e.getEvaluateType().equals(1)).map(TStrainReportDetail::getEvaluateTotal).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
List collect3 = reportDetails.stream().filter(e ->e.getEvaluateType()!=null&& e.getEvaluateType().equals(1)).collect(Collectors.toList());
if (!collect3.isEmpty()){
tStrainReportDetailEngineerVO.setInnovateStartTime(collect3.get(collect3.size()-1).getCreateTime());
}
tStrainReportDetailEngineerVO.setInnovateEndTime(byId.getCreateTime());
tStrainReportDetailEngineerVO.setRegulationCount((int)reportDetails.stream().filter(e->e.getEvaluateType()!=null&&e.getEvaluateType().equals(2)).count());
tStrainReportDetailEngineerVO.setRegulationIntegral(reportDetails.stream().filter(e->e.getEvaluateType()!=null&&e.getEvaluateType().equals(2)).map(TStrainReportDetail::getEvaluateTotal).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
List collect4 = reportDetails.stream().filter(e -> e.getEvaluateType()!=null&&e.getEvaluateType().equals(2)).collect(Collectors.toList());
if (!collect4.isEmpty()){
tStrainReportDetailEngineerVO.setRegulationStartTime(collect4.get(collect4.size()-1).getCreateTime());
}
tStrainReportDetailEngineerVO.setRegulationEndTime(byId.getCreateTime());
tStrainReportDetailEngineerVO.setHandleCount((int)reportDetails.stream().filter(e->e.getReportType().equals(1)).count());
tStrainReportDetailEngineerVO.setHandleIntegral(reportDetails.stream().filter(e->e.getReportType().equals(1)).map(TStrainReportDetail::getEvaluateTotal).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
List reportDetailList = reportDetails.stream().filter(e->e.getReportType().equals(1)).collect(Collectors.toList());
if (!reportDetailList.isEmpty()){
tStrainReportDetailEngineerVO.setHandleStartTime(reportDetailList.get(reportDetailList.size()-1).getCreateTime());
}
tStrainReportDetailEngineerVO.setHandleEndTime(byId.getCreateTime());
tStrainReportDetailVO.setDetailEngineerVO(tStrainReportDetailEngineerVO);
List userIds = new ArrayList<>();
List tStrainReportDetailExperimentVOS1 = new ArrayList<>();
List collect = tStrainReportDetails.stream().filter(e -> e.getEvaluateHumanType().equals(1)).collect(Collectors.toList());
for (TStrainReportDetail tStrainReportDetail : collect) {
if (userIds.contains(tStrainReportDetail.getExperimentId())){
continue;
}
userIds.add(tStrainReportDetail.getExperimentId());
TStrainReportDetailExperimentVO tStrainReportDetailExperimentVO = new TStrainReportDetailExperimentVO();
tStrainReportDetailExperimentVO.setUserName(sysUserService.selectUserById(Long.valueOf(tStrainReportDetail.getExperimentId())).getNickName());
tStrainReportDetailExperimentVO.setHandleCount((int) collect.stream().filter(e -> e.getExperimentId().equals(tStrainReportDetail.getExperimentId())).count());
BigDecimal handleIntegral = collect.stream()
.filter(e -> e.getEvaluateHumanType().equals(1)&&e.getExperimentId().equals(sysUser.getUserId()+""))
.map(TStrainReportDetail::getEvaluateTotal)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);
tStrainReportDetailExperimentVO.setHandleIntegral(handleIntegral);
List collect9 = collect.stream().filter(e -> e.getExperimentId().equals(sysUser.getUserId()+"")).collect(Collectors.toList());
if (!collect9.isEmpty()){
tStrainReportDetailExperimentVO.setHandleEndTime(collect9.get(collect9.size()-1).getCreateTime());
}
tStrainReportDetailExperimentVO.setHandleStartTime(byId.getCreateTime());
tStrainReportDetailExperimentVOS1.add(tStrainReportDetailExperimentVO);
}
tStrainReportDetailVO.setDetailExperimentVOS(tStrainReportDetailExperimentVOS1);
}
}
return R.ok(tStrainReportDetailVO);
}
@Resource
private TNoticeService noticeService;
/**
* 新增报告
*/
//@PreAuthorize("@ss.hasPermi('system:strainReport:add')")
@Log(title = "菌种库报告管理-新增报告", businessType = BusinessType.INSERT)
@ApiOperation(value = "新增报告",tags = "菌种报告库",response = TStrainReportDTO.class)
@PostMapping(value = "/api/t-strain-report/add")
public R add(@RequestBody String param) {
int size = strainReportService.lambdaQuery().list().size();
TStrainReportDTO dto = JSON.parseObject(param,TStrainReportDTO.class);
dto.setStatus(1);
TProjectTeam projectTeam = projectTeamService.getById(dto.getProjectId());
dto.setReportCode(projectTeam.getTeamName()+" - S"+dto.getReportType()+" - "+String.format("%03d", size+1));
dto.setCommitId(tokenService.getLoginUser().getUserId()+"");
dto.setCommitTime(LocalDateTime.now());
strainReportService.save(dto);
TStrainReportDetail tStrainReportDetail = new TStrainReportDetail();
tStrainReportDetail.setReportId(dto.getId());
tStrainReportDetail.setEvaluateId(tokenService.getLoginUser().getUserId()+"");
tStrainReportDetail.setExperimentId(dto.getExperimentId());
tStrainReportDetail.setEvaluate(dto.getEvaluate());
tStrainReportDetail.setEvaluateTotal(dto.getEvaluateTotal());
tStrainReportDetail.setEvaluateHumanType(1);
tStrainReportDetail.setReportType(dto.getReportType());
tStrainReportDetail.setEvaluateType(dto.getEvaluateType());
strainReportDetailService.save(tStrainReportDetail);
if (dto.getIsDraft()==0){
// 新增消息
TNotice tNotice = new TNotice();
TProjectTeamStaff projectTeamStaff = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, dto.getProjectId())
.eq(TProjectTeamStaff::getRoleType, 1).last("limit 1").one();
tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
tNotice.setUserId(projectTeamStaff.getUserId());
tNotice.setStatus(1);
tNotice.setNoticeContent("您有【1】条【菌种报告】【报告库"+dto.getReportType()+"】等待审核");
tNotice.setDataId(dto.getId());
tNotice.setNoticeType(1);
noticeService.save(tNotice);
// 新增消息
TNotice tNotice1 = new TNotice();
TProjectTeamStaff tProjectTeamStaff = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, dto.getProjectId())
.eq(TProjectTeamStaff::getRoleType, 3).last("limit 1").one();
tNotice1.setCommitId(tokenService.getLoginUser().getUserId()+"");
tNotice1.setUserId(tProjectTeamStaff.getUserId());
tNotice1.setStatus(1);
tNotice1.setNoticeContent("您有【1】条菌种库操作菌种工程师已评定;");
tNotice1.setDataId(dto.getId());
tNotice1.setNoticeType(9);
noticeService.save(tNotice1);
}
return R.ok();
}
/**
* 新增报告
*/
//@PreAuthorize("@ss.hasPermi('system:strainReport:update')")
@Log(title = "菌种库报告管理-编辑报告", businessType = BusinessType.UPDATE)
@ApiOperation(value = "编辑报告",tags = "菌种报告库",response = TStrainReportDTO.class)
@PostMapping(value = "/api/t-strain-report/update")
public R update(@RequestBody String param) {
TStrainReportDTO dto = JSON.parseObject(param,TStrainReportDTO.class);
dto.setStatus(1);
strainReportService.updateById(dto);
TStrainReportDetail tStrainReportDetail = strainReportDetailService.lambdaQuery().eq(TStrainReportDetail::getReportId, dto.getId())
.eq(TStrainReportDetail::getEvaluateHumanType, 1).one();
tStrainReportDetail.setReportId(dto.getId());
tStrainReportDetail.setExperimentId(dto.getExperimentId());
tStrainReportDetail.setEvaluate(dto.getEvaluate());
tStrainReportDetail.setEvaluateTotal(dto.getEvaluateTotal());
tStrainReportDetail.setEvaluateHumanType(1);
strainReportDetailService.updateById(tStrainReportDetail);
if (dto.getIsDraft()==0){
// 新增消息
TNotice tNotice = new TNotice();
TProjectTeamStaff projectTeamStaff = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, dto.getProjectId())
.eq(TProjectTeamStaff::getRoleType, 1).last("limit 1").one();
tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
tNotice.setUserId(projectTeamStaff.getUserId());
tNotice.setStatus(1);
tNotice.setNoticeContent("您有【1】条【菌种报告】【报告库"+dto.getReportType()+"】等待审核");
tNotice.setDataId(dto.getId());
tNotice.setNoticeType(1);
noticeService.save(tNotice);
}
return R.ok();
}
/**
* 菌种工程师撤销审批
*/
//@PreAuthorize("@ss.hasPermi('system:strainReport:cancelReport')")
@Log(title = "菌种库报告管理-菌种工程师撤销审批", businessType = BusinessType.UPDATE)
@ApiOperation(value = "菌种工程师撤销审批",tags = "菌种报告库")
@GetMapping(value = "/open/t-strain-report/cancelReport")
public R cancelReport(@RequestParam String id) {
TStrainReport strainReport = strainReportService.getById(id);
strainReport.setIsDraft(1);
strainReport.setStatus(1);
strainReportService.updateById(strainReport);
return R.ok();
}
/**
* 菌种工程师撤销审批
*/
//@PreAuthorize("@ss.hasPermi('system:strainReport:auditReport')")
@Log(title = "菌种库报告管理-菌种审批人审批", businessType = BusinessType.UPDATE)
@ApiOperation(value = "菌种审批人审批",tags = "菌种报告库",response = TStrainReportAuditDTO.class)
@PostMapping(value = "/api/t-strain-report/auditReport")
public R auditReport(@RequestBody String param) {
LoginUser loginUser = tokenService.getLoginUser();
if (loginUser==null){
return R.fail(401,"登陆失效");
}
TStrainReportAuditDTO dto = JSON.parseObject(param,TStrainReportAuditDTO.class);
TStrainReport strainReport = strainReportService.getById(dto.getId());
strainReport.setAuditRemark(dto.getAuditRemark());
strainReport.setAuditId(loginUser.getUserId()+"");
strainReport.setAuditTime(LocalDateTime.now());
strainReport.setStatus(dto.getStatus());
strainReportService.updateById(strainReport);
// 新增消息
TNotice tNotice = new TNotice();
tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
tNotice.setUserId(tokenService.getLoginUser().getUserId()+"");
tNotice.setStatus(1);
tNotice.setNoticeContent("您有【1】条【菌种报告】【报告库"+strainReport.getReportType()+"】等待评定");
tNotice.setDataId(dto.getId());
tNotice.setNoticeType(2);
noticeService.save(tNotice);
// 新增消息
TNotice notice = new TNotice();
TProjectTeamStaff tProjectTeamStaff = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, strainReport.getProjectId())
.eq(TProjectTeamStaff::getRoleType, 1).last("limit 1").one();
notice.setCommitId(tokenService.getLoginUser().getUserId()+"");
notice.setUserId(tProjectTeamStaff.getUserId());
notice.setStatus(1);
String temp=dto.getStatus()==2?"通过":"驳回";
notice.setNoticeContent("您有【1】条【菌种报告】【报告库"+strainReport.getReportType()+"】菌种审批人已操作【" +temp+"】");
notice.setDataId(dto.getId());
notice.setNoticeType(7);
noticeService.save(notice);
return R.ok();
}
/**
*/
//@PreAuthorize("@ss.hasPermi('system:strainReport:auditReport')")
@Log(title = "菌种库报告管理-菌种审批人/超级管理员评定", businessType = BusinessType.UPDATE)
@ApiOperation(value = "菌种审批人/超级管理员评定",tags = "菌种报告库",response = TStrainReportEvaluateDTO.class)
@PostMapping(value = "/api/t-strain-report/evaluateReport")
public R evaluateReport(@RequestBody String param) {
LoginUser loginUser = tokenService.getLoginUser();
if (loginUser==null){
return R.fail(401,"登陆失效");
}
TStrainReportEvaluateDTO dto = JSON.parseObject(param,TStrainReportEvaluateDTO.class);
TStrainReport strainReport = strainReportService.getById(dto.getId());
strainReport.setEvaluateTime(LocalDateTime.now());
strainReport.setEvaluateId(loginUser.getUserId()+"");
strainReport.setStatus(3);
strainReportService.updateById(strainReport);
TStrainReportDetail tStrainReportDetail = new TStrainReportDetail();
tStrainReportDetail.setReportId(strainReport.getId());
tStrainReportDetail.setEvaluate(dto.getEvaluate());
tStrainReportDetail.setEvaluateId(loginUser.getUserId()+"");
// tStrainReportDetail.setDetectionCode(dto.getDetectionCode());
// tStrainReportDetail.setDetectionName(dto.getDetectionName());
tStrainReportDetail.setEvaluateTotal(dto.getEvaluateTotal());
tStrainReportDetail.setExperimentId(strainReport.getCommitId());
tStrainReportDetail.setReportType(strainReport.getReportType());
tStrainReportDetail.setEvaluateHumanType(2);
tStrainReportDetail.setEvaluateType(dto.getEvaluateType());
strainReportDetailService.save(tStrainReportDetail);
// 新增消息
TNotice notice = new TNotice();
TProjectTeamStaff projectTeamStaff = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, strainReport.getProjectId())
.eq(TProjectTeamStaff::getRoleType, 1).last("limit 1").one();
notice.setCommitId(tokenService.getLoginUser().getUserId()+"");
notice.setUserId(projectTeamStaff.getUserId());
notice.setStatus(1);
notice.setNoticeContent("您有【1】条【菌种报告】【报告库"+strainReport.getReportType()+"】菌种审批人已评定");
notice.setDataId(dto.getId());
notice.setNoticeType(8);
noticeService.save(notice);
return R.ok();
}
/**
* 删除项目组
*/
//@PreAuthorize("@ss.hasPermi('system:projectTeam:delete')")
@Log(title = "菌种报告库-删除菌种报告库", businessType = BusinessType.DELETE)
@ApiOperation(value = "删除菌种报告库",tags = "菌种报告库")
@DeleteMapping(value = "/open/t-strain-report/deleteById")
public R deleteById(@RequestParam String id) {
return R.ok(strainReportService.remove(Wrappers.lambdaQuery(TStrainReport.class).eq(TStrainReport::getId, id)));
}
/**
* 菌种工程师查看报告详情
*/
//@PreAuthorize("@ss.hasPermi('system:strainReport:detail')")
@ApiOperation(value = "查看报告详情",tags = "菌种报告库",response = TStrainReportDetailVO.class)
@GetMapping(value = "/open/t-strain-report/detail")
public R detail(@RequestParam String id) {
TStrainReportDetailVO tStrainReportDetailVO = new TStrainReportDetailVO();
TStrainReport strainReport = strainReportService.getById(id);
if (strainReport.getAuditId()!=null){
SysUser sysUser = sysUserService.selectUserById(Long.valueOf(strainReport.getAuditId()));
if (sysUser!=null){
tStrainReportDetailVO.setAuditName(sysUser.getNickName());
}
}
BeanUtils.copyProperties(strainReport, tStrainReportDetailVO);
TProjectTeam projectTeam = projectTeamService.getById(strainReport.getProjectId());
List list = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getTeamId, projectTeam.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())){
projectTeam.setStaff(staffNames.substring(0, staffNames.toString().length() - 1));
}
tStrainReportDetailVO.setProjectTeam(projectTeam);
TStrainReportDetail strainReportDetail = strainReportDetailService.lambdaQuery().eq(TStrainReportDetail::getReportId, id)
.eq(TStrainReportDetail::getEvaluateHumanType, 1).one();
tStrainReportDetailVO.setEvaluate(strainReportDetail.getEvaluate());
tStrainReportDetailVO.setEvaluateTotal(strainReportDetail.getEvaluateTotal());
if (strainReport.getEvaluateId()!=null){
tStrainReportDetailVO.setEvaluateName(sysUserService.selectUserById(Long.valueOf(strainReport.getEvaluateId())).getNickName());
}
if (strainReportDetail.getExperimentId()!=null){
SysUser sysUser = sysUserService.selectUserById(Long.valueOf(strainReportDetail.getExperimentId()));
tStrainReportDetailVO.setExperimentName(sysUser.getNickName());
tStrainReportDetailVO.setExperimentAvatar(sysUser.getAvatar());
tStrainReportDetailVO.setExperimentId(strainReportDetail.getExperimentId());
}
tStrainReportDetailVO.setReportType(strainReport.getReportType());
if (strainReport.getCommitId()!=null){
tStrainReportDetailVO.setCommitName(sysUserService.selectUserById(Long.valueOf(strainReport.getCommitId())).getNickName());
}
return R.ok(tStrainReportDetailVO);
}
/**
* 菌种工程师查看报告详情
*/
@ApiOperation(value = "查看报告评定详情",tags = "菌种报告库")
@GetMapping(value = "/open/t-strain-report/detailReport")
public R detailReport(@RequestParam String id) {
TStrainReportDetailVO tStrainReportDetailVO = new TStrainReportDetailVO();
TStrainReport strainReport = strainReportService.getById(id);
BeanUtils.copyProperties(strainReport, tStrainReportDetailVO);
TProjectTeam projectTeam = projectTeamService.getById(strainReport.getProjectId());
tStrainReportDetailVO.setProjectTeam(projectTeam);
TStrainReportDetail strainReportDetail = strainReportDetailService.lambdaQuery().eq(TStrainReportDetail::getReportId, id)
.eq(TStrainReportDetail::getEvaluateHumanType, 2).one();
tStrainReportDetailVO.setEvaluate(strainReportDetail.getEvaluate());
tStrainReportDetailVO.setEvaluateTotal(strainReportDetail.getEvaluateTotal());
tStrainReportDetailVO.setEvaluateName(sysUserService.selectUserById(Long.valueOf(strainReport.getEvaluateId())).getNickName());
tStrainReportDetailVO.setExperimentName(sysUserService.selectUserById(Long.valueOf(strainReportDetail.getExperimentId())).getNickName());
tStrainReportDetailVO.setExperimentId(strainReportDetail.getExperimentId());
tStrainReportDetailVO.setReportType(strainReport.getReportType());
tStrainReportDetailVO.setCommitName(sysUserService.selectUserById(Long.valueOf(strainReport.getCommitId())).getNickName());
return R.ok(tStrainReportDetailVO);
}
}