package com.cpms.project.safety.controller;

import com.cpms.common.annotation.Log;
import com.cpms.common.core.controller.BaseController;
import com.cpms.common.core.domain.AjaxResult;
import com.cpms.common.core.page.TableDataInfo;
import com.cpms.common.enums.BusinessType;
import com.cpms.common.utils.poi.ExcelUtil;
import com.cpms.project.safety.domain.TSafetyEyeWasher;
import com.cpms.project.safety.service.ITSafetyEyeWasherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 洗眼器Controller
 *
 * @author ruoyi
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/safety/washer")
public class TSafetyEyeWasherController extends BaseController {
    @Autowired
    private ITSafetyEyeWasherService tSafetyEyeWasherService;

    /**
     * 查询洗眼器列表
     */
    @PreAuthorize("@ss.hasPermi('safety:washer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSafetyEyeWasher tSafetyEyeWasher) {
        startPage();
        List<TSafetyEyeWasher> list = tSafetyEyeWasherService.selectTSafetyEyeWasherList(tSafetyEyeWasher);
        return getDataTable(list);
    }

    /**
     * 导出洗眼器列表
     */
    @PreAuthorize("@ss.hasPermi('safety:washer:export')")
    @Log(title = "洗眼器", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSafetyEyeWasher tSafetyEyeWasher) {
        List<TSafetyEyeWasher> list = tSafetyEyeWasherService.selectTSafetyEyeWasherList(tSafetyEyeWasher);
        ExcelUtil<TSafetyEyeWasher> util = new ExcelUtil<TSafetyEyeWasher>(TSafetyEyeWasher.class);
        return util.exportExcel(list, "eyeWasher");
    }

    /**
     * 获取洗眼器详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:washer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tSafetyEyeWasherService.selectTSafetyEyeWasherById(id));
    }

    /**
     * 新增洗眼器
     */
    @PreAuthorize("@ss.hasPermi('safety:washer:add')")
    @Log(title = "洗眼器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSafetyEyeWasher tSafetyEyeWasher) {
        tSafetyEyeWasher.setCreatedate(new Date());
        tSafetyEyeWasher.setCreaterCode(getUserId().toString());
        return toAjax(tSafetyEyeWasherService.insertTSafetyEyeWasher(tSafetyEyeWasher));
    }

    /**
     * 修改洗眼器
     */
    @PreAuthorize("@ss.hasPermi('safety:washer:edit')")
    @Log(title = "洗眼器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSafetyEyeWasher tSafetyEyeWasher) {
        tSafetyEyeWasher.setUpdatedate(new Date());
        tSafetyEyeWasher.setUpdaterCode(getUserId().toString());
        return toAjax(tSafetyEyeWasherService.updateTSafetyEyeWasher(tSafetyEyeWasher));
    }

    /**
     * 删除洗眼器
     */
    @PreAuthorize("@ss.hasPermi('safety:washer:remove')")
    @Log(title = "洗眼器", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tSafetyEyeWasherService.deleteTSafetyEyeWasherByIds(ids));
    }
}
