无关风月
3 天以前 20739d95d85d5d6744690093a061292325ce4a9b
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TTesterOtherTaskController.java
@@ -1,9 +1,34 @@
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.common.enums.QaReportFileEnum;
import com.ruoyi.common.enums.QaReportTypeEnum;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TQaTestItemReportDTO;
import com.ruoyi.system.model.TProjectTeam;
import com.ruoyi.system.model.TProjectTeamStaff;
import com.ruoyi.system.model.TQaReportFile;
import com.ruoyi.system.model.TQaTestItemReport;
import com.ruoyi.system.query.TQaTestItemReportQuery;
import com.ruoyi.system.service.TProjectTeamService;
import com.ruoyi.system.service.TProjectTeamStaffService;
import com.ruoyi.system.service.TQaReportFileService;
import com.ruoyi.system.service.TQaTestItemReportService;
import com.ruoyi.system.vo.TQaTestItemReportVO;
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.Objects;
/**
 * <p>
@@ -18,5 +43,155 @@
@RequestMapping("/t-tester-other-task")
public class TTesterOtherTaskController {
    private final TQaTestItemReportService qaTestItemReportService;
    private final TQaReportFileService qaReportFileService;
    private final TokenService tokenService;
    private final TProjectTeamService projectTeamService;
    private final TProjectTeamStaffService projectTeamStaffService;
    @Autowired
    public TTesterOtherTaskController(TQaTestItemReportService qaTestItemReportService, TQaReportFileService qaReportFileService, TokenService tokenService, TProjectTeamService projectTeamService, TProjectTeamStaffService projectTeamStaffService) {
        this.qaTestItemReportService = qaTestItemReportService;
        this.qaReportFileService = qaReportFileService;
        this.tokenService = tokenService;
        this.projectTeamService = projectTeamService;
        this.projectTeamStaffService = projectTeamStaffService;
    }
    /**
     * 获取QA检测项报告管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:list')")
    @ApiOperation(value = "获取QA检测项报告管理分页列表-工艺工程师使用", response = TQaTestItemReportQuery.class)
    @PostMapping(value = "/api/t-qa-test-item-report/pageList")
    public R<PageInfo<TQaTestItemReportVO>> pageList(@RequestBody String param) {
        TQaTestItemReportQuery query = JSON.parseObject(param, TQaTestItemReportQuery.class);
        return R.ok(qaTestItemReportService.pageList(query));
    }
    /**
     * 获取QA检测项报告管理列表
     */
    @ApiOperation(value = "获取QA检测项报告管理下拉列表-化验师使用")
    @GetMapping(value = "/open/t-qa-test-item-report/getListByItemId")
    public R<List<TQaTestItemReport>> getListByItemId(@RequestParam String itemId) {
        List<TQaTestItemReport> list = qaTestItemReportService.list(Wrappers.lambdaQuery(TQaTestItemReport.class)
                .eq(TQaTestItemReport::getItemId, itemId));
        return R.ok(list);
    }
    /**
     * 添加QA检测项报告管理管理
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:add')")
    @Log(title = "QA检测项报告管理信息-新增QA检测项报告管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加QA检测项报告管理",response = TQaTestItemReportDTO.class)
    @PostMapping(value = "/api/t-qa-test-item-report/add")
    public R<Boolean> add(@RequestBody String param) {
        TQaTestItemReportDTO dto = JSON.parseObject(param,TQaTestItemReportDTO.class);
        // 通过当前用户查询项目组
        Long userId = tokenService.getLoginUser().getUserId();
        TProjectTeamStaff projectTeamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                .eq(TProjectTeamStaff::getUserId, userId)
                .last("LIMIT 1"));
        if(Objects.isNull(projectTeamStaff)){
            return R.fail("当前用户未分配项目组,无法创建项目课题方案");
        }
        // 查询项目组
        TProjectTeam projectTeam = projectTeamService.getById(projectTeamStaff.getTeamId());
        if(Objects.isNull(projectTeam)){
            return R.fail("项目组不存在");
        }
        if(projectTeam.getStatus() == 2){
            return R.fail("项目组已封存,无法创建项目课题方案");
        }
        // 生成中试、生产验证编号
        String reportCode = projectTeam.getTeamName() + "-" + QaReportTypeEnum.TEST_REPORT.getCode();
        // 查询上个项目课题方案的序号
        long count = qaTestItemReportService.count(Wrappers.lambdaQuery(TQaTestItemReport.class)
                .like(TQaTestItemReport::getReportCode, reportCode));
        reportCode = reportCode + "-" + String.format("%03d", count+1);
        dto.setReportCode(reportCode);
        qaTestItemReportService.save(dto);
        // 添加检测报告文件
        List<TQaReportFile> qaReportFiles = dto.getQaReportFiles();
        for (TQaReportFile qaReportFile : qaReportFiles) {
            qaReportFile.setReportId(dto.getId());
            qaReportFile.setReportType(QaReportFileEnum.TEST_REPORT.getCode());
        }
        qaReportFileService.saveBatch(qaReportFiles);
        return R.ok();
    }
    /**
     * 修改QA检测项报告管理
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:edit')")
    @Log(title = "QA检测项报告管理信息-修改QA检测项报告管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改QA检测项报告管理")
    @PostMapping(value = "/api/t-qa-test-item-report/update")
    public R<Boolean> update(@RequestBody String param) {
        TQaTestItemReportDTO dto = JSON.parseObject(param,TQaTestItemReportDTO.class);
        qaTestItemReportService.updateById(dto);
        qaReportFileService.remove(Wrappers.lambdaQuery(TQaReportFile.class)
                .eq(TQaReportFile::getReportId, dto.getId()));
        // 添加检测报告文件
        List<TQaReportFile> qaReportFiles = dto.getQaReportFiles();
        for (TQaReportFile qaReportFile : qaReportFiles) {
            qaReportFile.setReportId(dto.getId());
            qaReportFile.setReportType(QaReportFileEnum.TEST_REPORT.getCode());
        }
        qaReportFileService.saveBatch(qaReportFiles);
        return R.ok();
    }
    /**
     * 查看QA检测项报告管理详情
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:detail')")
    @ApiOperation(value = "查看QA检测项报告管理详情")
    @GetMapping(value = "/open/t-qa-test-item-report/getDetailById")
    public R<TQaTestItemReportVO> getDetailById(@RequestParam String id) {
        TQaTestItemReport testItemReport = qaTestItemReportService.getById(id);
        TQaTestItemReportVO testItemReportVO = new TQaTestItemReportVO();
        BeanUtils.copyProperties(testItemReport, testItemReportVO);
        // 查询检测报告文件
        List<TQaReportFile> qaReportFiles = qaReportFileService.list(Wrappers.lambdaQuery(TQaReportFile.class)
                .eq(TQaReportFile::getReportId, id)
                .eq(TQaReportFile::getReportType, QaReportFileEnum.TEST_REPORT.getCode()));
        testItemReportVO.setQaReportFileList(qaReportFiles);
        return R.ok(testItemReportVO);
    }
    /**
     * 删除QA检测项报告管理
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:delete')")
    @Log(title = "QA检测项报告管理信息-删除QA检测项报告管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除QA检测项报告管理")
    @DeleteMapping(value = "/open/t-qa-test-item-report/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        // 删除QA检测项报告文件
        qaReportFileService.remove(Wrappers.lambdaQuery(TQaReportFile.class).eq(TQaReportFile::getReportId, id)
                .in(TQaReportFile::getReportType, QaReportFileEnum.TEST_REPORT.getCode()));
        return R.ok(qaTestItemReportService.removeById(id));
    }
    /**
     * 批量删除QA检测项报告管理
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:delete')")
    @Log(title = "QA检测项报告管理信息-删除QA检测项报告管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除QA检测项报告管理")
    @DeleteMapping(value = "/open/t-qa-test-item-report/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        // 删除QA检测项报告检测报告文件
        qaReportFileService.remove(Wrappers.lambdaQuery(TQaReportFile.class).in(TQaReportFile::getReportId, ids)
                .in(TQaReportFile::getReportType, QaReportFileEnum.TEST_REPORT.getCode()));
        return R.ok(qaTestItemReportService.removeByIds(ids));
    }
}