|
|
@@ -37,78 +37,113 @@ public class MsgTranscationRunner {
|
|
|
@Autowired
|
|
|
private OrderStatusService orderStatusService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SocketHandle socketHandle;
|
|
|
+
|
|
|
+ public void handleOne(OrderStatus item){
|
|
|
+
|
|
|
+ if ((System.currentTimeMillis() - item.getEndTime()) > 5 * 60 * 1000 && item.getTransactionOrderReplyStatus() != 5) {
|
|
|
+ //五分钟上送最后一次结束,上送
|
|
|
+ if(socketHandle.existDeviceConnection(item.getPileCode())){
|
|
|
+ log.info("{}重新上报句柄不存在",item.getPileCode());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DeviceConnectionMsg deviceConnectionMsg = socketHandle.getDeviceConnection(item.getPileCode());
|
|
|
+ try {
|
|
|
+ //String bytes = redisCache.getCacheObject(orderStatus.getPileCode());
|
|
|
+ //byte[] bytes1 = Encrytion.aesEncrypt(orderStatus.getOriginalText(), bytes.getBytes());
|
|
|
+ //byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.TRANSACTION_RECORDS_REQUEST.getFrameType(), DeviceSendYkc.TRANSACTION_RECORDS_REQUEST.getEncryptFlag(), bytes1, bytes1.length);
|
|
|
+ deviceConnectionMsg.getOutputStream().write(item.getOriginalText());
|
|
|
+ deviceConnectionMsg.getOutputStream().flush();
|
|
|
+ deviceConnectionMsg.incrementMessageCount();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //将恢复结果状态转成5,记录为充电记录上传5分钟后失败
|
|
|
+ item.setTransactionOrderReplyStatus((byte) 5);
|
|
|
+ orderStatusService.updateById(item);
|
|
|
+ log.info("最新未收到上报的订单list5分钟推送最后一次>>" + item.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
@Async("transactionTaskAsyncPool")
|
|
|
public void transactionMsg(Map<String, DeviceConnectionMsg> map) throws Exception {
|
|
|
log.info("======transaction push task starting=====");
|
|
|
//任务处理 1.上报交易流水消息后没有响应回复的情况,30秒上送一次三次后停止,五分钟后上送最后一次,不管是否成功都不再上送:有结束时间,充电状态是结束充电的
|
|
|
QueryWrapper<OrderStatus> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("now_order_status", 1); //充电完成
|
|
|
- queryWrapper.eq("transaction_order_reporting_action_status", 1); //未上报
|
|
|
- queryWrapper.eq("transaction_order_reply_status", 0); //未上报
|
|
|
+ queryWrapper.eq("now_order_status", 1).orderByDesc("id"); //充电完成
|
|
|
+// queryWrapper.eq("transaction_order_reporting_action_status", 1); //已上送
|
|
|
+ queryWrapper.eq("transaction_order_reply_status", 0); //未回复的
|
|
|
+ queryWrapper.last("limit 1000");
|
|
|
|
|
|
List<OrderStatus> list = orderStatusService.list(queryWrapper);
|
|
|
|
|
|
+ list.forEach(item->{
|
|
|
+ log.info("检测订单上报{}",item.getPileCode());
|
|
|
+ handleOne(item);
|
|
|
+ });
|
|
|
+
|
|
|
// System.out.println(list);
|
|
|
|
|
|
- Map<String, OrderStatus> orderStatusMap = list.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- OrderStatus::getPileCode, orderStatus
|
|
|
- -> orderStatus,(existing, replacement)
|
|
|
- -> (Instant.ofEpochMilli(existing.getCreateTime())
|
|
|
- .atZone(ZoneId.systemDefault()).toLocalDateTime())
|
|
|
- .isAfter(Instant.ofEpochMilli(replacement.getCreateTime())
|
|
|
- .atZone(ZoneId.systemDefault()).toLocalDateTime())
|
|
|
- ? existing : replacement));
|
|
|
- List<OrderStatus> orderStatuses = orderStatusMap.values().stream()
|
|
|
- .collect(Collectors.toList());
|
|
|
+// Map<String, OrderStatus> orderStatusMap = list.stream()
|
|
|
+// .collect(Collectors.toMap(
|
|
|
+// OrderStatus::getPileCode, orderStatus
|
|
|
+// -> orderStatus,(existing, replacement)
|
|
|
+// -> (Instant.ofEpochMilli(existing.getCreateTime())
|
|
|
+// .atZone(ZoneId.systemDefault()).toLocalDateTime())
|
|
|
+// .isAfter(Instant.ofEpochMilli(replacement.getCreateTime())
|
|
|
+// .atZone(ZoneId.systemDefault()).toLocalDateTime())
|
|
|
+// ? existing : replacement));
|
|
|
+// List<OrderStatus> orderStatuses = orderStatusMap.values().stream()
|
|
|
+// .collect(Collectors.toList());
|
|
|
|
|
|
//过滤充电状态是结束的且已经上送未收到订单恢复的,说明交易订单上报没收到云快充消息,如果时间充电结束时间到现在大于30秒上送
|
|
|
- List<OrderStatus> collect = orderStatuses.stream().filter(orderStatus -> orderStatus.getNowOrderStatus() == 1 && orderStatus.getTransactionOrderReplyStatus() == 0 && orderStatus.getTransactionOrderReportingActionStatus() == 1).collect(Collectors.toList());
|
|
|
+// List<OrderStatus> collect = list.stream().filter(orderStatus -> orderStatus.getNowOrderStatus() == 1 && orderStatus.getTransactionOrderReplyStatus() == 0 && orderStatus.getTransactionOrderReportingActionStatus() == 1).collect(Collectors.toList());
|
|
|
//看订单时间进行重新上送
|
|
|
- if (collect.size() > 0) {
|
|
|
- collect.stream().forEach(orderStatus -> {
|
|
|
- //上送订单并且订单上送大于5分钟但是没有变成充电状态的订单,当成空上报一次
|
|
|
-
|
|
|
- /* if ((((System.currentTimeMillis()-orderStatus.getEndTime())/1000) / 30 )==1||(((System.currentTimeMillis()-orderStatus.getEndTime()) /1000) / 60 )==1||(((System.currentTimeMillis()-orderStatus.getEndTime()) /1000) / 90)==1){
|
|
|
- //各上送一次订单记录
|
|
|
- DeviceConnectionMsg deviceConnectionMsg = map.get(orderStatus.getPileCode());
|
|
|
- try {
|
|
|
- String bytes = redisCache.getCacheObject(orderStatus.getPileCode());
|
|
|
- byte[] bytes1 = Encrytion.aesEncrypt(orderStatus.getOriginalText(), bytes.getBytes());
|
|
|
- deviceConnectionMsg.getOutputStream().write(bytes1);
|
|
|
- deviceConnectionMsg.getOutputStream().flush();
|
|
|
- deviceConnectionMsg.incrementMessageCount();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }else*/
|
|
|
- if ((System.currentTimeMillis() - orderStatus.getEndTime()) > 5 * 60 * 1000 && orderStatus.getTransactionOrderReplyStatus() != 5) {
|
|
|
- //五分钟上送最后一次结束,上送
|
|
|
- DeviceConnectionMsg deviceConnectionMsg = map.get(orderStatus.getPileCode());
|
|
|
- if (deviceConnectionMsg!=null&&deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS){
|
|
|
- //wshizhengjuezhe zhewanyier meishajishuhanlian danshi zhedongxi queshi xilan
|
|
|
- return;
|
|
|
- }
|
|
|
- try {
|
|
|
- //String bytes = redisCache.getCacheObject(orderStatus.getPileCode());
|
|
|
- //byte[] bytes1 = Encrytion.aesEncrypt(orderStatus.getOriginalText(), bytes.getBytes());
|
|
|
-
|
|
|
- //byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.TRANSACTION_RECORDS_REQUEST.getFrameType(), DeviceSendYkc.TRANSACTION_RECORDS_REQUEST.getEncryptFlag(), bytes1, bytes1.length);
|
|
|
-
|
|
|
- deviceConnectionMsg.getOutputStream().write(orderStatus.getOriginalText());
|
|
|
- deviceConnectionMsg.getOutputStream().flush();
|
|
|
- deviceConnectionMsg.incrementMessageCount();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- //将恢复结果状态转成5,记录为充电记录上传5分钟后失败
|
|
|
- orderStatus.setTransactionOrderReplyStatus((byte) 5);
|
|
|
- orderStatusService.updateById(orderStatus);
|
|
|
- log.info("最新未收到上报的订单list5分钟推送最后一次>>" + orderStatuses.toString());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+// if (collect.size() > 0) {
|
|
|
+// collect.stream().forEach(orderStatus -> {
|
|
|
+// //上送订单并且订单上送大于5分钟但是没有变成充电状态的订单,当成空上报一次
|
|
|
+//
|
|
|
+// /* if ((((System.currentTimeMillis()-orderStatus.getEndTime())/1000) / 30 )==1||(((System.currentTimeMillis()-orderStatus.getEndTime()) /1000) / 60 )==1||(((System.currentTimeMillis()-orderStatus.getEndTime()) /1000) / 90)==1){
|
|
|
+// //各上送一次订单记录
|
|
|
+// DeviceConnectionMsg deviceConnectionMsg = map.get(orderStatus.getPileCode());
|
|
|
+// try {
|
|
|
+// String bytes = redisCache.getCacheObject(orderStatus.getPileCode());
|
|
|
+// byte[] bytes1 = Encrytion.aesEncrypt(orderStatus.getOriginalText(), bytes.getBytes());
|
|
|
+// deviceConnectionMsg.getOutputStream().write(bytes1);
|
|
|
+// deviceConnectionMsg.getOutputStream().flush();
|
|
|
+// deviceConnectionMsg.incrementMessageCount();
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }else*/
|
|
|
+// if ((System.currentTimeMillis() - orderStatus.getEndTime()) > 5 * 60 * 1000 && orderStatus.getTransactionOrderReplyStatus() != 5) {
|
|
|
+// //五分钟上送最后一次结束,上送
|
|
|
+// DeviceConnectionMsg deviceConnectionMsg = map.get(orderStatus.getPileCode());
|
|
|
+// if (deviceConnectionMsg!=null&&deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS){
|
|
|
+// //wshizhengjuezhe zhewanyier meishajishuhanlian danshi zhedongxi queshi xilan
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// //String bytes = redisCache.getCacheObject(orderStatus.getPileCode());
|
|
|
+// //byte[] bytes1 = Encrytion.aesEncrypt(orderStatus.getOriginalText(), bytes.getBytes());
|
|
|
+//
|
|
|
+// //byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.TRANSACTION_RECORDS_REQUEST.getFrameType(), DeviceSendYkc.TRANSACTION_RECORDS_REQUEST.getEncryptFlag(), bytes1, bytes1.length);
|
|
|
+//
|
|
|
+// deviceConnectionMsg.getOutputStream().write(orderStatus.getOriginalText());
|
|
|
+// deviceConnectionMsg.getOutputStream().flush();
|
|
|
+// deviceConnectionMsg.incrementMessageCount();
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// //将恢复结果状态转成5,记录为充电记录上传5分钟后失败
|
|
|
+// orderStatus.setTransactionOrderReplyStatus((byte) 5);
|
|
|
+// orderStatusService.updateById(orderStatus);
|
|
|
+// log.info("最新未收到上报的订单list5分钟推送最后一次>>" + orderStatuses.toString());
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
// List<OrderStatus> collects = list.stream().filter(orderStatus -> orderStatus.getOriginalText()==null||orderStatus.getEndTime()==0).collect(Collectors.toList());
|
|
|
// if (collects.size()>0){
|
|
|
// collects.forEach(orderStatus -> {
|