diff --git a/xhpc-modules/xhpc-activity/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-activity/src/main/resources/bootstrap.yml index 0ea9a7b4..64326cc2 100644 --- a/xhpc-modules/xhpc-activity/src/main/resources/bootstrap.yml +++ b/xhpc-modules/xhpc-activity/src/main/resources/bootstrap.yml @@ -19,19 +19,19 @@ spring: nacos: discovery: # 服务注册地址 - server-addr: 127.0.0.1:8848 + server-addr: 172.31.183.135:8848 config: # 配置中心地址 - server-addr: 127.0.0.1:8848 + server-addr: 172.31.183.135:8848 # 配置文件格式 file-extension: yml # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} -logging: - level: - root: info - com.xhpc.activity.mapper: debug +#logging: +# level: +# root: info +# com.xhpc.activity.mapper: debug wx: diff --git a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcDataBigScreenServiceImpl.java b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcDataBigScreenServiceImpl.java index 45ddd633..295a97f4 100644 --- a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcDataBigScreenServiceImpl.java +++ b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcDataBigScreenServiceImpl.java @@ -18,7 +18,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; -import java.util.stream.Collectors; /** * @author WH @@ -709,12 +708,7 @@ public class XhpcDataBigScreenServiceImpl implements XhpcDataBigScreenService { realtimeOrders.setTotalItems((long) realtimeOrderList.size()); for (Map realtimeOrderMap : realtimeOrderList) { RealtimeOrders.RealtimeOrder realtimeOrder = new RealtimeOrders.RealtimeOrder(); - Integer userType = (Integer) realtimeOrderMap.get("source"); - if (userType == 1) { - realtimeOrder.setUserType((String) realtimeOrderMap.get("chargingMode")); - } else { - realtimeOrder.setUserType((String) realtimeOrderMap.get("sourceMap")); - } + realtimeOrder.setUserType((String) realtimeOrderMap.get("chargingMode")); realtimeOrder.setStartChargingTime((String) realtimeOrderMap.get("startTime")); realtimeOrder.setChargingTime((String) realtimeOrderMap.get("chargingTime")); realtimeOrder.setChargedElectric((Double) realtimeOrderMap.get("chargingDegree")); diff --git a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml index e5bbe391..7d697c7a 100644 --- a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml +++ b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml @@ -80,10 +80,18 @@ and find_in_set(tenant_id, #{tenantIdsStr}) - - + + AND area_code in (select code from xhpc_area where pcode in(select code from xhpc_area where pcode =xa.code)) + + AND area_code in (select code from xhpc_area where pcode =xa.code) + + + AND area_code =xa.code + + + AND area_code in (select code from xhpc_area where pcode in(select code from xhpc_area where pcode =xa.code)) @@ -97,30 +105,29 @@ FROM xhpc_area as xa WHERE 1=1 - + and xa.level =#{number} - - and (SELECT count(charging_station_id) FROM xhpc_charging_station - WHERE del_flag = 0 - AND area_code in (select code from xhpc_area where pcode in(select code from xhpc_area where pcode =xa.code)))>0 - and (SELECT count(charging_station_id) FROM xhpc_charging_station WHERE del_flag = 0 AND area_code in (select code from xhpc_area where pcode in(select code from xhpc_area where pcode =xa.code)))>0 - + and (SELECT count(charging_station_id) FROM xhpc_charging_station WHERE del_flag = 0 AND area_code in (select code from xhpc_area where pcode =xa.code))>0 + AND (xa.code in (select code from xhpc_area where pcode in(select code from xhpc_area where pcode =#{areaCode})) + or xa.code in (select code from xhpc_area where pcode =#{areaCode}) + ) and (SELECT count(charging_station_id) FROM xhpc_charging_station WHERE del_flag = 0 AND area_code =xa.code )>0 + and xa.code in (select code from xhpc_area where pcode =#{areaCode}) - + and xa.level =1 and (SELECT count(charging_station_id) FROM xhpc_charging_station WHERE del_flag = 0 diff --git a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcHistoryOrderMapper.xml b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcHistoryOrderMapper.xml index 0a5a77f6..853d09fa 100644 --- a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcHistoryOrderMapper.xml +++ b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcHistoryOrderMapper.xml @@ -129,7 +129,7 @@ FROM xhpc_history_order WHERE - del_flag = 0 + del_flag = 0 and charging_mode is not null and find_in_set(tenant_id, #{tenantIdsStr}) @@ -174,7 +174,7 @@ FROM mysql.help_topic t WHERE - t.help_topic_id 15 + t.help_topic_id 31 ) a LEFT JOIN ( SELECT @@ -193,7 +193,7 @@ #{chargingStationId} - AND end_time =]]> DATE_ADD( now(), INTERVAL - 15 DAY ) + AND end_time =]]> DATE_ADD( now(), INTERVAL - 31 DAY ) GROUP BY DATE_FORMAT( end_time, "%Y-%m-%d" )) b ON a.`current_time` = b.end_time ORDER BY diff --git a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcRateTimeMapper.xml b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcRateTimeMapper.xml index d3367893..065289dd 100644 --- a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcRateTimeMapper.xml +++ b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcRateTimeMapper.xml @@ -35,59 +35,46 @@ delete diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java index c2cd2618..e305ae78 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java @@ -902,26 +902,6 @@ public class XhpcHistoryOrderController extends BaseController { } } } - @GetMapping("/test44") - public void test44(){ - //获取异常的订单 24小时之外的异常订单 - List> xhpcChargeOrderList= chargeOrderService.getXhpcChargeOrderStatus(2); - - if(xhpcChargeOrderList !=null && xhpcChargeOrderList.size()>0){ - for (int i = 0; i map = xhpcChargeOrderList.get(i); - if(map !=null){ - Long chargeOrderId = Long.valueOf(map.get("chargeOrderId").toString()); - if(map.get("realTimeOrderId")!=null){ - Long realTimeOrderId = Long.valueOf(map.get("realTimeOrderId").toString()); - xhpcHistoryOrderService.addXhpcChargeOrder(realTimeOrderId,chargeOrderId); - }else{ - xhpcHistoryOrderService.addXhpcChargeOrder(null,chargeOrderId); - } - } - } - } - } /** * 标记异常大于创建4小时,标记为异常 diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/dto/RateTime.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/dto/RateTime.java new file mode 100644 index 00000000..75471976 --- /dev/null +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/dto/RateTime.java @@ -0,0 +1,35 @@ +package com.xhpc.order.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * @author yuyang + * @date 2022/5/13 14:31 + */ +@Data +public class RateTime implements Serializable { + /** + * 开始时间 + */ + private String startTime; + + /** + * 结束时间 + */ + private String endTime; + + /** + * 服务费 + */ + private BigDecimal servicePrice; + + /** + * 服务费 + */ + private BigDecimal powerPrice; + + private static final long serialVersionUID = 1L; +} diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java index 28026d6d..409cd57e 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java @@ -4,6 +4,7 @@ import com.xhpc.order.domain.XhpcChargeOrderCurrent; import com.xhpc.order.domain.XhpcChargeOrderSoc; import com.xhpc.order.domain.XhpcChargeOrderVoltage; import com.xhpc.order.domain.XhpcRealTimeOrder; +import com.xhpc.order.dto.RateTime; import com.xhpc.order.dto.XhpcActivityDiscountDto; import com.xhpc.order.dto.XhpcActivityFormulaDomainDto; import com.xhpc.order.dto.XhpcActivityInternetDomainDto; @@ -163,9 +164,15 @@ public interface XhpcRealTimeOrderMapper { List getActivityDiscountTime(@Param("internetUserId")Long internetUserId, @Param("startTime")String startTime, @Param("userType")Integer userType, @Param("chargingStationId")Long chargingStationId, @Param("tenantId")String tenantId); + /** + * 查询该时段的计费公式 + */ + List getActivityFormulaById(@Param("activityId") Integer activityId); + //获取场站的费率时段 + List getRateTimeList(@Param("chargingStationId")Long chargingStationId, @Param("rateModelId")Long rateModelId,@Param("rateValue") String rateValue); - + XhpcActivityFormulaDomainDto getActivityFormulaTimeById(@Param("activityId") Integer activityId,@Param("startTime") String startTime, @Param("endTime") String endTime); } 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 2cfe61a6..d6ee3cab 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 @@ -465,8 +465,8 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis map1.put("chargingDegree", chargeOrder.getChargingDegree()); map1.put("actPrice", totalPrice); list.add(map1); - map.put("powerPriceTotal", 0); - map.put("servicePriceTotal", 0); + // map.put("powerPriceTotal", 0); + // map.put("servicePriceTotal", 0); map.put("list", list);//数据列表 return map; } @@ -483,8 +483,8 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis map1.put("actPrice", totalPrice); list.add(map1); map.put("list", list);//数据列表 - map.put("powerPriceTotal", 0); - map.put("servicePriceTotal", 0); + // map.put("powerPriceTotal", 0); + // map.put("servicePriceTotal", 0); return map; } //每分钟多少度 @@ -537,8 +537,8 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis } } } - map.put("powerPriceTotal", powerPriceTotal); - map.put("servicePriceTotal", servicePriceTotal); + // map.put("powerPriceTotal", powerPriceTotal); + // map.put("servicePriceTotal", servicePriceTotal); map.put("list", list);//数据列表 //map.put("chargingTimeTotal",chargeOrder.getChargingTime());//总时长 //map.put("powerPriceTotal",powerPriceTotal);//总电费单价(元/度) 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 18ec9820..ac18eb31 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 @@ -18,6 +18,7 @@ import com.xhpc.common.security.service.TokenService; import com.xhpc.common.util.EvcsUtil; import com.xhpc.common.util.UserTypeUtil; import com.xhpc.order.domain.*; +import com.xhpc.order.dto.RateTime; import com.xhpc.order.dto.XhpcActivityDiscountDto; import com.xhpc.order.dto.XhpcActivityFormulaDomainDto; import com.xhpc.order.dto.XhpcActivityInternetDomainDto; @@ -355,6 +356,20 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe Integer source = xhpcChargeOrder.getSource(); String tenantId = xhpcChargeOrder.getTenantId(); Map userMessage =new HashMap<>(); + XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder(); + + if(xhpcChargeOrder.getStartTime() ==null || xhpcChargeOrder.getEndTime()==null){ + //获取实时数据 + Map cacheMap = redisService.getCacheMap("order:"+xhpcChargeOrder.getSerialNumber()); + if(cacheMap !=null && cacheMap.get("realtimeDataList") !=null){ + List list = (List) cacheMap.get("realtimeDataList"); + if(list !=null && list.size()>0){ + xhpcChargeOrder.setEndTime(DateUtil.parse(list.get(list.size()-1).getCreateTime(),"yyyy-MM-dd HH:mm:ss")); + xhpcChargeOrder.setStartTime(DateUtil.parse(list.get(0).getCreateTime(),"yyyy-MM-dd HH:mm:ss")); + } + } + } + if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ R user = userTypeService.getUser(null, userId, source, null, tenantId); boolean judge = false; @@ -374,9 +389,15 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); return AjaxResult.error("用户id:" + userId + "为空"); } + }else{ + xhpcHistoryOrder.setInternetSerialNumber(xhpcChargeOrder.getInternetSerialNumber()); + Map pushOrder = redisService.getCacheMap("pushOrder:"+xhpcChargeOrder.getSerialNumber()); + if(pushOrder.get("operatorId3rdpty") !=null){ + xhpcHistoryOrder.setOperatorId3rdptyEvcs((String) pushOrder.get("operatorId3rdpty")); + } } //生成一条历史订单 - XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder(); + xhpcHistoryOrder.setStartTime(xhpcChargeOrder.getStartTime()); if(xhpcChargeOrder.getEndTime()==null ){ xhpcHistoryOrder.setEndTime(xhpcChargeOrder.getStartTime()); @@ -461,6 +482,8 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe Date endTime = xhpcChargeOrder.getEndTime(); Integer source = xhpcChargeOrder.getSource(); String internetSerialNumber = xhpcChargeOrder.getInternetSerialNumber(); + Long chargingStationId = xhpcChargeOrder.getChargingStationId(); + String tenantId = xhpcChargeOrder.getTenantId(); //判断是否有活动 logger.info("<<<<<<<<<<<<<<<判断是否有活动>>>>>>>>>>>>>>>>>"+xhpcChargeOrder.getSerialNumber()); boolean judge =false; @@ -468,100 +491,123 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe xhpcHistoryOrder.setChargingMode(xhpcChargeOrder.getUserId()+""); xhpcHistoryOrder.setInternetSerialNumber(xhpcChargeOrder.getInternetSerialNumber()); Double totalPower = xhpcHistoryOrder.getTotalPower(); - //yyyy-mm-dd(当前时间) - String parse2 = DateUtil.formatDate(startTime); - long time1 = startTime.getTime(); - long time2 = endTime.getTime(); - if( time1 != time2 && time2>time1){ - List activityStationTime = xhpcRealTimeOrderMapper.getActivityStationTime(internetUserId, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime), xhpcChargeOrder.getChargingStationId(), xhpcChargeOrder.getTenantId()); - //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); + Map judgeActivity= getRateOrActivityFormul(xhpcChargeOrder.getSerialNumber(), internetUserId, startTime, endTime, chargingStationId, tenantId, xhpcChargeOrder.getRateModelId()); - if(activityStationTime !=null && activityStationTime.size()==1){ - logger.info("<<<<<<<<<<<<<<<有流量方活动>>>>>>>>>>>>>>>>>"+xhpcChargeOrder.getSerialNumber()); - judge =true; + Map params1 =new HashMap<>(); + if("1".equals(judgeActivity.get("status").toString())){ + params1.put("T",money.doubleValue()); + params1.put("P",powerPrice.doubleValue()); + params1.put("S",servicePrice.doubleValue()); + params1.put("E",totalPower); + String computeFormula = judgeActivity.get("computeFormula").toString(); + int computeType = (int)judgeActivity.get("computeType"); + BigDecimal eval = new BigDecimal(Calc.eval(computeFormula, params1)).setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总服务费 + activityServicePriceTotal = servicePrice.setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总电费 + activityPowerPriceTotal = powerPrice.setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总金额 + activityTotalPriceTotal = money; + if(computeType==1){ + BigDecimal decimal1 = eval.multiply(new BigDecimal(0.5)).setScale(2, BigDecimal.ROUND_HALF_UP); + internetCommission = internetCommission.add(eval); + activityPowerPrice =activityPowerPrice.add(activityPowerPriceTotal.subtract(decimal1)); + activityServicePrice =activityServicePrice.add(activityServicePriceTotal.subtract(decimal1)); + }else if(computeType==2){ + internetSvcCommission = internetSvcCommission.add(eval); + activityServicePrice =activityServicePrice.add(activityServicePriceTotal.subtract(eval)); + activityPowerPrice =activityPowerPrice.add(activityPowerPriceTotal); + }else{ + //电量抽成 + internetDegreeCommission = internetDegreeCommission.add(eval); + //减服务费 + activityServicePrice =activityServicePrice.add(activityServicePriceTotal.subtract(eval)); + activityPowerPrice =activityPowerPrice.add(activityPowerPriceTotal); + } + promotionDiscount = money.subtract(activityTotalPriceTotal); + xhpcHistoryOrder.setActivityId(judgeActivity.get("activityId").toString()); + }else if("2".equals(judgeActivity.get("status").toString())){ - String start = DateUtil.formatTime(startTime); - String end = DateUtil.formatTime(endTime); - String activityId =""; - BigDecimal chargingDegree = new BigDecimal(0); - Map params =new HashMap<>(); - List activityFormulaTime1 =new ArrayList<>(); - List activityFormulaTime2 =new ArrayList<>(); - XhpcActivityInternetDomainDto activityInternet1 =new XhpcActivityInternetDomainDto(); - Long rateModelId = xhpcChargeOrder.getRateModelId(); - if(betweenDay>0){ - activityInternet1 = activityStationTime.get(0); - activityFormulaTime1 = xhpcRealTimeOrderMapper.getActivityFormulaTime(activityInternet1.getActivityId(), start, "24:00:00"); - activityFormulaTime2 = xhpcRealTimeOrderMapper.getActivityFormulaTime(activityInternet1.getActivityId(), "00:00:00", end); - activityId =activityInternet1.getActivityId()+""; - }else{ - activityInternet1 = activityStationTime.get(0); - activityFormulaTime1 = xhpcRealTimeOrderMapper.getActivityFormulaTime(activityInternet1.getActivityId(), start, end); - activityId =activityInternet1.getActivityId()+""; - } - for (int j = 0; j < activityFormulaTime1.size(); j++) { - XhpcActivityFormulaDomainDto activityFormula = activityFormulaTime1.get(j); - //计费类型 - int computeType = activityInternet1.getComputeType(); - BigDecimal activityServicePriceFormula = activityFormula.getServicePrice(); - BigDecimal activityPowerPriceFormula = activityFormula.getPowerPrice(); - //计算公式 - String computeFormula = activityFormula.getComputeFormula(); - BigDecimal degree =new BigDecimal(0); - if (activityFormulaTime2.size()==0 && activityFormulaTime1.size()-1==j) { - degree = new BigDecimal(totalPower).subtract(chargingDegree).setScale(2, BigDecimal.ROUND_HALF_UP); + String computeFormula = judgeActivity.get("computeFormula").toString(); + BigDecimal powerPrice1 = new BigDecimal(judgeActivity.get("powerPrice").toString()); + BigDecimal servicePrice1 = new BigDecimal(judgeActivity.get("servicePrice").toString()); + //活动总服务费 + activityServicePriceTotal = servicePrice1.multiply(new BigDecimal(totalPower)).setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总电费 + activityPowerPriceTotal = powerPrice1.multiply(new BigDecimal(totalPower)).setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总金额 + activityTotalPriceTotal = activityServicePriceTotal.add(activityPowerPriceTotal); + params1.put("T",activityTotalPriceTotal.doubleValue()); + params1.put("P",activityPowerPriceTotal.doubleValue()); + params1.put("S",activityServicePriceTotal.doubleValue()); + params1.put("E",totalPower); + + int computeType = (int)judgeActivity.get("computeType"); + BigDecimal eval = new BigDecimal(Calc.eval(computeFormula, params1)).setScale(2, BigDecimal.ROUND_HALF_UP); + if(computeType==1){ + BigDecimal decimal1 = eval.multiply(new BigDecimal(0.5)).setScale(2, BigDecimal.ROUND_HALF_UP); + internetCommission = internetCommission.add(eval); + activityPowerPrice =activityPowerPrice.add(activityPowerPriceTotal.subtract(decimal1)); + activityServicePrice =activityServicePrice.add(activityServicePriceTotal.subtract(decimal1)); + }else if(computeType==2){ + internetSvcCommission = internetSvcCommission.add(eval); + activityServicePrice =activityServicePrice.add(activityServicePriceTotal.subtract(eval)); + activityPowerPrice =activityPowerPrice.add(activityPowerPriceTotal); + }else{ + //电量抽成 + internetDegreeCommission = internetDegreeCommission.add(eval); + //减服务费 + activityServicePrice =activityServicePrice.add(activityServicePriceTotal.subtract(eval)); + activityPowerPrice =activityPowerPrice.add(activityPowerPriceTotal); + } + promotionDiscount = money.subtract(activityTotalPriceTotal); + xhpcHistoryOrder.setActivityId(judgeActivity.get("activityId").toString()); + }else{ + boolean activityInternet =false; + //yyyy-mm-dd(当前时间) + String parse2 = DateUtil.formatDate(startTime); + long time1 = startTime.getTime(); + long time2 = endTime.getTime(); + + if( time1 != time2 && time2>time1){ + List activityStationTime = xhpcRealTimeOrderMapper.getActivityStationTime(internetUserId, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime), chargingStationId, tenantId); + //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(activityStationTime !=null && activityStationTime.size()==1){ + logger.info("<<<<<<<<<<<<<<<有流量方活动>>>>>>>>>>>>>>>>>"+xhpcChargeOrder.getSerialNumber()); + judge =true; + + String start = DateUtil.formatTime(startTime); + String end = DateUtil.formatTime(endTime); + String activityId =""; + BigDecimal chargingDegree = new BigDecimal(0); + Map params =new HashMap<>(); + List activityFormulaTime1 =new ArrayList<>(); + List activityFormulaTime2 =new ArrayList<>(); + XhpcActivityInternetDomainDto activityInternet1 =new XhpcActivityInternetDomainDto(); + if(betweenDay>0){ + activityInternet1 = activityStationTime.get(0); + activityFormulaTime1 = xhpcRealTimeOrderMapper.getActivityFormulaTime(activityInternet1.getActivityId(), start, "24:00:00"); + activityFormulaTime2 = xhpcRealTimeOrderMapper.getActivityFormulaTime(activityInternet1.getActivityId(), "00:00:00", end); + activityId =activityInternet1.getActivityId()+""; }else{ - degree =getRealOrderTime(chargeOrderId, parse2+" "+activityFormula.getStartTime(), parse2+" "+activityFormula.getEndTime()).setScale(2,BigDecimal.ROUND_HALF_UP);; + activityInternet1 = activityStationTime.get(0); + activityFormulaTime1 = xhpcRealTimeOrderMapper.getActivityFormulaTime(activityInternet1.getActivityId(), start, end); + activityId =activityInternet1.getActivityId()+""; } - //挡前服务费 - BigDecimal activityServicePrice1 = activityServicePriceFormula.multiply(degree).setScale(2, BigDecimal.ROUND_HALF_UP); - //活动总服务费 - activityServicePriceTotal = activityServicePriceTotal.add(activityServicePrice1).setScale(2, BigDecimal.ROUND_HALF_UP); - //挡前电费 - BigDecimal activityPowerPrice1 = activityPowerPriceFormula.multiply(degree).setScale(2, BigDecimal.ROUND_HALF_UP); - //活动总电费 - activityPowerPriceTotal = activityPowerPriceTotal.add(activityPowerPrice1).setScale(2, BigDecimal.ROUND_HALF_UP); - //活动总金额 - activityTotalPriceTotal = activityTotalPriceTotal.add(activityServicePrice1.add(activityPowerPrice1)); - params.put("T",activityPowerPrice1.add(activityServicePrice1).doubleValue()); - params.put("P",activityPowerPrice1.doubleValue()); - params.put("S",activityServicePrice1.doubleValue()); - params.put("E",degree.doubleValue()); - //支付给流量方的钱 - BigDecimal eval = new BigDecimal(Calc.eval(computeFormula, params)).setScale(2, BigDecimal.ROUND_HALF_UP); - if(computeType==1){ - BigDecimal decimal1 = eval.multiply(new BigDecimal(0.5)).setScale(2, BigDecimal.ROUND_HALF_UP); - internetCommission = internetCommission.add(eval); - activityPowerPrice =activityPowerPrice.add(activityPowerPrice1.subtract(decimal1)); - activityServicePrice =activityServicePrice.add(activityServicePrice1.subtract(decimal1)); - }else if(computeType==2){ - internetSvcCommission = internetSvcCommission.add(eval); - activityServicePrice =activityServicePrice.add(activityServicePrice1.subtract(eval)); - activityPowerPrice =activityPowerPrice.add(activityPowerPrice1); - }else{ - //电量抽成 - internetDegreeCommission = internetDegreeCommission.add(eval); - //减服务费 - activityServicePrice =activityServicePrice.add(activityServicePrice1.subtract(eval)); - activityPowerPrice =activityPowerPrice.add(activityPowerPrice1); - } - chargingDegree = chargingDegree.add(degree); - } - if(activityFormulaTime2.size()>0){ - for (int j = 0; j < activityFormulaTime2.size(); j++) { + for (int j = 0; j < activityFormulaTime1.size(); j++) { + XhpcActivityFormulaDomainDto activityFormula = activityFormulaTime1.get(j); //计费类型 int computeType = activityInternet1.getComputeType(); - XhpcActivityFormulaDomainDto activityFormula = activityFormulaTime2.get(j); BigDecimal activityServicePriceFormula = activityFormula.getServicePrice(); BigDecimal activityPowerPriceFormula = activityFormula.getPowerPrice(); //计算公式 String computeFormula = activityFormula.getComputeFormula(); BigDecimal degree =new BigDecimal(0); - if (activityFormulaTime2.size()-1==j) { + if (activityFormulaTime2.size()==0 && activityFormulaTime1.size()-1==j) { degree = new BigDecimal(totalPower).subtract(chargingDegree).setScale(2, BigDecimal.ROUND_HALF_UP); }else{ degree =getRealOrderTime(chargeOrderId, parse2+" "+activityFormula.getStartTime(), parse2+" "+activityFormula.getEndTime()).setScale(2,BigDecimal.ROUND_HALF_UP);; @@ -600,18 +646,110 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe } chargingDegree = chargingDegree.add(degree); } - } - promotionDiscount = money.subtract(activityTotalPriceTotal); - xhpcHistoryOrder.setActivityId(activityId); - }else{ - if(activityStationTime.size()>1){ - xhpcHistoryOrder.setActivityId("同一时间活动有2个"); + if(activityFormulaTime2.size()>0){ + for (int j = 0; j < activityFormulaTime2.size(); j++) { + //计费类型 + int computeType = activityInternet1.getComputeType(); + XhpcActivityFormulaDomainDto activityFormula = activityFormulaTime2.get(j); + BigDecimal activityServicePriceFormula = activityFormula.getServicePrice(); + BigDecimal activityPowerPriceFormula = activityFormula.getPowerPrice(); + //计算公式 + String computeFormula = activityFormula.getComputeFormula(); + BigDecimal degree =new BigDecimal(0); + if (activityFormulaTime2.size()-1==j) { + degree = new BigDecimal(totalPower).subtract(chargingDegree).setScale(2, BigDecimal.ROUND_HALF_UP); + }else{ + degree =getRealOrderTime(chargeOrderId, parse2+" "+activityFormula.getStartTime(), parse2+" "+activityFormula.getEndTime()).setScale(2,BigDecimal.ROUND_HALF_UP);; + } + //挡前服务费 + BigDecimal activityServicePrice1 = activityServicePriceFormula.multiply(degree).setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总服务费 + activityServicePriceTotal = activityServicePriceTotal.add(activityServicePrice1).setScale(2, BigDecimal.ROUND_HALF_UP); + //挡前电费 + BigDecimal activityPowerPrice1 = activityPowerPriceFormula.multiply(degree).setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总电费 + activityPowerPriceTotal = activityPowerPriceTotal.add(activityPowerPrice1).setScale(2, BigDecimal.ROUND_HALF_UP); + //活动总金额 + activityTotalPriceTotal = activityTotalPriceTotal.add(activityServicePrice1.add(activityPowerPrice1)); + params.put("T",activityPowerPrice1.add(activityServicePrice1).doubleValue()); + params.put("P",activityPowerPrice1.doubleValue()); + params.put("S",activityServicePrice1.doubleValue()); + params.put("E",degree.doubleValue()); + //支付给流量方的钱 + BigDecimal eval = new BigDecimal(Calc.eval(computeFormula, params)).setScale(2, BigDecimal.ROUND_HALF_UP); + if(computeType==1){ + BigDecimal decimal1 = eval.multiply(new BigDecimal(0.5)).setScale(2, BigDecimal.ROUND_HALF_UP); + internetCommission = internetCommission.add(eval); + activityPowerPrice =activityPowerPrice.add(activityPowerPrice1.subtract(decimal1)); + activityServicePrice =activityServicePrice.add(activityServicePrice1.subtract(decimal1)); + }else if(computeType==2){ + internetSvcCommission = internetSvcCommission.add(eval); + activityServicePrice =activityServicePrice.add(activityServicePrice1.subtract(eval)); + activityPowerPrice =activityPowerPrice.add(activityPowerPrice1); + }else{ + //电量抽成 + internetDegreeCommission = internetDegreeCommission.add(eval); + //减服务费 + activityServicePrice =activityServicePrice.add(activityServicePrice1.subtract(eval)); + activityPowerPrice =activityPowerPrice.add(activityPowerPrice1); + } + chargingDegree = chargingDegree.add(degree); + } + } + promotionDiscount = money.subtract(activityTotalPriceTotal); + xhpcHistoryOrder.setActivityId(activityId); }else{ - xhpcHistoryOrder.setActivityId("无活动"); + //按照以前流量方折扣计算 + if(activityStationTime.size()>1){ + xhpcHistoryOrder.setActivityId("同一时间活动有2个"); + }else{ + xhpcHistoryOrder.setActivityId("无活动"); + } + activityInternet =true; + } + }else{ + activityInternet =true; + xhpcHistoryOrder.setActivityId("充电开始结束时间相等不做活动"); + } + if(activityInternet){ + logger.info("无活动,流量方按照以前抽成"); + String substring = internetSerialNumber.substring(0, 9); + xhpcHistoryOrder.setInternetSerialNumber(xhpcChargeOrder.getInternetSerialNumber()); + Map operatorIdEvcs = xhpcRealTimeOrderMapper.getOperatorIdEvcs(substring); + if(operatorIdEvcs !=null){ + if(operatorIdEvcs.get("operatorIdEvcs")!=null && operatorIdEvcs.get("commissionType")!=null && operatorIdEvcs.get("commissionRate")!=null){ + BigDecimal commissionRate = new BigDecimal(operatorIdEvcs.get("commissionRate").toString()).divide(new BigDecimal(100)); + String commissionType = operatorIdEvcs.get("commissionType").toString(); + if(operatorIdEvcs.get("internetUserId") !=null){ + xhpcHistoryOrder.setChargingMode(operatorIdEvcs.get("internetUserId").toString()); + } + //0总金额提成 1服务费提成 + if(new BigDecimal(0).compareTo(commissionRate)==-1){ + if("0".equals(commissionType) || "1".equals(commissionType)|| "2".equals(commissionType)){ + //流量方的钱 + if("0".equals(commissionType)){ + BigDecimal decimal1 = surplusPowerPrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); + internetCommission = decimal1.add(decimal2); + surplusPowerPrice =surplusPowerPrice.subtract(decimal1); + surplusServicePrice =surplusServicePrice.subtract(decimal2); + }else if("1".equals(commissionType)){ + BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_DOWN); + internetSvcCommission = decimal2; + surplusServicePrice = surplusServicePrice.subtract(decimal2); + }else{ + //电量抽成 + BigDecimal chargingDegree = xhpcChargeOrder.getChargingDegree(); + internetDegreeCommission = chargingDegree.multiply(new BigDecimal(operatorIdEvcs.get("commissionRate").toString())).setScale(2, BigDecimal.ROUND_DOWN); + //减服务费 + surplusServicePrice = surplusServicePrice.subtract(internetDegreeCommission); + } + } + } + } } } - }else{ - xhpcHistoryOrder.setActivityId("充电开始结束时间相等不做活动"); + } } // @@ -1453,11 +1591,122 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe //判斷活动时间、电费、服务费、公式是否和场站一致 - private boolean getRateOrActivityFormul(){ + private Map getRateOrActivityFormul(String serialNumber,Long internetUserId,Date startTime,Date endTime,Long chargingStationId,String tenantId,Long rateModelId){ + Map map =new HashMap<>(); + List activityStationTime = xhpcRealTimeOrderMapper.getActivityStationTime(internetUserId, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime), chargingStationId, tenantId); + if(activityStationTime !=null && activityStationTime.size()==1) { + //活动的时间、电费、服务费、公式 + Integer activityId = activityStationTime.get(0).getActivityId(); + int computeType = activityStationTime.get(0).getComputeType(); + List activityFormulaList = xhpcRealTimeOrderMapper.getActivityFormulaById(activityId); + //场站的电费和服务费 + List rateTimeList = xhpcRealTimeOrderMapper.getRateTimeList(chargingStationId, rateModelId, null); + String computeFormula = ""; + if (activityFormulaList != null && rateTimeList != null && activityFormulaList.size() > 0 && activityFormulaList.size() == rateTimeList.size()) { + for (int i = 0; i < activityFormulaList.size(); i++) { + XhpcActivityFormulaDomainDto activit = activityFormulaList.get(i); + RateTime rateTime = rateTimeList.get(i); + if (activit.getStartTime().equals(rateTime.getStartTime()) && activit.getEndTime().equals(rateTime.getEndTime()) && + activit.getServicePrice().compareTo(rateTime.getServicePrice()) == 0 && activit.getPowerPrice().compareTo(rateTime.getPowerPrice()) == 0) { + if (i == 0) { + computeFormula = activit.getComputeFormula(); + } else if (i != activityFormulaList.size() - 1) { + if (!computeFormula.equals(activit.getComputeFormula())) { + break; + } + } else { + if (!computeFormula.equals(activit.getComputeFormula())) { + break; + } else { + map.put("status","1"); + map.put("computeFormula",computeFormula); + map.put("activityId",activityId); + map.put("computeType",computeType); + return map; + } + } + } else { + break; + } + } + } + //查看结算报文是否夸时段 + Map cacheMap = redisService.getCacheMap("order:" + serialNumber); + if (cacheMap != null) { + CacheOrderData cacheOrderData = (CacheOrderData) cacheMap.get("orderData"); + if (cacheOrderData != null) { + int number = 0; + if (!"0".equals(cacheOrderData.getT1PowerQuantity().toString())) { + number++; + rateTimeList = xhpcRealTimeOrderMapper.getRateTimeList(chargingStationId, rateModelId, "00"); + } + if (!"0".equals(cacheOrderData.getT2PowerQuantity().toString())) { + number++; + rateTimeList = xhpcRealTimeOrderMapper.getRateTimeList(chargingStationId, rateModelId, "01"); + } + if (!"0".equals(cacheOrderData.getT3PowerQuantity().toString())) { + number++; + rateTimeList = xhpcRealTimeOrderMapper.getRateTimeList(chargingStationId, rateModelId, "02"); + } + if (!"0".equals(cacheOrderData.getT4PowerQuantity().toString())) { + number++; + rateTimeList = xhpcRealTimeOrderMapper.getRateTimeList(chargingStationId, rateModelId, "03"); + } + BigDecimal powerPrice = new BigDecimal(0); + BigDecimal servicePrice = new BigDecimal(0); + if (number == 1) { + for (int i = 0; i < rateTimeList.size(); i++) { + RateTime rateTime = rateTimeList.get(i); + XhpcActivityFormulaDomainDto activity = xhpcRealTimeOrderMapper.getActivityFormulaTimeById(activityStationTime.get(0).getActivityId(), rateTime.getStartTime(), rateTime.getEndTime()); + if (i == 0) { + computeFormula = activity.getComputeFormula(); + powerPrice = activity.getPowerPrice(); + servicePrice = activity.getServicePrice(); + if(rateTimeList.size()==1){ + map.put("status","2"); + map.put("computeFormula",computeFormula); + map.put("powerPrice",powerPrice); + map.put("servicePrice",servicePrice); + map.put("activityId",activityId); + map.put("computeType",computeType); + return map; + } + } else if (i != rateTimeList.size() - 1) { + if (computeFormula.equals(activity.getComputeFormula())) { + break; + } + if (powerPrice.compareTo(activity.getPowerPrice()) != 0) { + break; + } + if (servicePrice.compareTo(activity.getServicePrice()) != 0) { + break; + } + } else { + if (computeFormula.equals(activity.getComputeFormula())) { + break; + } + if (powerPrice.compareTo(activity.getPowerPrice()) != 0) { + break; + } + if (servicePrice.compareTo(activity.getServicePrice()) != 0) { + break; + } + map.put("status","2"); + map.put("computeFormula",computeFormula); + map.put("powerPrice",powerPrice); + map.put("servicePrice",servicePrice); + map.put("activityId",activityId); + map.put("computeType",computeType); + return map; + } + } + } + } - - - return false; + } + } + map.put("status","0"); + return map; } } diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml index a4f8902a..0d06ec99 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml @@ -827,4 +827,46 @@ order by xad.start_time asc + + + + + + + \ No newline at end of file