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;

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

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

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

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

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

    @Operation(summary = "02.05 删除水库信息")
    @Log(title = "水库管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{resCodes}")
    public AjaxResult remove(@PathVariable String[] resCodes) {
        return toAjax(reservoirService.deleteAttResBaseByIds(resCodes));
    }

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