package com.ruoyi.web.controller.api;
|
|
|
import com.alibaba.fastjson.JSON;
|
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.enums.BusinessType;
|
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.system.dto.ApplicationTerminationAuditDTO;
|
import com.ruoyi.system.dto.ApplicationTerminationDTO;
|
import com.ruoyi.system.dto.TExperimentSchemeDTO;
|
import com.ruoyi.system.mapper.SysUserMapper;
|
import com.ruoyi.system.model.*;
|
import com.ruoyi.system.query.TExperimentSchemeQuery;
|
import com.ruoyi.system.service.*;
|
import com.ruoyi.system.vo.TExperimentSchemeVO;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 实验方案管理 前端控制器
|
* </p>
|
*
|
* @author xiaochen
|
* @since 2025-04-08
|
*/
|
@Api(tags = "实验方案管理")
|
@RestController
|
@RequestMapping("")
|
public class TExperimentSchemeController {
|
|
private final TExperimentSchemeService experimentSchemeService;
|
private final TokenService tokenService;
|
private final ISysUserService sysUserService;
|
private final SysUserMapper sysUserMapper;
|
private final TExperimentSchemePersonService experimentSchemePersonService;
|
private final TExperimentDispatchParticipantsService experimentDispatchParticipantsService;
|
private final TExperimentDispatchService experimentDispatchService;
|
private final TProjectProposalService projectProposalService;
|
private final TExperimentDispatchGroupService experimentDispatchGroupService;
|
@Autowired
|
public TExperimentSchemeController(TExperimentSchemeService experimentSchemeService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TExperimentSchemePersonService experimentSchemePersonService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService, TExperimentDispatchService experimentDispatchService, TProjectProposalService projectProposalService, TExperimentDispatchGroupService experimentDispatchGroupService) {
|
this.experimentSchemeService = experimentSchemeService;
|
this.tokenService = tokenService;
|
this.sysUserService = sysUserService;
|
this.sysUserMapper = sysUserMapper;
|
this.experimentSchemePersonService = experimentSchemePersonService;
|
this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
|
this.experimentDispatchService = experimentDispatchService;
|
this.projectProposalService = projectProposalService;
|
this.experimentDispatchGroupService = experimentDispatchGroupService;
|
}
|
|
/**
|
* 获取实验方案管理列表
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:list')")
|
@ApiOperation(value = "获取实验方案分页列表",response = TExperimentSchemeQuery.class)
|
@PostMapping(value = "/api/t-experiment-scheme/pageList")
|
public R<PageInfo<TExperimentSchemeVO>> pageList(@RequestBody String param) {
|
TExperimentSchemeQuery query = JSON.parseObject(param, TExperimentSchemeQuery.class);
|
return R.ok(experimentSchemeService.pageList(query));
|
}
|
/**
|
* 获取实验方案管理列表-中止审批列表
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:list')")
|
@ApiOperation(value = "获取实验方案分页列表-中止审批列表",response = TExperimentSchemeQuery.class)
|
@PostMapping(value = "/api/t-experiment-scheme/auditPageList")
|
public R<PageInfo<TExperimentSchemeVO>> auditPageList(@RequestBody String param) {
|
TExperimentSchemeQuery query = JSON.parseObject(param, TExperimentSchemeQuery.class);
|
return R.ok(experimentSchemeService.auditPageList(query));
|
}
|
|
/**
|
* 通过实验调度查询查询组别列表
|
*/
|
@ApiOperation(value = "通过实验调度查询实验人员")
|
@GetMapping(value = "/open/t-experiment-scheme/getParticipantsByDispatchId")
|
public R<List<TExperimentDispatchParticipants>> getParticipantsByDispatchId(@RequestParam String dispatchId) {
|
List<TExperimentDispatchParticipants> list = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
|
.eq(TExperimentDispatchParticipants::getDispatchId, dispatchId)
|
.eq(TExperimentDispatchParticipants::getRoleType,5));
|
if(!CollectionUtils.isEmpty(list)){
|
List<Long> userIds = list.stream().map(TExperimentDispatchParticipants::getUserId).collect(Collectors.toList());
|
List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
|
list.forEach(tExperimentDispatchParticipant -> {
|
SysUser sysUser = sysUsers.stream().filter(user -> user.getUserId().equals(tExperimentDispatchParticipant.getUserId())).findFirst().orElse(null);
|
if(sysUser != null){
|
tExperimentDispatchParticipant.setNickName(sysUser.getNickName());
|
tExperimentDispatchParticipant.setAvatar(sysUser.getAvatar());
|
}
|
});
|
}
|
return R.ok(list);
|
}
|
/**
|
* 通过实验调度查询查询组别列表
|
*/
|
@ApiOperation(value = "通过实验调度查询查询组别列表")
|
@GetMapping(value = "/open/t-experiment-scheme/getGroupByDispatchId")
|
public R<List<TExperimentDispatchGroup>> getGroupByDispatchId(@RequestParam String dispatchId) {
|
List<TExperimentDispatchGroup> list = experimentDispatchGroupService.list(Wrappers.lambdaQuery(TExperimentDispatchGroup.class)
|
.eq(TExperimentDispatchGroup::getDispatchId, dispatchId));
|
return R.ok(list);
|
}
|
|
/**
|
* 添加实验方案管理
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:add')")
|
@Log(title = "实验方案信息-新增实验方案", businessType = BusinessType.INSERT)
|
@ApiOperation(value = "添加实验方案",response = TExperimentSchemeDTO.class)
|
@PostMapping(value = "/api/t-experiment-scheme/add")
|
public R<Boolean> add(@RequestBody String param) {
|
TExperimentSchemeDTO dto = JSON.parseObject(param,TExperimentSchemeDTO.class);
|
experimentSchemeService.save(dto);
|
List<TExperimentSchemePerson> experimentSchemePersons = dto.getExperimentSchemePersons();
|
experimentSchemePersons.forEach(experimentSchemePerson -> {
|
experimentSchemePerson.setSchemeId(dto.getId());
|
experimentSchemePerson.setCommitTime(LocalDateTime.now());
|
});
|
experimentSchemePersonService.saveBatch(experimentSchemePersons);
|
return R.ok();
|
}
|
|
/**
|
* 修改实验方案
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:edit')")
|
@Log(title = "实验方案信息-修改实验方案", businessType = BusinessType.UPDATE)
|
@ApiOperation(value = "修改实验方案")
|
@PostMapping(value = "/api/t-experiment-scheme/update")
|
public R<Boolean> update(@RequestBody String param) {
|
TExperimentSchemeDTO dto = JSON.parseObject(param,TExperimentSchemeDTO.class);
|
experimentSchemeService.updateById(dto);
|
experimentSchemePersonService.remove(Wrappers.lambdaQuery(TExperimentSchemePerson.class).eq(TExperimentSchemePerson::getSchemeId,dto.getId()));
|
List<TExperimentSchemePerson> experimentSchemePersons = dto.getExperimentSchemePersons();
|
experimentSchemePersons.forEach(experimentSchemePerson -> {
|
experimentSchemePerson.setSchemeId(dto.getId());
|
experimentSchemePerson.setCommitTime(LocalDateTime.now());
|
});
|
experimentSchemePersonService.saveBatch(experimentSchemePersons);
|
return R.ok();
|
}
|
|
/**
|
* 修改实验方案
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:edit')")
|
@Log(title = "实验方案信息-修改实验方案-实验员提交", businessType = BusinessType.UPDATE)
|
@ApiOperation(value = "修改实验方案-实验员提交")
|
@PostMapping(value = "/api/t-experiment-scheme/updateTester")
|
public R<Boolean> updateTester(@RequestBody String param) {
|
TExperimentSchemeDTO dto = JSON.parseObject(param,TExperimentSchemeDTO.class);
|
dto.setStatus(6);
|
experimentSchemeService.updateById(dto);
|
return R.ok();
|
}
|
|
/**
|
* 查看实验方案详情
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:detail')")
|
@ApiOperation(value = "查看实验方案详情")
|
@GetMapping(value = "/open/t-experiment-scheme/getDetailById")
|
public R<TExperimentSchemeVO> getDetailById(@RequestParam String id) {
|
TExperimentScheme experimentScheme = experimentSchemeService.getById(id);
|
TExperimentSchemeVO experimentSchemeVO = new TExperimentSchemeVO();
|
BeanUtils.copyProperties(experimentScheme, experimentSchemeVO);
|
|
// 查询实验调度信息
|
TExperimentDispatch experimentDispatch = experimentDispatchService.getById(experimentSchemeVO.getDispatchId());
|
if(Objects.nonNull(experimentDispatch)){
|
// 查询课题方案名称
|
TProjectProposal projectProposal = projectProposalService.getById(experimentDispatch.getProposalId());
|
if(Objects.nonNull(projectProposal)){
|
experimentDispatch.setProjectName(projectProposal.getProjectName());
|
experimentDispatch.setProjectCode(projectProposal.getProjectCode());
|
}
|
}
|
experimentSchemeVO.setExperimentDispatch(experimentDispatch);
|
|
// 查询组别
|
List<TExperimentDispatchParticipants> list = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
|
.eq(TExperimentDispatchParticipants::getDispatchId, experimentSchemeVO.getDispatchId()));
|
experimentSchemeVO.setExperimentDispatchParticipants(list);
|
|
// 获取实验人员
|
List<TExperimentSchemePerson> experimentSchemePersons = experimentSchemePersonService.list(Wrappers.lambdaQuery(TExperimentSchemePerson.class)
|
.eq(TExperimentSchemePerson::getSchemeId, id));
|
List<Long> userIds = experimentSchemePersons.stream().map(TExperimentSchemePerson::getUserId).collect(Collectors.toList());
|
List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
|
sysUsers.forEach(sysUser -> {
|
experimentSchemePersons.stream().filter(experimentSchemePerson -> experimentSchemePerson.getUserId().equals(sysUser.getUserId())).forEach(experimentSchemePerson -> {
|
experimentSchemePerson.setNickName(sysUser.getNickName());
|
experimentSchemePerson.setAvatar(sysUser.getAvatar());
|
});
|
});
|
experimentSchemeVO.setExperimentSchemePersons(experimentSchemePersons);
|
|
// 查询审核人姓名
|
SysUser sysUser = sysUserService.selectUserById(experimentScheme.getAuditPersonId());
|
if(Objects.nonNull(sysUser)){
|
experimentSchemeVO.setAuditPersonName(sysUser.getNickName());
|
}
|
|
return R.ok(experimentSchemeVO);
|
}
|
|
/**
|
* 删除实验方案
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:delete')")
|
@Log(title = "实验方案信息-删除实验方案", businessType = BusinessType.DELETE)
|
@ApiOperation(value = "删除实验方案")
|
@DeleteMapping(value = "/open/t-experiment-scheme/deleteById")
|
public R<Boolean> deleteById(@RequestParam String id) {
|
// 删除试验方案人员
|
experimentSchemePersonService.remove(Wrappers.lambdaQuery(TExperimentSchemePerson.class).eq(TExperimentSchemePerson::getSchemeId, id));
|
return R.ok(experimentSchemeService.removeById(id));
|
}
|
|
/**
|
* 批量删除实验方案
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:delete')")
|
@Log(title = "实验方案信息-删除实验方案", businessType = BusinessType.DELETE)
|
@ApiOperation(value = "批量删除实验方案")
|
@DeleteMapping(value = "/open/t-experiment-scheme/deleteByIds")
|
public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
|
// 删除试验方案人员
|
experimentSchemePersonService.remove(Wrappers.lambdaQuery(TExperimentSchemePerson.class).in(TExperimentSchemePerson::getSchemeId, ids));
|
return R.ok(experimentSchemeService.removeByIds(ids));
|
}
|
|
/**
|
* 批量删除实验方案
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:sign')")
|
@Log(title = "实验方案信息-申请中止实验", businessType = BusinessType.UPDATE)
|
@ApiOperation(value = "申请中止实验",response = ApplicationTerminationDTO.class)
|
@PostMapping(value = "/api/t-experiment-scheme/applicationTermination")
|
public R<Boolean> applicationTermination(@RequestBody String param) {
|
ApplicationTerminationDTO applicationTerminationDTO = JSON.parseObject(param, ApplicationTerminationDTO.class);
|
experimentSchemeService.update(Wrappers.lambdaUpdate(TExperimentScheme.class)
|
.eq(TExperimentScheme::getId, applicationTerminationDTO.getId())
|
.set(TExperimentScheme::getStatus, 2)
|
.set(TExperimentScheme::getStopReason, applicationTerminationDTO.getStopReason())
|
.set(TExperimentScheme::getStopFile, applicationTerminationDTO.getStopFile())
|
.set(TExperimentScheme::getStopFileName, applicationTerminationDTO.getStopFileName())
|
.set(TExperimentScheme::getCommitSign, applicationTerminationDTO.getCommitSign()));
|
return R.ok();
|
}
|
|
/**
|
* 批量删除实验方案
|
*/
|
//@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:audit')")
|
@Log(title = "实验方案信息-申请中止实验审核", businessType = BusinessType.UPDATE)
|
@ApiOperation(value = "申请中止实验审核")
|
@PostMapping(value = "/api/t-experiment-scheme/audit")
|
public R<Boolean> audit(@RequestBody String param) {
|
ApplicationTerminationAuditDTO applicationTerminationAuditDTO = JSON.parseObject(param, ApplicationTerminationAuditDTO.class);
|
Long userId = tokenService.getLoginUser().getUserId();
|
experimentSchemeService.update(Wrappers.lambdaUpdate(TExperimentScheme.class)
|
.eq(TExperimentScheme::getId, applicationTerminationAuditDTO.getId())
|
.set(TExperimentScheme::getStatus, applicationTerminationAuditDTO.getStatus())
|
.set(TExperimentScheme::getAuditRemark, applicationTerminationAuditDTO.getAuditRemark())
|
.set(TExperimentScheme::getAuditPersonId, userId)
|
.set(TExperimentScheme::getAuditTime, LocalDateTime.now()));
|
return R.ok();
|
}
|
|
}
|