package com.ho.business.controller;

import com.ho.business.service.PcsService;
import com.ho.business.service.StationHomeService;
import com.ho.business.vo.req.MonitorQuery;
import com.ho.business.vo.req.pcs.PcsReqVo;
import com.ho.business.vo.req.pcs.PcsUpdateReqVo;
import com.ho.business.vo.resp.AppRealTimeCurveRespVo;
import com.ho.business.vo.resp.pcs.PcsRunDataSetting;
import com.ho.common.tools.annotation.LogAnnotation;
import com.ho.common.tools.annotation.TokenIgnore;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.constant.RedisKeyConstant;
import com.ho.common.tools.entity.SimpleUser;
import com.ho.common.tools.exception.DataResult;
import com.ho.common.tools.service.RedisService;
import com.ho.common.tools.util.BigDecimalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description pcs展示页面
 * Author yule
 * Date 2023/5/6 16:06
 */
@RestController
@RequestMapping(ContextConstant.BUSINESS + "pcs")
@Api(tags = "pcs展示页面")
public class PcsController {

    @Autowired
    PcsService pcsService;

    @Autowired
    BigDecimalUtil bigDecimalUtil;

    @Autowired
    StationHomeService stationHomeService;

    @Autowired
    RedisService redisService;

    @PostMapping("runDataSetting")
    @ApiOperation(value = "查询运行数据")
    public DataResult<PcsRunDataSetting> getRunDataSetting(@RequestBody PcsReqVo vo, HttpServletRequest request) {
        String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
        SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);

        return DataResult.success();
    }

    @PostMapping("updateRunData")
    @ApiOperation(value = "修改运行数据")
    @LogAnnotation(title = "pcs展示页面", action = "修改运行数据")
    public DataResult updateRunData(@RequestBody List<PcsUpdateReqVo> vo) {
        return DataResult.success();
    }


    @PostMapping("/pcsCurve")
    @ApiOperation(value = "psc曲线")
    public DataResult<List<AppRealTimeCurveRespVo>> pcsCurve(@RequestBody MonitorQuery monitorQuery) {
        List<AppRealTimeCurveRespVo> resList = stationHomeService.getPcsCurve(monitorQuery);

        //返回值的BigDecimal类型保留两位小数
        for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
            bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
            bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
        }
        return DataResult.success(resList);
    }

    @PostMapping("/pvCurve")
    @ApiOperation(value = "mppt曲线")
    public DataResult<List<AppRealTimeCurveRespVo>> pvCurve(@RequestBody MonitorQuery monitorQuery) {
        List<AppRealTimeCurveRespVo> resList = stationHomeService.pvCurve(monitorQuery);

        //返回值的BigDecimal类型保留两位小数
        for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
            bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
            bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
        }
        return DataResult.success(resList);
    }

    @PostMapping("/opticalStorageCurve")
    @ApiOperation(value = "光储逆变器曲线")
    public DataResult<List<AppRealTimeCurveRespVo>> opticalStorageCurve(@RequestBody MonitorQuery monitorQuery) {
        List<AppRealTimeCurveRespVo> resList = stationHomeService.getOpticalStorageCurve(monitorQuery);

        //返回值的BigDecimal类型保留两位小数
        for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
            bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
            bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
        }
        return DataResult.success(resList);
    }
}
