package com.njcn.product.advance.harmonicUp.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.product.advance.harmonicUp.pojo.po.UpHarmonicDetail;
import com.njcn.product.advance.harmonicUp.pojo.vo.UpTableInfo;
import com.njcn.product.advance.harmonicUp.service.HarmonicUpService;
import com.njcn.product.terminal.mysqlTerminal.pojo.param.LargeScreenCountParam;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: cdf
 * @CreateTime: 2025-09-12
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("harmonicUp")
@Api(tags = "谐波放大")
@RequiredArgsConstructor
public class HarmonicUpController extends BaseController {

    private final HarmonicUpService harmonicUpService;

    @GetMapping("analyzePreData")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("谐波放大算法预处理")
    public HttpResult<Object> analyzePreData(@RequestParam("date")String date) {
        String methodDescribe = getMethodDescribe("analyzePreData");
        harmonicUpService.analyzePreData(date);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @PostMapping("getDetail")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取监测点谐波放大详情")
    public HttpResult<Page<UpHarmonicDetail>> getDetail(@RequestBody LargeScreenCountParam param) {
        String methodDescribe = getMethodDescribe("getDetail");
        checkParam(param);
        Page<UpHarmonicDetail> result = harmonicUpService.getDetail(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("getInfoList")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("谐波放大实时数据列表")
    public HttpResult<Page<UpHarmonicDetail>> getInfoList(@RequestBody LargeScreenCountParam param) {
        String methodDescribe = getMethodDescribe("getInfoList");
        Page<UpHarmonicDetail> result = harmonicUpService.getInfoList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @PostMapping("tableInfo")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("谐波放大热力图")
    public HttpResult<UpTableInfo> tableInfo(@RequestBody LargeScreenCountParam param) {
        String methodDescribe = getMethodDescribe("tableInfo");
        UpTableInfo result = harmonicUpService.tableInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }




    private void checkParam(LargeScreenCountParam param){
        if(StrUtil.isBlank(param.getSearchBeginTime())){
            throw new BusinessException(CommonResponseEnum.FAIL,"时间不可为空!");
        }
        if(StrUtil.isBlank(param.getLineId())){
            throw new BusinessException(CommonResponseEnum.FAIL,"监测点id不可为空!");
        }
      /*  if(StrUtil.isBlank(param.getDeptId())){
            throw new BusinessException(CommonResponseEnum.FAIL,"部门id不可为空!");
        }*/
    }
}
