package com.boman.web.core.controller;

import com.boman.common.core.utils.poi.ExcelUtil;
import com.boman.common.core.web.controller.BaseController;
import com.boman.common.log.annotation.Log;
import com.boman.common.log.enums.BusinessType;
import com.boman.domain.QianshanGrid;
import com.boman.domain.TableDataInfo;
import com.boman.domain.dto.AjaxResult;
import com.boman.web.core.service.qianshanGrid.IQianshanGridService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * 潜山网格信息Controller
 * 
 * @author ruoyi
 * @date 2022-06-20
 */
@RestController
@RequestMapping("/core/grid")
public class QianshanGridController extends BaseController
{
    @Autowired
    private IQianshanGridService qianshanGridService;

    /**
     * 查询潜山网格信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QianshanGrid qianshanGrid)
    {
        startPage();
        List<QianshanGrid> list = qianshanGridService.selectQianshanGridList(qianshanGrid);
        return getDataTable(list);
    }

    /**
     * 查询潜山网格信息列表
     */
    @GetMapping("/api/list/{pid}")
    public List<QianshanGrid> listApi(@PathVariable("pid") String pid)
    {
        return qianshanGridService.listApi(pid);
    }

    /**
     * 导出潜山网格信息列表
     */
    @SneakyThrows
    @Log(title = "潜山网格信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QianshanGrid qianshanGrid){
        List<QianshanGrid> list = qianshanGridService.selectQianshanGridList(qianshanGrid);
        ExcelUtil<QianshanGrid> util = new ExcelUtil<QianshanGrid>(QianshanGrid.class);
        util.exportExcel(response, list, "潜山网格信息数据");
    }

    /**
     * 获取潜山网格信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qianshanGridService.selectQianshanGridById(id));
    }

    /**
     * 新增潜山网格信息
     */
    @Log(title = "潜山网格信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QianshanGrid qianshanGrid)
    {
        return toAjax(qianshanGridService.insertQianshanGrid(qianshanGrid));
    }

    /**
     * 修改潜山网格信息
     */
    @Log(title = "潜山网格信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QianshanGrid qianshanGrid)
    {
        return toAjax(qianshanGridService.updateQianshanGrid(qianshanGrid));
    }

    /**
     * 删除潜山网格信息
     */
    @Log(title = "潜山网格信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qianshanGridService.deleteQianshanGridByIds(ids));
    }

    /***
     * 通过村ID获取网格信息
     */
    @Log(title = "潜山网格信息", businessType = BusinessType.INSERT)
    @PostMapping("/queryParent")
    public AjaxResult queryZu(@RequestBody QianshanGrid qianshanGrid)
    {
        return qianshanGridService.queryZu(qianshanGrid);
    }
}
