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.LabSafeClassified;
import com.zd.laboratory.service.ILabSafeClassifiedService;
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("/classified")
public class LabSafeClassifiedController extends BaseController
{
    @Autowired
    private ILabSafeClassifiedService labSafeClassifiedService;

    /**
     * 查询安全分级列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询安全分级列表")
    public TableDataInfo<LabSafeClassified> list(LabSafeClassified labSafeClassified)
    {
        startPage();
        List<LabSafeClassified> list = labSafeClassifiedService.selectLabSafeClassifiedList(labSafeClassified);
        return getDataTable(list);
    }


    /**
     * 查询安全分级列表
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询安全分级列表")
    public ResultData<List<LabSafeClassified>> listAll(LabSafeClassified labSafeClassified) {
        List<LabSafeClassified> list = labSafeClassifiedService.selectLabSafeClassifiedList(labSafeClassified);
        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, LabSafeClassified labSafeClassified) throws IOException
    {
        List<LabSafeClassified> list = labSafeClassifiedService.selectLabSafeClassifiedList(labSafeClassified);
        ExcelUtil<LabSafeClassified> util = new ExcelUtil<LabSafeClassified>(LabSafeClassified.class);
        util.exportExcel(response, list, "安全分级数据");
    }

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

    /**
     * 新增安全分级
     */
    @ApiOperation(value = "新增安全分级")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.ADD)
    @Log(title = "安全分级", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabSafeClassified labSafeClassified)
    {
        return ResultData.result(labSafeClassifiedService.insertLabSafeClassified(labSafeClassified));
    }

    /**
     * 修改安全分级
     */
    @ApiOperation(value = "修改安全分级")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.EDIT)
    @Log(title = "安全分级", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabSafeClassified labSafeClassified)
    {
        return  ResultData.result(labSafeClassifiedService.updateLabSafeClassified(labSafeClassified));
    }

    /**
     * 删除安全分级
     */
    @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(labSafeClassifiedService.deleteLabSafeClassifiedByIds(ids));
    }
}
