|
@@ -12,6 +12,7 @@ import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
|
|
|
import com.tmzn.devicelinkykc.constant.ykc.TransConstant;
|
|
import com.tmzn.devicelinkykc.constant.ykc.TransConstant;
|
|
|
import com.tmzn.devicelinkykc.entity.*;
|
|
import com.tmzn.devicelinkykc.entity.*;
|
|
|
import com.tmzn.devicelinkykc.frameMsg.DataConversion;
|
|
import com.tmzn.devicelinkykc.frameMsg.DataConversion;
|
|
|
|
|
+import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
|
|
|
import com.tmzn.devicelinkykc.frameMsg.TransMoney;
|
|
import com.tmzn.devicelinkykc.frameMsg.TransMoney;
|
|
|
import com.tmzn.devicelinkykc.frameMsg.frameType.*;
|
|
import com.tmzn.devicelinkykc.frameMsg.frameType.*;
|
|
|
import com.tmzn.devicelinkykc.mapstruct.TransMapping;
|
|
import com.tmzn.devicelinkykc.mapstruct.TransMapping;
|
|
@@ -207,6 +208,9 @@ public class YkcMsgHandle {
|
|
|
|
|
|
|
|
} else if (framType == YkcSendDevice.DEVICE_STATUS_REQUEST.getFrameType()) {
|
|
} else if (framType == YkcSendDevice.DEVICE_STATUS_REQUEST.getFrameType()) {
|
|
|
logger.info("↓↓↓↓↓{}读取实时监测数据",deviceConnectionMsg.getDeviceId());
|
|
logger.info("↓↓↓↓↓{}读取实时监测数据",deviceConnectionMsg.getDeviceId());
|
|
|
|
|
+ handleRealTimeReport(deviceConnectionMsg,respone_msg,fromMsgSeq);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
} else if (framType == YkcSendDevice.START_CHARNGING_REQUEST.getFrameType() || framType == YkcSendDevice.START_CHARNGING_REQUEST_16.getFrameType()) {
|
|
} else if (framType == YkcSendDevice.START_CHARNGING_REQUEST.getFrameType() || framType == YkcSendDevice.START_CHARNGING_REQUEST_16.getFrameType()) {
|
|
|
logger.info("↓↓↓↓↓{}运营平台远程控制启机" + framType,deviceConnectionMsg.getDeviceId());
|
|
logger.info("↓↓↓↓↓{}运营平台远程控制启机" + framType,deviceConnectionMsg.getDeviceId());
|
|
@@ -292,6 +296,108 @@ public class YkcMsgHandle {
|
|
|
//登录失败等心跳包10秒后进行重试
|
|
//登录失败等心跳包10秒后进行重试
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //读取时实数据
|
|
|
|
|
+ private void handleRealTimeReport(DeviceConnectionMsg deviceConnectionMsg, byte[] respone_msg,byte[] fromMsgSeq){
|
|
|
|
|
+ String pileCode = deviceConnectionMsg.getDeviceId();
|
|
|
|
|
+ int port = respone_msg[7] & 0xFF; //0正常 1禁用
|
|
|
|
|
+ //请求获取实时数据
|
|
|
|
|
+ //获取枪状态
|
|
|
|
|
+ QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ deviceStatusQueryWrapper.eq("pile_code", deviceConnectionMsg.getDeviceId());
|
|
|
|
|
+ deviceStatusQueryWrapper.eq("gun_port", port);
|
|
|
|
|
+ DeviceStatus deviceStatus = deviceStatusService.getOne(deviceStatusQueryWrapper);
|
|
|
|
|
+ if(deviceStatus==null){
|
|
|
|
|
+ logger.info("实时无端口信息");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //不是充电中 就上报空闲
|
|
|
|
|
+ if(deviceStatus.getGunStatus()!=StatusConstant.CHARGING){
|
|
|
|
|
+ realTimeStatusPushFrame.deviceStatusPush(fromMsgSeq,deviceConnectionMsg, FrameDataSplicing.
|
|
|
|
|
+ transactionNum(deviceStatus.getPileCode(), deviceConnectionMsg.getMessageCount()) , deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, zero, zero, 0);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //上报充电中的实时状态
|
|
|
|
|
+ //上送充电状态
|
|
|
|
|
+ JSONObject statusJSON = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + deviceStatus.getDeviceImei());
|
|
|
|
|
+ if(statusJSON==null){
|
|
|
|
|
+ logger.info("实时无最近103数据{}",pileCode);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //拿当前的订单去更新余额
|
|
|
|
|
+ QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ orderStatusQueryWrapper.eq("pile_code", pileCode).eq("guns_code", port).orderByDesc("create_time").last("limit 1");
|
|
|
|
|
+ OrderStatus orderStatus = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if(orderStatus==null){
|
|
|
|
|
+ logger.info("实时无订单{}",pileCode);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer voltage;
|
|
|
|
|
+ Integer power;
|
|
|
|
|
+
|
|
|
|
|
+ if(port==1){
|
|
|
|
|
+ voltage = statusJSON.getInteger("voltage");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ voltage = statusJSON.getInteger("voltage_1");
|
|
|
|
|
+ if(voltage==null){
|
|
|
|
|
+ voltage = statusJSON.getInteger("voltage");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(port == 1){
|
|
|
|
|
+ power = statusJSON.getInteger("power");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ power = statusJSON.getInteger("power_1");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(power==null){
|
|
|
|
|
+ power = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(voltage==null){
|
|
|
|
|
+ voltage = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //计算实时数据
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ //算电量
|
|
|
|
|
+ Map<String, BigDecimal> start = transMoney.getTransData();
|
|
|
|
|
+
|
|
|
|
|
+ String transCacheKey = "ChargingTrans:"+orderStatus.getId();
|
|
|
|
|
+ if(redisCache.hasKey(transCacheKey)){
|
|
|
|
|
+ start = redisCache.getCacheObject(transCacheKey);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //缓存120秒避免重复计算电量
|
|
|
|
|
+ try {
|
|
|
|
|
+ QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
|
|
|
|
|
+ billWapper.in("pile_code", pileCode);
|
|
|
|
|
+ BillingModel billingModel = billingModelService.getOne(billWapper);
|
|
|
|
|
+ start = transMoney.compute(port, billingModel, orderStatus.getCreateTime(), endTime);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ logger.error("计算订单异常{},{}",orderStatus.getPileCode(),e.getMessage());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ redisCache.setCacheObject(transCacheKey, start, 90, 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));
|
|
|
|
|
+ }
|
|
|
|
|
+ logger.info("{}-{}-{}充电中=>实时elec:{}>>>实时金额>>>{}=>p:{},v:{}" ,orderStatus.getPileCode(),port,elec,orderStatus.getGunsCode(),money,power,voltage);
|
|
|
|
|
+
|
|
|
|
|
+ int mi = (int) (System.currentTimeMillis() - orderStatus.getCreateTime()) / 1000 / 60;
|
|
|
|
|
+ realTimeStatusPushFrame.deviceStatusPush(fromMsgSeq,deviceConnectionMsg, orderStatus.getTransOrder(), deviceStatus.getPileCode(), deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), voltage, power, elec, money, mi);
|
|
|
|
|
+ logger.info("↑↑↑{},{},{}充电中实时状态上报 ",orderStatus.getPileCode(),orderStatus.getGunsCode(),orderStatus.getId());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|