|
|
@@ -16,6 +16,7 @@ import com.tmzn.devicelinkykc.frameMsg.frameType.HeartFrameSend;
|
|
|
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.message.DeviceMsgHandle;
|
|
|
import com.tmzn.devicelinkykc.redis.RedisCache;
|
|
|
import com.tmzn.devicelinkykc.service.*;
|
|
|
import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
|
|
|
@@ -65,6 +66,10 @@ public class MsgCharngingRunner {
|
|
|
private SocketHandle socketHandle;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ DeviceMsgHandle deviceMsgHandle;
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private DeviceControlerService deviceControlerService;
|
|
|
@Autowired
|
|
|
@@ -75,27 +80,20 @@ public class MsgCharngingRunner {
|
|
|
|
|
|
@Async("charngingTaskAsyncPool")
|
|
|
public void chargingMsg(Map<String, DeviceConnectionMsg> map) {
|
|
|
- log.info("======Charging status push task starting=====");
|
|
|
+ log.info("======充电中数据上报检测=====");
|
|
|
//这边需要给充电中的状态进行查询流水号,流水号是由云快充启动充电时的下发指令带来存库的,
|
|
|
if (map.size() < 1) {
|
|
|
return;
|
|
|
}
|
|
|
- Set<String> devicePileCodes = map.keySet();
|
|
|
- QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
|
- billWapper.in("pile_code", devicePileCodes);
|
|
|
- List<BillingModel> billingModels = billingModelService.list(billWapper);
|
|
|
-
|
|
|
- if (billingModels.size() < 1) {
|
|
|
- log.info("无计费可上报模型");
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
+ //查找所有充电中的订单
|
|
|
QueryWrapper<OrderStatus> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("now_order_status", 0); //充电中状态上报
|
|
|
|
|
|
+ //忽略10天前的订单
|
|
|
long nowTime = System.currentTimeMillis();
|
|
|
- long tm = nowTime-86400*10;
|
|
|
-
|
|
|
+ long tm = nowTime-86400*10*1000;
|
|
|
+ //10天前的就算了
|
|
|
queryWrapper.gt("create_time",tm ); //充电中状态上报
|
|
|
queryWrapper.orderByDesc("id");
|
|
|
|
|
|
@@ -106,28 +104,29 @@ public class MsgCharngingRunner {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ Set<String> devicePileCodes = map.keySet();
|
|
|
+ QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
|
+ billWapper.in("pile_code", devicePileCodes);
|
|
|
+ List<BillingModel> billingModels = billingModelService.list(billWapper);
|
|
|
+ if (billingModels.size() < 1) {
|
|
|
+ log.info("无计费可上报模型");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
Map<String, BillingModel> billingModelMap = billingModels.stream()
|
|
|
.collect(Collectors.toMap(BillingModel::getPileCode, billingModel -> billingModel));
|
|
|
|
|
|
-
|
|
|
//只上传最近的订单
|
|
|
Map<String, Boolean> dealMap = new HashMap<>();
|
|
|
list.forEach(item -> {
|
|
|
try {
|
|
|
- BillingModel b = billingModelMap.get(item.getPileCode());
|
|
|
- DeviceConnectionMsg deviceConnectionMsg = map.get(item.getPileCode());
|
|
|
-
|
|
|
- int mi = (int) (System.currentTimeMillis() - item.getCreateTime());
|
|
|
- if(mi>86400*10){
|
|
|
- log.info("{}10天前的订单忽略吧", item.getPileCode());
|
|
|
+ if(!deviceMsgHandle.checkConnection(item.getPileCode(),item.getDeviceImei())){
|
|
|
+ log.info("{}重新连接句柄不存在等待下次执行",item.getPileCode());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (deviceConnectionMsg == null) {
|
|
|
- log.info("{}上报充电中未连接", item.getPileCode());
|
|
|
- return;
|
|
|
- }
|
|
|
+ DeviceConnectionMsg deviceConnectionMsg = map.get(item.getPileCode());
|
|
|
+ BillingModel b = billingModelMap.get(item.getPileCode());
|
|
|
if (b == null) {
|
|
|
log.info("{}上报充电中未匹配计费模型", item.getPileCode());
|
|
|
return;
|
|
|
@@ -135,7 +134,7 @@ public class MsgCharngingRunner {
|
|
|
|
|
|
String k = item.getPileCode() + "_" + item.getGunsCode();
|
|
|
if (dealMap.containsKey(k)) {
|
|
|
- log.info("{}本轮已上报充电中", k);
|
|
|
+ log.info("{}本轮已上报充电中只报最后一个订单", k);
|
|
|
} else {
|
|
|
reportOne(item, b, deviceConnectionMsg);
|
|
|
dealMap.put(k, true);
|
|
|
@@ -149,65 +148,105 @@ public class MsgCharngingRunner {
|
|
|
log.info("======Charging status push task ending=====");
|
|
|
}
|
|
|
|
|
|
+ public void try103(OrderStatus orderStatus){
|
|
|
+
|
|
|
+ String key = "try103:_"+orderStatus.getDeviceImei();
|
|
|
+ if(redisCache.hasKey(key)){
|
|
|
+ log.info("{}-{}忽略下发103", orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("{}-{}2分钟内无状态下发一次103", orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
+ deviceControlerService.sendImeiDetail(orderStatus.getDeviceImei());
|
|
|
+ redisCache.setCacheObject(key, System.currentTimeMillis(),120, TimeUnit.SECONDS);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void stopOne(OrderStatus orderStatus){
|
|
|
+ int port = (int) orderStatus.getGunsCode();
|
|
|
+ orderStatus.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
+ orderStatus.setEndTime(System.currentTimeMillis());
|
|
|
+ orderStatusService.save(orderStatus);
|
|
|
+ //发送停止充电指令
|
|
|
+ orderStatus.setEndTime(System.currentTimeMillis() - 1000 * 60 * 5);
|
|
|
+ orderStatus.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
+ orderStatus.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
+ orderStatusService.updateById(orderStatus);
|
|
|
+ deviceControlerService.stopCharge(orderStatus.getDeviceImei(), orderStatus.getDeviceImei(), port);
|
|
|
+ log.info("{}--id:{}已停止充电",orderStatus.getPileCode(),orderStatus.getId());
|
|
|
+ }
|
|
|
+
|
|
|
public void reportOne(OrderStatus orderStatus, BillingModel billingModel, DeviceConnectionMsg deviceConnectionMsg) {
|
|
|
//获取订单状态
|
|
|
String cacheKey = orderStatus.getGunsCode() == 1 ? RedisConstant.ONLINE_DEVICE_ONE : RedisConstant.ONLINE_DEVICE_TWO;
|
|
|
DeviceStatus deviceStatus = redisCache.getCacheMapValue(cacheKey, orderStatus.getPileCode());
|
|
|
- if (deviceStatus == null) {
|
|
|
- log.info("{}-{}无状态记录", orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (deviceStatus.getGunStatus() != StatusConstant.CHARGING) {
|
|
|
- log.info("{}-{}已不在充电状态" + deviceStatus.getGunStatus(), orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
- //todo 是否要结束?
|
|
|
- return;
|
|
|
- }
|
|
|
- //存在设备上送充电状态
|
|
|
- if (deviceConnectionMsg.getLoginStatus() == Constant.DEVICE_NOT_LOGIN_STATUS) {
|
|
|
- QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
- Long heartTime = deviceConnectionMsg.getHeartTime();
|
|
|
- if (deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
- deviceQueryWrapper.eq("pile_code", orderStatus.getPileCode()).eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
- Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
- log.info("charngingTaskAsyncPool-1>not longin and heart normal>>" + orderStatus.getPileCode());
|
|
|
- loginFrame.loginMsgSend(deviceConnectionMsg, device);
|
|
|
+
|
|
|
+ long t = System.currentTimeMillis()-orderStatus.getCreateTime();
|
|
|
+
|
|
|
+ int port = (int) orderStatus.getGunsCode();
|
|
|
+
|
|
|
+ if(deviceStatus==null){
|
|
|
+ if(t<15*60*1000){
|
|
|
+ try103(orderStatus);
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ log.info("{}-{}无15分钟还没有记录要停止充电", orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
+ //状态那我为
|
|
|
+ stopOne(orderStatus);
|
|
|
}
|
|
|
- log.info("charngingTaskAsyncPool-1>not longin>>" + orderStatus.getPileCode());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (deviceConnectionMsg.getLoginStatus() != 1) {
|
|
|
- return;
|
|
|
+
|
|
|
+ if(deviceStatus.getGunStatus() != StatusConstant.CHARGING){
|
|
|
+ if(t<5*60*1000){
|
|
|
+ log.info("{}-{}5分钟内还未变充电状态忽略", orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ log.info("{}-{}5分钟后还不是充电状态录要停止充电", orderStatus.getPileCode(), orderStatus.getGunsCode());
|
|
|
+ //状态那我为
|
|
|
+ stopOne(orderStatus);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ //上送充电状态
|
|
|
JSONObject statusJSON = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei());
|
|
|
if(statusJSON==null){
|
|
|
+ log.info("无最近103数据{}",orderStatus.getPileCode());
|
|
|
+ try103(orderStatus);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Integer voltage = statusJSON.getInteger("voltage");
|
|
|
- Integer power = statusJSON.getInteger("power");
|
|
|
+ Integer voltage;
|
|
|
+ Integer power;
|
|
|
+
|
|
|
+ if(port==1){
|
|
|
+ voltage = statusJSON.getInteger("voltage");
|
|
|
+ power = statusJSON.getInteger("power");
|
|
|
+ }else{
|
|
|
+ voltage = statusJSON.getInteger("voltage_1");
|
|
|
+ power = statusJSON.getInteger("power_1");
|
|
|
+ }
|
|
|
|
|
|
//计算实时数据
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
//算电量
|
|
|
- Map<String, BigDecimal> start = null;
|
|
|
- try {
|
|
|
- start = transMoney.getTransData();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- //log.info(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1 + ">>redis过期的时间" + redisCache.getExpire(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1));
|
|
|
- //log.info(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1 + "redis的键是否存在" + redisCache.hasKey(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1));
|
|
|
- if (redisCache.hasKey(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1) && redisCache.getExpire(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1) > 1) {
|
|
|
- start = redisCache.getCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1);
|
|
|
- } else {
|
|
|
+ Map<String, BigDecimal> start = transMoney.getTransData();
|
|
|
+
|
|
|
+ String transCacheKey = "ChargingTrans:"+orderStatus.getId();
|
|
|
+ if(redisCache.hasKey(transCacheKey)){
|
|
|
+ start = redisCache.getCacheObject(cacheKey);
|
|
|
+ }else{
|
|
|
+ //缓存120秒避免重复计算电量
|
|
|
try {
|
|
|
- start = transMoney.compute(1, billingModel, orderStatus.getCreateTime(), endTime);
|
|
|
+ start = transMoney.compute(port, billingModel, orderStatus.getCreateTime(), endTime);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ log.error("计算订单异常{},{}",orderStatus.getPileCode(),e.getMessage());
|
|
|
+ return;
|
|
|
}
|
|
|
- redisCache.setCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1, start, 60, TimeUnit.SECONDS);
|
|
|
+ redisCache.setCacheObject(cacheKey, start, 120, TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
BigDecimal elec = start.get("elec");
|
|
|
@@ -229,273 +268,13 @@ public class MsgCharngingRunner {
|
|
|
orderStatus.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
orderStatus.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
orderStatusService.updateById(orderStatus);
|
|
|
-
|
|
|
- deviceControlerService.sendPortDetailCmd(deviceParam);
|
|
|
deviceControlerService.stopCharge(orderStatus.getDeviceImei(), orderStatus.getDeviceImei(), 1);
|
|
|
-
|
|
|
- //这里为了保证余额不足的情况时:上报实时状态的最后电量费用不超过余额,上报的最后一帧为前一帧数据
|
|
|
- //Map<String, BigDecimal> map1 = realTimeMoney.start(power/1000, billingModel, orderStatus.getCreateTime(),orderStatus.getEndTime());
|
|
|
- //Map<String, BigDecimal> start = transMoney.compute(1, billingModel, orderStatus.getCreateTime(),orderStatus.getEndTime());
|
|
|
-
|
|
|
- //redisCache.setCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode()+1, start, 5 * 60 , TimeUnit.SECONDS);
|
|
|
- //elec=start.get("elec");
|
|
|
- //money=start.get("money");
|
|
|
+ return;
|
|
|
}
|
|
|
int mi = (int) (System.currentTimeMillis() - orderStatus.getCreateTime()) / 1000 / 60;
|
|
|
-
|
|
|
- log.info("↑↑↑{},{},{}充电中实时状态上报 ",orderStatus.getPileCode(),orderStatus.getGunsCode(),orderStatus.getId());
|
|
|
realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, orderStatus.getTransOrder(), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), voltage, power, elec, money, mi);
|
|
|
-
|
|
|
+ log.info("↑↑↑{},{},{}充电中实时状态上报 ",orderStatus.getPileCode(),orderStatus.getGunsCode(),orderStatus.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
- ////// 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());
|
|
|
- ////
|
|
|
- ////
|
|
|
- //// //redis取出在线设备集合
|
|
|
- //// devicePileCodes.stream().forEach(devicePileCode -> {
|
|
|
- //// try {
|
|
|
- //// if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_ONE)) {
|
|
|
- //// DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, devicePileCode);
|
|
|
- //// if (deviceStatus != null) {
|
|
|
- //// if (deviceStatus.getGunStatus() != StatusConstant.CHARGING) {
|
|
|
- //// log.info("chargingMsg>>>deviceguns status>>" + deviceStatus.getGunStatus());
|
|
|
- //// return;
|
|
|
- //// }
|
|
|
- //// //存在设备上送充电状态
|
|
|
- //// DeviceConnectionMsg deviceConnectionMsg = map.get(devicePileCode);
|
|
|
- //// if (deviceConnectionMsg.getLoginStatus() == Constant.DEVICE_NOT_LOGIN_STATUS) {
|
|
|
- //// //
|
|
|
- //// QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
- //// deviceQueryWrapper.eq("pile_code", devicePileCode).eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
- //// Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
- //// Long heartTime = deviceConnectionMsg.getHeartTime();
|
|
|
- //// if (deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
- //// log.info("charngingTaskAsyncPool-1>not longin and heart normal>>" + devicePileCode);
|
|
|
- //// loginFrame.loginMsgSend(deviceConnectionMsg, device);
|
|
|
- //// }
|
|
|
- //// log.info("charngingTaskAsyncPool-1>not longin>>" + devicePileCode);
|
|
|
- //// return;
|
|
|
- //// }
|
|
|
- //// if (deviceStatus.getGunStatus() == StatusConstant.CHARGING) {
|
|
|
- //// if (deviceConnectionMsg.getLoginStatus() == 1) {
|
|
|
- //// if (redisCache.hasKey(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei())) {
|
|
|
- //// //TODO:充电时间 电量 金额 按计费模板进行计算后上报,不使用主板消息
|
|
|
- //// //设备当前状态筛选
|
|
|
- //// List<OrderStatus> orderStatuselist = orderStatuses.stream().filter(orderStatus -> orderStatus.getPileCode().equals(deviceStatus.getPileCode())).collect(Collectors.toList());
|
|
|
- //// if (orderStatuselist.size() > 0) {
|
|
|
- //// orderStatuselist.stream().forEach(orderStatus -> {
|
|
|
- //// //设备计费模板筛选
|
|
|
- //// List<BillingModel> billingModelList = billingModels.stream().filter(billingModel -> orderStatus.getPileCode().equals(billingModel.getPileCode())).collect(Collectors.toList());
|
|
|
- //// if (billingModelList.size() > 0) {
|
|
|
- //// //费用计算
|
|
|
- //// billingModelList.stream().forEach(billingModel -> {
|
|
|
- //// JSONObject statusJSON = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei());
|
|
|
- //// Integer voltage = statusJSON.getInteger("voltage");
|
|
|
- //// Integer power = statusJSON.getInteger("power");
|
|
|
- ////
|
|
|
- //// //计算实时数据
|
|
|
- //// long endTime = System.currentTimeMillis();
|
|
|
- //// //算电量
|
|
|
- //// Map<String, BigDecimal> start = null;
|
|
|
- //// try {
|
|
|
- //// start = transMoney.compute(1, billingModel, orderStatus.getCreateTime(), endTime, false);
|
|
|
- //// } catch (Exception e) {
|
|
|
- //// e.printStackTrace();
|
|
|
- //// }
|
|
|
- //// //log.info(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1 + ">>redis过期的时间" + redisCache.getExpire(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1));
|
|
|
- //// //log.info(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1 + "redis的键是否存在" + redisCache.hasKey(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1));
|
|
|
- //// if (redisCache.hasKey(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1) && redisCache.getExpire(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1) > 1) {
|
|
|
- //// start = redisCache.getCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1);
|
|
|
- //// } else {
|
|
|
- //// try {
|
|
|
- //// start = transMoney.compute(1, billingModel, orderStatus.getCreateTime(), endTime, true);
|
|
|
- //// } catch (Exception e) {
|
|
|
- //// e.printStackTrace();
|
|
|
- //// }
|
|
|
- //// redisCache.setCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 1, start, 60, TimeUnit.SECONDS);
|
|
|
- //// }
|
|
|
- //// BigDecimal elec = start.get("elec");
|
|
|
- //// BigDecimal money = start.get("money");
|
|
|
- //// if (elec.equals(new BigDecimal("0.0000"))) {
|
|
|
- //// elec = elec.add(new BigDecimal("0.0001").setScale(4, BigDecimal.ROUND_DOWN));
|
|
|
- //// }
|
|
|
- //// log.info(devicePileCode + "充电中-1=>实时elec>>>" + elec);
|
|
|
- //// //????????????????????????????
|
|
|
- //// if (money.compareTo(orderStatus.getStartMoney()) > 0) {
|
|
|
- //// //余额没有了,停充
|
|
|
- //// log.info("实时状态校验时余额不足>>>>>>停充>>>>");
|
|
|
- //// DeviceParam deviceParam = new DeviceParam();
|
|
|
- //// deviceParam.setDeviceId(orderStatus.getDeviceImei());
|
|
|
- //// deviceParam.setCcid(orderStatus.getDeviceImei());
|
|
|
- //// orderStatus.setEndTime(System.currentTimeMillis() - 1000 * 60 * 5);
|
|
|
- //// orderStatus.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
- //// orderStatusService.updateById(orderStatus);
|
|
|
- ////
|
|
|
- //// deviceControlerService.sendPortDetailCmd(deviceParam);
|
|
|
- //// deviceControlerService.stopCharge(orderStatus.getDeviceImei(), orderStatus.getDeviceImei(), 1);
|
|
|
- ////
|
|
|
- //// //这里为了保证余额不足的情况时:上报实时状态的最后电量费用不超过余额,上报的最后一帧为前一帧数据
|
|
|
- //// //Map<String, BigDecimal> map1 = realTimeMoney.start(power/1000, billingModel, orderStatus.getCreateTime(),orderStatus.getEndTime());
|
|
|
- //// //Map<String, BigDecimal> start = transMoney.compute(1, billingModel, orderStatus.getCreateTime(),orderStatus.getEndTime());
|
|
|
- ////
|
|
|
- //// //redisCache.setCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode()+1, start, 5 * 60 , TimeUnit.SECONDS);
|
|
|
- //// //elec=start.get("elec");
|
|
|
- //// //money=start.get("money");
|
|
|
- //// }
|
|
|
- //// int mi = (int) (System.currentTimeMillis() - orderStatus.getCreateTime()) / 1000 / 60;
|
|
|
- ////
|
|
|
- //// log.info("↑↑↑↑↑↑↑↑↑↑↑↑↑充电中实时状态上报-1↑↑↑↑↑↑↑↑↑↑↑↑↑mi " + mi);
|
|
|
- //// realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, orderStatus.getTransOrder(), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), voltage, power, elec, money, mi);
|
|
|
- //// });
|
|
|
- //// }
|
|
|
- //// });
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_TWO)) {
|
|
|
- //// DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, devicePileCode);
|
|
|
- //// if (deviceStatus != null) {
|
|
|
- //// //存在设备上送充电状态
|
|
|
- //// DeviceConnectionMsg deviceConnectionMsg = map.get(devicePileCode);
|
|
|
- //// if (deviceConnectionMsg.getLoginStatus() == Constant.DEVICE_NOT_LOGIN_STATUS) {
|
|
|
- //// //
|
|
|
- //// QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
|
|
|
- //// deviceQueryWrapper.eq("pile_code", devicePileCode).eq("disabled", DeviceOnlineStatus.NORMAL);
|
|
|
- //// Device device = deviceService.getOne(deviceQueryWrapper);
|
|
|
- //// Long heartTime = deviceConnectionMsg.getHeartTime();
|
|
|
- //// if (deviceStatus.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
- //// log.info("charngingTaskAsyncPool-2>not longin and heart normal>>" + devicePileCode);
|
|
|
- //// loginFrame.loginMsgSend(deviceConnectionMsg, device);
|
|
|
- //// }
|
|
|
- //// log.info("charngingTaskAsyncPool-2>not longin>>" + devicePileCode);
|
|
|
- //// return;
|
|
|
- //// }
|
|
|
- //// if (deviceStatus.getGunStatus() == StatusConstant.CHARGING) {
|
|
|
- //// if (deviceConnectionMsg.getLoginStatus() == 1) {
|
|
|
- //// if (redisCache.hasKey(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei())) {
|
|
|
- //// //TODO:充电时间 电量 金额 按计费模板进行计算后上报,不使用主板消息
|
|
|
- //// //设备当前状态筛选
|
|
|
- //// List<OrderStatus> orderStatusList = orderStatuses.stream().filter(orderStatus -> orderStatus.getPileCode().equals(deviceStatus.getPileCode())).collect(Collectors.toList());
|
|
|
- //// if (orderStatusList.size() > 0) {
|
|
|
- //// orderStatusList.stream().forEach(orderStatus -> {
|
|
|
- //// //设备计费模板筛选
|
|
|
- //// List<BillingModel> billingModelList = billingModels.stream().filter(billingModel -> orderStatus.getPileCode().equals(billingModel.getPileCode())).collect(Collectors.toList());
|
|
|
- //// if (billingModelList.size() > 0) {
|
|
|
- //// //费用计算
|
|
|
- //// billingModelList.stream().forEach(billingModel -> {
|
|
|
- //// JSONObject statusJSON = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei());
|
|
|
- //// Integer voltage = statusJSON.getInteger("voltage");
|
|
|
- //// Integer power = statusJSON.getInteger("power");
|
|
|
- //// long endTime = 0L;
|
|
|
- //// if (endTime == 0) {
|
|
|
- //// endTime = System.currentTimeMillis();
|
|
|
- //// }
|
|
|
- //// Map<String, BigDecimal> start = null;
|
|
|
- //// try {
|
|
|
- //// start = transMoney.compute(1, billingModel, orderStatus.getCreateTime(), endTime, false);
|
|
|
- //// } catch (Exception e) {
|
|
|
- //// e.printStackTrace();
|
|
|
- //// }
|
|
|
- //// if (redisCache.hasKey(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 2) && redisCache.getExpire(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 2) > 60 * 1000) {
|
|
|
- //// start = redisCache.getCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 2);
|
|
|
- //// } else {
|
|
|
- //// try {
|
|
|
- //// start = transMoney.compute(2, billingModel, orderStatus.getCreateTime(), endTime, true);
|
|
|
- //// } catch (Exception e) {
|
|
|
- //// e.printStackTrace();
|
|
|
- //// }
|
|
|
- //// redisCache.setCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 2, start, 5 * 60 * 1000, TimeUnit.MILLISECONDS);
|
|
|
- //// }
|
|
|
- //// BigDecimal elec = start.get("elec");
|
|
|
- //// BigDecimal money = start.get("money");
|
|
|
- //// if (elec.equals(BigDecimal.ZERO)) {
|
|
|
- //// elec = elec.add(new BigDecimal("0.0001"));
|
|
|
- //// }
|
|
|
- //// log.info(devicePileCode + "充电中-2=>实时elec>>>" + elec);
|
|
|
- //// if (money.compareTo(orderStatus.getStartMoney()) > 0) {
|
|
|
- //// //余额没有了,停充
|
|
|
- //// log.info("实时状态校验时余额不足>>>>>>停充>>>>");
|
|
|
- //// DeviceParam deviceParam = new DeviceParam();
|
|
|
- //// deviceParam.setDeviceId(orderStatus.getDeviceImei());
|
|
|
- //// deviceParam.setCcid(orderStatus.getDeviceImei());
|
|
|
- //// orderStatus.setEndTime(System.currentTimeMillis() - 1000 * 60 * 5);
|
|
|
- //// orderStatus.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
- //// orderStatusService.updateById(orderStatus);
|
|
|
- ////
|
|
|
- //// deviceControlerService.sendPortDetailCmd(deviceParam);
|
|
|
- //// deviceControlerService.stopCharge(orderStatus.getDeviceImei(), orderStatus.getDeviceImei(), 2);
|
|
|
- //// //余额没有了,停充
|
|
|
- ////// DeviceParam deviceParam = new DeviceParam();
|
|
|
- ////// deviceParam.setDeviceId(orderStatus.getDeviceImei());
|
|
|
- ////// deviceParam.setCcid(orderStatus.getDeviceImei());
|
|
|
- ////// deviceControlerService.sendPortDetailCmd(deviceParam);
|
|
|
- ////// deviceControlerService.stopCharge(orderStatus.getDeviceImei(), orderStatus.getDeviceImei(), 2);
|
|
|
- //////
|
|
|
- ////// money = orderStatus.getStartMoney();
|
|
|
- ////// orderStatus.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
- ////// orderStatusService.updateById(orderStatus);
|
|
|
- //// //这里为了保证余额不足的情况时:上报实时状态的最后电量费用不超过余额,上报的最后一帧为前一帧数据
|
|
|
- //// //Map<String, BigDecimal> map1 = realTimeMoney.start(power/1000, billingModel, orderStatus.getCreateTime(),orderStatus.getEndTime());
|
|
|
- //// redisCache.setCacheObject(RedisConstant.DEVICE_CHARNGING_INFO + orderStatus.getPileCode() + 2, start, 5 * 60 * 1000, TimeUnit.MILLISECONDS);
|
|
|
- //// elec = start.get("elec");
|
|
|
- //// money = start.get("money");
|
|
|
- //// }
|
|
|
- //// int mi = (int) (System.currentTimeMillis() - orderStatus.getCreateTime()) / 1000 / 60;
|
|
|
- //// log.info("↑↑↑↑↑↑↑↑↑↑↑↑↑充电中实时状态上报-2↑↑↑↑↑↑↑↑↑↑↑↑↑mi " + mi);
|
|
|
- //// realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, orderStatus.getTransOrder(), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), voltage, power, elec, money, mi);
|
|
|
- //// });
|
|
|
- //// }
|
|
|
- //// });
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// } catch (Exception e) {
|
|
|
- //// log.info("charging status push exception===" + e.toString());
|
|
|
- //// e.printStackTrace();
|
|
|
- //// }
|
|
|
- //// });
|
|
|
- ///*
|
|
|
- //
|
|
|
- // if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_ONE)) {
|
|
|
- // List<DeviceStatus> listOne = redisCache.getCacheObject(RedisConstant.ONLINE_DEVICE_ONE);
|
|
|
- // listOne.stream().forEach(deviceStatus -> {
|
|
|
- // //根据状态上报,15s的只报充电状态
|
|
|
- // DeviceConnectionMsg deviceConnectionMsg = map.get(deviceStatus.getPileCode());
|
|
|
- // if (deviceStatus.getGunStatus() == StatusConstant.CHARGING) {
|
|
|
- // if (redisCache.hasKey(RedisConstant.DEVICE_PORT_STATUS+deviceStatus.getDeviceImei())){
|
|
|
- // //++++ 20240319-15 这里费用计算需要用到计费模型
|
|
|
- // JSONObject statusJSON = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei());
|
|
|
- // Integer voltage = statusJSON.getInteger("voltage");
|
|
|
- // Integer power = statusJSON.getInteger("power");
|
|
|
- //
|
|
|
- // //++++
|
|
|
- // realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, FrameDataSplicing.transactionNum(deviceStatus.getPileCode(), deviceConnectionMsg.getMessageCount()), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, 0, 0, 0);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }
|
|
|
- // if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_TWO)) {
|
|
|
- // List<DeviceStatus> listTwo = redisCache.getCacheObject(RedisConstant.ONLINE_DEVICE_TWO);
|
|
|
- // listTwo.stream().forEach(deviceStatus -> {
|
|
|
- // //根据状态上报,15s的只报充电状态
|
|
|
- // DeviceConnectionMsg deviceConnectionMsg = map.get(deviceStatus.getPileCode());
|
|
|
- // if (deviceStatus.getGunStatus() == StatusConstant.CHARGING) {
|
|
|
- // //realTimeStatusPushFrame.deviceStatusPush(deviceConnectionMsg, FrameDataSplicing.transactionNum(deviceStatus.getPileCode(), deviceConnectionMsg.getMessageCount()), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, 0, 0, 0);
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }*/
|
|
|
-
|
|
|
-
|
|
|
}
|