From 6919cff922ea336b356d092bf16268406baf269f Mon Sep 17 00:00:00 2001 From: yuyang Date: Thu, 13 Jan 2022 18:05:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E5=B8=B8=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/mapper/XhpcHistoryOrderMapper.java | 6 + .../service/IXhpcRealTimeOrderService.java | 5 + .../impl/XhpcHistoryOrderServiceImpl.java | 129 +++++++++++++++++- .../impl/XhpcRealTimeOrderServiceImpl.java | 5 + .../mapper/XhpcHistoryOrderMapper.xml | 45 ++++++ .../mapper/XhpcUserAccountStatementMapper.xml | 4 +- 6 files changed, 187 insertions(+), 7 deletions(-) diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java index 6c7f51af..334dff6b 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java @@ -112,4 +112,10 @@ public interface XhpcHistoryOrderMapper { * 获取登陆用户信息 */ Map getLandUser(@Param("userId")Long userId); + + + /** + * 查询启动订单表 + */ + Map getchargingOrderById(@Param("chargingOrderId")Long chargingOrderId); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java index b5137124..1bddceb4 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java @@ -138,4 +138,9 @@ public interface IXhpcRealTimeOrderService { */ Map addOrderTime(CacheRealtimeData cacheRealtimeData, XhpcChargeOrder xhpcChargeOrder, String orderNo, Integer type); + + /** + * 获取一条实时数据 + */ + XhpcRealTimeOrder getChargingOrderId(Long chargingOrderId,Integer type); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java index d49637f9..e32078a3 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java @@ -20,6 +20,7 @@ import com.xhpc.common.util.EvcsUtil; import com.xhpc.common.util.UserTypeUtil; import com.xhpc.order.domain.XhpcChargeOrder; import com.xhpc.order.domain.XhpcHistoryOrder; +import com.xhpc.order.domain.XhpcRealTimeOrder; import com.xhpc.order.dto.XhpcChargeHistoryOrder; import com.xhpc.order.mapper.XhpcHistoryOrderMapper; import com.xhpc.order.mapper.XhpcRealTimeOrderMapper; @@ -104,7 +105,95 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis @Override public AjaxResult gethistotyOrderMessage(HttpServletRequest request, Long userId, Long historyOrderId, Integer type, Long chargingOrderId) { LoginUser loginUser = tokenService.getLoginUser(request); - return AjaxResult.success(xhpcHistoryOrderMapper.gethistotyOrderMessage(loginUser.getUserid(), historyOrderId, type, chargingOrderId,loginUser.getTenantId())); + + Map map = xhpcHistoryOrderMapper.gethistotyOrderMessage(loginUser.getUserid(), historyOrderId, type, chargingOrderId, loginUser.getTenantId()); + if(map !=null){ + return AjaxResult.success(map); + } + //查询最后一帧数据 + if(chargingOrderId !=null){ + Map stringObjectMap = xhpcHistoryOrderMapper.getchargingOrderById(chargingOrderId); + if(stringObjectMap !=null){ + //获取该订单最后一条实时数据 + Map cacheMap = redisService.getCacheMap("order:" + stringObjectMap.get("serialNumber").toString()); + List list = (List) cacheMap.get("realtimeDataList"); + CacheRealtimeData startData =new CacheRealtimeData(); + CacheRealtimeData endData =new CacheRealtimeData(); + + Date startTime = null; + Date endTime = null; + BigDecimal amountCharged = new BigDecimal(0); + //充电度数 + BigDecimal chargingDegree = new BigDecimal(0); + if (list != null && list.size() > 0) { + endData =list.get(list.size()-1); + for (int i = 0; i 0){ + break; + } + } + } + Long rateModelId = Long.valueOf(stringObjectMap.get("rateModelId").toString()); + if(endData !=null && endData.getAmountCharged() !=null){ + //最后一祯时间 + endTime = DateUtil.parse(endData.getCreateTime()); + startTime =DateUtil.parse(startData.getCreateTime()); + //充电时长 + Long tiem = (endTime.getTime() - startTime.getTime()) / 1000; + if (tiem > 3600) { + long hours = tiem / 3600; + double mins = (double) ((tiem - (hours * 3600)) / 60); + stringObjectMap.put("chargingTime",hours + "时" + new BigDecimal(mins).setScale(0) + "分"); + } else { + double mins = (double) (tiem / 60); + stringObjectMap.put("chargingTime",new BigDecimal(mins).setScale(0) + "分"); + } + chargingDegree = new BigDecimal(endData.getChargingDegree()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_DOWN); + stringObjectMap.put("chargingDegree",chargingDegree); + amountCharged = new BigDecimal(endData.getAmountCharged()).divide(new BigDecimal(10000),2,BigDecimal.ROUND_DOWN); + stringObjectMap.put("actPrice",amountCharged); + }else{ + //当没有缓存数据时,查询数据库 + XhpcRealTimeOrder startRealTimeOrder = xhpcRealTimeOrderService.getChargingOrderId(chargingOrderId, 1); + XhpcRealTimeOrder endRealTimeOrder = xhpcRealTimeOrderService.getChargingOrderId(chargingOrderId, 2); + if(startRealTimeOrder==null || endRealTimeOrder==null){ + return AjaxResult.success(); + } + //最后一祯时间 + endTime = endRealTimeOrder.getCreateTime(); + startTime = startRealTimeOrder.getCreateTime(); + chargingDegree = endRealTimeOrder.getChargingDegree(); + stringObjectMap.put("chargingDegree",chargingDegree); + stringObjectMap.put("chargingTime",endRealTimeOrder.getChargingTime()); + amountCharged=endRealTimeOrder.getAmountCharged(); + stringObjectMap.put("actPrice",amountCharged); + } + BigDecimal powerPriceTotal =new BigDecimal(0); + //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"); + //每分钟多少度电 + BigDecimal decimal = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_DOWN); + BigDecimal divide = chargingDegree.divide(decimal,4,BigDecimal.ROUND_DOWN); + long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY); + if(betweenDay==0){ + powerPriceTotal = getBigDecimal(rateModelId,DateUtil.formatTime(startTime), DateUtil.formatTime(endTime), powerPriceTotal, divide); + }else{ + //跨天 + powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime), "23:59:59", powerPriceTotal, divide); + System.out.println(">>>>>>跨天前>>>>>>>"+powerPriceTotal); + //明天 + DateTime tomorrow = DateUtil.offsetDay(startTime,1); + Date startTime3 = DateUtil.beginOfDay(tomorrow); + powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime3), DateUtil.formatTime(endTime), powerPriceTotal, divide); + System.out.println(">>>>>>跨天后>>>>>>>"+powerPriceTotal); + } + stringObjectMap.put("actPowerPrice",powerPriceTotal); + } + return AjaxResult.success(stringObjectMap); + } + return AjaxResult.success(); } @Override @@ -803,11 +892,41 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis return powerPriceTotal; } - private BigDecimal getRateTimeList(String startTime, String endTime, BigDecimal degree, BigDecimal powerPrice) { - BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime()) / 60000).multiply(degree); - BigDecimal multiply = powerPrice.multiply(v).setScale(2, BigDecimal.ROUND_DOWN); - return multiply; + private BigDecimal getBigDecimal(Long rateModelId, String startTime, String updateTime, BigDecimal powerPriceTotal, BigDecimal divide) { + List> reatTimeList = getReatTimeList(startTime,updateTime, rateModelId); + for (int i = 0; i map = reatTimeList.get(i); + String startTime1 = map.get("startTime").toString(); + String endTime1 = map.get("endTime").toString(); + BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString()); + if("00:00:00".equals(endTime1)){ + endTime1="23:59:59"; + } + //获取费率 + if(size==1){ + powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,updateTime,divide,powerFee)); + }else{ + if(i==0){ + powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime1,divide,powerFee)); + } else if(i> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime,updateTime, rateModelId); for (int i = 0; i select user_id as userId,user_type as userType,operator_id as operatorId from sys_user where user_id =#{userId} + + diff --git a/xhpc-modules/xhpc-payment/src/main/resources/mapper/XhpcUserAccountStatementMapper.xml b/xhpc-modules/xhpc-payment/src/main/resources/mapper/XhpcUserAccountStatementMapper.xml index 4c20481c..9a6cdc92 100644 --- a/xhpc-modules/xhpc-payment/src/main/resources/mapper/XhpcUserAccountStatementMapper.xml +++ b/xhpc-modules/xhpc-payment/src/main/resources/mapper/XhpcUserAccountStatementMapper.xml @@ -139,10 +139,10 @@ and xau.app_user_id = #{appUserId} - and xau.tenant_id = #{tenantId} + and xuas.tenant_id = #{tenantId} - and xau.source = #{source} + and xuas.source = #{source} ORDER BY xuas.create_time DESC