package com.zd.laboratory.controller;

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

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.log.annotation.Log;
import com.zd.laboratory.domain.vo.LabSecurityGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabSecurityGroup;
import com.zd.laboratory.service.ILabSecurityGroupService;
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 com.zd.common.core.web.page.TableDataInfo;

/**
 * 安全准入资格Controller
 *
 * @author zd
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/group")
public class LabSecurityGroupController extends BaseController {
    @Autowired
    private ILabSecurityGroupService labSecurityGroupService;

    /**
     * 查询安全准入资格列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_GROUP + PerFun.LIST)
    @GetMapping("/list")
    public TableDataInfo list(LabSecurityGroup labSecurityGroup) {
        startPage();
        List<LabSecurityGroup> list = labSecurityGroupService.selectLabSecurityGroupList(labSecurityGroup);
        return getDataTable(list);
    }

    /**
     * 导出安全准入资格列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_GROUP + PerFun.EXPORT)
    @Log(title = "安全准入资格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSecurityGroup labSecurityGroup) throws IOException {
        List<LabSecurityGroup> list = labSecurityGroupService.selectLabSecurityGroupList(labSecurityGroup);
        ExcelUtil<LabSecurityGroup> util = new ExcelUtil<LabSecurityGroup>(LabSecurityGroup.class);
        util.exportExcel(response, list, "安全准入资格数据");
    }

    /**
     * 获取安全准入资格详细信息
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_GROUP + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(labSecurityGroupService.selectLabSecurityGroupById(id));
    }

    /**
     * 新增安全准入资格
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_GROUP + PerFun.ADD)
    @Log(title = "安全准入资格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid LabSecurityGroupVO labSecurityGroupVO) {
        return toAjax(labSecurityGroupService.insertLabSecurityGroup(labSecurityGroupVO));
    }

    /**
     * 修改安全准入资格
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_GROUP + PerFun.EDIT)
    @Log(title = "安全准入资格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabSecurityGroupVO labSecurityGroupVo) {
        return toAjax(labSecurityGroupService.updateLabSecurityGroup(labSecurityGroupVo));
    }

    /**
     * 删除安全准入资格
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_GROUP + PerFun.REMOVE)
    @Log(title = "安全准入资格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(labSecurityGroupService.deleteLabSecurityGroupById(ids[0]));
    }


//    @PutMapping("/accessReview")
//    public AjaxResult accessReview(@RequestBody LabSecurityGroupVO labSecurityGroupVo) {
//        return toAjax(labSecurityGroupService.updateLabSecurityGroup(labSecurityGroupVo));
//    }
}
