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.AttPustBase;
import com.goldenwater.slgc.service.PustService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "03. 水闸信息管理")
@RestController
@RequestMapping("/slgc/pust")
public class PustController extends BaseController {
    @Autowired
    private PustService pustService;

    @Operation(summary = "03.01 查询水闸信息列表")
    @GetMapping("/list")
    public TableDataInfo list(AttPustBase attPustBase) {
        startPage();
        List<AttPustBase> list = pustService.selectAttPustBaseList(attPustBase);
        return getDataTable(list);
    }

    @Operation(summary = "03.02 获取水闸信息详细信息")
    @GetMapping(value = "/{pustCode}")
    public AjaxResult getInfo(@PathVariable String pustCode) {
        return success(pustService.selectAttPustBaseById(pustCode));
    }

    @Operation(summary = "03.03 新增水闸信息")
    @Log(title = "水闸管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttPustBase attPustBase) {
        return toAjax(pustService.insertAttPustBase(attPustBase));
    }

    @Operation(summary = "03.04 修改水闸信息")
    @Log(title = "水闸管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttPustBase attPustBase) {
        return toAjax(pustService.updateAttPustBase(attPustBase));
    }

    @Operation(summary = "03.05 删除水闸信息")
    @Log(title = "水闸管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pustCodes}")
    public AjaxResult remove(@PathVariable String[] pustCodes) {
        return toAjax(pustService.deleteAttPustBaseByIds(pustCodes));
    }

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