package com.xhpc.evcs.notification;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xhpc.common.api.ChargingStationService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.dto.XhpcRateTimeDto;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.evcs.domain.AuthSecretToken;
import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository;
import com.xhpc.evcs.utils.JSONUtil;
import com.xhpc.order.domain.XhpcHistoryOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;

/**
 * 推送订单信息
 * @Author HongYun on 2021/11/1
 */
@Component
@RestController
@RequestMapping("/api/chargeOrderInfo")
public class NotificationChargeOrderInfoTask extends CoreDispatcher {

    @Autowired
    private XhpcHistoryOrderRepository xhpcHistoryOrderRepository;
    @Autowired
    private AuthSecretTokenRepository authSecretTokenRepository;
    @Autowired
    private ChargingStationService chargingStationService;
    @Autowired
    private RedisService redisService;
    private final Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfoTask.class);


    //都开放
    @GetMapping("/infoTask")
    //@Scheduled(cron = "0/30 * * * * ? ")
    @Scheduled(fixedRate = 1000 * 30)
    public void run() throws JsonProcessingException {
        List<AuthSecretToken> authSecretTokenList = authSecretTokenRepository.findBySecretTokenType(SECRET_TOKEN_TYPE_OUT);

        String formatYu = cn.hutool.core.date.DateUtil.format(DateUtil.offsetDay(new Date(),-90), "yyyy-MM-dd HH:mm:ss");

        List<XhpcHistoryOrder> xhpcHistoryOrderList =xhpcHistoryOrderRepository.findByCreateTimeGreaterThanAndConfirmResultAndSource(DateUtil.parse(formatYu),-1, 1);
        for (XhpcHistoryOrder horder : xhpcHistoryOrderList) {
            if("765367656".equals(horder.getInternetSerialNumber().substring(0, 9)) || "MA6CC2LK7".equals(horder.getInternetSerialNumber().substring(0, 9))){
                //老监管平台不推送，新监管平台单独推送
                continue;
            }
            for (AuthSecretToken authSecretToken : authSecretTokenList) {
                String operatorId3rdptyEvcs = horder.getOperatorId3rdptyEvcs();
                if (operatorId3rdptyEvcs == null) {
                    if (horder.getInternetSerialNumber() != null) {
                        operatorId3rdptyEvcs = horder.getInternetSerialNumber().substring(0, 9);
                        horder.setOperatorId3rdptyEvcs(operatorId3rdptyEvcs);
                        xhpcHistoryOrderRepository.save(horder); // mending
                    }
                }
                if (authSecretToken.getOperatorId3irdpty().equals(operatorId3rdptyEvcs)) {
                    //下面方法跨天会改变开始时间，先提出
                    ChargeOrderInfo chargeOrderInfo = new ChargeOrderInfo(horder);
                    if(new BigDecimal(0).compareTo(horder.getTotalPrice())<0){
                        XhpcHistoryOrder horder1  =new XhpcHistoryOrder();
                        BeanUtils.copyProperties(horder,horder1);
                        chargeOrderInfo = calculateEmYu(horder1,chargeOrderInfo);

                        if(chargeOrderInfo==null){
                            continue;
                        }

                    }

                    final ChargeOrderInfoResponse pushResp = notify(chargeOrderInfo, authSecretToken);
                    if (pushResp != null) {
                        horder.setConfirmResult(pushResp.getConfirmResult());
                        logger.debug("3rd part order {} push result: {}", horder.getSerialNumber(),pushResp.getConfirmResult());

                        if(pushResp.getConfirmResult()!=0){
                            //解析原因
                            horder.setRemark(pushResp.getConfirmResultMessage());
                            if(pushResp.getConfirmResult()==1 && "充电账单争议：运营商已推送过账单再次收到的账单无效".equals(pushResp.getConfirmResultMessage())){
                                horder.setConfirmResult(0);
                            }
                        }
                        logger.info("==============推送返回值================="+pushResp.getConfirmResult()+"=========="+horder.getSerialNumber());
                        xhpcHistoryOrderRepository.save(horder);
                        REDIS.setCacheMapValue("pushOrder:".concat(horder.getSerialNumber()), "horderpushed", true);
                    } else {
                        logger.info("==============推送开始=====3333=================="+horder.getSerialNumber()+"========3333==========="+horder.getInternetSerialNumber());
                        logger.error("3dp[{}] order[{}/{}] push fail", operatorId3rdptyEvcs,horder.getSerialNumber(), horder.getInternetSerialNumber());
                    }
                }
            }
        }
    }


    public  ChargeOrderInfo calculateEmYu(XhpcHistoryOrder horder,ChargeOrderInfo chargeOrderInfo) {
      try {
          String startTime = chargeOrderInfo.getStartTime();

          String endTime = chargeOrderInfo.getEndTime();

          DateTime parse = cn.hutool.core.date.DateUtil.parse(startTime, "yyyy-MM-dd");
          DateTime parse1 = cn.hutool.core.date.DateUtil.parse(endTime, "yyyy-MM-dd");
          long betweenDay = cn.hutool.core.date.DateUtil.between(parse, parse1, DateUnit.DAY);
          System.out.println("======1111====SerialNumber========222======" + horder.getSerialNumber());
          Map<String, Object> cacheMap = REDIS.getCacheMap("order:" + horder.getSerialNumber());
          CacheOrderData cacheOrderData = (CacheOrderData) cacheMap.get("orderData");
          boolean t1NonZero = new BigDecimal(cacheOrderData.getT1PowerQuantity()).compareTo(BigDecimal.ZERO) != 0;
          boolean t2NonZero = new BigDecimal(cacheOrderData.getT2PowerQuantity()).compareTo(BigDecimal.ZERO) != 0;
          boolean t3NonZero = new BigDecimal(cacheOrderData.getT3PowerQuantity()).compareTo(BigDecimal.ZERO) != 0;
          boolean t4NonZero = new BigDecimal(cacheOrderData.getT4PowerQuantity()).compareTo(BigDecimal.ZERO) != 0;
          // 跨天还是在同一个时间段内
          BigDecimal decimalYu = new BigDecimal((horder.getEndTime().getTime() - horder.getStartTime().getTime())).divide(new BigDecimal(60000), 4, BigDecimal.ROUND_HALF_UP);
          BigDecimal divideYu = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(new BigDecimal(10000), 4, BigDecimal.ROUND_HALF_UP);
          //每分钟多少度电
          BigDecimal quantity = new BigDecimal(0);
          if (decimalYu.compareTo(new BigDecimal(0)) != 0) {
              quantity = divideYu.divide(decimalYu, 4, BigDecimal.ROUND_HALF_UP);
          }
          if ((t1NonZero ? 1 : 0) + (t2NonZero ? 1 : 0) + (t3NonZero ? 1 : 0) + (t4NonZero ? 1 : 0) == 1) {
              if (betweenDay > 0) {
                  R r = chargingStationService.getXhpcRateTimeOrder(horder.getRateModelId(), cn.hutool.core.date.DateUtil.formatTime(horder.getStartTime()), cn.hutool.core.date.DateUtil.formatTime(horder.getEndTime()), horder.getSerialNumber());
                  if (r.getCode() == 200) {
                      Stack<ChargeDetails> stack = new Stack<>();
                      Map<String, Object> cacheMapYu = REDIS.getCacheMap("Yu" + horder.getSerialNumber());
                      List<XhpcRateTimeDto> xhpcRateTimes = (List<XhpcRateTimeDto>) cacheMapYu.get(horder.getSerialNumber());

                      BigDecimal powerFee = new BigDecimal(0);
                      BigDecimal serviceFee = new BigDecimal(0);
                      for (XhpcRateTimeDto xpcRateTime : xhpcRateTimes) {
                          powerFee = xpcRateTime.getPowerFee();
                          serviceFee = xpcRateTime.getServiceFee();
                      }
                      Date endTime1 = horder.getEndTime();
                      horder.setEndTime(cn.hutool.core.date.DateUtil.parse(startTime.substring(0, 10) + " 23:59:59"));
                      long betweenDay4 = getDiffMinutes(horder.getStartTime(), horder.getEndTime());
                      //获得电量
                      BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                      ChargeDetails chargeDetails = new ChargeDetails();

                      chargeDetails.setDetailStartTime(cn.hutool.core.date.DateUtil.format(horder.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
                      chargeDetails.setDetailEndTime(cn.hutool.core.date.DateUtil.format(horder.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
                      chargeDetails.setElecPrice(powerFee.doubleValue());
                      chargeDetails.setSevicePrice(serviceFee.doubleValue());
                      BigDecimal multiply1 = multiply.multiply(powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
                      BigDecimal multiply2 = multiply.multiply(serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP);
                      chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                      chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                      chargeDetails.setDetailPower(multiply.doubleValue());
                      stack.push(chargeDetails);
                      Stack<ChargeDetails> stack1 = new Stack<>();
                      //剩余电量
                      BigDecimal bigDecimal1 = divideYu.subtract(multiply);
                      horder.setStartTime(cn.hutool.core.date.DateUtil.parse(endTime.substring(0, 10) + " 00:00:00"));
                      ChargeDetails chargeDetails1 = new ChargeDetails();
                      chargeDetails1.setDetailStartTime(cn.hutool.core.date.DateUtil.format(horder.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
                      chargeDetails1.setDetailEndTime(cn.hutool.core.date.DateUtil.format(endTime1, "yyyy-MM-dd HH:mm:ss"));
                      chargeDetails1.setElecPrice(powerFee.doubleValue());
                      chargeDetails1.setSevicePrice(serviceFee.doubleValue());
                      BigDecimal multiply3 = bigDecimal1.multiply(powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
                      BigDecimal multiply4 = bigDecimal1.multiply(serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP);
                      chargeDetails1.setDetailElecMoney(multiply3.doubleValue());
                      chargeDetails1.setDetailSeviceMoney(multiply4.doubleValue());
                      chargeDetails1.setDetailPower(bigDecimal1.doubleValue());
                      stack1.push(chargeDetails1);

                      Stack<ChargeDetails> mergedStack = new Stack<>();
                      // 先添加stack2的所有元素（保持原顺序）
                      for (ChargeDetails detail : stack) {
                          mergedStack.push(detail);
                      }

                      // 再添加stack1的所有元素（保持原顺序）
                      for (ChargeDetails detail : stack1) {
                          mergedStack.push(detail);
                      }
                      ChargeDetails[] cda = new ChargeDetails[mergedStack.size()];
                      chargeOrderInfo.setChargeDetails(mergedStack.toArray(cda));
                  }
              } else {
                  Stack<ChargeDetails> stack = extracted(horder, chargeOrderInfo);
                  ChargeDetails[] cda = new ChargeDetails[stack.size()];
                  chargeOrderInfo.setChargeDetails(stack.toArray(cda));
              }
          } else if (betweenDay == 0) {
              //没有跨天
              Stack<ChargeDetails> stack = extracted(horder, chargeOrderInfo);

              ChargeDetails[] cda = new ChargeDetails[stack.size()];
              chargeOrderInfo.setChargeDetails(stack.toArray(cda));
          } else {

//              Date endTime1 = horder.getEndTime();
//              horder.setEndTime(cn.hutool.core.date.DateUtil.parse(startTime.substring(0, 10) + " 23:59:59"));
//
//              long betweenDay4 = getDiffMinutes(horder.getStartTime(), horder.getEndTime());
//              BigDecimal power = new BigDecimal(betweenDay4).multiply(quantity);
//              horder.setTotalPower(power.doubleValue());
//
//              Stack<ChargeDetails> stack = extracted(horder, chargeOrderInfo);
//              horder.setStartTime(cn.hutool.core.date.DateUtil.parse(endTime.substring(0, 10) + " 00:00:00"));
//              horder.setEndTime(endTime1);
//
//              horder.setTotalPower(divideYu.subtract(power).doubleValue());
//              Stack<ChargeDetails> stack1 = extracted(horder, chargeOrderInfo);
//
//              Stack<ChargeDetails> mergedStack = new Stack<>();
//
//              // 先添加stack2的所有元素（保持原顺序）
//              for (ChargeDetails detail : stack) {
//                  mergedStack.push(detail);
//              }
//
//              // 再添加stack1的所有元素（保持原顺序）
//              for (ChargeDetails detail : stack1) {
//                  mergedStack.push(detail);
//              }
//
//              ChargeDetails[] cda = new ChargeDetails[mergedStack.size()];
//              chargeOrderInfo.setChargeDetails(mergedStack.toArray(cda));

              chargeOrderInfo = extractedCrossDay(horder, chargeOrderInfo);
          }

          return chargeOrderInfo;
      }catch (Exception e){
          return null;
      }
    }

    /**
     *
     * @param horder
     * @param chargeOrderInfo
     * @return
     */
    private Stack<ChargeDetails> extracted(XhpcHistoryOrder horder, ChargeOrderInfo chargeOrderInfo) {
        Stack<ChargeDetails> chargeDetailsStack =new Stack<>();
        R r = chargingStationService.getXhpcRateTimeOrder(horder.getRateModelId(), cn.hutool.core.date.DateUtil.formatTime(horder.getStartTime()), cn.hutool.core.date.DateUtil.formatTime(horder.getEndTime()),horder.getSerialNumber());
        if(r.getCode()==200){
            Map<String, Object> cacheMapYu = REDIS.getCacheMap("Yu"+horder.getSerialNumber());
            List<XhpcRateTimeDto> xhpcRateTimes = (List<XhpcRateTimeDto>)cacheMapYu.get(horder.getSerialNumber());

            Map<String, Object> cacheMap = REDIS.getCacheMap("order:"+ horder.getSerialNumber());
            CacheOrderData cacheOrderData = (CacheOrderData)cacheMap.get("orderData");
            BigDecimal bigDecimal = new BigDecimal(10000);
            int t1=0;
            int t12 =2;
            int t13 =3;
            BigDecimal bigDecimal1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
            int t2 =0;
            int t22 =2;
            int t23 =3;
            BigDecimal bigDecimal2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
            int t3 =0;
            int t32 =2;
            int t33 =3;
            BigDecimal bigDecimal3 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
            int t4 =0;
            int t43 =3;
            int t42 =2;
            BigDecimal bigDecimal4 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);

            for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes) {
                String rateValue = xpcRateTime.getRateValue();
                if("00".equals(rateValue)){
                    t1=t1+1;
                } else if ("01".equals(rateValue)) {
                    t2=t2+1;
                }else if ("02".equals(rateValue)) {
                    t3=t3+1;
                }else if ("03".equals(rateValue)) {
                    t4=t4+1;
                }
            }
            BigDecimal decimalYu = new BigDecimal((horder.getEndTime().getTime() - horder.getStartTime().getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP);
            BigDecimal divideYu = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(new BigDecimal(10000),4,BigDecimal.ROUND_HALF_UP);
            logger.info("=====66666=====开始推送====推送返回值============decimalYu====="+decimalYu+"=========divideYu========="+divideYu);
            //每分钟多少度电
            BigDecimal quantity =new BigDecimal(0);
            if(decimalYu.compareTo(new BigDecimal(0))!=0){
                quantity = divideYu.divide(decimalYu,4,BigDecimal.ROUND_HALF_UP);
            }
            for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes) {
                ChargeDetails chargeDetails = new ChargeDetails();
                String rateValue = xpcRateTime.getRateValue();

                String rateStartTime = cn.hutool.core.date.DateUtil.format(xpcRateTime.getStartTime(), "HH:mm:ss");

                String orderStartTime = cn.hutool.core.date.DateUtil.format(horder.getStartTime(), "yyyy-MM-dd HH:mm:ss");

                rateStartTime = orderStartTime.substring(0,10)+" "+rateStartTime;

                String rateEndTime = cn.hutool.core.date.DateUtil.format(xpcRateTime.getEndTime(), "HH:mm:ss");

                String orderEndTime = cn.hutool.core.date.DateUtil.format(horder.getEndTime(), "yyyy-MM-dd HH:mm:ss");

                rateEndTime = orderStartTime.substring(0,10)+" "+rateEndTime;

                DateTime startTime1 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");

                DateTime endTime1 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");

                if("00".equals(rateValue)){
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t1==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                    }else if(t1==2){

                        if(t12==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                            //剩余电量
                            bigDecimal1 = bigDecimal1.subtract(multiply);

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                        }else{
                            BigDecimal multiply1 = bigDecimal1.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal1.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal1.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t12 = t12-1;
                    }else if(t1==3){
                        if(t13==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                            //剩余电量
                            bigDecimal1 = bigDecimal1.subtract(multiply);

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }else if(t13==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal1 = bigDecimal1.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal1.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal1.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal1.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t13 = t13-1;
                    }

                } else if ("01".equals(rateValue)) {
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t2==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                    }else if(t2==2){

                        if(t22==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal2 = bigDecimal2.subtract(multiply);

                        }else{
                            BigDecimal multiply1 = bigDecimal2.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal2.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal2.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t22 = t22-1;
                    }else if(t2==3){
                        if(t23==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal2 = bigDecimal2.subtract(multiply);
                        }else if(t23==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal2 = bigDecimal2.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal2.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal2.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal2.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t23 = t23-1;
                    }

                }else if ("02".equals(rateValue)) {
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t3==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                    }else if(t3==2){

                        if(t32==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal3 = bigDecimal3.subtract(multiply);

                        }else{
                            BigDecimal multiply1 = bigDecimal3.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal3.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal3.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t32 = t32-1;
                    }else if(t3==3){
                        if(t33==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal3 = bigDecimal3.subtract(multiply);
                        }else if(t33==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal3 = bigDecimal3.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal3.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal3.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal3.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t33 = t33-1;
                    }

                }else if ("03".equals(rateValue)) {
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t4==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);

                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                    }else if(t4==2){

                        if(t42==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal4 = bigDecimal4.subtract(multiply);

                        }else{
                            BigDecimal multiply1 = bigDecimal4.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal4.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal4.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t42 = t42-1;
                    }else if(t4==3){
                        if(t43==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal4 = bigDecimal4.subtract(multiply);
                        }else if(t43==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal4 = bigDecimal4.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal4.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal4.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal4.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t43 = t43-1;
                    }
                }
            }
        }
        //REDIS.deleteObject("Yu"+horder.getSerialNumber());
        return chargeDetailsStack;
    }


    /**
     * 跨天
     */
    private ChargeOrderInfo extractedCrossDay(XhpcHistoryOrder horder, ChargeOrderInfo chargeOrderInfo){
        Date endTimeYu = horder.getEndTime();
        String startTime = chargeOrderInfo.getStartTime();
        String endTime = chargeOrderInfo.getEndTime();
        R r = chargingStationService.getCrossDayXhpcRateTimeOrder(horder.getRateModelId(), cn.hutool.core.date.DateUtil.format(horder.getStartTime(),"yyyy-MM-dd HH:mm:ss"), cn.hutool.core.date.DateUtil.format(horder.getEndTime(),"yyyy-MM-dd HH:mm:ss"), horder.getSerialNumber());
        if (r.getCode() == 200) {
            Map<String, Object> cacheMapYu1 = REDIS.getCacheMap("Yu" + horder.getSerialNumber());
            List<XhpcRateTimeDto> xhpcRateTimes1 = (List<XhpcRateTimeDto>) cacheMapYu1.get(horder.getSerialNumber());
            int one=0;
            int two =0;
            int three =0;
            int four =0;
            for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes1) {
                String rateValue = xpcRateTime.getRateValue();
                if("00".equals(rateValue)){
                    one=one+1;
                } else if ("01".equals(rateValue)) {
                    two=two+1;
                }else if ("02".equals(rateValue)) {
                    three=three+1;
                }else if ("03".equals(rateValue)) {
                    four=four+1;
                }
            }
            Map<String, Object> cacheMap = REDIS.getCacheMap("order:" + horder.getSerialNumber());
            CacheOrderData cacheOrderData1 = (CacheOrderData) cacheMap.get("orderData");
            CacheOrderData cacheOrderData  =new CacheOrderData();
            CacheOrderData cacheOrderDataTotal  =new CacheOrderData();
            BeanUtils.copyProperties(cacheOrderData1, cacheOrderData);
            BeanUtils.copyProperties(cacheOrderData1, cacheOrderDataTotal);
            BigDecimal decimalYu = new BigDecimal((horder.getEndTime().getTime() - horder.getStartTime().getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP);
            BigDecimal divideYu = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(new BigDecimal(10000),4,BigDecimal.ROUND_HALF_UP);
            //每分钟多少度电
            BigDecimal quantity =new BigDecimal(0);
            if(decimalYu.compareTo(new BigDecimal(0))!=0){
                quantity = divideYu.divide(decimalYu,4,BigDecimal.ROUND_HALF_UP);
            }

            horder.setEndTime(cn.hutool.core.date.DateUtil.parse(startTime.substring(0, 10) + " 23:59:59"));
            //前一天
            R r1 = chargingStationService.getXhpcRateTimeOrder(horder.getRateModelId(), cn.hutool.core.date.DateUtil.formatTime(horder.getStartTime()), cn.hutool.core.date.DateUtil.formatTime(horder.getEndTime()),horder.getSerialNumber());
            Stack<ChargeDetails> chargeDetailsStack =new Stack<>();
            if(r1.getCode()==200){
                Map<String, Object> cacheMapYu = REDIS.getCacheMap("Yu"+horder.getSerialNumber());
                List<XhpcRateTimeDto> xhpcRateTimes = (List<XhpcRateTimeDto>)cacheMapYu.get(horder.getSerialNumber());
                BigDecimal bigDecimal = new BigDecimal(10000);
                int t1=0;
                int t12 =2;
                int t13 =3;
                BigDecimal bigDecimal1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
                int t2 =0;
                int t22 =2;
                int t23 =3;
                BigDecimal bigDecimal2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
                int t3 =0;
                int t32 =2;
                int t33 =3;
                BigDecimal bigDecimal3 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                int t4 =0;
                int t43 =3;
                int t42 =2;
                BigDecimal bigDecimal4 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);

                for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes) {
                    String rateValue = xpcRateTime.getRateValue();
                    if("00".equals(rateValue)){
                        t1=t1+1;
                    } else if ("01".equals(rateValue)) {
                        t2=t2+1;
                    }else if ("02".equals(rateValue)) {
                        t3=t3+1;
                    }else if ("03".equals(rateValue)) {
                        t4=t4+1;
                    }
                }

                BigDecimal t1Cost =new BigDecimal(0);
                BigDecimal t2Cost =new BigDecimal(0);
                BigDecimal t3Cost =new BigDecimal(0);
                BigDecimal t4Cost =new BigDecimal(0);

                for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes) {
                    ChargeDetails chargeDetails = new ChargeDetails();
                    String rateValue = xpcRateTime.getRateValue();

                    String rateStartTime = cn.hutool.core.date.DateUtil.format(xpcRateTime.getStartTime(), "HH:mm:ss");

                    String orderStartTime = cn.hutool.core.date.DateUtil.format(horder.getStartTime(), "yyyy-MM-dd HH:mm:ss");

                    rateStartTime = orderStartTime.substring(0,10)+" "+rateStartTime;

                    String rateEndTime = cn.hutool.core.date.DateUtil.format(xpcRateTime.getEndTime(), "HH:mm:ss");

                    String orderEndTime = cn.hutool.core.date.DateUtil.format(horder.getEndTime(), "yyyy-MM-dd HH:mm:ss");

                    if("00:00:00".equals(rateEndTime)){
                        rateEndTime ="23:59:59";
                    }
                    rateEndTime = orderStartTime.substring(0,10)+" "+rateEndTime;

                    DateTime startTime1 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");

                    DateTime endTime1 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");

                    if("00".equals(rateValue)){
                        boolean judgeStart =false;
                        boolean judgeEnd =false;

                        if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                            chargeDetails.setDetailStartTime(orderStartTime);
                            judgeStart =true;
                        }else{
                            chargeDetails.setDetailStartTime(rateStartTime);
                        }
                        if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                            chargeDetails.setDetailEndTime(rateEndTime);
                        }else{
                            chargeDetails.setDetailEndTime(orderEndTime);
                            judgeEnd =true;
                        }
                        chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                        chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                        if(one==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }else if (one==2){
                            if(t1==1){
                                //还有一个时间是跨天
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }
                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                                //剩余电量
                                bigDecimal1 = bigDecimal1.subtract(multiply);

                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);
                                BigDecimal divide = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT1PowerQuantity(bigDecimal1.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT1Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT1Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                            }else{
                                if(t12==2){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                                    //剩余电量
                                    bigDecimal1 = bigDecimal1.subtract(multiply);

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                }else{
                                    BigDecimal multiply1 = bigDecimal1.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal1.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal1.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t12 = t12-1;
                            }
                        }else if (one==3){

                            if(t1==1){
                                //还有2个时间是跨天
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                                //剩余电量
                                bigDecimal1 = bigDecimal1.subtract(multiply);

                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);
                                BigDecimal divide = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT1PowerQuantity(bigDecimal1.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT1Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT1Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                            }else if (t1==2){

                                if(t12==2){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                                    //剩余电量
                                    bigDecimal1 = bigDecimal1.subtract(multiply);

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                    t1Cost = t1Cost.add(multiply1.add(multiply2));
                                    t12 =t12-1;
                                }else{
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                                    //剩余电量
                                    bigDecimal1 = bigDecimal1.subtract(multiply);

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    t1Cost = t1Cost.add(multiply1.add(multiply2));

                                    cacheOrderDataTotal.setT1PowerQuantity(bigDecimal1.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT1Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT1Cost(t1CostYu.subtract(t1Cost).multiply(bigDecimal).intValue());
                                }
                            }else if (t1==3){
                                if(t13==3){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                                    //剩余电量
                                    bigDecimal1 = bigDecimal1.subtract(multiply);

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }else if(t13==2){

                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal1 = bigDecimal1.subtract(multiply);
                                }else{
                                    BigDecimal multiply1 = bigDecimal1.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal1.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal1.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t13 = t13-1;
                            }
                        }
                    }else if("01".equals(rateValue)){
                        boolean judgeStart =false;
                        boolean judgeEnd =false;

                        if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                            chargeDetails.setDetailStartTime(orderStartTime);
                            judgeStart =true;
                        }else{
                            chargeDetails.setDetailStartTime(rateStartTime);
                        }
                        if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                            chargeDetails.setDetailEndTime(rateEndTime);
                        }else{
                            chargeDetails.setDetailEndTime(orderEndTime);
                            judgeEnd =true;
                        }
                        chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                        chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                        if(two==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }else if(two==2){
                            if(t2==1){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal2 = bigDecimal2.subtract(multiply);

                                BigDecimal divide = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT2PowerQuantity(bigDecimal2.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT2Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT2Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }

                            }else{
                                if(t22==2){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal2 = bigDecimal2.subtract(multiply);
                                }else{
                                    BigDecimal multiply1 = bigDecimal2.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal2.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal2.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t22 = t22-1;
                            }
                        }else if(two==3){
                            if(t2==1){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal2 = bigDecimal2.subtract(multiply);

                                BigDecimal divide = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT2PowerQuantity(bigDecimal2.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT2Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT2Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                            }else if(t2==2){

                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal2 = bigDecimal2.subtract(multiply);
                                    t2Cost = t2Cost.add(multiply1.add(multiply2));
                                    if(t22==1){
                                        cacheOrderDataTotal.setT2PowerQuantity(bigDecimal2.multiply(bigDecimal).intValue());
                                        BigDecimal t2CostYu = new BigDecimal(cacheOrderData.getT2Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                        cacheOrderDataTotal.setT2Cost(t2CostYu.subtract(t2Cost).multiply(bigDecimal).intValue());
                                    }
                                    t22 = t22-1;
                            }else if(t2==3){
                                if(t23==3){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal2 = bigDecimal2.subtract(multiply);
                                }else if(t23==2){

                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal2 = bigDecimal2.subtract(multiply);
                                }else{
                                    BigDecimal multiply1 = bigDecimal2.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal2.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal2.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t23 = t23-1;
                            }
                        }
                    }else if("02".equals(rateValue)){
                        boolean judgeStart =false;
                        boolean judgeEnd =false;

                        if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                            chargeDetails.setDetailStartTime(orderStartTime);
                            judgeStart =true;
                        }else{
                            chargeDetails.setDetailStartTime(rateStartTime);
                        }
                        if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                            chargeDetails.setDetailEndTime(rateEndTime);
                        }else{
                            chargeDetails.setDetailEndTime(orderEndTime);
                            judgeEnd =true;
                        }
                        chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                        chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                        if(three==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }else if(three==2){
                            if(t3==1){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal3 = bigDecimal3.subtract(multiply);

                                BigDecimal divide = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT3PowerQuantity(bigDecimal3.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT3Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT3Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                            }else if(t3==2){
                                if(three==1){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal3 = bigDecimal3.subtract(multiply);

                                    BigDecimal divide = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                                    if(multiply.compareTo(divide)==-1){
                                        cacheOrderDataTotal.setT3PowerQuantity(bigDecimal3.multiply(bigDecimal).intValue());
                                        BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT3Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                        cacheOrderDataTotal.setT3Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                    }
                                }else{
                                    if(t32==2){
                                        if(judgeStart){
                                            rateStartTime = orderStartTime;
                                        }
                                        if(judgeEnd){
                                            rateEndTime = orderEndTime;
                                        }

                                        DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                        DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                        long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                        //获得电量
                                        BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                        BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                        BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                        chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                        chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                        chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                        chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                        chargeDetails.setDetailPower(multiply.doubleValue());
                                        chargeDetailsStack.push(chargeDetails);

                                        //剩余电量
                                        bigDecimal3 = bigDecimal3.subtract(multiply);

                                    }else{
                                        BigDecimal multiply1 = bigDecimal3.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                        BigDecimal multiply2 = bigDecimal3.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                        chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                        chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                        chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                        chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                        chargeDetails.setDetailPower(bigDecimal3.doubleValue());
                                        chargeDetailsStack.push(chargeDetails);
                                    }
                                    t32 = t32-1;
                                }
                            }
                        }else if(three==3){
                            if(t3==1){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal3 = bigDecimal3.subtract(multiply);

                                BigDecimal divide = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT3PowerQuantity(bigDecimal3.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT3Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT3Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                            }else if (t3==2){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal3 = bigDecimal3.subtract(multiply);
                                t3Cost = t3Cost.add(multiply1.add(multiply2));
                                if(t23==1){
                                    cacheOrderDataTotal.setT3PowerQuantity(bigDecimal3.multiply(bigDecimal).intValue());
                                    BigDecimal t3CostYu = new BigDecimal(cacheOrderData.getT3Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT3Cost(t3CostYu.subtract(t3Cost).multiply(bigDecimal).intValue());
                                }
                                t23 = t23-1;
                            }else if(t3==3){
                                if(t33==3){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal3 = bigDecimal3.subtract(multiply);
                                }else if(t33==2){

                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal3 = bigDecimal3.subtract(multiply);
                                }else{
                                    BigDecimal multiply1 = bigDecimal3.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal3.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal3.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t33 = t33-1;
                            }
                        }
                    }else if("03".equals(rateValue)){
                        boolean judgeStart =false;
                        boolean judgeEnd =false;

                        if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                            chargeDetails.setDetailStartTime(orderStartTime);
                            judgeStart =true;
                        }else{
                            chargeDetails.setDetailStartTime(rateStartTime);
                        }
                        if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                            chargeDetails.setDetailEndTime(rateEndTime);
                        }else{
                            chargeDetails.setDetailEndTime(orderEndTime);
                            judgeEnd =true;
                        }
                        chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                        chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                        if(four==1){
                            BigDecimal divide = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);
                            BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(divide.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }else if(four==2){
                            if(t4==1){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal4 = bigDecimal4.subtract(multiply);

                                BigDecimal divide = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT4PowerQuantity(bigDecimal4.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT4Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT4Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                            }else{
                                if(t42==2){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }

                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal4 = bigDecimal4.subtract(multiply);

                                }else{
                                    BigDecimal multiply1 = bigDecimal4.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal4.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal4.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t42 = t42-1;
                            }
                        }else if(four==3){
                            if(t4==1){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal4 = bigDecimal4.subtract(multiply);

                                BigDecimal divide = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);
                                if(multiply.compareTo(divide)==-1){
                                    cacheOrderDataTotal.setT4PowerQuantity(bigDecimal4.multiply(bigDecimal).intValue());
                                    BigDecimal t1CostYu = new BigDecimal(cacheOrderData.getT4Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT4Cost(t1CostYu.subtract(multiply1.add(multiply2)).multiply(bigDecimal).intValue());
                                }
                           }else if (t4==2){
                                if(judgeStart){
                                    rateStartTime = orderStartTime;
                                }
                                if(judgeEnd){
                                    rateEndTime = orderEndTime;
                                }

                                DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                                //获得电量
                                BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                chargeDetails.setDetailPower(multiply.doubleValue());
                                chargeDetailsStack.push(chargeDetails);

                                //剩余电量
                                bigDecimal2 = bigDecimal2.subtract(multiply);
                                t4Cost = t4Cost.add(multiply1.add(multiply2));
                                if(t23==1){
                                    cacheOrderDataTotal.setT4PowerQuantity(bigDecimal2.multiply(bigDecimal).intValue());
                                    BigDecimal t4CostYu = new BigDecimal(cacheOrderData.getT4Cost()).divide(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    cacheOrderDataTotal.setT4Cost(t4CostYu.subtract(t4Cost).multiply(bigDecimal).intValue());
                                }
                                t23 = t23-1;
                            }else if(t4==3){
                                if(t43==3){
                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal4 = bigDecimal4.subtract(multiply);
                                }else if(t43==2){

                                    if(judgeStart){
                                        rateStartTime = orderStartTime;
                                    }
                                    if(judgeEnd){
                                        rateEndTime = orderEndTime;
                                    }
                                    DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                                    DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                                    long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                                    //获得电量
                                    BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                                    BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(multiply.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);

                                    //剩余电量
                                    bigDecimal4 = bigDecimal4.subtract(multiply);
                                }else{
                                    BigDecimal multiply1 = bigDecimal4.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                                    BigDecimal multiply2 = bigDecimal4.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                                    chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                                    chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                                    chargeDetails.setDetailPower(bigDecimal4.doubleValue());
                                    chargeDetailsStack.push(chargeDetails);
                                }
                                t43 = t43-1;
                            }
                        }
                    }
                }
            }
            //后一天

            horder.setStartTime(cn.hutool.core.date.DateUtil.parse(endTime.substring(0, 10) + " 00:00:00"));
            horder.setEndTime(endTimeYu);
            Stack<ChargeDetails> stack1 = extractedCrossDayYu(horder, cacheOrderDataTotal);

            Stack<ChargeDetails> mergedStack = new Stack<>();

            // 先添加stack2的所有元素（保持原顺序）
            for (ChargeDetails detail : chargeDetailsStack) {
                mergedStack.push(detail);
            }

            // 再添加stack1的所有元素（保持原顺序）
            for (ChargeDetails detail : stack1) {
                mergedStack.push(detail);
            }

            ChargeDetails[] cda = new ChargeDetails[mergedStack.size()];
            chargeOrderInfo.setChargeDetails(mergedStack.toArray(cda));

        }

        return chargeOrderInfo;
    }


    private Stack<ChargeDetails> extractedCrossDayYu(XhpcHistoryOrder horder, CacheOrderData cacheOrderData) {
        Stack<ChargeDetails> chargeDetailsStack =new Stack<>();
        R r = chargingStationService.getXhpcRateTimeOrder(horder.getRateModelId(), cn.hutool.core.date.DateUtil.formatTime(horder.getStartTime()), cn.hutool.core.date.DateUtil.formatTime(horder.getEndTime()),horder.getSerialNumber());
        if(r.getCode()==200){
            Map<String, Object> cacheMapYu = REDIS.getCacheMap("Yu"+horder.getSerialNumber());
            List<XhpcRateTimeDto> xhpcRateTimes = (List<XhpcRateTimeDto>)cacheMapYu.get(horder.getSerialNumber());

            Map<String, Object> cacheMap = REDIS.getCacheMap("order:"+ horder.getSerialNumber());

            BigDecimal bigDecimal = new BigDecimal(10000);
            int t1=0;
            int t12 =2;
            int t13 =3;
            BigDecimal bigDecimal1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
            int t2 =0;
            int t22 =2;
            int t23 =3;
            BigDecimal bigDecimal2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
            int t3 =0;
            int t32 =2;
            int t33 =3;
            BigDecimal bigDecimal3 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
            int t4 =0;
            int t43 =3;
            int t42 =2;
            BigDecimal bigDecimal4 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);

            for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes) {
                String rateValue = xpcRateTime.getRateValue();
                if("00".equals(rateValue)){
                    t1=t1+1;
                } else if ("01".equals(rateValue)) {
                    t2=t2+1;
                }else if ("02".equals(rateValue)) {
                    t3=t3+1;
                }else if ("03".equals(rateValue)) {
                    t4=t4+1;
                }
            }
            BigDecimal decimalYu = new BigDecimal((horder.getEndTime().getTime() - horder.getStartTime().getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP);
            BigDecimal divideYu = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(new BigDecimal(10000),4,BigDecimal.ROUND_HALF_UP);
            //每分钟多少度电
            BigDecimal quantity =new BigDecimal(0);
            if(decimalYu.compareTo(new BigDecimal(0))!=0){
                quantity = divideYu.divide(decimalYu,4,BigDecimal.ROUND_HALF_UP);
            }
            for (XhpcRateTimeDto xpcRateTime:xhpcRateTimes) {
                ChargeDetails chargeDetails = new ChargeDetails();
                String rateValue = xpcRateTime.getRateValue();

                String rateStartTime = cn.hutool.core.date.DateUtil.format(xpcRateTime.getStartTime(), "HH:mm:ss");

                String orderStartTime = cn.hutool.core.date.DateUtil.format(horder.getStartTime(), "yyyy-MM-dd HH:mm:ss");

                rateStartTime = orderStartTime.substring(0,10)+" "+rateStartTime;

                String rateEndTime = cn.hutool.core.date.DateUtil.format(xpcRateTime.getEndTime(), "HH:mm:ss");

                String orderEndTime = cn.hutool.core.date.DateUtil.format(horder.getEndTime(), "yyyy-MM-dd HH:mm:ss");

                rateEndTime = orderStartTime.substring(0,10)+" "+rateEndTime;

                DateTime startTime1 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");

                DateTime endTime1 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");

                if("00".equals(rateValue)){
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t1==1){
                        BigDecimal divide = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal);
                        BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                        chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                        chargeDetails.setDetailPower(divide.doubleValue());
                        chargeDetailsStack.push(chargeDetails);
                    }else if(t1==2){

                        if(t12==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                            //剩余电量
                            bigDecimal1 = bigDecimal1.subtract(multiply);

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                        }else{
                            BigDecimal multiply1 = bigDecimal1.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal1.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal1.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t12 = t12-1;
                    }else if(t1==3){
                        if(t13==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));
                            //剩余电量
                            bigDecimal1 = bigDecimal1.subtract(multiply);

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }else if(t13==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal1 = bigDecimal1.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal1.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal1.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal1.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t13 = t13-1;
                    }

                } else if ("01".equals(rateValue)) {
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t2==1){
                        BigDecimal divide = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal);
                        BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                        chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                        chargeDetails.setDetailPower(divide.doubleValue());
                        chargeDetailsStack.push(chargeDetails);
                    }else if(t2==2){

                        if(t22==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal2 = bigDecimal2.subtract(multiply);

                        }else{
                            BigDecimal multiply1 = bigDecimal2.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal2.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal2.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t22 = t22-1;
                    }else if(t2==3){
                        if(t23==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal2 = bigDecimal2.subtract(multiply);
                        }else if(t23==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal2 = bigDecimal2.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal2.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal2.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal2.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t23 = t23-1;
                    }

                }else if ("02".equals(rateValue)) {
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t3==1){
                        BigDecimal divide = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal);
                        BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                        chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                        chargeDetails.setDetailPower(divide.doubleValue());
                        chargeDetailsStack.push(chargeDetails);
                    }else if(t3==2){

                        if(t32==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal3 = bigDecimal3.subtract(multiply);

                        }else{
                            BigDecimal multiply1 = bigDecimal3.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal3.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal3.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t32 = t32-1;
                    }else if(t3==3){
                        if(t33==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal3 = bigDecimal3.subtract(multiply);
                        }else if(t33==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal3 = bigDecimal3.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal3.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal3.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal3.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t33 = t33-1;
                    }

                }else if ("03".equals(rateValue)) {
                    boolean judgeStart =false;
                    boolean judgeEnd =false;

                    if(horder.getStartTime().getTime()-startTime1.getTime()>0){
                        chargeDetails.setDetailStartTime(orderStartTime);
                        judgeStart =true;
                    }else{
                        chargeDetails.setDetailStartTime(rateStartTime);
                    }
                    if(horder.getEndTime().getTime()-endTime1.getTime()>0){
                        chargeDetails.setDetailEndTime(rateEndTime);
                    }else{
                        chargeDetails.setDetailEndTime(orderEndTime);
                        judgeEnd =true;
                    }
                    chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                    chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());

                    if(t4==1){
                        BigDecimal divide = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal);

                        BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                        chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                        chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                        chargeDetails.setDetailPower(divide.doubleValue());
                        chargeDetailsStack.push(chargeDetails);
                    }else if(t4==2){

                        if(t42==2){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }

                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);

                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal4 = bigDecimal4.subtract(multiply);

                        }else{
                            BigDecimal multiply1 = bigDecimal4.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal4.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal4.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t42 = t42-1;
                    }else if(t4==3){
                        if(t43==3){
                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));

                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal4 = bigDecimal4.subtract(multiply);
                        }else if(t43==2){

                            if(judgeStart){
                                rateStartTime = orderStartTime;
                            }
                            if(judgeEnd){
                                rateEndTime = orderEndTime;
                            }
                            DateTime parse2 = cn.hutool.core.date.DateUtil.parse(rateStartTime, "yyyy-MM-dd HH:mm:ss");
                            DateTime parse3 = cn.hutool.core.date.DateUtil.parse(rateEndTime, "yyyy-MM-dd HH:mm:ss");
                            long betweenDay4 = cn.hutool.core.date.DateUtil.between(parse3,parse2, DateUnit.MINUTE);
                            //获得电量
                            BigDecimal multiply = quantity.multiply(new BigDecimal(betweenDay4));


                            BigDecimal multiply1 = multiply.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = multiply.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(multiply.doubleValue());
                            chargeDetailsStack.push(chargeDetails);

                            //剩余电量
                            bigDecimal4 = bigDecimal4.subtract(multiply);
                        }else{
                            BigDecimal multiply1 = bigDecimal4.multiply(xpcRateTime.getPowerFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal multiply2 = bigDecimal4.multiply(xpcRateTime.getServiceFee()).setScale(2, BigDecimal.ROUND_HALF_UP);

                            chargeDetails.setElecPrice(xpcRateTime.getPowerFee().doubleValue());
                            chargeDetails.setSevicePrice(xpcRateTime.getServiceFee().doubleValue());
                            chargeDetails.setDetailElecMoney(multiply1.doubleValue());
                            chargeDetails.setDetailSeviceMoney(multiply2.doubleValue());
                            chargeDetails.setDetailPower(bigDecimal4.doubleValue());
                            chargeDetailsStack.push(chargeDetails);
                        }
                        t43 = t43-1;
                    }
                }
            }
        }
        //REDIS.deleteObject("Yu"+horder.getSerialNumber());
        return chargeDetailsStack;
    }

    @Scheduled(fixedRate = 1000 * 30)
    public void runYu() throws JsonProcessingException {

        Collection<String> realtimeOrder = REDIS.keys("notification:*");
        for (String okey : realtimeOrder) {

            // 获取 JSON 字符串
            String chargeOrderInfoJson = redisService.getCacheObject(okey);

            ChargeOrderInfo chargeOrderInfo = com.alibaba.fastjson.JSON.parseObject(chargeOrderInfoJson, ChargeOrderInfo.class);
            String substring = chargeOrderInfo.getStartChargeSeq().substring(0, 9);
            AuthSecretToken authSecretToken  = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(substring, SECRET_TOKEN_TYPE_OUT).orElse(null);
            if (null != authSecretToken) {
                XhpcHistoryOrder horder = xhpcHistoryOrderRepository.findBySerialNumber(okey.substring(13));
                final ChargeOrderInfoResponse pushResp = notify(chargeOrderInfo, authSecretToken);
                if (pushResp != null) {
                    horder.setConfirmResult(pushResp.getConfirmResult());
                    logger.debug("3rd part order {} push result: {}", horder.getSerialNumber(),pushResp.getConfirmResult());
                    if(pushResp.getConfirmResult()!=0){
                        //解析原因
                        horder.setRemark(pushResp.getConfirmResultMessage());
                        if(pushResp.getConfirmResult()==1 && "充电账单争议：运营商已推送过账单再次收到的账单无效".equals(pushResp.getConfirmResultMessage())){
                            horder.setConfirmResult(0);
                        }
                    }
                    logger.info("==============推送返回值================="+pushResp.getConfirmResult()+"=========="+horder.getSerialNumber());
                    xhpcHistoryOrderRepository.save(horder);
                    REDIS.setCacheMapValue("pushOrder:".concat(horder.getSerialNumber()), "horderpushed", true);

                    redisService.deleteObject(okey);
                }
            }
        }
    }

    public ChargeOrderInfoResponse notify(ChargeOrderInfo chargeOrderInfo, AuthSecretToken authSecretTokenOut) throws JsonProcessingException {

        String data = JSONUtil.toJSONString(chargeOrderInfo);

        logger.info("=====99999=====开始推送====推送返回值============data====="+data);
        CommonRequest<ChargeOrderInfo> commonRequest = new CommonRequest<>();
        commonRequest.setData(data);
        String responseBody = ok(commonRequest, "/notification_charge_order_info", authSecretTokenOut);
        logger.info("==============推送返回值==========responseBody============="+responseBody);
        return DTOJsonHelper.parseResponseData(responseBody,
                ChargeOrderInfoResponse.class, authSecretTokenOut);


    }

    public long getDiffMinutes(Date startTime, Date endTime) {
        if (startTime == null || endTime == null) {
            return 0; // 或抛异常，根据业务决定
        }
        long diffMillis = endTime.getTime() - startTime.getTime();
        return diffMillis / (1000 * 60);
    }

    public static void main(String[] args) {

    }
}
