diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java index ddf8ee76..43067841 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java @@ -10,6 +10,7 @@ import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.data.redis.CacheOrderData; import com.xhpc.common.data.redis.CacheRealtimeData; +import com.xhpc.common.domain.XhpcRate; import com.xhpc.common.redis.service.RedisService; import com.xhpc.common.util.ConnectionRabbitMQUtil; import com.xhpc.order.domain.*; @@ -134,7 +135,7 @@ public class XhpcPileOrderController extends BaseController { BigDecimal decimal = new BigDecimal(10000); CacheRealtimeData cacheRealtimeData = list.get(number); xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal)); - xhpcChargeOrder.setChargingTimeNumber(cacheRealtimeData.getChargingTime()); + xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime())); xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal)); } }else{ @@ -201,25 +202,61 @@ public class XhpcPileOrderController extends BaseController { //获取实时订单 Map cacheMap = redisService.getCacheMap("order:"+orderNo); CacheOrderData cacheOrderData = (CacheOrderData)cacheMap.get("orderData"); + //获取充电订单 + XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); //解析订单编号 - Date date = new Date(); + Date date = new Date(); //总金额 BigDecimal bigDecimal = new BigDecimal(10000); BigDecimal money = new BigDecimal(cacheOrderData.getCost()).divide(bigDecimal); - int sumCost =cacheOrderData.getT1Cost()+cacheOrderData.getT2Cost()+cacheOrderData.getT3Cost()+cacheOrderData.getT4Cost(); - int sumService = cacheOrderData.getCost()-sumCost; + //00: 尖费率 01: 峰费率 02: 平费率 03: 谷费率 + BigDecimal t1powerFee =new BigDecimal(0); + BigDecimal t2powerFee =new BigDecimal(0); + BigDecimal t3powerFee =new BigDecimal(0); + BigDecimal t4powerFee =new BigDecimal(0); + //费率计费模型 + List rateModelList = xhpcChargeOrderService.getRateModelId(xhpcChargeOrder.getRateModelId()); + for (XhpcRate xhpcRate:rateModelList) { + if("00".equals(xhpcRate.getRateValue())){ + t1powerFee = xhpcRate.getPowerFee(); + } + if("01".equals(xhpcRate.getRateValue())){ + t2powerFee = xhpcRate.getPowerFee(); + } + if("02".equals(xhpcRate.getRateValue())){ + t3powerFee = xhpcRate.getPowerFee(); + } + if("03".equals(xhpcRate.getRateValue())){ + t4powerFee = xhpcRate.getPowerFee(); + } + } //总电费 - BigDecimal powerPrice = new BigDecimal(sumCost).divide(bigDecimal); + BigDecimal powerPrice =new BigDecimal(0); + if(!"0".equals(cacheOrderData.getT1PowerQuantity().toString())){ + BigDecimal multiply = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1powerFee); + powerPrice=powerPrice.add(multiply); + } + if(!"0".equals(cacheOrderData.getT2PowerQuantity().toString())){ + BigDecimal multiply = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2powerFee); + powerPrice=powerPrice.add(multiply); + } + if(!"0".equals(cacheOrderData.getT3PowerQuantity().toString())){ + BigDecimal multiply = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3powerFee); + powerPrice=powerPrice.add(multiply); + } + if(!"0".equals(cacheOrderData.getT4PowerQuantity().toString())){ + BigDecimal multiply = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4powerFee); + powerPrice=powerPrice.add(multiply); + } //总服务费 - BigDecimal servicePrice = new BigDecimal(sumService).divide(bigDecimal); + BigDecimal servicePrice = money.subtract(powerPrice); //剩余的电费 BigDecimal surplusPowerPrice = powerPrice; //剩余的服务费 BigDecimal surplusServicePrice = servicePrice; int startSoc = cacheOrderData.getStartSoc(); int endSoc = cacheOrderData.getEndSoc(); - //获取充电订单 - XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); + xhpcChargeOrder.setStartSoc(startSoc + ""); xhpcChargeOrder.setEndSoc(endSoc + ""); @@ -230,8 +267,6 @@ public class XhpcPileOrderController extends BaseController { DateTime endTime = DateUtil.parse(cacheOrderData.getEndTime()); xhpcChargeOrder.setStartTime(startTime); xhpcChargeOrder.setEndTime(endTime); - System.out.println(endTime.getTime()); - System.out.println(startTime.getTime()); //充电时长 Long tiem = (endTime.getTime() - startTime.getTime()) / 1000; if (tiem > 3600) { @@ -242,10 +277,10 @@ public class XhpcPileOrderController extends BaseController { double mins = (double) (tiem / 60); xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分"); } - xhpcChargeOrder.setChargingTimeNumber(tiem.intValue()); + xhpcChargeOrder.setChargingTimeNumber(tiem); BigDecimal divide = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(bigDecimal); - xhpcChargeOrder.setChargingDegree(divide.divide(bigDecimal)); - xhpcChargeOrder.setAmountCharged(money.divide(bigDecimal)); + xhpcChargeOrder.setChargingDegree(divide); + xhpcChargeOrder.setAmountCharged(money); String stopReason = cacheOrderData.getStopReason(); xhpcChargeOrder.setErroRemark(stopReason); xhpcChargeOrder.setUpdateTime(date); @@ -388,23 +423,22 @@ public class XhpcPileOrderController extends BaseController { xhpcHistoryOrder.setSortingStatus(0); xhpcHistoryOrder.setType(1); //订单总价---运维服务费抽成 - xhpcHistoryOrder.setTotalPrice(money); - xhpcHistoryOrder.setPromotionDiscount(promotionDiscount); - xhpcHistoryOrder.setActPrice(actPrice); - xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice); - xhpcHistoryOrder.setActServicePrice(surplusServicePrice); - xhpcHistoryOrder.setInternetCommission(internetCommission); - xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission); - xhpcHistoryOrder.setPlatformCommission(platformCommission); - xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission); - xhpcHistoryOrder.setOperationCommission(operationCommission); - xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission); + xhpcHistoryOrder.setTotalPrice(money.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setPromotionDiscount(promotionDiscount.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setActPrice(actPrice.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setActServicePrice(surplusServicePrice.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setInternetCommission(internetCommission.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setPlatformCommission(platformCommission.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setOperationCommission(operationCommission.setScale(2, BigDecimal.ROUND_HALF_UP)); + xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission.setScale(2, BigDecimal.ROUND_HALF_UP)); xhpcHistoryOrder.setStartSoc(startSoc+""); xhpcHistoryOrder.setEndSoc(endSoc+""); xhpcHistoryOrder.setReconciliationStatus(0); xhpcHistoryOrder.setCreateTime(date); - //扣除用户实际消费金额,添加消费记录 Map user = xhpcChargeOrderService.getUserMessage(userId); //剩余的钱 @@ -423,7 +457,7 @@ public class XhpcPileOrderController extends BaseController { try{ //发送短信 if(user.get("phone") !=null){ - String content = "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getChargingDegree() + ",总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"; + String content = "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + endSoc + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"; smsService.sendNotice(user.get("phone").toString(),content); } }catch (Exception e){ diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcChargeOrder.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcChargeOrder.java index fdfc684c..dfd31a21 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcChargeOrder.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcChargeOrder.java @@ -84,8 +84,8 @@ public class XhpcChargeOrder extends BaseEntity { /** 充电时长 */ private String chargingTime; - /** 充电时长(分) */ - private Integer chargingTimeNumber; + /** 充电时长(秒) */ + private Long chargingTimeNumber; /** 充电度数 */ private BigDecimal chargingDegree; @@ -312,12 +312,12 @@ public class XhpcChargeOrder extends BaseEntity { this.power = power; } - public Integer getChargingTimeNumber() { + public Long getChargingTimeNumber() { return chargingTimeNumber; } - public void setChargingTimeNumber(Integer chargingTimeNumber) { + public void setChargingTimeNumber(Long chargingTimeNumber) { this.chargingTimeNumber = chargingTimeNumber; } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java index 5696ea2f..2c14f833 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java @@ -1,5 +1,6 @@ package com.xhpc.order.mapper; +import com.xhpc.common.domain.XhpcRate; import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.order.domain.XhpcChargeOrder; import com.xhpc.order.domain.XhpcOrderRedisRecord; @@ -136,4 +137,8 @@ public interface XhpcChargeOrderMapper { */ int addUserAccountStatement(@Param("userId") Long userId,@Param("amount") BigDecimal amount,@Param("remainingSum") BigDecimal remainingSum,@Param("chargeOrderId") Long chargeOrderId,@Param("type") Integer type,@Param("date") Date date); + /** + * 获取费率 + */ + List getRateModelId(@Param("rateModelId")Long rateModelId); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java index c6b33e1c..b1707dda 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcChargeOrderService.java @@ -1,6 +1,7 @@ package com.xhpc.order.service; import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.domain.XhpcRate; import com.xhpc.order.domain.XhpcChargeOrder; import com.xhpc.order.domain.XhpcOrderRedisRecord; @@ -121,4 +122,9 @@ public interface IXhpcChargeOrderService { XhpcChargeOrder getChargingOrderId(Long chargingOrderId); + + /** + * 获取费率 + */ + List getRateModelId(Long rateModelId); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java index 15473cc4..b4d3cf31 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java @@ -6,6 +6,7 @@ import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.data.down.StartChargingData; import com.xhpc.common.data.redis.StaticBeanUtil; +import com.xhpc.common.domain.XhpcRate; import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.common.redis.service.RedisService; import com.xhpc.order.domain.XhpcChargeOrder; @@ -290,5 +291,10 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { return xhpcChargeOrderMapper.getChargingOrderId(chargingOrderId); } + @Override + public List getRateModelId(Long rateModelId) { + return xhpcChargeOrderMapper.getRateModelId(rateModelId); + } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java index 49b8ac6c..b04b4bb3 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java @@ -13,10 +13,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author yuyang @@ -92,56 +89,59 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { @Override public AjaxResult getExamine(Long chargingOrderId) { - //获取开始充电时间、结束时间、计费模型、充电度数、已充金额 XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(chargingOrderId); - String startTime = DateUtil.formatTime(chargeOrder.getStartTime()); - String endTime = DateUtil.formatTime(chargeOrder.getEndTime()); Long rateModelId = chargeOrder.getRateModelId(); - BigDecimal chargingDegree =chargeOrder.getChargingDegree(); + Date startTime2 = chargeOrder.getStartTime(); + Date updateTime2 = chargeOrder.getUpdateTime(); BigDecimal amountCharged = chargeOrder.getAmountCharged(); - //每分钟充电度数=累计时间/60 - BigDecimal s = chargingDegree.divide(new BigDecimal(60), 4, BigDecimal.ROUND_HALF_UP); + //充电度数 + BigDecimal chargingDegree = chargeOrder.getChargingDegree(); BigDecimal powerPriceTotal =new BigDecimal(0); //1时间没有跨天 - long betweenDay = DateUtil.between(chargeOrder.getStartTime(), chargeOrder.getEndTime(), DateUnit.DAY); + long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY); if(betweenDay==0){ - - }else{ - //跨天 - - } - - //获取费率时段集合 - List> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime, endTime, rateModelId); - if(reatTimeList !=null && reatTimeList.size()>0){ - int size = reatTimeList.size(); - if(size==1){ - BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString()); - powerPriceTotal = powerFee.multiply(s); - }else{ - for (int i = 0; i objectMap = reatTimeList.get(i); - BigDecimal powerFee =new BigDecimal(objectMap.get("powerFee").toString()); - String startTime1 = objectMap.get("startTime").toString(); - String endTime1 = objectMap.get("endTime").toString(); - if(i==0){ - powerPriceTotal=getRateTimeList(startTime1,endTime,s,powerFee,powerPriceTotal); - }else{ - if(size==2){ - powerPriceTotal=getRateTimeList(startTime1,endTime,s,powerFee,powerPriceTotal); + //算出相差时间,分 + double time = (updateTime2.getTime()-startTime2.getTime())/60000; + BigDecimal decimal = new BigDecimal(time).setScale(2); + //每分钟多少度 + BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_HALF_UP); + //获取费率时间段 + String startTime = DateUtil.formatTime(startTime2); + String endTime = DateUtil.formatTime(updateTime2); + List> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime, endTime, rateModelId); + if(reatTimeList !=null && reatTimeList.size()>0){ + int size = reatTimeList.size(); + if(size==1){ + BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString()); + powerPriceTotal = powerFee.multiply(chargingDegree).setScale(2); + }else{ + for (int i = 0; i objectMap = reatTimeList.get(i); + BigDecimal powerFee =new BigDecimal(objectMap.get("powerFee").toString()); + String startTime1 = objectMap.get("startTime").toString(); + String endTime1 = objectMap.get("endTime").toString(); + if(i==0){ + powerPriceTotal=getRateTimeList(startTime1,endTime,degree,powerFee,powerPriceTotal); }else{ - //三个时段以上 - if(i message = new HashMap<>(); diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml index 7d3ab6cb..a57296c7 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -53,6 +53,23 @@ + + + + + + + + + + + + + + + + + + select * from xhpc_rate where rate_model_id=#{rateModelId} and status=0 and del_flag=0 +