package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ems.domain.PlantCarbonSink;
import com.ruoyi.ems.service.IPlantCarbonSinkService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 植物碳汇维Controller
 *
 * @author ruoyi
 * @date 2025-11-12
 */
@RestController
@RequestMapping("/plantCarbonSink")
public class PlantCarbonSinkController extends BaseController {
    @Autowired
    private IPlantCarbonSinkService service;

    /**
     * 查询植物碳汇维列表
     */
    @RequiresPermissions("basecfg:casink:list")
    @GetMapping("/list")
    public TableDataInfo list(PlantCarbonSink param) {
        startPage();
        List<PlantCarbonSink> list = service.selectList(param);
        return getDataTable(list);
    }

    /**
     * 查询植物碳汇维列表
     */
    @RequiresPermissions("basecfg:casink:list")
    @GetMapping("/areaCfg")
    public AjaxResult getAreaCfg(@RequestParam(name = "areaCode") String areaCode) {
        List<PlantCarbonSink> list = service.getAreaCfg(areaCode);
        return success(list);
    }

    /**
     * 查询植物碳汇维列表
     */
    @RequiresPermissions("basecfg:casink:list")
    @PutMapping("/areaCfg")
    public AjaxResult mergeAreaCfg(@RequestParam(name = "areaCode") String areaCode,
        @RequestBody List<PlantCarbonSink> list) {
        service.mergeAreaCfg(areaCode, list);
        return success();
    }

    /**
     * 获取植物碳汇维详细信息
     */
    @RequiresPermissions("basecfg:casink:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(service.selectById(id));
    }

    /**
     * 新增植物碳汇维
     */
    @RequiresPermissions("basecfg:casink:add")
    @Log(title = "植物碳汇维", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlantCarbonSink param) {
        return toAjax(service.insert(param));
    }

    /**
     * 修改植物碳汇维
     */
    @RequiresPermissions("basecfg:casink:edit")
    @Log(title = "植物碳汇维", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlantCarbonSink param) {
        return toAjax(service.update(param));
    }

    /**
     * 删除植物碳汇维
     */
    @RequiresPermissions("basecfg:casink:remove")
    @Log(title = "植物碳汇维", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(service.deleteById(id));
    }
}
