package com.njcn.csharmonic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csharmonic.param.CsHarmonicPlanParam;
import com.njcn.csharmonic.pojo.po.CsHarmonicPlan;
import com.njcn.csharmonic.service.ICsHarmonicPlanService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 稳态指标方案 前端控制器
 * </p>
 *
 * @author xy
 * @since 2026-04-15
 */
@Slf4j
@RestController
@RequestMapping("/csHarmonicPlan")
@Api(tags = "稳态指标方案")
@AllArgsConstructor
public class CsHarmonicPlanController extends BaseController {

    private final ICsHarmonicPlanService csHarmonicPlanService;

    /**
     * 新增稳态指标方案(包含监测点关联)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/save")
    @ApiOperation("新增稳态指标方案")
    public HttpResult<Boolean> save(@RequestBody @Validated CsHarmonicPlanParam param) {
        String methodDescribe = getMethodDescribe("save");
        csHarmonicPlanService.save(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 修改稳态指标方案(包含监测点关联)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改稳态指标方案")
    public HttpResult<Boolean> update(@RequestBody @Validated CsHarmonicPlanParam.UpdateCsHarmonicPlanParam param) {
        String methodDescribe = getMethodDescribe("update");
        csHarmonicPlanService.update(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 删除稳态指标方案(同时删除监测点关联)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/delete")
    @ApiOperation("删除稳态指标方案")
    @ApiImplicitParam(name = "ids", value = "ID集合")
    public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delete");
        csHarmonicPlanService.deleteWithLines(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 根据ID查询稳态指标方案(包含监测点列表)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getById")
    @ApiOperation("根据ID查询稳态指标方案")
    @ApiImplicitParam(name = "id", value = "ID", required = true)
    public HttpResult<CsHarmonicPlan> getById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getById");
        CsHarmonicPlan plan = csHarmonicPlanService.getByIdWithLines(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, plan, methodDescribe);
    }

    /**
     * 分页查询稳态指标方案
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPage")
    @ApiOperation("分页查询稳态指标方案")
    @ApiImplicitParam(name = "param", value = "查询参数", required = true)
    public HttpResult<Page<CsHarmonicPlan>> getPage(@RequestBody CsHarmonicPlanParam.QueryParam param) {
        String methodDescribe = getMethodDescribe("getPage");
        Page<CsHarmonicPlan> page = csHarmonicPlanService.getPage(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    /**
     * 查询所有稳态指标方案
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/list")
    @ApiOperation("查询所有稳态指标方案")
    public HttpResult<List<CsHarmonicPlan>> list() {
        String methodDescribe = getMethodDescribe("list");
        List<CsHarmonicPlan> list = csHarmonicPlanService.listAllOrderBySort();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 根据ID查询稳态指标方案(包含监测点列表)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getByName")
    @ApiOperation("根据名称查询稳态指标方案")
    @ApiImplicitParam(name = "name", value = "name", required = true)
    public HttpResult<List<CsHarmonicPlan>> getByName(@RequestParam("name") String name) {
        String methodDescribe = getMethodDescribe("getByName");
        List<CsHarmonicPlan> plan = csHarmonicPlanService.getByName(name);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, plan, methodDescribe);
    }
}
