From 4bf9185195316791f0339af501f12d97d8519c2c Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期六, 04 一月 2025 11:52:47 +0800
Subject: [PATCH] 修改计费bug

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java                          |  182 ++++++++++++++++++++++++++++++--------------
 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java              |    8 +-
 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java             |    2 
 ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/ConfirmTransactionRecord.java                  |    2 
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java |    6 
 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/produce/IotMessageProduce.java               |    1 
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java                             |    2 
 7 files changed, 134 insertions(+), 69 deletions(-)

diff --git a/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/ConfirmTransactionRecord.java b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/ConfirmTransactionRecord.java
index 69c7681..56edb57 100644
--- a/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/ConfirmTransactionRecord.java
+++ b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/ConfirmTransactionRecord.java
@@ -13,7 +13,7 @@
 @Document(collection = "confirm_transaction_record") //指定要对应的文档名(表名)
 @Accessors(chain = true)
 public class ConfirmTransactionRecord extends BaseModel {
-    private String transaction_serial_number;// 桩编码
+    private String transaction_serial_number;// 交易流水号
     private Integer confirm_result;// 确认结果(0:上传成功,1:非法账单)
 
 }
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
index 82450f6..2216d2a 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
@@ -176,13 +176,13 @@
         }
         // 查询最高折扣的会员
         TVip monthlyCardDiscount = vipClient.getVipInfoByType(3).getData();
-        strategyPriceVO.setServiceFeeDiscount(monthlyCardDiscount.getMonthlyCardDiscount());
+        strategyPriceVO.setServiceFeeDiscount(null == monthlyCardDiscount ? new BigDecimal(10) : monthlyCardDiscount.getMonthlyCardDiscount());
         // 查询最高优惠的会员
         TVip maximumDeduction = vipClient.getVipInfoByType(1).getData();
-        strategyPriceVO.setMaxDiscountAmount(maximumDeduction.getMaximumDeduction());
+        strategyPriceVO.setMaxDiscountAmount(null == maximumDeduction ? new BigDecimal(10) : maximumDeduction.getMaximumDeduction());
         // 查询最低起步价会员
         TVip monthlyCard = vipClient.getVipInfoByType(2).getData();
-        strategyPriceVO.setVipStartPrice(monthlyCard.getMonthlyCard());
+        strategyPriceVO.setVipStartPrice(null == monthlyCard ? new BigDecimal(10) : monthlyCard.getMonthlyCard());
         // 模板折扣
         strategyPriceVO.setDiscount(accountingStrategy.getDiscount());
         return strategyPriceVO;
diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java
index 3ae6927..34414fd 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java
@@ -117,10 +117,10 @@
      * @param confirmTransactionRecord 实体对象
      * @return
      */
-    @PostMapping("/confirmTransactionRecord")
-    public String confirmTransactionRecord(@RequestBody ConfirmTransactionRecord confirmTransactionRecord){
-        return  iotMessageProduce.sendMessage(confirmTransactionRecord.getTransaction_serial_number(), ServiceIdMenu.CONFIRM_TRANSACTION_RECORD.getKey(),messageUtil.confirmTransactionRecord(confirmTransactionRecord));
-    }
+//    @PostMapping("/confirmTransactionRecord")
+//    public String confirmTransactionRecord(@RequestBody ConfirmTransactionRecord confirmTransactionRecord){
+//        return  iotMessageProduce.sendMessage(confirmTransactionRecord.getTransaction_serial_number(), ServiceIdMenu.CONFIRM_TRANSACTION_RECORD.getKey(),messageUtil.confirmTransactionRecord(confirmTransactionRecord));
+//    }
 
     /**
      * 远程账户余额更新
diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
index 6d7c65e..37d2b4b 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
@@ -235,7 +235,7 @@
                 ConfirmTransactionRecord confirmTransactionRecord = new ConfirmTransactionRecord();
                 confirmTransactionRecord.setTransaction_serial_number(transactionRecordMessage.getTransaction_serial_number());
                 confirmTransactionRecord.setConfirm_result(0);
-                iotMessageProduce.sendMessage(confirmTransactionRecord.getTransaction_serial_number(), ServiceIdMenu.CONFIRM_TRANSACTION_RECORD.getKey(),messageUtil.confirmTransactionRecord(confirmTransactionRecord));
+                iotMessageProduce.sendMessage(transactionRecordMessage.getCharging_pile_code(), ServiceIdMenu.CONFIRM_TRANSACTION_RECORD.getKey(),messageUtil.confirmTransactionRecord(confirmTransactionRecord));
                 sendResult = enhanceProduce.chargingMessage(chargingMessage);
                 break;
             case SendTagConstant.UPDATE_BALANCE_REPLY:
diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/produce/IotMessageProduce.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/produce/IotMessageProduce.java
index 69cf6c7..6e7aa8d 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/produce/IotMessageProduce.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/produce/IotMessageProduce.java
@@ -39,6 +39,7 @@
      */
     @PostMapping("/sendMessage")
     public String sendMessage(String code, String name, JSONObject message){
+        log.info("消息下发至设备:code={},name={},message={}", code, name, message);
         CreateMessageRequest request = new CreateMessageRequest();
         System.err.println(code);
         System.err.println(JSONObject.toJSONString(config));
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
index 4089d09..7a7cbb3 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
@@ -230,7 +230,7 @@
         data.setRecords(res1);
         return R.ok(data);
     }
-public static List<PayOrderDto> testing5(long total, long current, long size, List<PayOrderDto> str){
+    public static List<PayOrderDto> testing5(long total, long current, long size, List<PayOrderDto> str){
     List<PayOrderDto> result = new ArrayList<>();
     //获取初始化分页结构
     com.ruoyi.order.util.Page<PayOrderDto> page = new com.ruoyi.order.util.Page().getPage(total, size, current - 1);
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
index e21b823..6766c5f 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -1928,68 +1928,132 @@
 		chargingOrderAccountingStrategyService.remove(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
 		SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		List<AccountingStrategyDetailOrderVo> lists = new ArrayList<>();
-		for (int i = 0; i < accountingStrategyDetailOrderList.size(); i++) {
-			Class<? extends TransactionRecordMessageVO> clazz = vo.getClass();
-			try {
-				AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i);
-				//阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
-				Object invoke = null;
-				switch (strategyDetail.getType()){
-					case 1:
-						//充电度数
-						invoke = clazz.getMethod("getSpike_charge" + (i + 1)).invoke(vo);
-						break;
-					case 2:
-						//充电度数
-						invoke = clazz.getMethod("getPeak_charge" + (i + 1)).invoke(vo);
-						break;
-					case 3:
-						//充电度数
-						invoke = clazz.getMethod("getFlat_charge" + (i + 1)).invoke(vo);
-						break;
-					case 4:
-						//充电度数
-						invoke = clazz.getMethod("getValley_charge" + (i + 1)).invoke(vo);
-						break;
+		try {
+			//跨天
+			if(!vo.getStart_time().split(" ")[0].equals(vo.getEnd_time().split(" ")[0])){
+				//当天的
+				//开始通过计费策略遍历解析每个时段的费用明细
+				String start_time = vo.getStart_time();
+				String end_time = vo.getEnd_time();
+				long start = sdfs.parse(start_time).getTime();
+				long end = sdfs.parse(end_time).getTime();
+				boolean b = false;
+				Class<? extends TransactionRecordMessageVO> clazz = vo.getClass();
+				for (int i = 0; i < accountingStrategyDetailOrderList.size(); i++) {
+					AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i);
+					long time = sdfs.parse(start_time.split(" ")[0] + " " + strategyDetail.getStartTime() + ":00").getTime();
+					if(start >= time){
+						b = true;
+					}
+					//开始充电
+					if(b){
+						//阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
+						Object invoke = null;
+						switch (strategyDetail.getType()){
+							case 1:
+								//充电度数
+								invoke = clazz.getMethod("getSpike_charge" + (i + 1)).invoke(vo);
+								break;
+							case 2:
+								//充电度数
+								invoke = clazz.getMethod("getPeak_charge" + (i + 1)).invoke(vo);
+								break;
+							case 3:
+								//充电度数
+								invoke = clazz.getMethod("getFlat_charge" + (i + 1)).invoke(vo);
+								break;
+							case 4:
+								//充电度数
+								invoke = clazz.getMethod("getValley_charge" + (i + 1)).invoke(vo);
+								break;
+						}
+						if(null == invoke || Double.valueOf(invoke.toString()) == 0){
+							continue;
+						}
+						BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
+						AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
+						BeanUtils.copyProperties(strategyDetail, vo1);
+						vo1.setChargingCapacity(sharp_peak_charge);
+						lists.add(vo1);
+					}
 				}
-				if(null == invoke || Double.valueOf(invoke.toString()) == 0){
-					continue;
+				
+				//第二天的
+				//开始通过计费策略遍历解析每个时段的费用明细
+				for (int i = 0; i < accountingStrategyDetailOrderList.size(); i++) {
+					AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i);
+					long time = sdfs.parse(end_time.split(" ")[0] + " " + strategyDetail.getStartTime() + ":00").getTime();
+					if(time > end){
+						break;
+					}
+					//开始充电
+					if(b){
+						//阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
+						Object invoke = null;
+						switch (strategyDetail.getType()){
+							case 1:
+								//充电度数
+								invoke = clazz.getMethod("getSpike_charge" + (i + 1)).invoke(vo);
+								break;
+							case 2:
+								//充电度数
+								invoke = clazz.getMethod("getPeak_charge" + (i + 1)).invoke(vo);
+								break;
+							case 3:
+								//充电度数
+								invoke = clazz.getMethod("getFlat_charge" + (i + 1)).invoke(vo);
+								break;
+							case 4:
+								//充电度数
+								invoke = clazz.getMethod("getValley_charge" + (i + 1)).invoke(vo);
+								break;
+						}
+						if(null == invoke || Double.valueOf(invoke.toString()) == 0){
+							continue;
+						}
+						BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
+						AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
+						BeanUtils.copyProperties(strategyDetail, vo1);
+						vo1.setChargingCapacity(sharp_peak_charge);
+						lists.add(vo1);
+					}
 				}
-				BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
-				AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
-				BeanUtils.copyProperties(strategyDetail, vo1);
-				vo1.setStart(sdfs.parse(vo.getStart_time().split(" ")[0] + " " + strategyDetail.getStartTime() + ":00").getTime());
-				vo1.setEnd(sdfs.parse(vo.getStart_time().split(" ")[0] + " " + strategyDetail.getEndTime() + ":00").getTime());
-				vo1.setChargingCapacity(sharp_peak_charge);
-				lists.add(vo1);
-			} catch (IllegalAccessException e) {
-				throw new RuntimeException(e);
-			} catch (InvocationTargetException e) {
-				throw new RuntimeException(e);
-			} catch (NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			} catch (ParseException e) {
-				throw new RuntimeException(e);
+			}else{
+				for (int i = 0; i < accountingStrategyDetailOrderList.size(); i++) {
+					Class<? extends TransactionRecordMessageVO> clazz = vo.getClass();
+					AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i);
+					//阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
+					Object invoke = null;
+					switch (strategyDetail.getType()){
+						case 1:
+							//充电度数
+							invoke = clazz.getMethod("getSpike_charge" + (i + 1)).invoke(vo);
+							break;
+						case 2:
+							//充电度数
+							invoke = clazz.getMethod("getPeak_charge" + (i + 1)).invoke(vo);
+							break;
+						case 3:
+							//充电度数
+							invoke = clazz.getMethod("getFlat_charge" + (i + 1)).invoke(vo);
+							break;
+						case 4:
+							//充电度数
+							invoke = clazz.getMethod("getValley_charge" + (i + 1)).invoke(vo);
+							break;
+					}
+					if(null == invoke || Double.valueOf(invoke.toString()) == 0){
+						continue;
+					}
+					BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
+					AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
+					BeanUtils.copyProperties(strategyDetail, vo1);
+					vo1.setChargingCapacity(sharp_peak_charge);
+					lists.add(vo1);
+				}
 			}
-		}
-		Collections.sort(lists, new Comparator<AccountingStrategyDetailOrderVo>() {
-			public int compare(AccountingStrategyDetailOrderVo s1, AccountingStrategyDetailOrderVo s2) {
-				return s1.getStart() < s2.getStart() ? -1 : s1.getStart() == s2.getStart() ? 0 : 1;
-			}
-		});
-		if(!vo.getStart_time().split(" ")[0].equals(vo.getEnd_time().split(" ")[0])){
-			List<AccountingStrategyDetailOrderVo> list1 = new ArrayList<>(lists);
-			for (AccountingStrategyDetailOrderVo orderVo : list1) {
-				Calendar start = Calendar.getInstance();
-				start.setTimeInMillis(orderVo.getStart());
-				start.set(Calendar.DAY_OF_YEAR, start.get(Calendar.DAY_OF_YEAR) + 1);
-				orderVo.setStart(start.getTimeInMillis());
-				Calendar end = Calendar.getInstance();
-				end.setTimeInMillis(orderVo.getEnd());
-				end.set(Calendar.DAY_OF_YEAR, end.get(Calendar.DAY_OF_YEAR) + 1);
-				orderVo.setEnd(end.getTimeInMillis());
-			}
-			lists.addAll(list1);
+		}catch (Exception e){
+			e.printStackTrace();
 		}
 		
 		//开始处理明细

--
Gitblit v1.7.1