package com.ruoyi.project.shiftmgr.controller;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
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.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.shiftmgr.domain.TShiftAccident;
import com.ruoyi.project.shiftmgr.service.ITShiftAccidentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 事故记录Controller
 *
 * @author ruoyi
 * @date 2022-07-29
 */
@RestController
@RequestMapping("/shiftmgr/accident")
public class TShiftAccidentController extends BaseController
{
    @Autowired
    private ITShiftAccidentService tShiftAccidentService;

    /**
     * 查询事故记录列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:accident:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShiftAccident tShiftAccident)
    {
        startPage();
        List<TShiftAccident> list = tShiftAccidentService.selectTShiftAccidentList(tShiftAccident);
        return getDataTable(list);
    }

    /**
     * 导出事故记录列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:accident:export')")
    @Log(title = "事故记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TShiftAccident tShiftAccident)
    {
        List<TShiftAccident> list = tShiftAccidentService.selectTShiftAccidentList(tShiftAccident);
        ExcelUtil<TShiftAccident> util = new ExcelUtil<TShiftAccident>(TShiftAccident.class);
        return util.exportExcel(list, "accident");
    }

    /**
     * 获取事故记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:accident:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tShiftAccidentService.selectTShiftAccidentById(id));
    }

    /**
     * 新增事故记录
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:accident:add')")
    @Log(title = "事故记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShiftAccident tShiftAccident)
    {
        tShiftAccident.setCreaterCode(getUserId());
        tShiftAccident.setCreatedate(new Date());
        return toAjax(tShiftAccidentService.insertTShiftAccident(tShiftAccident));
    }

    /**
     * 修改事故记录
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:accident:edit')")
    @Log(title = "事故记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShiftAccident tShiftAccident)
    {
        tShiftAccident.setUpdaterCode(getUserId());
        tShiftAccident.setUpdatedate(new Date());
        return toAjax(tShiftAccidentService.updateTShiftAccident(tShiftAccident));
    }

    /**
     * 删除事故记录
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:accident:remove')")
    @Log(title = "事故记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tShiftAccidentService.deleteTShiftAccidentByIds(ids));
    }
}
