package com.goldenwater.slgc.controller;

import java.util.List;
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.SlgcWaterUnit;
import com.goldenwater.slgc.domain.SlgcWaterUnitRecord;
import com.goldenwater.slgc.service.WaterUnitService;
import com.goldenwater.slgc.service.WaterUnitRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "11. 水利考核管理")
@RestController
@RequestMapping("/slgc/water-unit")
public class WaterUnitController extends BaseController {
    @Autowired
    private WaterUnitService waterUnitService;
    @Autowired
    private WaterUnitRecordService waterUnitRecordService;

    @Operation(summary = "11.01 查询水管单位列表")
    @GetMapping("/list")
    public TableDataInfo list(SlgcWaterUnit slgcWaterUnit) {
        startPage();
        List<SlgcWaterUnit> list = waterUnitService.selectWaterUnitList(slgcWaterUnit);
        return getDataTable(list);
    }

    @Operation(summary = "11.02 获取水管单位详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable String id) {
        return success(waterUnitService.selectWaterUnitById(id));
    }

    @Operation(summary = "11.03 新增水管单位")
    @Log(title = "水利考核管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlgcWaterUnit slgcWaterUnit) {
        return toAjax(waterUnitService.insertWaterUnit(slgcWaterUnit));
    }

    @Operation(summary = "11.04 修改水管单位")
    @Log(title = "水利考核管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlgcWaterUnit slgcWaterUnit) {
        return toAjax(waterUnitService.updateWaterUnit(slgcWaterUnit));
    }

    @Operation(summary = "11.05 删除水管单位")
    @Log(title = "水利考核管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(waterUnitService.deleteWaterUnitByIds(ids));
    }

    @Operation(summary = "11.06 查询审核记录列表")
    @GetMapping("/record/list")
    public TableDataInfo listRecord(String unitId) {
        startPage();
        List<SlgcWaterUnitRecord> list = waterUnitRecordService.selectWaterUnitRecordList(unitId);
        return getDataTable(list);
    }

    @Operation(summary = "11.07 获取审核记录详细信息")
    @GetMapping("/record/{id}")
    public AjaxResult getInfoRecord(@PathVariable String id) {
        return success(waterUnitRecordService.selectWaterUnitRecordById(id));
    }

    @Operation(summary = "11.08 新增审核记录")
    @Log(title = "水利考核管理", businessType = BusinessType.INSERT)
    @PostMapping("/record")
    public AjaxResult addRecord(@RequestBody SlgcWaterUnitRecord record) {
        return toAjax(waterUnitRecordService.insertWaterUnitRecord(record));
    }

    @Operation(summary = "11.09 修改审核记录")
    @Log(title = "水利考核管理", businessType = BusinessType.UPDATE)
    @PutMapping("/record")
    public AjaxResult editRecord(@RequestBody SlgcWaterUnitRecord record) {
        return toAjax(waterUnitRecordService.updateWaterUnitRecord(record));
    }

    @Operation(summary = "11.10 删除审核记录")
    @Log(title = "水利考核管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/record/{ids}")
    public AjaxResult removeRecord(@PathVariable String[] ids) {
        return toAjax(waterUnitRecordService.deleteWaterUnitRecordByIds(ids));
    }
}
