xuhy
3 天以前 05fed078888dd5c2624751b6b29c5e16b7f1b2e6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TExperimentResultReportController.java
@@ -1,9 +1,26 @@
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.*;
import com.ruoyi.system.query.TExperimentResultReportQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TExperimentResultReportVO;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
/**
 * <p>
@@ -15,8 +32,169 @@
 */
@Api(tags = "实验结果汇报")
@RestController
@RequestMapping("/t-experiment-result-report")
@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;
    private final TProjectTeamStaffService projectTeamStaffService;
    private final TExperimentDispatchParticipantsService experimentDispatchParticipantsService;
    @Autowired
    public TExperimentResultReportController(TExperimentResultReportService experimentResultReportService, TokenService tokenService, ISysUserService sysUserService, TResultWorkEvaluateService resultWorkEvaluateService, TExperimentSchemeService experimentSchemeService, TInspectionReportService inspectionReportService, TProjectTeamStaffService projectTeamStaffService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService) {
        this.experimentResultReportService = experimentResultReportService;
        this.tokenService = tokenService;
        this.sysUserService = sysUserService;
        this.resultWorkEvaluateService = resultWorkEvaluateService;
        this.experimentSchemeService = experimentSchemeService;
        this.inspectionReportService = inspectionReportService;
        this.projectTeamStaffService = projectTeamStaffService;
        this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
    }
    /**
     * 获取实验结果汇报管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:experimentResultReport:list')")
    @ApiOperation(value = "获取实验结果汇报分页列表",response = TExperimentResultReportQuery.class)
    @PostMapping(value = "/api/t-experiment-result-report/pageList")
    public R<PageInfo<TExperimentResultReportVO>> pageList(@RequestBody String param) {
        TExperimentResultReportQuery query = JSON.parseObject(param, TExperimentResultReportQuery.class);
        Long userId = tokenService.getLoginUser().getUserId();
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        if(roleType != 1){
            // 查询用户所参与的实验调度
            List<TExperimentDispatchParticipants> experimentDispatchParticipants = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                    .eq(TExperimentDispatchParticipants::getUserId, userId));
            if(experimentDispatchParticipants.size() > 0){
                // 查询项目组id
                List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
                query.setDispatchIds(dispatchIds);
            }
        }
        return R.ok(experimentResultReportService.pageList(query));
    }
    /**
     * 获取实验结果汇报评定列表
     */
    //@PreAuthorize("@ss.hasPermi('system:experimentResultReport:list')")
    @ApiOperation(value = "获取实验结果汇报评定列表-审批人使用",response = TExperimentResultReportQuery.class)
    @PostMapping(value = "/api/t-experiment-result-report/evaluatePageList")
    public R<PageInfo<TExperimentResultReportVO>> evaluatePageList(@RequestBody String param) {
        TExperimentResultReportQuery query = JSON.parseObject(param, TExperimentResultReportQuery.class);
        Long userId = tokenService.getLoginUser().getUserId();
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        if(roleType != 1){
            // 查询用户所参与的实验调度
            List<TExperimentDispatchParticipants> experimentDispatchParticipants = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                    .eq(TExperimentDispatchParticipants::getUserId, userId));
            if(experimentDispatchParticipants.size() > 0){
                // 查询项目组id
                List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
                query.setDispatchIds(dispatchIds);
            }
        }
        return R.ok(experimentResultReportService.evaluatePageList(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<Boolean> add(@RequestBody String param) {
        TExperimentResultReportDTO dto = JSON.parseObject(param,TExperimentResultReportDTO.class);
        experimentResultReportService.save(dto);
        // 添加实验结果工作评价
        List<TResultWorkEvaluate> 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<Boolean> update(@RequestBody String param) {
        TExperimentResultReportDTO dto = JSON.parseObject(param,TExperimentResultReportDTO.class);
        experimentResultReportService.updateById(dto);
        // 修改实验结果工作评价
        List<TResultWorkEvaluate> 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<Boolean> 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<TExperimentResultReportVO> getDetailById(@RequestParam String id) {
        TExperimentResultReport experimentResultReport = experimentResultReportService.getById(id);
        TExperimentResultReportVO experimentResultReportVO = new TExperimentResultReportVO();
        BeanUtils.copyProperties(experimentResultReport, experimentResultReportVO);
        // 获取评分列表
        List<TResultWorkEvaluate> resultWorkEvaluates = resultWorkEvaluateService.list(Wrappers.lambdaQuery(TResultWorkEvaluate.class)
                .eq(TResultWorkEvaluate::getResultReportId, id));
        experimentResultReportVO.setResultWorkEvaluates(resultWorkEvaluates);
        // 查询实验结果列表
        List<TExperimentScheme> experimentSchemes = experimentSchemeService.list(Wrappers.lambdaQuery(TExperimentScheme.class)
                .eq(TExperimentScheme::getDispatchId, experimentResultReport.getDispatchId()));
        experimentResultReportVO.setExperimentSchemes(experimentSchemes);
        // 查询检验报告列表
        List<TInspectionReport> 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<Boolean> 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<Boolean> deleteByIds(@RequestBody List<String> ids) {
        return R.ok(experimentResultReportService.removeByIds(ids));
    }
}