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.FmsTaskpatrol;
import com.yunfeiyun.agmp.fms.domain.reqvo.FmsTaskPatrolListReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.FmsTaskPatrolListResVo;
import com.yunfeiyun.agmp.fms.util.DataAuthUtil;
import com.yunfeiyun.agmp.fms.service.IFmsTaskpatrolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 巡田Controller
 * 
 * @author 杨晓辉
 * @date 2023-05-23
 */
@RestController
@RequestMapping("/fms/taskpatrol")
public class FmsTaskpatrolController extends BaseController
{
    @Autowired
    private IFmsTaskpatrolService fmsTaskpatrolService;

    @Resource
    private DataAuthUtil dataAuthUtil;

    /**
     * 查询巡田列表
     */
    @PreAuthorize("@ss.hasPermi('fms:taskpatrol:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsTaskPatrolListReqVo fmsTaskPatrolListReqVo)
    {

        fmsTaskPatrolListReqVo.setDataFilter(dataAuthUtil.isValidate());
        fmsTaskPatrolListReqVo.setLandIds(dataAuthUtil.landList());
        if(fmsTaskPatrolListReqVo.getDataFilter()&&fmsTaskPatrolListReqVo.getLandIds().isEmpty()){
            return getDataTable(new ArrayList<>());
        }
        startPage();
        List<FmsTaskPatrolListResVo> list = fmsTaskpatrolService.selectFmsTaskpatrolList(fmsTaskPatrolListReqVo);
        return getDataTable(list);
    }

    /**
     * 导出巡田列表
     */
    @PreAuthorize("@ss.hasPermi('fms:taskpatrol:export')")
    @Log(title = "巡田", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsTaskPatrolListReqVo fmsTaskPatrolListReqVo)
    {
        List<FmsTaskPatrolListResVo> list = fmsTaskpatrolService.selectFmsTaskpatrolList(fmsTaskPatrolListReqVo);
        ExcelUtil<FmsTaskPatrolListResVo> util = new ExcelUtil<FmsTaskPatrolListResVo>(FmsTaskPatrolListResVo.class);
        util.exportExcel(response, list, "巡田数据");
    }

    /**
     * 获取巡田详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:taskpatrol:query')")
    @GetMapping(value = "/{taskpatrolId}")
    public AjaxResult getInfo(@PathVariable("taskpatrolId") String taskpatrolId)
    {
        return success(fmsTaskpatrolService.selectFmsTaskpatrolByTaskpatrolId(taskpatrolId));
    }

    /**
     * 新增巡田
     */
    @PreAuthorize("@ss.hasPermi('fms:taskpatrol:add')")
    @Log(title = "巡田", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmsTaskpatrol fmsTaskpatrol)
    {
        return toAjax(fmsTaskpatrolService.insertFmsTaskpatrol(fmsTaskpatrol));
    }

    /**
     * 修改巡田
     */
    @PreAuthorize("@ss.hasPermi('fms:taskpatrol:edit')")
    @Log(title = "巡田", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmsTaskpatrol fmsTaskpatrol)
    {
        return toAjax(fmsTaskpatrolService.updateFmsTaskpatrol(fmsTaskpatrol));
    }

    /**
     * 删除巡田
     */
    @PreAuthorize("@ss.hasPermi('fms:taskpatrol:remove')")
    @Log(title = "巡田", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskpatrolIds}")
    public AjaxResult remove(@PathVariable String[] taskpatrolIds)
    {
        return toAjax(fmsTaskpatrolService.deleteFmsTaskpatrolByTaskpatrolIds(taskpatrolIds));
    }
}
