package com.microservices.pms.project.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.Logical;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.pms.project.domain.vo.PmsProjectTestReportDetailVo;
import com.microservices.pms.project.domain.vo.PmsProjectTestReportInputVo;
import com.microservices.pms.project.domain.vo.PmsProjectTestReportSearchVo;
import com.microservices.pms.project.domain.vo.PmsProjectTestReportUpdateVo;
import com.microservices.pms.project.service.IPmsProjectTestReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 测试报告Controller
 * 
 * @author wanjia
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/{enterpriseIdentifier}/testReport")
@Api(tags = "项目管理-测试报告相关接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class PmsProjectTestReportController extends BaseController
{
    @Autowired
    private IPmsProjectTestReportService pmsProjectTestReportService;

    /**
     * 查询测试报告列表
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe"}, logical = Logical.OR)
    @GetMapping("/list")
    @ApiOperation(value = "测试报告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "orderByColumn", value = "排序列（更新时间：updateTime，创建时间：createTime）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
    })
    public GenericsTableDataInfo<PmsProjectTestReportDetailVo> list(PmsProjectTestReportSearchVo pmsProjectTestReportSearchVo)
    {
        return pmsProjectTestReportService.selectPmsProjectTestReportList(pmsProjectTestReportSearchVo);
    }

    /**
     * 获取测试报告详细信息
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe"}, logical = Logical.OR)
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取测试报告详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsProjectTestReportService.selectPmsProjectTestReportDetailById(id));
    }

    /**
     * 获取测试报告及统计数据
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe"}, logical = Logical.OR)
    @GetMapping(value = "/chart/{id}")
    @ApiOperation(value = "获取测试报告及统计数据")
    public AjaxResult getReport(@PathVariable("id") Long id)
    {
        return success(pmsProjectTestReportService.selectPmsProjectTestReportChartById(id));
    }

    /**
     * 新增测试报告
     */
    @RequiresPermissions("pms:testReport:manage")
    @Log(title = "测试报告", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增测试报告")
    public AjaxResult add(@RequestBody @Validated PmsProjectTestReportInputVo pmsProjectTestReportInputVo)
    {
        return toAjax(pmsProjectTestReportService.insertPmsProjectTestReportByInputVo(pmsProjectTestReportInputVo));
    }

    /**
     * 修改测试报告
     */
    @RequiresPermissions("pms:testReport:manage")
    @Log(title = "测试报告", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改测试报告")
    public AjaxResult edit(@RequestBody @Validated PmsProjectTestReportUpdateVo pmsProjectTestReportUpdateVo)
    {
        return toAjax(pmsProjectTestReportService.updatePmsProjectTestReportByUpdateVo(pmsProjectTestReportUpdateVo));
    }

    /**
     * 删除测试报告
     */
    @RequiresPermissions("pms:testReport:manage")
    @Log(title = "测试报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value = "删除测试报告")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsProjectTestReportService.deletePmsProjectTestReportByIds(ids));
    }
}
