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

@Tag(name = "09. 公里桩信息管理")
@RestController
@RequestMapping("/slgc/km")
public class KmController extends BaseController {
    @Autowired
    private KmService kmService;

    @Operation(summary = "09.01 查询公里桩信息列表")
    @GetMapping("/list")
    public TableDataInfo list(AttKmBase attKmBase) {
        startPage();
        List<AttKmBase> list = kmService.selectAttKmBaseList(attKmBase);
        return getDataTable(list);
    }

    @Operation(summary = "09.02 获取公里桩信息详细信息")
    @GetMapping(value = "/{kmCode}")
    public AjaxResult getInfo(@PathVariable String kmCode) {
        return success(kmService.selectAttKmBaseById(kmCode));
    }

    @Operation(summary = "09.03 新增公里桩信息")
    @Log(title = "公里桩管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttKmBase attKmBase) {
        return toAjax(kmService.insertAttKmBase(attKmBase));
    }

    @Operation(summary = "09.04 修改公里桩信息")
    @Log(title = "公里桩管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttKmBase attKmBase) {
        return toAjax(kmService.updateAttKmBase(attKmBase));
    }

    @Operation(summary = "09.05 删除公里桩信息")
    @Log(title = "公里桩管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{kmCodes}")
    public AjaxResult remove(@PathVariable String[] kmCodes) {
        return toAjax(kmService.deleteAttKmBaseByIds(kmCodes));
    }
}
