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.TShiftDailyInstruction;
import com.ruoyi.project.shiftmgr.service.ITShiftDailyInstructionService;
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-03
 */
@RestController
@RequestMapping("/shiftmgr/instruction")
public class TShiftDailyInstructionController extends BaseController
{
    @Autowired
    private ITShiftDailyInstructionService tShiftDailyInstructionService;

    /**
     * 查询每日生产指令列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:instruction:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShiftDailyInstruction tShiftDailyInstruction)
    {
        startPage();
        List<TShiftDailyInstruction> list = tShiftDailyInstructionService.selectTShiftDailyInstructionList(tShiftDailyInstruction);
        return getDataTable(list);
    }

    /**
     * 导出每日生产指令列表
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:instruction:export')")
    @Log(title = "每日生产指令", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TShiftDailyInstruction tShiftDailyInstruction)
    {
        List<TShiftDailyInstruction> list = tShiftDailyInstructionService.selectTShiftDailyInstructionList(tShiftDailyInstruction);
        ExcelUtil<TShiftDailyInstruction> util = new ExcelUtil<TShiftDailyInstruction>(TShiftDailyInstruction.class);
        return util.exportExcel(list, "instruction");
    }

    /**
     * 获取每日生产指令详细信息
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:instruction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tShiftDailyInstructionService.selectTShiftDailyInstructionById(id));
    }

    /**
     * 新增每日生产指令
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:instruction:add')")
    @Log(title = "每日生产指令", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShiftDailyInstruction tShiftDailyInstruction)
    {
        tShiftDailyInstruction.setCreaterCode(getUserId());
        tShiftDailyInstruction.setCreatedate(new Date());
        return toAjax(tShiftDailyInstructionService.insertTShiftDailyInstruction(tShiftDailyInstruction));
    }

    /**
     * 修改每日生产指令
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:instruction:edit')")
    @Log(title = "每日生产指令", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShiftDailyInstruction tShiftDailyInstruction)
    {
        tShiftDailyInstruction.setUpdaterCode(getUserId());
        tShiftDailyInstruction.setUpdatedate(new Date());
        return toAjax(tShiftDailyInstructionService.updateTShiftDailyInstruction(tShiftDailyInstruction));
    }

    /**
     * 删除每日生产指令
     */
    @PreAuthorize("@ss.hasPermi('shiftmgr:instruction:remove')")
    @Log(title = "每日生产指令", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tShiftDailyInstructionService.deleteTShiftDailyInstructionByIds(ids));
    }
}
