|
@@ -35,6 +35,7 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -78,31 +79,42 @@ public class MsgCharngingRunner {
|
|
|
private static final BigDecimal zero = new BigDecimal("0");
|
|
private static final BigDecimal zero = new BigDecimal("0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // 使用AtomicBoolean替代基本的boolean
|
|
|
|
|
+ private final AtomicBoolean isRunning = new AtomicBoolean(false);
|
|
|
|
|
+
|
|
|
@Async("charngingTaskAsyncPool")
|
|
@Async("charngingTaskAsyncPool")
|
|
|
- public void chargingMsg(Map<String, DeviceConnectionMsg> map) {
|
|
|
|
|
- log.info("======充电中数据上报检测=====");
|
|
|
|
|
- //这边需要给充电中的状态进行查询流水号,流水号是由云快充启动充电时的下发指令带来存库的,
|
|
|
|
|
- if (map.size() < 1) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void chargingMsg(Map<String, DeviceConnectionMsg> map) {
|
|
|
|
|
+ try{
|
|
|
|
|
+ log.info("======充电中数据上报检测=====");
|
|
|
|
|
+ if (!isRunning.compareAndSet(false, true)) {
|
|
|
|
|
+ log.info("任务正在执行中,跳过本次处理");
|
|
|
|
|
+ return; // 如果任务已在运行,则直接返回
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //查找所有充电中的订单
|
|
|
|
|
- QueryWrapper<OrderStatus> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
- queryWrapper.eq("now_order_status", 0); //充电中状态上报
|
|
|
|
|
-
|
|
|
|
|
- //忽略10天前的订单
|
|
|
|
|
- long nowTime = System.currentTimeMillis();
|
|
|
|
|
- long tm = nowTime-86400*10*1000;
|
|
|
|
|
- //10天前的就算了
|
|
|
|
|
- queryWrapper.gt("create_time",tm ); //充电中状态上报
|
|
|
|
|
- queryWrapper.orderByDesc("id");
|
|
|
|
|
-
|
|
|
|
|
- //查询所有充电中设备的最新的订单记录,来上报设备状态消息.........?????????????????
|
|
|
|
|
- List<OrderStatus> list = orderStatusService.list(queryWrapper);
|
|
|
|
|
- if (list.isEmpty()) {
|
|
|
|
|
- log.info("无充电中订单上报");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// Thread.sleep(20000);
|
|
|
|
|
+
|
|
|
|
|
+ //这边需要给充电中的状态进行查询流水号,流水号是由云快充启动充电时的下发指令带来存库的,
|
|
|
|
|
+ if (map.size() < 1) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查找所有充电中的订单
|
|
|
|
|
+ QueryWrapper<OrderStatus> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("now_order_status", 0); //充电中状态上报
|
|
|
|
|
+
|
|
|
|
|
+ //忽略10天前的订单
|
|
|
|
|
+ long nowTime = System.currentTimeMillis();
|
|
|
|
|
+ long tm = nowTime-86400*10*1000;
|
|
|
|
|
+ //10天前的就算了
|
|
|
|
|
+ queryWrapper.gt("create_time",tm ); //充电中状态上报
|
|
|
|
|
+ queryWrapper.orderByDesc("id");
|
|
|
|
|
+
|
|
|
|
|
+ //查询所有充电中设备的最新的订单记录,来上报设备状态消息.........?????????????????
|
|
|
|
|
+ List<OrderStatus> list = orderStatusService.list(queryWrapper);
|
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
|
+ log.info("无充电中订单上报");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Set<String> devicePileCodes = map.keySet();
|
|
// Set<String> devicePileCodes = map.keySet();
|
|
|
// QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
// QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
@@ -116,50 +128,53 @@ public class MsgCharngingRunner {
|
|
|
// Map<String, BillingModel> billingModelMap = billingModels.stream()
|
|
// Map<String, BillingModel> billingModelMap = billingModels.stream()
|
|
|
// .collect(Collectors.toMap(BillingModel::getPileCode, billingModel -> billingModel));
|
|
// .collect(Collectors.toMap(BillingModel::getPileCode, billingModel -> billingModel));
|
|
|
|
|
|
|
|
- //只上传最近的订单
|
|
|
|
|
- Map<String, Boolean> dealMap = new HashMap<>();
|
|
|
|
|
- list.forEach(item -> {
|
|
|
|
|
- try {
|
|
|
|
|
- //检查设备是否在线
|
|
|
|
|
- QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
- deviceStatusQueryWrapper.eq("pile_code", item.getPileCode());
|
|
|
|
|
- deviceStatusQueryWrapper.eq("gun_port", item.getGunsCode());
|
|
|
|
|
|
|
+ //只上传最近的订单
|
|
|
|
|
+ Map<String, Boolean> dealMap = new HashMap<>();
|
|
|
|
|
+ list.forEach(item -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //检查设备是否在线
|
|
|
|
|
+ QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ deviceStatusQueryWrapper.eq("pile_code", item.getPileCode());
|
|
|
|
|
+ deviceStatusQueryWrapper.eq("gun_port", item.getGunsCode());
|
|
|
// deviceStatusQueryWrapper.last("limit 1");
|
|
// deviceStatusQueryWrapper.last("limit 1");
|
|
|
- DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
|
|
|
|
|
- if(statusServiceOne != null && statusServiceOne.getOnlineStatus()==StatusConstant.OFFLINE){
|
|
|
|
|
- log.info("{}设备已离线不上报",item.getPileCode());
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
|
|
|
- billWapper.eq("pile_code", item.getPileCode());
|
|
|
|
|
- billWapper.eq("device_imei", item.getDeviceImei());
|
|
|
|
|
- BillingModel b = billingModelService.getOne(billWapper);
|
|
|
|
|
- if (b == null) {
|
|
|
|
|
- log.info("{}上报充电中未匹配计费模型", item.getPileCode());
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(!deviceMsgHandle.checkConnection(item.getPileCode(),item.getDeviceImei())){
|
|
|
|
|
- log.info("{}重新连接句柄不存在等待下次执行",item.getPileCode());
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- DeviceConnectionMsg deviceConnectionMsg = map.get(item.getPileCode());
|
|
|
|
|
-
|
|
|
|
|
- String k = item.getPileCode() + "_" + item.getGunsCode();
|
|
|
|
|
- if (dealMap.containsKey(k)) {
|
|
|
|
|
- log.info("{}本轮已上报充电中只报最后一个订单", k);
|
|
|
|
|
- } else {
|
|
|
|
|
- reportOne(item, b, deviceConnectionMsg);
|
|
|
|
|
- dealMap.put(k, true);
|
|
|
|
|
|
|
+ DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
|
|
|
|
|
+ if(statusServiceOne != null && statusServiceOne.getOnlineStatus()==StatusConstant.OFFLINE){
|
|
|
|
|
+ log.info("{}设备已离线不上报",item.getPileCode());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
|
|
|
+ billWapper.eq("pile_code", item.getPileCode());
|
|
|
|
|
+ billWapper.eq("device_imei", item.getDeviceImei());
|
|
|
|
|
+ BillingModel b = billingModelService.getOne(billWapper);
|
|
|
|
|
+ if (b == null) {
|
|
|
|
|
+ log.info("{}上报充电中未匹配计费模型", item.getPileCode());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!deviceMsgHandle.checkConnection(item.getPileCode(),item.getDeviceImei())){
|
|
|
|
|
+ log.info("{}重新连接句柄不存在等待下次执行",item.getPileCode());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DeviceConnectionMsg deviceConnectionMsg = map.get(item.getPileCode());
|
|
|
|
|
+
|
|
|
|
|
+ String k = item.getPileCode() + "_" + item.getGunsCode();
|
|
|
|
|
+ if (dealMap.containsKey(k)) {
|
|
|
|
|
+ log.info("{}本轮已上报充电中只报最后一个订单", k);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reportOne(item, b, deviceConnectionMsg);
|
|
|
|
|
+ dealMap.put(k, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.info("{}上报充电中异常", item.getPileCode()+e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.info("{}上报充电中异常", item.getPileCode()+e.getMessage());
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ isRunning.set(false);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
log.info("======Charging status push task ending=====");
|
|
log.info("======Charging status push task ending=====");
|
|
|
}
|
|
}
|