package com.yunfeiyun.agmp.fms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yunfeiyun.agmp.fms.domain.MppTask;
import com.yunfeiyun.agmp.fms.domain.reqvo.AddMppTaskReqVo;
import com.yunfeiyun.agmp.fms.service.IMppTaskService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;

/**
 * 农产品生产任务Controller
 * 
 * @author 杨晓辉
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/mpp/task")
public class MppTaskController extends BaseController
{
    @Autowired
    private IMppTaskService mppTaskService;

    /**
     * 查询农产品生产任务列表
     */
    @PreAuthorize("@ss.hasPermi('mpp:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(MppTask mppTask)
    {
        startPage();
        List<MppTask> list = mppTaskService.selectMppTaskList(mppTask);
        return getDataTable(list);
    }

    /**
     * 导出农产品生产任务列表
     */
    @PreAuthorize("@ss.hasPermi('mpp:task:export')")
    @Log(title = "农产品生产任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MppTask mppTask)
    {
        List<MppTask> list = mppTaskService.selectMppTaskList(mppTask);
        ExcelUtil<MppTask> util = new ExcelUtil<MppTask>(MppTask.class);
        util.exportExcel(response, list, "农产品生产任务数据");
    }

    /**
     * 获取农产品生产任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('mpp:task:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("taskId") String taskId)
    {
        return success(mppTaskService.selectMppTaskByTaskId(taskId));
    }

    /**
     * 新增农产品生产任务
     */
    @PreAuthorize("@ss.hasPermi('mpp:task:add')")
    @Log(title = "农产品生产任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AddMppTaskReqVo reqVo)
    {
        return mppTaskService.insertMppTask(reqVo);
    }

    /**
     * 修改农产品生产任务
     */
    @PreAuthorize("@ss.hasPermi('mpp:task:edit')")
    @Log(title = "农产品生产任务", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MppTask mppTask)
    {
        return toAjax(mppTaskService.updateMppTask(mppTask));
    }

    /**
     * 删除农产品生产任务
     */
    @PreAuthorize("@ss.hasPermi('mpp:task:delete')")
    @Log(title = "农产品生产任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete")
    public AjaxResult remove(@RequestParam("taskIds") String[] taskIds)
    {
        return toAjax(mppTaskService.deleteMppTaskByTaskIds(taskIds));
    }
}
