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.TDailyProductionReport;
import com.ruoyi.project.production.service.ITDailyProductionReportService;
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-23
 */
@RestController
@RequestMapping("/production/report")
public class TDailyProductionReportController extends BaseController
{
    @Autowired
    private ITDailyProductionReportService tDailyProductionReportService;

    /**
     * 查询每日生产报告列表
     */
    @PreAuthorize("@ss.hasPermi('production:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDailyProductionReport tDailyProductionReport)
    {
        startPage();
        List<TDailyProductionReport> list = tDailyProductionReportService.selectTDailyProductionReportList(tDailyProductionReport);
        return getDataTable(list);
    }

    /**
     * 导出每日生产报告列表
     */
    @PreAuthorize("@ss.hasPermi('production:report:export')")
    @Log(title = "每日生产报告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDailyProductionReport tDailyProductionReport)
    {
        List<TDailyProductionReport> list = tDailyProductionReportService.selectTDailyProductionReportList(tDailyProductionReport);
        ExcelUtil<TDailyProductionReport> util = new ExcelUtil<TDailyProductionReport>(TDailyProductionReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 获取每日生产报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDailyProductionReportService.selectTDailyProductionReportById(id));
    }

    /**
     * 按日期获取每日生产报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:report:query')")
    @GetMapping(value = "/getInfoByReportDate/{reportDate}")
    public AjaxResult getInfoByReportDate(@PathVariable("reportDate") Date reportDate)
    {
        return AjaxResult.success(tDailyProductionReportService.selectTDailyProductionReportByReportDate(reportDate));
    }

    /**
     * 新增每日生产报告
     */
    @PreAuthorize("@ss.hasPermi('production:report:add')")
    @Log(title = "每日生产报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDailyProductionReport tDailyProductionReport)
    {
        return toAjax(tDailyProductionReportService.insertTDailyProductionReport(tDailyProductionReport));
    }

    /**
     * 修改每日生产报告
     */
    @PreAuthorize("@ss.hasPermi('production:report:edit')")
    @Log(title = "每日生产报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDailyProductionReport tDailyProductionReport)
    {
        return toAjax(tDailyProductionReportService.updateTDailyProductionReport(tDailyProductionReport));
    }

    /**
     * 删除每日生产报告
     */
    @PreAuthorize("@ss.hasPermi('production:report:remove')")
    @Log(title = "每日生产报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDailyProductionReportService.deleteTDailyProductionReportByIds(ids));
    }
}
