package com.fastbee.data.controller.userRecharge;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.rechargecard.domain.NgIrrigationArea;
import com.fastbee.rechargecard.service.INgIrrigationAreaService;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.common.core.page.TableDataInfo;

/**
 * 灌区Controller
 *
 * @author kerwincui
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/rechargecard/area")
@Api(tags = "灌区")
public class NgIrrigationAreaController extends BaseController
{
    @Autowired
    private INgIrrigationAreaService ngIrrigationAreaService;

/**
 * 查询灌区列表
 */
@PreAuthorize("@ss.hasPermi('rechargecard:area:list')")
@GetMapping("/list")
@ApiOperation("查询灌区列表")
    public TableDataInfo list(NgIrrigationArea ngIrrigationArea)
    {
        startPage();
        List<NgIrrigationArea> list = ngIrrigationAreaService.selectNgIrrigationAreaList(ngIrrigationArea);
        return getDataTable(list);
    }

    /**
     * 导出灌区列表
     */
    @ApiOperation("导出灌区列表")
    @PreAuthorize("@ss.hasPermi('rechargecard:area:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, NgIrrigationArea ngIrrigationArea)
    {
        List<NgIrrigationArea> list = ngIrrigationAreaService.selectNgIrrigationAreaList(ngIrrigationArea);
        ExcelUtil<NgIrrigationArea> util = new ExcelUtil<NgIrrigationArea>(NgIrrigationArea.class);
        util.exportExcel(response, list, "灌区数据");
    }

    /**
     * 获取灌区详细信息
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:area:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取灌区详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ngIrrigationAreaService.selectNgIrrigationAreaById(id));
    }

    /**
     * 新增灌区
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:area:add')")
    @PostMapping
    @ApiOperation("新增灌区")
    public AjaxResult add(@RequestBody NgIrrigationArea ngIrrigationArea)
    {
        return toAjax(ngIrrigationAreaService.insertNgIrrigationArea(ngIrrigationArea));
    }

    /**
     * 修改灌区
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:area:edit')")
    @PutMapping
    @ApiOperation("修改灌区")
    public AjaxResult edit(@RequestBody NgIrrigationArea ngIrrigationArea)
    {
        return toAjax(ngIrrigationAreaService.updateNgIrrigationArea(ngIrrigationArea));
    }

    /**
     * 删除灌区
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:area:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除灌区")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ngIrrigationAreaService.deleteNgIrrigationAreaByIds(ids));
    }
}
