package com.ho.business.controller;

import com.ho.business.service.BatteryStackService;
import com.ho.business.vo.req.batteryStack.CurveReqVo;
import com.ho.business.vo.resp.batteryStack.CurveRespVo;
import com.ho.business.vo.resp.point.PointCurveResp;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import com.ho.common.tools.util.BigDecimalUtil;
import com.ho.common.tools.vo.req.StationHomeRespVo;
import com.ho.common.tools.vo.req.StatisticsCurve;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.util.List;

/**
 * @author gyan
 * @desc: 电池堆控制层
 * @DateTime: 2023/5/8 10:58
 */
@RestController
@RequestMapping(ContextConstant.BUSINESS + "batteryStack")
@Api(tags = "电池堆")
@Slf4j
public class BatteryStackController {

    @Autowired
    BigDecimalUtil bigDecimalUtil;

    @Autowired
    BatteryStackService batteryStackService;


    //温湿度  （抽样）
    @PostMapping("/universalCurve")
    @ApiOperation(value = "通用曲线")
    public DataResult<List<CurveRespVo>> universalCurve(@RequestBody CurveReqVo vo) {
        List<CurveRespVo> resList = batteryStackService.getUniversalCurve(vo);
        //返回值的BigDecimal类型保留两位小数
        for (CurveRespVo curveRespVo : resList) {
            List<StationHomeRespVo> list = curveRespVo.getStaticCurveList();
            for (StationHomeRespVo stationHomeRespVo : list) {
                bigDecimalUtil.keepTwoDecimalPlaces(stationHomeRespVo);
                //bigDecimalUtil.ifIsNUll(stationHomeRespVo);
            }
        }
        return DataResult.success(resList);
    }

    @PostMapping("/socCurve")
    @ApiOperation(value = "soc曲线")
    public DataResult<List<CurveRespVo>> socCurve(@RequestBody CurveReqVo vo) {
        List<CurveRespVo> resList = batteryStackService.getSocCurve(vo);
        //返回值的BigDecimal类型保留两位小数
        for (CurveRespVo curveRespVo : resList) {
            List<StationHomeRespVo> list = curveRespVo.getStaticCurveList();
            for (StationHomeRespVo stationHomeRespVo : list) {
                bigDecimalUtil.keepTwoDecimalPlaces(stationHomeRespVo);
                //bigDecimalUtil.ifIsNUll(stationHomeRespVo);
            }
        }
        return DataResult.success(resList);
    }

    //历史曲线
    @PostMapping("/stackHisData")
    @ApiOperation(value = "历史数据")
    public DataResult<List<PointCurveResp>> stackHisData(@RequestBody CurveReqVo vo) {
        List<PointCurveResp> resList = batteryStackService.getStackHisData(vo);
        //返回值的BigDecimal类型保留两位小数
        for (PointCurveResp pointCurveResp : resList) {
            List<StatisticsCurve> staticCurveList = pointCurveResp.getStaticCurveList();
            for (StatisticsCurve statisticsRespVO : staticCurveList) {
                bigDecimalUtil.keepTwoDecimalPlaces(statisticsRespVO);
                //bigDecimalUtil.ifIsNUll(statisticsRespVO);
            }
        }
        return DataResult.success(resList);
    }
}
