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.AttDikeBase;
import com.goldenwater.slgc.service.DikeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;

@Tag(name = "01. 堤防信息管理")
@RestController
@RequestMapping("/slgc/dike")
public class DikeController extends BaseController {
    @Autowired
    private DikeService dikeService;

    @Operation(summary = "01.01 查询堤防信息列表")
    @GetMapping("/list")
    public TableDataInfo list(AttDikeBase attDikeBase) {
        startPage();
        List<AttDikeBase> list = dikeService.selectAttDikeBaseList(attDikeBase);
        return getDataTable(list);
    }

    @Operation(summary = "01.02 获取堤防信息详细信息")
    @GetMapping(value = "/{dikeCode}")
    public AjaxResult getInfo(@PathVariable String dikeCode) {
        return success(dikeService.selectAttDikeBaseById(dikeCode));
    }

    @Operation(summary = "01.03 新增堤防信息")
    @Log(title = "堤防管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttDikeBase attDikeBase) {
        return toAjax(dikeService.insertAttDikeBase(attDikeBase));
    }

    @Operation(summary = "01.04 修改堤防信息")
    @Log(title = "堤防管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttDikeBase attDikeBase) {
        return toAjax(dikeService.updateAttDikeBase(attDikeBase));
    }

    @Operation(summary = "01.05 删除堤防信息")
    @Log(title = "堤防管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dikeCodes}")
    public AjaxResult remove(@PathVariable String[] dikeCodes) {
        return toAjax(dikeService.deleteAttDikeBaseByIds(dikeCodes));
    }

    @Operation(summary = "01.6 统计堤防类型分布")
    @GetMapping("/countType")
    public AjaxResult countType() {
        List<Map<String, Object>> list = dikeService.countType();
        return success(list);
    }
}
