浏览代码

调整云快充

liuf 6 月之前
父节点
当前提交
a52dd3ec55

+ 46 - 2
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -9,11 +9,15 @@ import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
 import com.tmzn.devicelinkykc.entity.BillingModel;
 import com.tmzn.devicelinkykc.entity.Device;
 import com.tmzn.devicelinkykc.entity.DeviceStatus;
+import com.tmzn.devicelinkykc.entity.OrderStatus;
 import com.tmzn.devicelinkykc.entity.param.AjaxResult;
 import com.tmzn.devicelinkykc.entity.param.dto.BillingModelDTO;
 import com.tmzn.devicelinkykc.frameMsg.DataConversion;
 import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
+import com.tmzn.devicelinkykc.frameMsg.TransMoney;
 import com.tmzn.devicelinkykc.frameMsg.frameType.LoginFrame;
+import com.tmzn.devicelinkykc.frameMsg.frameType.RealTimeStatusPushFrame;
+import com.tmzn.devicelinkykc.frameMsg.frameType.TransactionFlowPushFrame;
 import com.tmzn.devicelinkykc.mapstruct.BillingModelMapping;
 import com.tmzn.devicelinkykc.message.DeviceMsgHandle;
 import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
@@ -21,6 +25,7 @@ import com.tmzn.devicelinkykc.redis.RedisCache;
 import com.tmzn.devicelinkykc.service.BillingModelService;
 import com.tmzn.devicelinkykc.service.DeviceControlerService;
 import com.tmzn.devicelinkykc.service.DeviceStatusService;
+import com.tmzn.devicelinkykc.service.OrderStatusService;
 import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
 import com.tmzn.devicelinkykc.transdata.entity.DeviceParam;
 import com.tmzn.devicelinkykc.msgparser.MessageParseMgr;
@@ -42,6 +47,7 @@ import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -71,10 +77,48 @@ public class TestController {
     @Autowired
     private DeviceMsgHandle deviceMsgHandle;
 
+    @Autowired
+    private TransactionFlowPushFrame transactionFlowPushFrame;
+
+    @Autowired
+    private OrderStatusService orderStatusService;
+
+    @Autowired
+    private TransMoney transMoney;
     @PostMapping("/msg")
-    public String testMsg(@RequestBody String message) {
+    public String testMsg() {
         try {
-            deviceMsgHandle.testMsg(message);
+
+//            realTimeStatusPushFrame.upStatusDevice(null,);
+
+            String pileCode = "51220002000016";
+            QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
+            billWapper.eq("pile_code", pileCode);
+            BillingModel b = billingModelService.getOne(billWapper);
+
+
+            //查找所有充电中的订单
+            QueryWrapper<OrderStatus> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("id", 57303); //充电中状态上报
+
+            //查询所有充电中设备的最新的订单记录,来上报设备状态消息.........?????????????????
+            OrderStatus orderStatus = orderStatusService.getOne(queryWrapper);
+
+            Map<String, BigDecimal> map = transMoney.compute(orderStatus.getGunsCode(), b, orderStatus.getCreateTime(), orderStatus.getEndTime());
+
+           byte[] params = transactionFlowPushFrame.params16(orderStatus.getTransOrder(), pileCode, orderStatus.getGunsCode(),
+                   orderStatus.getCreateTime(), orderStatus.getEndTime(), b, orderStatus.getCard(), map,0);
+            //deviceMsgHandle.testMsg(message);
+
+            System.out.println( DataConversion.bytesToHexString(params));
+
+            int frameType = DeviceSendYkc.TRANSACTION_RECORDS_REQUEST_16.getFrameType();
+            byte[] encrypt = new byte[0];
+            encrypt = params;
+            byte[] b1 = FrameDataSplicing.spliceing(0,frameType , 0, encrypt, encrypt.length,false);
+
+
+            System.out.println( DataConversion.bytesToHexString(b1));
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 5 - 2
src/main/java/com/tmzn/devicelinkykc/frameMsg/TransMoney.java

@@ -33,7 +33,6 @@ public class TransMoney {
 
     public static final BigDecimal hourToMin = new BigDecimal(60);
 
-    public static Map<String, BigDecimal> transData = new HashMap<>();
 
     @Value("${billingInterface}")
     private String url;
@@ -42,6 +41,7 @@ public class TransMoney {
 
     public Map<String,BigDecimal> getTransData(){
         BigDecimal bigDecimal = new BigDecimal("0.0000");
+        Map<String, BigDecimal> transData = new HashMap<>();
         transData.put("elec",bigDecimal);
         transData.put("elec1",bigDecimal);
         transData.put("elec2",bigDecimal);
@@ -67,7 +67,7 @@ public class TransMoney {
      */
     public Map<String,BigDecimal> compute(int port,BillingModel billingModel,Long startTime,Long endTime) throws Exception{
 
-        Map<String,BigDecimal>   transData = getTransData();
+        Map<String,BigDecimal> transData = getTransData();
         try {
             TimeUnit.MILLISECONDS.sleep(1000);
         } catch (Exception e) {
@@ -231,6 +231,7 @@ public class TransMoney {
 
 
         BigDecimal init = new BigDecimal(0);
+        Map<String, BigDecimal> transData = new HashMap<>();
         transData.put("money", money);
         transData.put("elec", elec);
         transData.put("money1", money);
@@ -261,6 +262,7 @@ public class TransMoney {
         Date endDate = new Date(endTime);
         log.info("startTime:"+startDate+";endTime:"+endDate);
         BigDecimal init = new BigDecimal(0);
+        Map<String,BigDecimal> transData = getTransData();
         transData.put("money1", init);
         transData.put("money2", init);
         transData.put("money3", init);
@@ -534,6 +536,7 @@ public class TransMoney {
      */
     private BigDecimal money(byte b, BigDecimal chargingTime, BigDecimal power, BillingModel billingModel)  throws Exception{
         //电价  段电价+服务费
+        Map<String,BigDecimal> transData = getTransData();
         BigDecimal sharpPrice = billingModel.getSharpPrice().add(billingModel.getSharpServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);
         BigDecimal peakPrice = billingModel.getPeakPrice().add(billingModel.getPeakServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);
         BigDecimal flatPrice = billingModel.getFlatPrice().add(billingModel.getFlatServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);

+ 6 - 6
src/main/java/com/tmzn/devicelinkykc/taskQueue/queue/MsgCharngingQueue.java

@@ -16,18 +16,18 @@ import java.util.concurrent.BlockingQueue;
 @Slf4j(topic = "MsgCharngingQueue")
 public class MsgCharngingQueue  extends Thread implements ApplicationRunner {
 
-      private BlockingQueue<Map<String, DeviceConnectionMsg>> charngingQueue = new ArrayBlockingQueue(1024);
+      private BlockingQueue<Map<String, DeviceConnectionMsg>> charngingQueue = new ArrayBlockingQueue(1);
 
 
     @Autowired
     private MsgCharngingRunner msgCharngingRunner;
 
     public void add(Map<String, DeviceConnectionMsg> object){
-        try {
-               charngingQueue.put(object);
-
-        } catch (InterruptedException e) {
-            e.printStackTrace();
+        //               charngingQueue.put(object);
+        // 非阻塞
+        boolean success = charngingQueue.offer(object);
+        if (!success) {
+            log.info("队列已满,丢弃设备状态更新: size={}", object.size());
         }
     }
 

+ 9 - 9
src/main/java/com/tmzn/devicelinkykc/taskQueue/queue/TaskExecutePool.java

@@ -17,9 +17,9 @@ public class TaskExecutePool {
     @Bean
     public Executor heartTaskAsyncPool() {
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
-        executor.setCorePoolSize(1); //核心线程数
-        executor.setMaxPoolSize(1);  //最大线程数
-        executor.setQueueCapacity(0); //队列大小
+        executor.setCorePoolSize(2); //核心线程数
+        executor.setMaxPoolSize(4);  //最大线程数
+        executor.setQueueCapacity(1000); //队列大小
         executor.setKeepAliveSeconds(300); //线程最大空闲时间
         executor.setThreadNamePrefix("async-heartExecutor-");
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略(一共四种,此处省略)
@@ -41,9 +41,9 @@ public class TaskExecutePool {
     @Bean
     public Executor freeTaskAsyncPool() {
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
-        executor.setCorePoolSize(1); //核心线程数
-        executor.setMaxPoolSize(1);  //最大线程数
-        executor.setQueueCapacity(0); //队列大小
+        executor.setCorePoolSize(2); //核心线程数
+        executor.setMaxPoolSize(4);  //最大线程数
+        executor.setQueueCapacity(1000); //队列大小
         executor.setKeepAliveSeconds(300); //线程最大空闲时间
         executor.setThreadNamePrefix("async-freeExecutor-");
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略(一共四种,此处省略)
@@ -53,9 +53,9 @@ public class TaskExecutePool {
     @Bean
     public Executor transactionTaskAsyncPool() {
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
-        executor.setCorePoolSize(1); //核心线程数
-        executor.setMaxPoolSize(1);  //最大线程数
-        executor.setQueueCapacity(0); //队列大小
+        executor.setCorePoolSize(2); //核心线程数
+        executor.setMaxPoolSize(4);  //最大线程数
+        executor.setQueueCapacity(1000); //队列大小
         executor.setKeepAliveSeconds(300); //线程最大空闲时间
         executor.setThreadNamePrefix("async-transactionExecutor-");
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略(一共四种,此处省略)