package com.goldenwater.slgc.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.slgc.domain.AttResBase;
import com.goldenwater.slgc.service.ReservoirService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 水库信息管理
 *
 * @author goldenwater
 */
@Tag(name = "02. 水库信息管理")
@RestController
@RequestMapping("/slgc/reservoir")
public class ReservoirController extends BaseController {
    @Autowired
    private ReservoirService reservoirService;

    /**
     * 查询水库信息列表
     *
     * @param attResBase 水库信息查询条件
     * @return 分页列表数据
     */
    @Operation(summary = "02.01 查询水库信息列表")
    @GetMapping("/list")
    public TableDataInfo list(AttResBase attResBase) {
        startPage();
        List<AttResBase> list = reservoirService.selectAttResBaseList(attResBase);
        return getDataTable(list);
    }

    /**
     * 获取水库信息详细信息
     *
     * @param resCode 水库编码
     * @return 水库信息
     */
    @Operation(summary = "02.02 获取水库信息详细信息")
    @GetMapping(value = "/{resCode}")
    public AjaxResult getInfo(@PathVariable String resCode) {
        return success(reservoirService.selectAttResBaseById(resCode));
    }

    /**
     * 新增水库信息
     *
     * @param attResBase 水库信息
     * @return 操作结果
     */
    @Operation(summary = "02.03 新增水库信息")
    @Log(title = "水库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttResBase attResBase) {
        return toAjax(reservoirService.insertAttResBase(attResBase));
    }

    /**
     * 修改水库信息
     *
     * @param attResBase 水库信息
     * @return 操作结果
     */
    @Operation(summary = "02.04 修改水库信息")
    @Log(title = "水库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttResBase attResBase) {
        return toAjax(reservoirService.updateAttResBase(attResBase));
    }

    /**
     * 删除水库信息
     *
     * @param resCodes 待删除的水库编码数组
     * @return 操作结果
     */
    @Operation(summary = "02.05 删除水库信息")
    @Log(title = "水库管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{resCodes}")
    public AjaxResult remove(@PathVariable String[] resCodes) {
        return toAjax(reservoirService.deleteAttResBaseByIds(resCodes));
    }

    /**
     * 统计水库规模分布
     *
     * @return 统计结果列表
     */
    @Operation(summary = "02.06 统计水库规模分布")
    @GetMapping("/countType")
    public AjaxResult countType() {
        List<Map<String, Object>> list = reservoirService.countType();
        return success(list);
    }
}
