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.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TExperimentResultReportDTO;
import com.ruoyi.system.model.TExperimentResultReport;
import com.ruoyi.system.model.TExperimentScheme;
import com.ruoyi.system.model.TInspectionReport;
import com.ruoyi.system.model.TResultWorkEvaluate;
import com.ruoyi.system.query.TExperimentResultReportQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TExperimentResultReportVO;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
* 实验结果汇报 前端控制器
*
*
* @author xiaochen
* @since 2025-04-08
*/
@Api(tags = "实验结果汇报")
@RestController
@RequestMapping("")
public class TExperimentResultReportController {
private final TExperimentResultReportService experimentResultReportService;
private final TokenService tokenService;
private final ISysUserService sysUserService;
private final TResultWorkEvaluateService resultWorkEvaluateService;
private final TExperimentSchemeService experimentSchemeService;
private final TInspectionReportService inspectionReportService;
@Autowired
public TExperimentResultReportController(TExperimentResultReportService experimentResultReportService, TokenService tokenService, ISysUserService sysUserService, TResultWorkEvaluateService resultWorkEvaluateService, TExperimentSchemeService experimentSchemeService, TInspectionReportService inspectionReportService) {
this.experimentResultReportService = experimentResultReportService;
this.tokenService = tokenService;
this.sysUserService = sysUserService;
this.resultWorkEvaluateService = resultWorkEvaluateService;
this.experimentSchemeService = experimentSchemeService;
this.inspectionReportService = inspectionReportService;
}
/**
* 获取实验结果汇报管理列表
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:list')")
@ApiOperation(value = "获取实验结果汇报分页列表")
@PostMapping(value = "/api/t-experiment-result-report/pageList")
public R> pageList(@RequestBody String param) {
TExperimentResultReportQuery query = JSON.parseObject(param, TExperimentResultReportQuery.class);
return R.ok(experimentResultReportService.pageList(query));
}
/**
* 添加实验结果汇报管理
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:add')")
@Log(title = "实验结果汇报信息-新增实验结果汇报", businessType = BusinessType.INSERT)
@ApiOperation(value = "添加实验结果汇报",response = TExperimentResultReportDTO.class)
@PostMapping(value = "/api/t-experiment-result-report/add")
public R add(@RequestBody String param) {
TExperimentResultReportDTO dto = JSON.parseObject(param,TExperimentResultReportDTO.class);
experimentResultReportService.save(dto);
// 添加实验结果工作评价
List resultWorkEvaluates = dto.getResultWorkEvaluates();
for (TResultWorkEvaluate resultWorkEvaluate : resultWorkEvaluates) {
resultWorkEvaluate.setResultReportId(dto.getId());
}
resultWorkEvaluateService.saveBatch(resultWorkEvaluates);
return R.ok();
}
/**
* 修改实验结果汇报
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:edit')")
@Log(title = "实验结果汇报信息-修改实验结果汇报", businessType = BusinessType.UPDATE)
@ApiOperation(value = "修改实验结果汇报")
@PostMapping(value = "/api/t-experiment-result-report/update")
public R update(@RequestBody String param) {
TExperimentResultReportDTO dto = JSON.parseObject(param,TExperimentResultReportDTO.class);
experimentResultReportService.updateById(dto);
// 修改实验结果工作评价
List resultWorkEvaluates = dto.getResultWorkEvaluates();
resultWorkEvaluateService.updateBatchById(resultWorkEvaluates);
return R.ok();
}
/**
* 修改实验结果汇报
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:edit')")
@Log(title = "实验结果汇报信息-评定工艺工程师实验", businessType = BusinessType.UPDATE)
@ApiOperation(value = "评定工艺工程师实验")
@PostMapping(value = "/api/t-experiment-result-report/evaluateProcess")
public R evaluateProcess(@RequestBody String param) {
TResultWorkEvaluate resultWorkEvaluate = JSON.parseObject(param,TResultWorkEvaluate.class);
resultWorkEvaluateService.save(resultWorkEvaluate);
return R.ok();
}
/**
* 查看实验结果汇报详情
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:detail')")
@ApiOperation(value = "查看实验结果汇报详情")
@GetMapping(value = "/open/t-experiment-result-report/getDetailById")
public R getDetailById(@RequestParam String id) {
TExperimentResultReport experimentResultReport = experimentResultReportService.getById(id);
TExperimentResultReportVO experimentResultReportVO = new TExperimentResultReportVO();
BeanUtils.copyProperties(experimentResultReport, experimentResultReportVO);
// 获取评分列表
List resultWorkEvaluates = resultWorkEvaluateService.list(Wrappers.lambdaQuery(TResultWorkEvaluate.class)
.eq(TResultWorkEvaluate::getResultReportId, id));
experimentResultReportVO.setResultWorkEvaluates(resultWorkEvaluates);
// 查询实验结果列表
List experimentSchemes = experimentSchemeService.list(Wrappers.lambdaQuery(TExperimentScheme.class)
.eq(TExperimentScheme::getDispatchId, experimentResultReport.getDispatchId()));
experimentResultReportVO.setExperimentSchemes(experimentSchemes);
// 查询检验报告列表
List inspectionReports = inspectionReportService.list(Wrappers.lambdaQuery(TInspectionReport.class)
.eq(TInspectionReport::getDispatchId, experimentResultReport.getDispatchId()));
experimentResultReportVO.setInspectionReports(inspectionReports);
return R.ok(experimentResultReportVO);
}
/**
* 删除实验结果汇报
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:delete')")
@Log(title = "实验结果汇报信息-删除实验结果汇报", businessType = BusinessType.DELETE)
@ApiOperation(value = "删除实验结果汇报")
@DeleteMapping(value = "/open/t-experiment-result-report/deleteById")
public R deleteById(@RequestParam String id) {
return R.ok(experimentResultReportService.removeById(id));
}
/**
* 批量删除实验结果汇报
*/
@PreAuthorize("@ss.hasPermi('system:experimentResultReport:delete')")
@Log(title = "实验结果汇报信息-删除实验结果汇报", businessType = BusinessType.DELETE)
@ApiOperation(value = "批量删除实验结果汇报")
@DeleteMapping(value = "/open/t-experiment-result-report/deleteByIds")
public R deleteByIds(@RequestBody List ids) {
return R.ok(experimentResultReportService.removeByIds(ids));
}
}