package com.njcn.csdevice.controller.equipment;


import com.baomidou.mybatisplus.core.metadata.IPage;
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.param.EnergyBaseParam;
import com.njcn.csdevice.pojo.vo.CsGroupVO;
import com.njcn.csdevice.pojo.vo.DataGroupTemplateVO;
import com.njcn.csdevice.service.ICsGroupService;
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
import com.njcn.csharmonic.param.FittingDataQueryParam;
import com.njcn.csharmonic.param.SensitiveUserTrendDataQueryParam;
import com.njcn.csharmonic.param.TrendDataQueryParam;
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
import com.njcn.system.pojo.po.EleEpdPqd;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 数据分组表 前端控制器
 * </p>
 *
 * @author xuyang
 * @since 2023-06-16
 */
@Slf4j
@RestController
@RequestMapping("/csGroup")
@Api(tags = "指标分组")
@AllArgsConstructor
public class CsGroupController extends BaseController {

    private final ICsGroupService csGroupService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGroup")
    @ApiOperation("查询分组")
    @ApiImplicitParam(name = "dataSet", value = "数据集id", required = true)
    public HttpResult<List<CsGroupVO>> getGroupData(@RequestParam("dataSet") String dataSet){
        String methodDescribe = getMethodDescribe("getGroupData");
        List<CsGroupVO> list = csGroupService.getGroupData(dataSet);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deviceRtData")
    @ApiOperation("装置分组实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "tab选项id", required = true),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", required = true),
            @ApiImplicitParam(name = "lineId", value = "监测点id", required = true),
            @ApiImplicitParam(name = "searchValue", value = "搜索值", required = true),
            @ApiImplicitParam(name = "dataLevel", value = "数据标志", required = true)
    })
    public HttpResult<IPage<DataGroupTemplateVO>> getDeviceRtData(@RequestParam("id") String id, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, @RequestParam(value = "lineId")String lineId, @RequestParam(value = "searchValue") String searchValue, @RequestParam(value = "dataLevel",required = false) String dataLevel){
        String methodDescribe = getMethodDescribe("getDeviceRtData");
        IPage<DataGroupTemplateVO> list = csGroupService.getDeviceRtData(id, pageNum, pageSize,lineId,searchValue,dataLevel);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deviceHistoryData")
    @ApiOperation("装置分组历史数据")
    @ApiImplicitParam(name = "energyBaseParam",required = true)
    public HttpResult<IPage<DataGroupTemplateVO>> getDeviceHistoryData(@RequestBody EnergyBaseParam energyBaseParam){
        String methodDescribe = getMethodDescribe("getDeviceHistoryData");
        IPage<DataGroupTemplateVO> list = csGroupService.getDeviceHistoryData(energyBaseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deviceDataByType")
    @ApiOperation("根据类型查询趋势数据、暂态数据、实时数据")
    @ApiImplicitParam(name = "commonStatisticalQueryParam",required = true)
    public HttpResult<Object> deviceDataByType(@RequestBody CommonStatisticalQueryParam commonStatisticalQueryParam){
        String methodDescribe = getMethodDescribe("deviceDataByType");
        Object obj = csGroupService.deviceDataByType(commonStatisticalQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, obj, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getDeviceTrendData")
    @ApiOperation("查询实时数据中实时趋势")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "devId", value = "设备ID", required = true),
            @ApiImplicitParam(name = "lineId", value = "监测点id", required = true),
            @ApiImplicitParam(name = "groupId", value = "指标分组ID", required = false)
    })
    public HttpResult<List<ThdDataTdVO>> getDeviceTrendData(@RequestParam("devId") String devId, @RequestParam(value = "lineId")String lineId,
                                                            @RequestParam(value = "groupId",required = false)String groupId){
        String methodDescribe = getMethodDescribe("getDeviceTrendData");
        List<ThdDataTdVO> list = csGroupService.getDeviceTrendData(devId,lineId,groupId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getDeviceTrendDataGroup")
    @ApiOperation("查询实时数据中实时趋势中指标分组")
    public HttpResult<List<ThdDataTdVO>> getDeviceTrendDataGroup(){
        String methodDescribe = getMethodDescribe("getDeviceTrendDataGroup");
        List<ThdDataTdVO> list = csGroupService.getDeviceTrendDataGroup();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDeviceHarmonicSpectrumData")
    @ApiOperation("查询实时数据中谐波频谱")
    @ApiImplicitParam(name = "commonStatisticalQueryParam",required = true)
    public HttpResult<List<ThdDataTdVO.ThdDataSpectrumVOData>> getDeviceHarmonicSpectrumData(@RequestBody CommonStatisticalQueryParam commonStatisticalQueryParam){
        String methodDescribe = getMethodDescribe("getDeviceHarmonicSpectrumData");
        List<ThdDataTdVO.ThdDataSpectrumVOData> list = csGroupService.getDeviceHarmonicSpectrumData(commonStatisticalQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getGroupPortableStatistical")
    @ApiOperation("查询稳态指标并按照指标名称分组(A、B、...)")
    public HttpResult<List<List<EleEpdPqd>>> getGroupPortableStatistical(){
        String methodDescribe = getMethodDescribe("getGroupPortableStatistical");
        List<List<EleEpdPqd>> list = csGroupService.getGroupPortableStatistical();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deleteGroup")
    @ApiOperation("删除分组")
    @ApiImplicitParam(name = "groupId", value = "组id", required = true)
    @Deprecated
    public HttpResult<String> deleteGroup(@RequestParam("groupId") String groupId){
        String methodDescribe = getMethodDescribe("deleteGroup");
        csGroupService.deleteGroup(groupId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/trendData")
    @ApiOperation("查询指标趋势图数据")
    @ApiImplicitParam(name = "param",required = true)
    public HttpResult<List<ThdDataVO>> trendData(@RequestBody @Validated TrendDataQueryParam param){
        String methodDescribe = getMethodDescribe("trendData");
        List<ThdDataVO> list = csGroupService.trendData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/fittingData")
    @ApiOperation("查询指标拟合图数据")
    @ApiImplicitParam(name = "param",required = true)
    public HttpResult<List<ThdDataVO>> fittingData(@RequestBody @Validated FittingDataQueryParam param){
        String methodDescribe = getMethodDescribe("fittingData");
        List<ThdDataVO> list = csGroupService.fittingData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/sensitiveUserTrendData")
    @ApiOperation("查询监测对象电网侧和负载侧监测点指标趋势对比数据")
    @ApiImplicitParam(name = "param",required = true)
    public HttpResult<Map<String,List<ThdDataVO>>> sensitiveUserTrendData(@RequestBody @Validated SensitiveUserTrendDataQueryParam param){
        String methodDescribe = getMethodDescribe("sensitiveUserTrendData");
        Map<String,List<ThdDataVO>> result = csGroupService.sensitiveUserTrendData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}

