package com.cmvr.web.controller.test;

import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.test.model.domain.TeDetectionItem;
import com.cmvr.test.model.vo.TeDetectionItemVO;
import com.cmvr.test.service.ITeDetectionItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "测试--检测项配置")
@RestController
@RequestMapping("/test/detect")
@RequiredArgsConstructor
public class TeDetectionItemController extends BaseController {
    private final ITeDetectionItemService teDetectionItemService;

    @ApiOperation("查询检测项配置列表")
    @PreAuthorize("@ss.hasPermi('test:detect:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeDetectionItem teDetectionItem) {
        startPage();
        List<TeDetectionItemVO> list = teDetectionItemService.selectTeDetectionItemList(teDetectionItem);
        return getDataTable(list);
    }

    @ApiOperation("导出检测项配置列表")
    @PreAuthorize("@ss.hasPermi('test:detect:export')")
    @Log(title = "检测项配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeDetectionItem teDetectionItem) {
        List<TeDetectionItemVO> list = teDetectionItemService.selectTeDetectionItemList(teDetectionItem);
        ExcelUtil<TeDetectionItemVO> util = new ExcelUtil<TeDetectionItemVO>(TeDetectionItemVO.class);
        util.exportExcel(response, list, "检测项配置数据");
    }

    @ApiOperation("获取检测项配置详细信息")
    @PreAuthorize("@ss.hasPermi('test:detect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(teDetectionItemService.selectTeDetectionItemById(id));
    }

    @ApiOperation("新增检测项配置")
    @PreAuthorize("@ss.hasPermi('test:detect:add')")
    @Log(title = "检测项配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeDetectionItem teDetectionItem) {
        int rows = teDetectionItemService.insertTeDetectionItem(teDetectionItem);
        return toAjax(rows);
    }

    @ApiOperation("修改检测项配置")
    @PreAuthorize("@ss.hasPermi('test:detect:edit')")
    @Log(title = "检测项配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeDetectionItem teDetectionItem) {
        return toAjax(teDetectionItemService.updateTeDetectionItem(teDetectionItem));
    }

    @ApiOperation("删除检测项配置")
    @PreAuthorize("@ss.hasPermi('test:detect:remove')")
    @Log(title = "检测项配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(teDetectionItemService.deleteTeDetectionItemByIds(ids));
    }
}
