package com.hdkj.lt.si.controller.measurement;

import com.hdkj.lt.core.bizms.modle.dto.StateEstimation;
import com.hdkj.lt.core.bizms.modle.request.StateEstimationEquipRequest;
import com.hdkj.lt.feign.IMeasurementApiClient;
import com.hdkj.lt.modle.dto.measurement.*;
import com.hdkj.lt.modle.vo.measurement.*;
import com.hdkj.lt.si.service.measurement.IMeasurementApiService;
import com.hdkj.hussar.ApiResponse;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author rj
 * @date 2025/5/24 下午3:25
 * @description
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/measurement")
public class MeasurementApiController implements IMeasurementApiClient {

    private final IMeasurementApiService measurementApiService;

    @Override
    public ApiResponse<MeasurementTokenVO> getAccessToken(MeasurementTokenDTO measurementTokenDTO) {
        return ApiResponse.success(measurementApiService.getAccessToken(measurementTokenDTO));
    }

    @Override
    public ApiResponse<ContainDeviceMeasurementVO> getTelesignalCommonQuery(ContainDeviceMeasurementDTO containDeviceMeasurementDTO) {
        return ApiResponse.success(measurementApiService.getTelesignalCommonQuery(containDeviceMeasurementDTO));
    }

    @Override
    @ApiOperation(value = "获取曲线图信息")
    public ApiResponse<DistributionTransformerVO> getTelemetryCommonQuery(@RequestBody DistributionTransformerDTO distributionTransformerDTO) {
        return ApiResponse.success(measurementApiService.getTelemetryCommonQuery(distributionTransformerDTO));
    }

    @PostMapping("/queryCommonQueryByDay")
    @ApiOperation(value = "按日期获取曲线图信息")
    @Override
    public ApiResponse<RecordsVO> queryCommonQueryByDay(@RequestBody DistributionTransformerDTO distributionTransformerDTO) {
        return ApiResponse.success(measurementApiService.queryCommonQueryByDay(distributionTransformerDTO));
    }

    /**
     * 获取线路与7天最大电流的平均值
     *
     * @param request
     * @return
     */
    @Override
    @PostMapping("/queryPeriodByCommonQuery")
    @ApiOperation(value = "获取线路七天最大电流平均值")
    public ApiResponse<Map<String, BigDecimal>> queryPeriodByCommonQuery(@RequestBody StateEstimationEquipRequest request) {
        return ApiResponse.success(measurementApiService.queryPeriodByCommonQuery(request));
    }

    /**
     * 获取线路开关量测数
     *
     * @param request
     * @return
     */
    @Override
    public ApiResponse<StateEstimation> queryByFeederSaveCommonQuery(@RequestBody StateEstimationEquipRequest request) {
        return null;
    }

    /**
     * 缓存量测数据
     */
    @Override
    @ApiOperation(value = "保存获取曲线图信息")
    @PostMapping("/saveQuery")
    public ApiResponse saveQuery(@RequestBody DistributionReceiveVO request) {
        measurementApiService.SaveCommonQuery(request);
        return ApiResponse.success();
    }

}
