package com.test.test.controller;

import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType;
import com.test.common.utils.poi.ExcelUtil;
import com.test.test.domain.TestPlanDefect;
import com.test.test.domain.qo.TestPlanDefectQO;
import com.test.test.domain.qo.TestPlanDefectRelQO;
import com.test.test.domain.vo.TestPlanDefectVo;
import com.test.test.service.ITestPlanDefectService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 测试计划测试缺陷关联Controller
 *
 * @author test
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/testPlan/defect")
public class TestPlanDefectController extends BaseController
{
    @Autowired
    private ITestPlanDefectService testPlanDefectService;

    /**
     * 查询测试计划测试缺陷关联列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TestPlanDefectQO testPlanDefect)
    {
        startPage();
        List<TestPlanDefectVo> list = testPlanDefectService.selectTestPlanDefectList(testPlanDefect);
        return getDataTable(list);
    }

    /**
     * 导出测试计划测试缺陷关联列表
     */
    @Log(title = "测试计划测试缺陷关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestPlanDefectQO testPlanDefect)
    {
        List<TestPlanDefectVo> list = testPlanDefectService.selectTestPlanDefectList(testPlanDefect);
        ExcelUtil<TestPlanDefectVo> util = new ExcelUtil<TestPlanDefectVo>(TestPlanDefectVo.class);
        util.exportExcel(response, list, "测试计划测试缺陷关联数据");
    }

    /**
     * 获取测试计划测试缺陷关联详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(testPlanDefectService.selectTestPlanDefectById(id));
    }

    /**
     * 新增测试计划测试缺陷关联
     */
    @Log(title = "测试计划测试缺陷关联", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addRelDefect")
    public AjaxResult add(@RequestBody TestPlanDefectRelQO qo)
    {
        testPlanDefectService.insertTestPlanDefect(qo);
        return success(qo);
    }

    /**
     * 修改测试计划测试缺陷关联
     */
    @Log(title = "测试计划测试缺陷关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestPlanDefect testPlanDefect)
    {
        return toAjax(testPlanDefectService.updateTestPlanDefect(testPlanDefect));
    }

    /**
     * 删除测试计划测试缺陷关联
     */
    @Log(title = "测试计划测试缺陷关联", businessType = BusinessType.DELETE)
    @PostMapping("/delRelDefect/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(testPlanDefectService.deleteTestPlanDefectByIds(ids));
    }
}
