package com.xhpc.order.controller;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.order.domain.XhpcChargeOrder;
import com.xhpc.order.domain.XhpcHistoryOrder;
import com.xhpc.order.domain.XhpcStatisticsStation;
import com.xhpc.order.domain.XhpcStatisticsTimeInterval;
import com.xhpc.order.dto.XhpcChargeHistoryOrder;
import com.xhpc.order.service.IXhpcChargeOrderService;
import com.xhpc.order.service.IXhpcHistoryOrderService;
import com.xhpc.order.service.IXhpcStatisticsService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 历史订单
 * @author yuyang
 * @date 2021/8/3 21:19
 */
@EnableScheduling
@RestController
@RequestMapping("/histotyOrder")
@Api(value = "历史订单接口", tags = "历史订单接口")
public class XhpcHistoryOrderController extends BaseController {

    @Autowired
    private IXhpcHistoryOrderService xhpcHistoryOrderService;
    @Autowired
    private IXhpcStatisticsService xhpcStatisticsService;

    @Autowired
    private IXhpcChargeOrderService chargeOrderService;


    private static final Logger logger = LoggerFactory.getLogger(XhpcHistoryOrderController.class);

    /**
     * 历史订单
     * @param phone                         用户账号
     * @param transactionNumber             订单编号
     * @param type                        1 自动结算 2 平台结算
     * @param chargingStationName           电站名称
     * @param operatorId                    运营商id
     * @param source                        用户类型  0C端用户 1流量用户
     * @param startTime                     订单开始时间
     * @param endTime                       订单结束时间
     * @param userId                        用户id
     * @param status                        1 平台 2 运营商 3流量方
     * @return
     */
    @GetMapping("/getListPage")
    public TableDataInfo  getListPage(String phone,String transactionNumber,@RequestParam("status")Integer status,String chargingStationName,Long operatorId,Integer source,String startTime,String endTime,@RequestParam("userId") Long userId, Integer type)
    {
        startPage();
        List<Map<String, Object>> listPage = xhpcHistoryOrderService.getListPage(phone, transactionNumber, status, chargingStationName, operatorId, source, startTime, endTime, userId, type);
        return getDataTable(listPage);
    }

    /**
     * 历史订单详情
     * @param historyOrderId 历史订单id
     * @return
     */
    @GetMapping("/getById")
    public AjaxResult getById(@RequestParam("historyOrderId")Long historyOrderId){
        return xhpcHistoryOrderService.getById(historyOrderId);
    }

    /**
     * 终端统计
     */
    @GetMapping("/test3")
    @Scheduled(cron = "0 0/8 * * * ?")
    public void test3(){
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>终端统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>终端统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>终端统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        add(1000,3);
    }
    /**
     * 场站统计
     */
    @GetMapping("/test2")
    @Scheduled(cron = "0 0/7 * * * ?")
    public void test2(){
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>场站统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>场站统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>场站统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        add(1000,2);
    }

    /**
     * 日期统计
     */
    @GetMapping("/test1")
    @Scheduled(cron = "0 0/6 * * * ?")
    public void test1(){
        add(1000,1);
    }
    /**
     * 日期统计(已废弃)
     */
    @GetMapping("/test7")
    //@Scheduled(cron = "0 0/6 * * * ?")
    public void test7(){
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>日期统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>日期统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>日期统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        //获取500条待统计历史订单
        //跨时段，跨费率，计费模型
        //日期统计
        int type =1;
        List<XhpcChargeHistoryOrder> list = xhpcHistoryOrderService.getStatistisList(1000,type);
        //是否跨天
        if(list !=null && list.size()>0){
            for (XhpcChargeHistoryOrder xhpc:list) {
                //是否跨天
                Date startTime = xhpc.getStartTime();
                Date endTime = xhpc.getEndTime();
                //1时间没有跨天
                DateTime parse = DateUtil.parse(DateUtil.format(startTime, "yyyy-MM-dd"), "yyyy-MM-dd");
                DateTime parse1 = DateUtil.parse(DateUtil.format(endTime, "yyyy-MM-dd"), "yyyy-MM-dd");
                long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY);

                if(xhpc.getTotalPrice().compareTo(new BigDecimal(0)) !=1){
                    continue;
                }
                if(xhpc.getChargingDegree().compareTo(new BigDecimal(0)) !=1){
                    continue;
                }
                //每分钟多少度电
                BigDecimal decimal = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),2,BigDecimal.ROUND_DOWN);
                if(decimal.compareTo(new BigDecimal(0)) !=1){
                    continue;
                }
                BigDecimal divide = xhpc.getChargingDegree().divide(decimal,2,BigDecimal.ROUND_DOWN);

                if(betweenDay==0){
                    XhpcStatisticsStation xhpcSt =new XhpcStatisticsStation();
                    xhpcSt.setChargingDegree(xhpc.getChargingDegree());
                    xhpcSt.setChargingTime(decimal);
                    xhpcSt.setChargingNumber(1);
                    xhpcSt.setPowerPrice(xhpc.getPowerPriceTotal());
                    xhpcSt.setServicePrice(xhpc.getServicePriceTotal());
                    xhpcSt.setTotalPrice(xhpc.getTotalPrice());
                    xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount());
                    xhpcSt.setActPrice(xhpc.getActPrice());
                    xhpcSt.setInternetCommission(xhpc.getInternetCommission());
                    xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission());
                    xhpcSt.setPlatformCommission(xhpc.getPlatformCommission());
                    xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion());
                    xhpcSt.setOperationCommission(xhpc.getOperationCommission());
                    xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission());
                    xhpcSt.setActPowerPrice(xhpc.getActPowerPrice());
                    xhpcSt.setActServicePrice(xhpc.getActServicePrice());
                    if(xhpc.getSource()==1){
                        xhpcSt.setInternetUserId(xhpc.getUserId());
                    }
                    xhpcSt.setOperatorId(xhpc.getOperatorId());
                    xhpcSt.setChargingStationId(xhpc.getChargingStationId());
                    xhpcSt.setCreateTime(Calendar.getInstance().getTime());
                    xhpcSt.setTerminalId(xhpc.getTerminalId());
                    xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId());
                    xhpcSt.setChargingPileId(xhpc.getChargingPileId());
                    xhpcSt.setType(type);
                    xhpcSt.setCreateTime(xhpc.getEndTime());
                    xhpcStatisticsService.addStatisticsStation(xhpcSt);
                    //修改历史订单表状态
                    xhpcHistoryOrderService.updateXhpcHistoryOrder(xhpc.getHistoryOrderId(),type + 1);
                }else{
                    //跨天
                    DateTime tomorrow = DateUtil.offsetDay(startTime,1);
                    Date startTime3 =DateUtil.beginOfDay(tomorrow);

                    Map<String, BigDecimal> map =addStatisticsStation(new HashMap<String,BigDecimal>(),xhpc, DateUtil.formatTime(startTime), "23:59:59",divide,1,1);

                    addStatisticsStation(map,xhpc, DateUtil.formatTime(startTime3), DateUtil.formatTime(endTime),divide,2,1);

                }

            }
        }
    }

    private Map<String,BigDecimal> addStatisticsStation(Map<String,BigDecimal> map1, XhpcChargeHistoryOrder xhpc, String startTime, String endTime, BigDecimal divide,int number,int type) {

        //总金额
        BigDecimal totalPrice =new BigDecimal(0);
        //总电费
        BigDecimal powerPriceTotal =new BigDecimal(0);
        //总服务费
        BigDecimal servicePriceTotal =new BigDecimal(0);
        //实收电费
        BigDecimal actPowerPrice =new BigDecimal(0);
        //实收服务费
        BigDecimal actServicePrice =new BigDecimal(0);
        //总充电电量
        BigDecimal chargingDegree =new BigDecimal(0);
        //电站活动抵扣--抵扣的总金额
        BigDecimal promotionDiscount =new BigDecimal(0);
        //实际价格-用户支付的钱
        BigDecimal actPrice =new BigDecimal(0);
        if(number ==2){
            totalPrice =map1.get("totalPrice");
            powerPriceTotal =map1.get("powerPriceTotal");
            servicePriceTotal =map1.get("servicePriceTotal");
            actPowerPrice =map1.get("actPowerPrice");
            actServicePrice =map1.get("actServicePrice");
            chargingDegree =map1.get("chargingDegree");
            promotionDiscount =map1.get("promotionDiscount");
            actPrice =map1.get("actPrice");
        }else{
            totalPrice = xhpc.getTotalPrice();
            powerPriceTotal =xhpc.getPowerPriceTotal();
            servicePriceTotal =xhpc.getServicePriceTotal();
            actPowerPrice =xhpc.getActPowerPrice();
            actServicePrice =xhpc.getActServicePrice();
            chargingDegree =xhpc.getChargingDegree();
            promotionDiscount = xhpc.getPromotionDiscount();
            actPrice = xhpc.getActPrice();
        }

        //叠加总电费
        BigDecimal powerPriceTotal1 =new BigDecimal(0);
        //叠加总服务费
        BigDecimal servicePriceTotal1 =new BigDecimal(0);


        //时长
        BigDecimal timeInterval = new BigDecimal(0);
        //时长
        BigDecimal chargingDegree2 = new BigDecimal(0);


        List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime, endTime, xhpc.getRateModelId());
        for (int i = 0; i <reatTimeList.size() ; i++) {
            BigDecimal powerFee =new BigDecimal(0);
            BigDecimal serviceFee =new BigDecimal(0);
            String startTime1 =startTime;
            String endTime1 =endTime;
            Map<String, Object> map = reatTimeList.get(i);
            //获取费率
            if(reatTimeList.size()==1){
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
            }else if (i==0){
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
                endTime1 = map.get("endTime").toString();
                if("00:00:00".equals(endTime1)){
                    endTime1="23:59:59";
                }
            }else if(i!=reatTimeList.size()-1){
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
                startTime1 = map.get("startTime").toString();
                endTime1 = map.get("endTime").toString();
                if("00:00:00".equals(endTime1)){
                    endTime1="23:59:59";
                }
            }else{
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
                startTime1 = map.get("startTime").toString();
            }
            timeInterval =timeInterval.add(new BigDecimal((DateUtil.parse(endTime1).getTime()-DateUtil.parse(startTime1).getTime())).divide(new BigDecimal(60000),2, BigDecimal.ROUND_DOWN));
            powerPriceTotal1 = powerPriceTotal1.add(powerFee.multiply(divide).setScale(2, BigDecimal.ROUND_DOWN));
            servicePriceTotal1 = servicePriceTotal1.add(serviceFee.multiply(divide).setScale(2, BigDecimal.ROUND_DOWN));
            chargingDegree2 =chargingDegree2.add(timeInterval.multiply(divide).setScale(2,BigDecimal.ROUND_DOWN));
        }
        XhpcStatisticsStation xhpcSt =new XhpcStatisticsStation();
        xhpcSt.setChargingDegree(chargingDegree2);
        xhpcSt.setChargingTime(timeInterval.divide(new BigDecimal(60),2,BigDecimal.ROUND_DOWN));
        xhpcSt.setChargingNumber(1);
        xhpcSt.setPowerPrice(powerPriceTotal1);
        xhpcSt.setServicePrice(servicePriceTotal1);
        xhpcSt.setActPowerPrice(powerPriceTotal1);
        xhpcSt.setActServicePrice(servicePriceTotal1);
        xhpcSt.setTotalPrice(powerPriceTotal1.add(servicePriceTotal1));
        BigDecimal actPrice2 =powerPriceTotal1.add(servicePriceTotal1);
        BigDecimal promotion =new BigDecimal(2);
        xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(promotion,2, BigDecimal.ROUND_DOWN));
        xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(promotion,2, BigDecimal.ROUND_DOWN));
        xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(promotion,2, BigDecimal.ROUND_DOWN));
        xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(promotion,2, BigDecimal.ROUND_DOWN));
        xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(promotion,2, BigDecimal.ROUND_DOWN));
        xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(promotion,2, BigDecimal.ROUND_DOWN));
        xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(promotion,2, BigDecimal.ROUND_DOWN));
        if(number==1){
            BigDecimal internetCommission = xhpcSt.getInternetCommission();
            if(internetCommission.compareTo(new BigDecimal(0))!=0){
                actPrice2 = actPrice2.subtract(internetCommission);
            }else{
                actPrice2 =actPrice2.subtract(xhpcSt.getInternetSvcCommission());
            }
            actPrice2 = actPrice2.subtract(xhpcSt.getPromotionDiscount());
            xhpcSt.setActPrice(actPrice2);
            //总金额
            BigDecimal totalPrice1 = xhpcSt.getTotalPrice();
            if(totalPrice.compareTo(totalPrice1)==1){
                totalPrice=totalPrice.subtract(totalPrice1);
            }else{
                xhpcSt.setTotalPrice(totalPrice);
            }
            //总电费
            BigDecimal powerPrice1 = xhpcSt.getPowerPrice();
            if(powerPriceTotal.compareTo(powerPrice1)==1){
                powerPriceTotal=powerPriceTotal.subtract(powerPrice1);
            }else{
                xhpcSt.setPowerPrice(powerPriceTotal);
            }
            //总服务费
            BigDecimal servicePrice1 = xhpcSt.getServicePrice();
            if(servicePriceTotal.compareTo(servicePrice1)==1){
                servicePriceTotal=servicePriceTotal.subtract(servicePrice1);
            }else{
                xhpcSt.setServicePrice(servicePriceTotal);
            }
            //实收电费
            BigDecimal actPowerPrice1 = xhpcSt.getActPowerPrice();
            if(actPowerPrice.compareTo(actPowerPrice1)==1){
                actPowerPrice=actPowerPrice.subtract(actPowerPrice1);
            }else{
                xhpcSt.setActPowerPrice(actPowerPrice);
            }
            //实收服务费
            BigDecimal actServicePrice1 = xhpcSt.getActServicePrice();
            if(actServicePrice.compareTo(actServicePrice1)==1){
                actServicePrice=actServicePrice.subtract(actServicePrice1);
            }else{
                xhpcSt.setActServicePrice(actServicePrice);
            }
            //总充电电量
            BigDecimal chargingDegree1 = xhpcSt.getChargingDegree();
            if(chargingDegree.compareTo(chargingDegree1)==1){
                chargingDegree=chargingDegree.subtract(chargingDegree1);
            }else{
                xhpcSt.setChargingDegree(chargingDegree);
            }

            //实际价格-用户支付的钱
            BigDecimal actPrice1 = xhpcSt.getActPrice();
            if(actPrice.compareTo(actPrice1)==1){
                actPrice=actPrice.subtract(actPrice1);
            }else{
                xhpcSt.setActPrice(actPrice);
            }
        }else{
            xhpcSt.setPowerPrice(powerPriceTotal);
            xhpcSt.setServicePrice(servicePriceTotal);
            xhpcSt.setTotalPrice(totalPrice);
            xhpcSt.setPromotionDiscount(promotionDiscount);
            xhpcSt.setActPrice(actPrice);
            xhpcSt.setActPowerPrice(actPowerPrice);
            xhpcSt.setActServicePrice(actServicePrice);
            xhpcSt.setChargingDegree(chargingDegree);
        }

        if(xhpc.getSource()==1){
            xhpcSt.setInternetUserId(xhpc.getUserId());
        }
        xhpcSt.setOperatorId(xhpc.getOperatorId());
        xhpcSt.setChargingStationId(xhpc.getChargingStationId());
        xhpcSt.setCreateTime(Calendar.getInstance().getTime());
        xhpcSt.setTerminalId(xhpc.getTerminalId());
        xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId());
        xhpcSt.setChargingPileId(xhpc.getChargingPileId());
        xhpcSt.setType(type);
        xhpcSt.setCreateTime(xhpc.getEndTime());
        xhpcStatisticsService.addStatisticsStation(xhpcSt);

        //修改历史订单表状态
        xhpcHistoryOrderService.updateXhpcHistoryOrder(xhpc.getHistoryOrderId(),type + 1);

        Map<String,BigDecimal> map2 =new HashMap<>();
        map2.put("totalPrice",totalPrice);
        map2.put("powerPriceTotal",powerPriceTotal);
        map2.put("servicePriceTotal",servicePriceTotal);
        map2.put("actPowerPrice",actPowerPrice);
        map2.put("actServicePrice",actServicePrice);
        map2.put("chargingDegree",chargingDegree);
        map2.put("promotionDiscount",promotionDiscount);
        map2.put("actPrice",actPrice);
        return map2;

    }

    /**
     * 小时统计
     */
    @GetMapping("/test")
    @Scheduled(cron = "0 0/5 * * * ?")
    public void test(){
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        try{
            //小时统计
            List<XhpcChargeHistoryOrder> list = xhpcHistoryOrderService.getStatistisList(500,0);
            if(list !=null && list.size()>0){
                for (XhpcChargeHistoryOrder xhpc:list) {
                    //开始时间、结束时间、模型id、状态、用户id、运营商、订单id、场站id、终端id、历史订单id、时间
                    Date startTime = xhpc.getStartTime();
                    Date endTime = xhpc.getEndTime();
                    Long rateModelId = xhpc.getRateModelId();
                    Long operatorId =xhpc.getOperatorId();
                    Long chargingStationId = xhpc.getChargingStationId();
                    Long terminalId = xhpc.getTerminalId();
                    Long historyOrderId = xhpc.getHistoryOrderId();
                    Date data = Calendar.getInstance().getTime();
                    if(xhpc.getTotalPrice().compareTo(new BigDecimal(0)) !=1){
                        continue;
                    }
                    if(xhpc.getChargingDegree().compareTo(new BigDecimal(0)) !=1){
                        continue;
                    }
                    //每分钟多少度电
                    BigDecimal v = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),2,BigDecimal.ROUND_DOWN);
                    if(v.compareTo(new BigDecimal(0)) !=1){
                        continue;
                    }
                    int endHour = DateUtil.hour(endTime, true);

                    //没有跨时段
                    XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval();
                    xhpcSt.setStatus(endHour+1);
                    xhpcSt.setChargingDegree(xhpc.getChargingDegree());
                    xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()).divide(new BigDecimal(3600),2, BigDecimal.ROUND_DOWN));
                    xhpcSt.setChargingNumber(1);
                    xhpcSt.setPowerPrice(xhpc.getPowerPriceTotal());
                    xhpcSt.setServicePrice(xhpc.getServicePriceTotal());
                    xhpcSt.setTotalPrice(xhpc.getTotalPrice());
                    xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount());
                    xhpcSt.setActPrice(xhpc.getActPrice());
                    xhpcSt.setActPowerPrice(xhpc.getActPowerPrice());
                    xhpcSt.setActServicePrice(xhpc.getActServicePrice());
                    xhpcSt.setInternetCommission(xhpc.getInternetCommission());
                    xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission());
                    xhpcSt.setPlatformCommission(xhpc.getPlatformCommission());
                    xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion());
                    xhpcSt.setOperationCommission(xhpc.getOperationCommission());
                    xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission());
                    xhpcSt.setOperatorId(operatorId);
                    xhpcSt.setChargingStationId(chargingStationId);
                    xhpcSt.setCreateTime(data);
                    xhpcSt.setTerminalId(terminalId);
                    xhpcSt.setHistoryOrderId(historyOrderId);
                    if(xhpc.getSource()==1){
                        xhpcSt.setInternetUserId(xhpc.getUserId());
                    }
                    List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(DateUtil.formatTime(startTime), DateUtil.formatTime(endTime), rateModelId);
                    Map<String, Object> map = reatTimeList.get(0);
                    xhpcSt.setElecPriceEvcs(new BigDecimal(map.get("powerFee").toString()));
                    xhpcSt.setServicePriceEvcs(new BigDecimal(map.get("serviceFee").toString()));
                    xhpcSt.setStartTimeEvcs(DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss"));
                    xhpcSt.setEndTimeEvcs(DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss"));
                    xhpcSt.setCreateTime(xhpc.getEndTime());
                    xhpcStatisticsService.addStatisticsTime(xhpcSt);
                    //修改历史订单表状态
                    xhpcHistoryOrderService.updateXhpcHistoryOrder(xhpc.getHistoryOrderId(),1);
                }
            }
        }catch (Exception e){

        }

    }



    /**
     * 小时统计(精确统计)
     */
    @GetMapping("/test8")
    //@Scheduled(cron = "0 0/5 * * * ?")
    public void test8(){
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务>>>>>>>>>>>>>>>>>>>>>");
        //获取500条待统计历史订单
        //跨时段，跨费率，计费模型
        try{
            //小时统计
            List<XhpcChargeHistoryOrder> list = xhpcHistoryOrderService.getStatistisList(500,0);
            if(list !=null && list.size()>0){
                for (XhpcChargeHistoryOrder xhpc:list) {
                    //开始时间、结束时间、模型id、状态、用户id、运营商、订单id、场站id、终端id、历史订单id、时间
                    Date startTime = xhpc.getStartTime();
                    Date endTime = xhpc.getEndTime();
                    Long rateModelId = xhpc.getRateModelId();
                    Long operatorId =xhpc.getOperatorId();
                    Long chargingStationId = xhpc.getChargingStationId();
                    Long terminalId = xhpc.getTerminalId();
                    Long historyOrderId = xhpc.getHistoryOrderId();
                    Date data = Calendar.getInstance().getTime();
                    if(xhpc.getTotalPrice().compareTo(new BigDecimal(0)) !=1){
                        continue;
                    }
                    if(xhpc.getChargingDegree().compareTo(new BigDecimal(0)) !=1){
                        continue;
                    }
                    //每分钟多少度电
                    BigDecimal v = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),2,BigDecimal.ROUND_DOWN);
                    if(v.compareTo(new BigDecimal(0)) !=1){
                        continue;
                    }
                    //1时间没有跨天
                    DateTime parse = DateUtil.parse(DateUtil.format(startTime, "yyyy-MM-dd"), "yyyy-MM-dd");
                    DateTime parse1 = DateUtil.parse(DateUtil.format(endTime, "yyyy-MM-dd"), "yyyy-MM-dd");
                    long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY);
                    if(betweenDay==0){
                        //没有跨天
                        //是否跨时段
                        int startHour = DateUtil.hour(startTime, true);
                        int endHour = DateUtil.hour(endTime, true);
                        if(endHour==startHour){
                            //没有跨时段
                            XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval();
                            xhpcSt.setStatus(endHour+1);
                            xhpcSt.setChargingDegree(xhpc.getChargingDegree());
                            xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()).divide(new BigDecimal(3600),2, BigDecimal.ROUND_DOWN));
                            xhpcSt.setChargingNumber(1);
                            xhpcSt.setPowerPrice(xhpc.getPowerPriceTotal());
                            xhpcSt.setServicePrice(xhpc.getServicePriceTotal());
                            xhpcSt.setTotalPrice(xhpc.getTotalPrice());
                            xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount());
                            xhpcSt.setActPrice(xhpc.getActPrice());
                            xhpcSt.setActPowerPrice(xhpc.getActPowerPrice());
                            xhpcSt.setActServicePrice(xhpc.getActServicePrice());
                            xhpcSt.setInternetCommission(xhpc.getInternetCommission());
                            xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission());
                            xhpcSt.setPlatformCommission(xhpc.getPlatformCommission());
                            xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion());
                            xhpcSt.setOperationCommission(xhpc.getOperationCommission());
                            xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission());
                            xhpcSt.setOperatorId(operatorId);
                            xhpcSt.setChargingStationId(chargingStationId);
                            xhpcSt.setCreateTime(data);
                            xhpcSt.setTerminalId(terminalId);
                            xhpcSt.setHistoryOrderId(historyOrderId);
                            if(xhpc.getSource()==1){
                                xhpcSt.setInternetUserId(xhpc.getUserId());
                            }
                            List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(DateUtil.formatTime(startTime), DateUtil.formatTime(endTime), rateModelId);
                            Map<String, Object> map = reatTimeList.get(0);
                            xhpcSt.setElecPriceEvcs(new BigDecimal(map.get("powerFee").toString()));
                            xhpcSt.setServicePriceEvcs(new BigDecimal(map.get("serviceFee").toString()));
                            xhpcSt.setStartTimeEvcs(DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss"));
                            xhpcSt.setEndTimeEvcs(DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss"));
                            xhpcSt.setCreateTime(xhpc.getEndTime());
                            xhpcStatisticsService.addStatisticsTime(xhpcSt);
                            //修改历史订单表状态
                            xhpcHistoryOrderService.updateXhpcHistoryOrder(xhpc.getHistoryOrderId(),1);
                        }else {
                            //总共多少时段
                            int number=endHour + 1 - startHour;
                            addStatisticsTime(new HashMap<String,BigDecimal>(),xhpc, startTime, endTime, rateModelId, startHour, endHour,1,number);
                        }
                    }else{
                        //跨天
                        Date updateTime2= DateUtil.endOfDay(startTime);
                        int startHour = DateUtil.hour(startTime, true);
                        int endHour = DateUtil.hour(updateTime2, true);
                        int number=endHour + 1 - startHour;

                        //明天
                        DateTime tomorrow = DateUtil.offsetDay(startTime,1);
                        Date startTime3 =DateUtil.beginOfDay(tomorrow);
                        int startHour1 = DateUtil.hour(startTime3, true);
                        int endHour1 = DateUtil.hour(endTime, true);
                        int number1=endHour1 + 1 - startHour1;
                        Map<String, BigDecimal> map = addStatisticsTime(new HashMap<String,BigDecimal>(),xhpc, startTime, updateTime2, rateModelId, startHour, endHour, 2, number + number1);
                        addStatisticsTime(map,xhpc, startTime3, endTime, rateModelId, startHour1, endHour1,3,number+number1);
                    }

                }
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务异常>>>>>>>>>>>>>>>>>>>>>");
            logger.info(">>>>>>>>>>>>>>>>>>>>>>>小时统计定时任务异常>>>>>>>>>>>>>>>>>>>>");
        }
    }

    /**
     *
     * @param xhpc
     * @param startTime
     * @param endTime
     * @param rateModelId
     * @param startHour
     * @param endHour
     * @param type        1 需要减去之前统计的值 2 不需要
     */
    private Map<String,BigDecimal> addStatisticsTime(Map<String,BigDecimal> map1,XhpcChargeHistoryOrder xhpc, Date startTime, Date endTime, Long rateModelId, int startHour, int endHour,int type,int number) {

        //跨时段
        //总共时段 endHour+1-startHour
        String yyyyMMdd = DateUtil.format(startTime, "yyyy-MM-dd");

        //总金额
        BigDecimal totalPrice =new BigDecimal(0);
        //总电费
        BigDecimal powerPriceTotal =new BigDecimal(0);
        //总服务费
        BigDecimal servicePriceTotal =new BigDecimal(0);
        //实收电费
        BigDecimal actPowerPrice =new BigDecimal(0);
        //实收服务费
        BigDecimal actServicePrice =new BigDecimal(0);
        //总充电电量
        BigDecimal chargingDegree =new BigDecimal(0);
        //电站活动抵扣--抵扣的总金额
        BigDecimal promotionDiscount =new BigDecimal(0);
        //实际价格-用户支付的钱
        BigDecimal actPrice =new BigDecimal(0);
        if(type==3){
            totalPrice =map1.get("totalPrice");
            powerPriceTotal =map1.get("powerPriceTotal");
            servicePriceTotal =map1.get("servicePriceTotal");
            actPowerPrice =map1.get("actPowerPrice");
            actServicePrice =map1.get("actServicePrice");
            chargingDegree =map1.get("chargingDegree");
            promotionDiscount =map1.get("promotionDiscount");
            actPrice =map1.get("actPrice");
        }else{
            totalPrice = xhpc.getTotalPrice();
            powerPriceTotal =xhpc.getPowerPriceTotal();
            servicePriceTotal =xhpc.getServicePriceTotal();
            actPowerPrice =xhpc.getActPowerPrice();
            actServicePrice =xhpc.getActServicePrice();
            chargingDegree =xhpc.getChargingDegree();
            promotionDiscount = xhpc.getPromotionDiscount();
            actPrice = xhpc.getActPrice();
        }
        //总时长
        BigDecimal time = new BigDecimal((xhpc.getEndTime().getTime()-xhpc.getStartTime().getTime())).divide(new BigDecimal(60000),2, BigDecimal.ROUND_DOWN);
        //每分钟多少度电
        BigDecimal decimal = chargingDegree.divide(time,2,BigDecimal.ROUND_DOWN);
        BigDecimal powerFee =new BigDecimal(0);
        BigDecimal serviceFee =new BigDecimal(0);
        BigDecimal timeInterval = new BigDecimal(0);
        String srt ="";
        String endt ="";
        for (int i = startHour; i < endHour + 1; i++) {
            String end = String.format("%02d", i);
            //获取费率
            if (i == startHour) {
                srt = DateUtil.formatTime(startTime);
                endt = end + ":59:59";
                Map<String, Object> map =getReatTimeList(srt,endt,rateModelId);
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
                timeInterval =new BigDecimal((DateUtil.parse(endt).getTime()-DateUtil.parse(srt).getTime())).divide(new BigDecimal(60000),2, BigDecimal.ROUND_DOWN);
            } else if (i != endHour) {
                srt = end + ":00:00";
                endt = end + ":59:59";
                Map<String, Object> map =getReatTimeList(srt,endt,rateModelId);
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
                timeInterval =new BigDecimal((DateUtil.parse(endt).getTime()-DateUtil.parse(srt).getTime())).divide(new BigDecimal(60000),2, BigDecimal.ROUND_DOWN);
            } else {
                srt = end + ":00:00";
                endt = DateUtil.formatTime(endTime);
                Map<String, Object> map =getReatTimeList(srt,endt,rateModelId);
                powerFee =new BigDecimal(map.get("powerFee").toString());
                serviceFee =new BigDecimal(map.get("serviceFee").toString());
                timeInterval =new BigDecimal((DateUtil.parse(endt).getTime()-DateUtil.parse(srt).getTime())).divide(new BigDecimal(60000),2, BigDecimal.ROUND_DOWN);
            }
            XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval();
            xhpcSt.setStatus(i+1);
            xhpcSt.setChargingTime(timeInterval.divide(new BigDecimal(60),2,BigDecimal.ROUND_DOWN));
            //电量
            BigDecimal decimal1 = timeInterval.multiply(decimal).setScale(2, BigDecimal.ROUND_DOWN);
            xhpcSt.setChargingDegree(decimal1);
            xhpcSt.setChargingNumber(1);
            xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(new BigDecimal(number),2,BigDecimal.ROUND_DOWN));
            if(i!=endHour || type==2){

                xhpcSt.setPowerPrice(powerFee.multiply(decimal1).setScale(2, BigDecimal.ROUND_DOWN));
                xhpcSt.setServicePrice(serviceFee.multiply(decimal1).setScale(2, BigDecimal.ROUND_DOWN));
                BigDecimal powerPrice =xhpcSt.getPowerPrice();
                BigDecimal servicePrice =xhpcSt.getServicePrice();
                xhpcSt.setTotalPrice(powerPrice.add(servicePrice));

                BigDecimal internetCommission = xhpcSt.getInternetCommission();

                BigDecimal actPrice2 = powerPrice.add(servicePrice);

                if(internetCommission.compareTo(new BigDecimal(0))!=0){
                    powerPrice =powerPrice.multiply(internetCommission.divide(new BigDecimal(2),2,BigDecimal.ROUND_DOWN));
                    servicePrice=servicePrice.multiply(internetCommission.divide(new BigDecimal(2),2,BigDecimal.ROUND_DOWN));
                    actPrice2 = actPrice2.subtract(internetCommission);
                }else{
                    servicePrice=servicePrice.multiply(xhpcSt.getInternetSvcCommission());
                    actPrice2 =actPrice2.subtract(xhpcSt.getInternetSvcCommission());
                }
                BigDecimal platformCommission = xhpcSt.getPlatformCommission();
                if(platformCommission.compareTo(new BigDecimal(0))!=0){
                    powerPrice =powerPrice.multiply(platformCommission.divide(new BigDecimal(2),2,BigDecimal.ROUND_DOWN));
                    servicePrice=servicePrice.multiply(platformCommission.divide(new BigDecimal(2),2,BigDecimal.ROUND_DOWN));
                }else{
                    servicePrice=servicePrice.multiply(xhpcSt.getPlatformSvcCommisssion());
                }

                BigDecimal operationCommission = xhpcSt.getOperationCommission();
                if(operationCommission.compareTo(new BigDecimal(0))!=0){
                    powerPrice =powerPrice.multiply(operationCommission.divide(new BigDecimal(2),2,BigDecimal.ROUND_DOWN));
                    servicePrice=servicePrice.multiply(operationCommission.divide(new BigDecimal(2),2,BigDecimal.ROUND_DOWN));
                }else{
                    servicePrice=servicePrice.multiply(xhpcSt.getOperationSvcCommission());
                }

                xhpcSt.setActPowerPrice(powerPrice);
                xhpcSt.setActServicePrice(servicePrice);

                xhpcSt.setElecPriceEvcs(powerFee);
                xhpcSt.setServicePriceEvcs(serviceFee);
                //电站活动抵扣--抵扣的总金额
                BigDecimal promotionDiscount1 = xhpcSt.getPromotionDiscount();
                if(promotionDiscount.compareTo(promotionDiscount1)==1){
                    promotionDiscount=promotionDiscount.subtract(promotionDiscount1);
                    actPrice2 = actPrice2.subtract(promotionDiscount1);
                }else{
                    xhpcSt.setPromotionDiscount(promotionDiscount);
                    actPrice2 = actPrice2.subtract(promotionDiscount);
                }
                xhpcSt.setActPrice(actPrice2);
                //总金额
                BigDecimal totalPrice1 = xhpcSt.getTotalPrice();
                if(totalPrice.compareTo(totalPrice1)==1){
                    totalPrice=totalPrice.subtract(totalPrice1);
                }else{
                    xhpcSt.setTotalPrice(totalPrice);
                }
                //总电费
                BigDecimal powerPrice1 = xhpcSt.getPowerPrice();
                if(powerPriceTotal.compareTo(powerPrice1)==1){
                    powerPriceTotal=powerPriceTotal.subtract(powerPrice1);
                }else{
                    xhpcSt.setPowerPrice(powerPriceTotal);
                }
                //总服务费
                BigDecimal servicePrice1 = xhpcSt.getServicePrice();
                if(servicePriceTotal.compareTo(servicePrice1)==1){
                    servicePriceTotal=servicePriceTotal.subtract(servicePrice1);
                }else{
                    xhpcSt.setServicePrice(servicePriceTotal);
                }
                //实收电费
                BigDecimal actPowerPrice1 = xhpcSt.getActPowerPrice();
                if(actPowerPrice.compareTo(actPowerPrice1)==1){
                    actPowerPrice=actPowerPrice.subtract(actPowerPrice1);
                }else{
                    xhpcSt.setActPowerPrice(actPowerPrice);
                }
                //实收服务费
                BigDecimal actServicePrice1 = xhpcSt.getActServicePrice();
                if(actServicePrice.compareTo(actServicePrice1)==1){
                    actServicePrice=actServicePrice.subtract(actServicePrice1);
                }else{
                    xhpcSt.setActServicePrice(actServicePrice);
                }
                //总充电电量
                BigDecimal chargingDegree1 = xhpcSt.getChargingDegree();
                if(chargingDegree.compareTo(chargingDegree1)==1){
                    chargingDegree=chargingDegree.subtract(chargingDegree1);
                }else{
                    xhpcSt.setChargingDegree(chargingDegree);
                }

                //实际价格-用户支付的钱
                BigDecimal actPrice1 = xhpcSt.getActPrice();
                if(actPrice.compareTo(actPrice1)==1){
                    actPrice=actPrice.subtract(actPrice1);
                }else{
                    xhpcSt.setActPrice(actPrice);
                }
            }else{
                xhpcSt.setPowerPrice(powerPriceTotal);
                xhpcSt.setServicePrice(servicePriceTotal);
                xhpcSt.setTotalPrice(totalPrice);
                xhpcSt.setPromotionDiscount(promotionDiscount);
                 xhpcSt.setActPrice(actPrice);
                xhpcSt.setActPowerPrice(actPowerPrice);
                 xhpcSt.setActServicePrice(actServicePrice);
                xhpcSt.setChargingDegree(chargingDegree);
            }
            xhpcSt.setActPrice(xhpcSt.getTotalPrice().subtract(xhpcSt.getPromotionDiscount()));
            if(xhpc.getSource()==1){
                xhpcSt.setInternetUserId(xhpc.getUserId());
            }
            xhpcSt.setOperatorId(xhpc.getOperatorId());
            xhpcSt.setChargingStationId(xhpc.getChargingStationId());
            xhpcSt.setDelFlag(0);
            xhpcSt.setCreateTime(xhpc.getEndTime());
            xhpcSt.setTerminalId(xhpc.getTerminalId());
            xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId());
            xhpcSt.setStartTimeEvcs(yyyyMMdd+" "+srt);
            xhpcSt.setEndTimeEvcs(yyyyMMdd+" "+endt);
            xhpcStatisticsService.addStatisticsTime(xhpcSt);
            //修改历史订单表状态
            xhpcHistoryOrderService.updateXhpcHistoryOrder(xhpc.getHistoryOrderId(),1);
        }
        Map<String,BigDecimal> map2 =new HashMap<>();
        map2.put("totalPrice",totalPrice);
        map2.put("powerPriceTotal",powerPriceTotal);
        map2.put("servicePriceTotal",servicePriceTotal);
        map2.put("actPowerPrice",actPowerPrice);
        map2.put("actServicePrice",actServicePrice);
        map2.put("chargingDegree",chargingDegree);
        map2.put("promotionDiscount",promotionDiscount);
        map2.put("actPrice",actPrice);
        return map2;
    }

    private Map<String, Object> getReatTimeList(String startTime,String endTime,Long rateModelId) {
        Map<String, Object> map =new HashMap<>();
        List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime,endTime, rateModelId);
        for (int j = 0; j < reatTimeList.size(); j++) {
            Map<String, Object> map1 = reatTimeList.get(j);
            return map1;
        }

        return map;
    }

    /**
     * 24小时异常订单自动结算
     */
    @GetMapping("/test4")
    @Scheduled(cron = "0 0/5 * * * ?")
    public void test4(){
           //获取异常的订单 24小时之外的异常订单
        List<XhpcChargeOrder> xhpcChargeOrderList= chargeOrderService.getXhpcChargeOrderStatus(2, 0);

        if(xhpcChargeOrderList !=null && xhpcChargeOrderList.size()>0){
            for (int i = 0; i <xhpcChargeOrderList.size() ; i++) {
                XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderList.get(i);
                xhpcHistoryOrderService.addXhpcChargeOrder(xhpcChargeOrder.getSerialNumber(),2);
            }
        }
    }

    /**
     * 标记异常大于创建4小时，标记为异常
     * @param
     * @param
     */
    @GetMapping("/test5")
    @Scheduled(cron = "0 0/5 * * * ?")
    public void test5(){
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>标记异常大于创建4小时，标记为异常>>>>>>>>>>>>>>>>>>>>>");
        chargeOrderService.updateStatus();
    }

    public void add(int number,int type){
        //获取500条待统计历史订单
        List<XhpcChargeHistoryOrder> list = xhpcHistoryOrderService.getStatistisList(number,type);
        //场站、运营商、流量方
        if(list !=null && list.size()>0){
            for (XhpcChargeHistoryOrder xhpc:list) {
                XhpcStatisticsStation xhpcSt =new XhpcStatisticsStation();
                xhpcSt.setChargingDegree(xhpc.getChargingDegree());
                xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()).divide(new BigDecimal(3600), 2, BigDecimal.ROUND_DOWN));
                xhpcSt.setChargingNumber(1);
                xhpcSt.setPowerPrice(xhpc.getPowerPriceTotal());
                xhpcSt.setServicePrice(xhpc.getServicePriceTotal());
                xhpcSt.setTotalPrice(xhpc.getTotalPrice());
                xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount());
                xhpcSt.setActPrice(xhpc.getActPrice());
                xhpcSt.setInternetCommission(xhpc.getInternetCommission());
                xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission());
                xhpcSt.setPlatformCommission(xhpc.getPlatformCommission());
                xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion());
                xhpcSt.setOperationCommission(xhpc.getOperationCommission());
                xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission());
                xhpcSt.setActPowerPrice(xhpc.getActPowerPrice());
                xhpcSt.setActServicePrice(xhpc.getActServicePrice());
                if(xhpc.getSource()==1){
                    xhpcSt.setInternetUserId(xhpc.getUserId());
                }
                xhpcSt.setOperatorId(xhpc.getOperatorId());
                xhpcSt.setChargingStationId(xhpc.getChargingStationId());
                xhpcSt.setCreateTime(Calendar.getInstance().getTime());
                xhpcSt.setTerminalId(xhpc.getTerminalId());
                xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId());
                xhpcSt.setChargingPileId(xhpc.getChargingPileId());
                xhpcSt.setType(type);
                xhpcSt.setCreateTime(xhpc.getEndTime());
                xhpcStatisticsService.addStatisticsStation(xhpcSt);

                //修改历史订单表状态
                xhpcHistoryOrderService.updateXhpcHistoryOrder(xhpc.getHistoryOrderId(),type+1);
            }
        }
    }

    public static void main(String[] args) {
//        String dateStr = "2017-03-01 20:33:23";
//        Date date = DateUtil.parse(dateStr);
//
//
//        String dateStr1 = "2017-03-01 22:33:23";
//        Date date1 = DateUtil.parse(dateStr1);
//
//        System.out.println(date1.getTime()-date.getTime());
//
//
//        DateTime startTime = DateUtil.parse("2021-10-19 17:35:19");
//        DateTime endTime = DateUtil.parse("2021-10-19 17:36:02");
//
//        //充电时长
//        Long tiem = (endTime.getTime() - startTime.getTime())/1000;
//        System.out.println(">>>>"+tiem);
//
//
//        BigDecimal decimal = new BigDecimal(72);
//        BigDecimal decimal1 = new BigDecimal(3600);
//
//        System.out.println(decimal.divide(decimal1,2,BigDecimal.ROUND_DOWN));

    }
}
