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.TShiftAnnualPlan;
import com.ruoyi.project.shiftmgr.service.ITShiftAnnualPlanService;
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-08-02
 */
@RestController
@RequestMapping("/shiftmgr/plan")
public class TShiftAnnualPlanController extends BaseController
{
    @Autowired
    private ITShiftAnnualPlanService tShiftAnnualPlanService;

    /**
     * 查询年度计划列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShiftAnnualPlan tShiftAnnualPlan)
    {
        startPage();
        List<TShiftAnnualPlan> list = tShiftAnnualPlanService.selectTShiftAnnualPlanList(tShiftAnnualPlan);
        return getDataTable(list);
    }

    /**
     * 导出年度计划列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:plan:export')")
    @Log(title = "年度计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TShiftAnnualPlan tShiftAnnualPlan)
    {
        List<TShiftAnnualPlan> list = tShiftAnnualPlanService.selectTShiftAnnualPlanList(tShiftAnnualPlan);
        ExcelUtil<TShiftAnnualPlan> util = new ExcelUtil<TShiftAnnualPlan>(TShiftAnnualPlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 获取年度计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tShiftAnnualPlanService.selectTShiftAnnualPlanById(id));
    }

    /**
     * 新增年度计划
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:plan:add')")
    @Log(title = "年度计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShiftAnnualPlan tShiftAnnualPlan)
    {
        tShiftAnnualPlan.setCreaterCode(getUserId());
        tShiftAnnualPlan.setCreatedate(new Date());
        return toAjax(tShiftAnnualPlanService.insertTShiftAnnualPlan(tShiftAnnualPlan));
    }

    /**
     * 修改年度计划
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:plan:edit')")
    @Log(title = "年度计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShiftAnnualPlan tShiftAnnualPlan)
    {
        tShiftAnnualPlan.setUpdaterCode(getUserId());
        tShiftAnnualPlan.setUpdatedate(new Date());
        return toAjax(tShiftAnnualPlanService.updateTShiftAnnualPlan(tShiftAnnualPlan));
    }

    /**
     * 删除年度计划
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:plan:remove')")
    @Log(title = "年度计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tShiftAnnualPlanService.deleteTShiftAnnualPlanByIds(ids));
    }
}
