package com.zd.laboratory.controller;

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabSafeClasstype;
import com.zd.laboratory.service.ILabSafeClasstypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 安全分级类型Controller
 *
 * @author zd
 * @date 2021-12-18
 */
@RestController
@Api(tags = "【安全分级类型】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@RequestMapping("/classtype")
public class LabSafeClasstypeController extends BaseController {
    @Autowired
    private ILabSafeClasstypeService labSafeClasstypeService;

    /**
     * 查询安全分级类型列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询安全分级类型列表")
    public TableDataInfo<LabSafeClasstype> list(LabSafeClasstype labSafeClasstype) {
        startPage();
        List<LabSafeClasstype> list = labSafeClasstypeService.selectLabSafeClasstypeList(labSafeClasstype);
        return getDataTable(list);
    }

    /**
     * 查询安全分类列表
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询安全分类列表")
    public ResultData<List<LabSafeClasstype>> listAll(LabSafeClasstype labSafeClasstype) {
        List<LabSafeClasstype> list = labSafeClasstypeService.selectLabSafeClasstypeList(labSafeClasstype);
        return ResultData.success(list);
    }

    /**
     * 导出安全分级类型列表
     */
    @ApiOperation(value = "导出安全分级类型列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.EXPORT)
    @Log(title = "安全分级类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSafeClasstype labSafeClasstype) throws IOException {
        List<LabSafeClasstype> list = labSafeClasstypeService.selectLabSafeClasstypeList(labSafeClasstype);
        ExcelUtil<LabSafeClasstype> util = new ExcelUtil<LabSafeClasstype>(LabSafeClasstype.class);
        util.exportExcel(response, list, "安全分级类型数据");
    }

    /**
     * 获取安全分级类型详细信息
     */
    @ApiOperation(value = "获取安全分级类型详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabSafeClasstype> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(labSafeClasstypeService.selectLabSafeClasstypeById(id));
    }

    /**
     * 新增安全分级类型
     */
    @ApiOperation(value = "新增安全分级类型")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.ADD)
    @Log(title = "安全分级类型", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabSafeClasstype labSafeClasstype) {
        return ResultData.result(labSafeClasstypeService.insertLabSafeClasstype(labSafeClasstype));
    }

    /**
     * 修改安全分级类型
     */
    @ApiOperation(value = "修改安全分级类型")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.EDIT)
    @Log(title = "安全分级类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabSafeClasstype labSafeClasstype) {
        return ResultData.result(labSafeClasstypeService.updateLabSafeClasstype(labSafeClasstype));
    }

    /**
     * 删除安全分级类型
     */
    @ApiOperation(value = "删除安全分级类型")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.REMOVE)
    @Log(title = "安全分级类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(labSafeClasstypeService.deleteLabSafeClasstypeByIds(ids));
    }
}
