package com.ruoyi.project.production.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.production.domain.TMonthplan;
import com.ruoyi.project.production.service.ITMonthplanService;
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 2020-11-26
 */
@RestController
@RequestMapping("/production/monthplan")
public class TMonthplanController extends BaseController
{
    @Autowired
    private ITMonthplanService tMonthplanService;

    /**
     * 查询生产计划及月报列表
     */
    @PreAuthorize("@ss.hasPermi('production:monthplan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMonthplan tMonthplan)
    {
        startPage();
        List<TMonthplan> list = tMonthplanService.selectTMonthplanList(tMonthplan);
        return getDataTable(list);
    }

    /**
     * 导出生产计划及月报列表
     */
    @PreAuthorize("@ss.hasPermi('production:monthplan:export')")
    @Log(title = "生产计划及月报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMonthplan tMonthplan)
    {
        List<TMonthplan> list = tMonthplanService.selectTMonthplanList(tMonthplan);
        ExcelUtil<TMonthplan> util = new ExcelUtil<TMonthplan>(TMonthplan.class);
        return util.exportExcel(list, "monthplan");
    }

    /**
     * 获取生产计划及月报详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:monthplan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMonthplanService.selectTMonthplanById(id));
    }

    /**
     * 新增生产计划及月报
     */
    @PreAuthorize("@ss.hasPermi('production:monthplan:add')")
    @Log(title = "生产计划及月报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMonthplan tMonthplan)
    {
        tMonthplan.setCreaterCode(getUserId().toString());
        return toAjax(tMonthplanService.insertTMonthplan(tMonthplan));
    }

    /**
     * 修改生产计划及月报
     */
    @PreAuthorize("@ss.hasPermi('production:monthplan:edit')")
    @Log(title = "生产计划及月报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMonthplan tMonthplan)
    {
        tMonthplan.setUpdaterCode(getUserId().toString());
        tMonthplan.setUpdatedate(new Date());
        return toAjax(tMonthplanService.updateTMonthplan(tMonthplan));
    }

    /**
     * 删除生产计划及月报
     */
    @PreAuthorize("@ss.hasPermi('production:monthplan:remove')")
    @Log(title = "生产计划及月报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMonthplanService.deleteTMonthplanByIds(ids));
    }
}