package com.ruoyi.project.ticket.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.ticket.domain.THazardWorkPermit;
import com.ruoyi.project.ticket.service.ITHazardWorkPermitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 危害工作许可证Controller
 *
 * @author ruoyi
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/ticket/hazardworks")
public class THazardWorkPermitController extends BaseController {
    @Autowired
    private ITHazardWorkPermitService tHazardWorkPermitService;

    /**
     * 查询危害工作许可证列表
     */
    @GetMapping("/list")
    public TableDataInfo list(THazardWorkPermit tHazardWorkPermit) {
        startPage();
        List<THazardWorkPermit> list = tHazardWorkPermitService.selectTHazardWorkPermitList(tHazardWorkPermit);
        return getDataTable(list);
    }

    /**
     * 导出危害工作许可证列表
     */
    @Log(title = "危害工作许可证", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(THazardWorkPermit tHazardWorkPermit) {
        List<THazardWorkPermit> list = tHazardWorkPermitService.selectTHazardWorkPermitList(tHazardWorkPermit);
        ExcelUtil<THazardWorkPermit> util = new ExcelUtil<THazardWorkPermit>(THazardWorkPermit.class);
        return util.exportExcel(list, "permit");
    }

    /**
     * 获取危害工作许可证详细信息
     */
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId) {
        return AjaxResult.success(tHazardWorkPermitService.selectTHazardWorkPermitById(aId));
    }

    /**
     * 新增危害工作许可证
     */
    @Log(title = "危害工作许可证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody THazardWorkPermit tHazardWorkPermit) {
        return toAjax(tHazardWorkPermitService.insertTHazardWorkPermit(tHazardWorkPermit));
    }

    /**
     * 修改危害工作许可证
     */
    @Log(title = "危害工作许可证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody THazardWorkPermit tHazardWorkPermit) {
        return toAjax(tHazardWorkPermitService.updateTHazardWorkPermit(tHazardWorkPermit));
    }

    /**
     * 删除危害工作许可证
     */
    @Log(title = "危害工作许可证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{aIds}")
    public AjaxResult remove(@PathVariable Long[] aIds) {
        return toAjax(tHazardWorkPermitService.deleteTHazardWorkPermitByIds(aIds));
    }
}
