package com.xinyilu.web.controller.testcategoryitem;

import com.xinyilu.common.annotation.Log;
import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.common.core.page.TableDataInfo;
import com.xinyilu.common.enums.BusinessType;
import com.xinyilu.common.utils.poi.ExcelUtil;
import com.xinyilu.system.domain.testcategoryitem.TestCategoryItem;
import com.xinyilu.system.service.testcategoryitem.ITestCategoryItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测试分类和测试项目关系Controller
 *
 * @author xinyilu
 * @date 2022-11-03
 */
@RestController
@RequestMapping("/system/testCategoryItem")
public class TestCategoryItemController extends BaseController {
    @Resource
    private ITestCategoryItemService testCategoryItemService;

    /**
     * 查询测试分类和测试项目关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:testCategoryItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestCategoryItem testCategoryItem) {
        startPage();
        List<TestCategoryItem> list = testCategoryItemService.selectTestCategoryItemList(testCategoryItem);
        return getDataTable(list);
    }

    /**
     * 导出测试分类和测试项目关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:testCategoryItem:export')")
    @Log(title = "测试分类和测试项目关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestCategoryItem testCategoryItem) {
        List<TestCategoryItem> list = testCategoryItemService.selectTestCategoryItemList(testCategoryItem);
        ExcelUtil<TestCategoryItem> util = new ExcelUtil<TestCategoryItem>(TestCategoryItem.class);
        util.exportExcel(response, list, "测试分类和测试项目关系数据");
    }

    /**
     * 获取测试分类和测试项目关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:testCategoryItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(testCategoryItemService.selectTestCategoryItemById(id));
    }

    /**
     * 新增测试分类和测试项目关系
     */
    @PreAuthorize("@ss.hasPermi('system:testCategoryItem:add')")
    @Log(title = "测试分类和测试项目关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestCategoryItem testCategoryItem) {
        return toAjax(testCategoryItemService.insertTestCategoryItem(testCategoryItem));
    }

    /**
     * 修改测试分类和测试项目关系
     */
    @PreAuthorize("@ss.hasPermi('system:testCategoryItem:edit')")
    @Log(title = "测试分类和测试项目关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestCategoryItem testCategoryItem) {
        return toAjax(testCategoryItemService.updateTestCategoryItem(testCategoryItem));
    }

    /**
     * 删除测试分类和测试项目关系
     */
    @PreAuthorize("@ss.hasPermi('system:testCategoryItem:remove')")
    @Log(title = "测试分类和测试项目关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(testCategoryItemService.deleteTestCategoryItemByIds(ids));
    }
}
