package com.ruoyi.web.controller.plotmanage;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.plotmanage.domain.AdPlot;
import com.ruoyi.web.plotmanage.service.IAdPlotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 cyx
 * @date 2022-11-23
 */
@Api("小区信息管理")
@RestController
@RequestMapping("/plotmanage/plot")
public class AdPlotController extends BaseController
{
    @Autowired
    private IAdPlotService adPlotService;

    /**
     * 查询小区管理列表
     */
    @ApiOperation("获取小区列表")
    @PreAuthorize("@ss.hasPermi('plotmanage:plot:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdPlot adPlot)
    {
        startPage();
        List<AdPlot> list = adPlotService.selectAdPlotList(adPlot);
        return getDataTable(list);
    }

    /**
     * 导出小区管理列表
     */
    @ApiOperation("导出小区管理列表")
    @PreAuthorize("@ss.hasPermi('plotmanage:plot:export')")
    @Log(title = "小区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdPlot adPlot)
    {
        List<AdPlot> list = adPlotService.selectAdPlotList(adPlot);
        ExcelUtil<AdPlot> util = new ExcelUtil<AdPlot>(AdPlot.class);
        util.exportExcel(response, list, "小区管理数据");
    }

    /**
     * 获取小区管理详细信息
     */
    @ApiOperation("获取小区管理详细信息")
    @PreAuthorize("@ss.hasPermi('plotmanage:plot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(adPlotService.selectAdPlotById(id));
    }

    /**
     * 新增小区管理
     */
    @ApiOperation("新增小区管理")
    @PreAuthorize("@ss.hasPermi('plotmanage:plot:add')")
    @Log(title = "小区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdPlot adPlot)
    {
        return toAjax(adPlotService.insertAdPlot(adPlot));
    }

    /**
     * 修改小区管理
     */
    @ApiOperation("修改小区管理")
    @PreAuthorize("@ss.hasPermi('plotmanage:plot:edit')")
    @Log(title = "小区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdPlot adPlot)
    {
        return toAjax(adPlotService.updateAdPlot(adPlot));
    }

    /**
     * 删除小区管理
     */
    @ApiOperation("删除小区")
    @PreAuthorize("@ss.hasPermi('plotmanage:plot:remove')")
    @Log(title = "小区管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(adPlotService.deleteAdPlotByIds(ids));
    }
}
