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.TShiftImprovement;
import com.ruoyi.project.shiftmgr.service.ITShiftImprovementService;
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-28
 */
@RestController
@RequestMapping("/shiftmgr/improvement")
public class TShiftImprovementController extends BaseController
{
    @Autowired
    private ITShiftImprovementService tShiftImprovementService;

    /**
     * 查询合理化建议记录列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:improvement:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShiftImprovement tShiftImprovement)
    {
        startPage();
        List<TShiftImprovement> list = tShiftImprovementService.selectTShiftImprovementList(tShiftImprovement);
        return getDataTable(list);
    }

    /**
     * 导出合理化建议记录列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:improvement:export')")
    @Log(title = "合理化建议记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TShiftImprovement tShiftImprovement)
    {
        List<TShiftImprovement> list = tShiftImprovementService.selectTShiftImprovementList(tShiftImprovement);
        ExcelUtil<TShiftImprovement> util = new ExcelUtil<TShiftImprovement>(TShiftImprovement.class);
        return util.exportExcel(list, "improvement");
    }

    /**
     * 获取合理化建议记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:improvement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tShiftImprovementService.selectTShiftImprovementById(id));
    }

    /**
     * 新增合理化建议记录
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:improvement:add')")
    @Log(title = "合理化建议记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShiftImprovement tShiftImprovement)
    {
        tShiftImprovement.setCreaterCode(getUserId());
        tShiftImprovement.setCreatedate(new Date());
        return toAjax(tShiftImprovementService.insertTShiftImprovement(tShiftImprovement));
    }

    /**
     * 修改合理化建议记录
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:improvement:edit')")
    @Log(title = "合理化建议记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShiftImprovement tShiftImprovement)
    {
        tShiftImprovement.setUpdaterCode(getUserId());
        tShiftImprovement.setUpdatedate(new Date());
        return toAjax(tShiftImprovementService.updateTShiftImprovement(tShiftImprovement));
    }

    /**
     * 删除合理化建议记录
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:improvement:remove')")
    @Log(title = "合理化建议记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tShiftImprovementService.deleteTShiftImprovementByIds(ids));
    }
}
