package com.yunfeiyun.agmp.fms.controller;

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.core.page.TableDataInfo;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.fms.domain.FmsTaskmachine;
import com.yunfeiyun.agmp.fms.service.IFmsTaskmachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 农事任务农具Controller
 * 
 * @author 杨晓辉
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/fms/taskmachine")
public class FmsTaskmachineController extends BaseController
{
    @Autowired
    private IFmsTaskmachineService fmsTaskmachineService;

    /**
     * 查询农事任务农具列表
     */
    @PreAuthorize("@ss.hasPermi('fms:taskmachine:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsTaskmachine fmsTaskmachine)
    {
        startPage();
        List<FmsTaskmachine> list = fmsTaskmachineService.selectFmsTaskmachineList(fmsTaskmachine);
        return getDataTable(list);
    }

    /**
     * 导出农事任务农具列表
     */
    @PreAuthorize("@ss.hasPermi('fms:taskmachine:export')")
    @Log(title = "农事任务农具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsTaskmachine fmsTaskmachine)
    {
        List<FmsTaskmachine> list = fmsTaskmachineService.selectFmsTaskmachineList(fmsTaskmachine);
        ExcelUtil<FmsTaskmachine> util = new ExcelUtil<FmsTaskmachine>(FmsTaskmachine.class);
        util.exportExcel(response, list, "农事任务农具数据");
    }

    /**
     * 获取农事任务农具详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:taskmachine:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("taskmachId") String taskmachId)
    {
        return success(fmsTaskmachineService.selectFmsTaskmachineByTaskmachId(taskmachId));
    }

    /**
     * 新增农事任务农具
     */
    @PreAuthorize("@ss.hasPermi('fms:taskmachine:add')")
    @Log(title = "农事任务农具", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FmsTaskmachine fmsTaskmachine)
    {
        return toAjax(fmsTaskmachineService.insertFmsTaskmachine(fmsTaskmachine));
    }

    /**
     * 修改农事任务农具
     */
    @PreAuthorize("@ss.hasPermi('fms:taskmachine:edit')")
    @Log(title = "农事任务农具", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FmsTaskmachine fmsTaskmachine)
    {
        return toAjax(fmsTaskmachineService.updateFmsTaskmachine(fmsTaskmachine));
    }

    /**
     * 删除农事任务农具
     */
    @PreAuthorize("@ss.hasPermi('fms:taskmachine:delete')")
    @Log(title = "农事任务农具", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete")
    public AjaxResult remove(@RequestParam("taskmachIds") String[] taskmachIds)
    {
        return toAjax(fmsTaskmachineService.deleteFmsTaskmachineByTaskmachIds(taskmachIds));
    }
}
