package com.njcn.csdevice.controller.equipment;


import com.njcn.common.pojo.annotation.OperateInfo;
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.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.vo.LineTargetVO;
import com.njcn.csdevice.service.ICsDataSetService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 数据集表 前端控制器
 * </p>
 *
 * @author xuyang
 * @since 2023-05-31
 */
@Slf4j
@RestController
@RequestMapping("/csDataSet")
@Api(tags = "终端数据集")
@AllArgsConstructor
public class CsDataSetController extends BaseController {

    private final ICsDataSetService csDataSetService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSetByModelId")
    @ApiOperation("根据模板Id获取数据集")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "modelId", value = "模板id", required = true),
        @ApiImplicitParam(name = "clDev", value = "逻辑子设备标识", required = true),
    })
    public HttpResult<List<CsDataSet>> getSetByModelId(@RequestParam("modelId") String modelId, @RequestParam("clDev") Integer clDev){
        String methodDescribe = getMethodDescribe("getSetByModelId");
        List<CsDataSet> list = csDataSetService.findDataSetByModelId(modelId,clDev);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDataSet")
    @ApiOperation("获取数据集")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "modelId", value = "模板id", required = true),
        @ApiImplicitParam(name = "clDev", value = "逻辑子设备标识", required = true)
    })
    public HttpResult<List<LineTargetVO>> getDataSet(@RequestParam("modelId") String modelId,@RequestParam("clDev") Integer clDev){
        String methodDescribe = getMethodDescribe("getDataSet");
        List<LineTargetVO> list = csDataSetService.getDataSet(modelId,clDev);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getModuleDataSet")
    @ApiOperation("获取子模块数据集")
    @ApiImplicitParam(name = "modelId", value = "模板id", required = true)
    public HttpResult<List<CsDataSet>> getModuleDataSet(@RequestParam("modelId") String modelId){
        String methodDescribe = getMethodDescribe("getModuleDataSet");
        List<CsDataSet> list = csDataSetService.getModuleDataSet(modelId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDataSetBySetIds")
    @ApiOperation("根据测点获取数据集")
    @ApiImplicitParam(name = "lineIds", value = "监测点ids", required = true)
    public HttpResult<List<CsDataSet>> getDataSetBySetIds(@RequestBody List<String> lineIds){
        String methodDescribe = getMethodDescribe("getDataSetBySetIds");
        List<CsDataSet> list = csDataSetService.getDataSetBySetIds(lineIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getBaseDataSet")
    @ApiOperation("获取实时数据-基础数据集")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelId", value = "模板id", required = true),
            @ApiImplicitParam(name = "clDev", value = "逻辑子设备标识", required = true)
    })
    public HttpResult<CsDataSet> getBaseDataSet(@RequestParam("modelId") String modelId,@RequestParam("clDev") Integer clDev){
        String methodDescribe = getMethodDescribe("getBaseDataSet");
        CsDataSet dataSet = csDataSetService.getBaseDataSet(modelId,clDev);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataSet, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getHarmonicDataSet")
    @ApiOperation("获取实时数据-谐波数据集")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelId", value = "模板id", required = true),
            @ApiImplicitParam(name = "clDev", value = "逻辑子设备标识", required = true),
            @ApiImplicitParam(name = "target", value = "指标序号", required = true),
    })
    public HttpResult<CsDataSet> getHarmonicDataSet(@RequestParam("modelId") String modelId,@RequestParam("clDev") Integer clDev,@RequestParam("target") Integer target){
        String methodDescribe = getMethodDescribe("getHarmonicDataSet");
        CsDataSet dataSet = csDataSetService.getHarmonicDataSet(modelId,clDev,target);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataSet, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDataSetByIdx")
    @ApiOperation("根据idx获取数据集数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelId", value = "模板id", required = true),
            @ApiImplicitParam(name = "idx", value = "数据集序号", required = true)
    })
    public HttpResult<CsDataSet> getDataSetByIdx(@RequestParam("modelId") String modelId,@RequestParam("idx") Integer idx){
        String methodDescribe = getMethodDescribe("getDataSetByIdx");
        CsDataSet csDataSet = csDataSetService.getDataSetByIdx(modelId,idx);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csDataSet, methodDescribe);
    }

}

