package com.zd.laboratory.controller;

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

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.LabSecurityMaterialrelation;
import com.zd.laboratory.service.ILabSecurityMaterialrelationService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zd.common.swagger.config.Knife4jConfiguration;

import com.zd.common.core.web.page.TableDataInfo;

/**
 * 安全准入申请材料关系Controller
 *
 * @author zd
 * @date 2022-01-25
 */
@RestController
@Api(tags = "【安全准入申请材料关系】")
@RequestMapping("/materialrelation")
public class LabSecurityMaterialrelationController extends BaseController
{
    @Autowired
    private ILabSecurityMaterialrelationService labSecurityMaterialrelationService;

    /**
     * 查询安全准入申请材料关系列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_MATERIALRELATION + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询安全准入申请材料关系列表")
    public TableDataInfo<LabSecurityMaterialrelation> list(LabSecurityMaterialrelation labSecurityMaterialrelation)
    {
        startPage();
        List<LabSecurityMaterialrelation> list = labSecurityMaterialrelationService.selectLabSecurityMaterialrelationList(labSecurityMaterialrelation);
        return getDataTable(list);
    }

    /**
     * 导出安全准入申请材料关系列表
     */
    @ApiOperation(value = "导出安全准入申请材料关系列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_MATERIALRELATION + PerFun.EXPORT)
    @Log(title = "安全准入申请材料关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSecurityMaterialrelation labSecurityMaterialrelation) throws IOException
    {
        List<LabSecurityMaterialrelation> list = labSecurityMaterialrelationService.selectLabSecurityMaterialrelationList(labSecurityMaterialrelation);
        ExcelUtil<LabSecurityMaterialrelation> util = new ExcelUtil<LabSecurityMaterialrelation>(LabSecurityMaterialrelation.class);
        util.exportExcel(response, list, "安全准入申请材料关系数据");
    }

    /**
     * 获取安全准入申请材料关系详细信息
     */
    @ApiOperation(value = "获取安全准入申请材料关系详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_MATERIALRELATION + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabSecurityMaterialrelation> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(labSecurityMaterialrelationService.selectLabSecurityMaterialrelationById(id));
    }

    /**
     * 新增安全准入申请材料关系
     */
    @ApiOperation(value = "新增安全准入申请材料关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_MATERIALRELATION + PerFun.ADD)
    @Log(title = "安全准入申请材料关系", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabSecurityMaterialrelation labSecurityMaterialrelation)
    {
        return ResultData.result(labSecurityMaterialrelationService.insertLabSecurityMaterialrelation(labSecurityMaterialrelation));
    }

    /**
     * 修改安全准入申请材料关系
     */
    @ApiOperation(value = "修改安全准入申请材料关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_MATERIALRELATION + PerFun.EDIT)
    @Log(title = "安全准入申请材料关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabSecurityMaterialrelation labSecurityMaterialrelation)
    {
        return  ResultData.result(labSecurityMaterialrelationService.updateLabSecurityMaterialrelation(labSecurityMaterialrelation));
    }

    /**
     * 删除安全准入申请材料关系
     */
    @ApiOperation(value = "删除安全准入申请材料关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_MATERIALRELATION + PerFun.REMOVE)
    @Log(title = "安全准入申请材料关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(labSecurityMaterialrelationService.deleteLabSecurityMaterialrelationByIds(ids));
    }
}
