package com.njcn.csharmonic.controller;


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.CsHarmonicPlanLineParam;
import com.njcn.csharmonic.pojo.po.CsHarmonicPlanLine;
import com.njcn.csharmonic.service.ICsHarmonicPlanLineService;
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("/csHarmonicPlanLine")
@Api(tags = "稳态指标方案与测点关系")
@AllArgsConstructor
public class CsHarmonicPlanLineController extends BaseController {

    private final ICsHarmonicPlanLineService csHarmonicPlanLineService;

    /**
     * 根据方案ID查询关联的监测点
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getByPlanId")
    @ApiOperation("根据方案ID查询关联的监测点")
    @ApiImplicitParam(name = "id", value = "方案ID", required = true)
    public HttpResult<List<CsHarmonicPlanLine>> getByPlanId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getByPlanId");
        List<CsHarmonicPlanLine> list = csHarmonicPlanLineService.getByPlanId(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 新增方案与监测点关联
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/savePlanLines")
    @ApiOperation("新增方案与监测点关联")
    public HttpResult<Boolean> savePlanLines(@RequestBody @Validated CsHarmonicPlanLineParam param) {
        String methodDescribe = getMethodDescribe("savePlanLines");
        csHarmonicPlanLineService.savePlanLines(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 根据监测点ID集合删除关联
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/deleteByLineIds")
    @ApiOperation("根据监测点ID集合删除关联")
    @ApiImplicitParam(name = "lineIds", value = "监测点ID集合")
    public HttpResult<Boolean> deleteByLineIds(@RequestBody List<String> lineIds) {
        String methodDescribe = getMethodDescribe("deleteByLineIds");
        csHarmonicPlanLineService.deleteByLineIds(lineIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 根据监测点ID查询方案ID
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getPlanIdByLineId")
    @ApiOperation("根据监测点ID查询方案ID")
    @ApiImplicitParam(name = "lineId", value = "监测点ID", required = true)
    public HttpResult<String> getPlanIdByLineId(@RequestParam("lineId") String lineId) {
        String methodDescribe = getMethodDescribe("getPlanIdByLineId");
        String planId = csHarmonicPlanLineService.getPlanIdByLineId(lineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, planId, methodDescribe);
    }
}
