|
|
@@ -153,6 +153,35 @@ public class DeviceMsgHandle {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //处理离线消息
|
|
|
+ //查找所有端口状态置为下线 并推送状态给云快充
|
|
|
+ private void _handleDeviceOfflineMsg(String imei){
|
|
|
+ QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
+ deviceStatusQueryWrapper.eq("device_imei", imei);
|
|
|
+ List<DeviceStatus> list = deviceStatusService.list(deviceStatusQueryWrapper);
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ for (DeviceStatus deviceStatus : list) {
|
|
|
+ //deviceStatus.setInsertGunStatus(StatusConstant.INSERT_GUNS_NO);
|
|
|
+ //deviceStatus.setGunStatus(StatusConstant.OFFLINE);
|
|
|
+ deviceStatus.setOnlineStatus(DeviceOnlineStatus.OFFLINE);
|
|
|
+ deviceStatus.setUpdateTime(System.currentTimeMillis());
|
|
|
+ deviceStatusService.updateById(deviceStatus);
|
|
|
+ if (socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
|
|
|
+ String pilecode = deviceStatus.getPileCode();
|
|
|
+ DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(pilecode);
|
|
|
+ byte[] transactionNum = new byte[16]; //FrameDataSplicing.transactionNum(pilecode, deviceConnection.getMessageCount());
|
|
|
+ if (deviceStatus.getGunStatus() == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
+ deviceStatus.setGunStatus(StatusConstant.FREE);
|
|
|
+ }
|
|
|
+ realTimeStatusPushFrame.deviceStatusPush(deviceConnection, transactionNum, pilecode, (byte) deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, zero, zero, 0);
|
|
|
+ socketHandle.removeDeviceConnection(deviceStatus.getPileCode());
|
|
|
+ redisCache.deleteObject(RedisConstant.DEVICE_PORT_STATUS + imei);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设备状态按照设备上报和设备心跳上送时间校验修改,这里就必须更新状态的修改时间;通过定时任务判断在线设备接收心跳包超10分钟改为离线
|
|
|
*
|
|
|
@@ -161,51 +190,31 @@ public class DeviceMsgHandle {
|
|
|
*/
|
|
|
private boolean checkDeviceStatus(JSONObject jsonObject) throws Exception {
|
|
|
String imei = jsonObject.getString("imei");
|
|
|
-
|
|
|
Integer cmd = jsonObject.getInteger("cmd");
|
|
|
if (!jsonObject.containsKey("type")) {
|
|
|
//TODO:离线判断:设备上报+?设备心跳时间校验?
|
|
|
//没有type但是cmd指令是离线时37896=========
|
|
|
if (cmd == 37896) {
|
|
|
- QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
|
|
|
- deviceStatusQueryWrapper.eq("device_imei", imei);
|
|
|
- List<DeviceStatus> list = deviceStatusService.list(deviceStatusQueryWrapper);
|
|
|
- if (list.size() > 0) {
|
|
|
- for (DeviceStatus deviceStatus : list) {
|
|
|
- //deviceStatus.setInsertGunStatus(StatusConstant.INSERT_GUNS_NO);
|
|
|
- //deviceStatus.setGunStatus(StatusConstant.OFFLINE);
|
|
|
- deviceStatus.setOnlineStatus(DeviceOnlineStatus.OFFLINE);
|
|
|
- deviceStatus.setUpdateTime(System.currentTimeMillis());
|
|
|
- deviceStatusService.updateById(deviceStatus);
|
|
|
- if (socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
|
|
|
- String pilecode = deviceStatus.getPileCode();
|
|
|
- DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(pilecode);
|
|
|
- byte[] transactionNum = new byte[16]; //FrameDataSplicing.transactionNum(pilecode, deviceConnection.getMessageCount());
|
|
|
- if (deviceStatus.getGunStatus() == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
- deviceStatus.setGunStatus(StatusConstant.FREE);
|
|
|
- }
|
|
|
- realTimeStatusPushFrame.deviceStatusPush(deviceConnection, transactionNum, pilecode, (byte) deviceStatus.getGunPort(), deviceStatus.getGunStatus(), deviceStatus.getInsertGunStatus(), 0, 0, zero, zero, 0);
|
|
|
- socketHandle.removeDeviceConnection(deviceStatus.getPileCode());
|
|
|
- redisCache.deleteObject(RedisConstant.DEVICE_PORT_STATUS + imei);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //处理离线消息
|
|
|
+ _handleDeviceOfflineMsg(imei);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
Integer type = jsonObject.getInteger("type");
|
|
|
- //TODO:设备状态的修改这里进行监听变化 ,?? 1.设备消息cmd:75960设备上报消息是的命令,只要设备报的不是离线当做设备在线 2.设备上报指令后根据type类型来分类处理消息包括:设备设为在线 是否插枪状态 枪状态(端口状态)
|
|
|
- if (NormalChargeConstant.CMD_SET_MAINBOARD.equals(cmd)) {
|
|
|
|
|
|
- if (NormalChargeConstant.KEY_PORT_DETAIL.equals(type)) {
|
|
|
- //103状态是带电压功率等信息的,所以需要对该信息进行处理操作
|
|
|
- JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
- Integer port_first_status = data.getInteger("port_first_status");
|
|
|
- Integer port_second_status = data.getInteger("port_second_status");
|
|
|
- Integer power = data.getInteger("power");
|
|
|
+ if(!NormalChargeConstant.CMD_SET_MAINBOARD.equals(cmd)){
|
|
|
+ logger.error("不支持的命令");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- //功率为0时,还是充电中状态,将状态转换成空闲,结束充电
|
|
|
+ if(NormalChargeConstant.KEY_PORT_DETAIL.equals(type)){
|
|
|
+ //103状态是带电压功率等信息的,所以需要对该信息进行处理操作
|
|
|
+ JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
+ Integer port_first_status = data.getInteger("port_first_status");
|
|
|
+ Integer port_second_status = data.getInteger("port_second_status");
|
|
|
+ Integer power = data.getInteger("power");
|
|
|
+ //功率为0时,还是充电中状态,将状态转换成空闲,结束充电
|
|
|
// 20240608现场使用时出现充电状态第一次103上来就是power是0情况
|
|
|
// if (port_first_status != null&&power==0&&port_first_status==PortStatusConstant.CHARGING){
|
|
|
// port_first_status=PortStatusConstant.FREE;
|
|
|
@@ -213,35 +222,45 @@ public class DeviceMsgHandle {
|
|
|
// if (port_second_status != null&&power==0&&port_second_status==PortStatusConstant.CHARGING){
|
|
|
// port_second_status=PortStatusConstant.FREE;
|
|
|
// }
|
|
|
- redisCache.setCacheObject(RedisConstant.DEVICE_PORT_STATUS + imei, data, 15, TimeUnit.MINUTES);
|
|
|
- if (port_first_status != null) {
|
|
|
- checkPort(port_first_status, 1, imei, type);
|
|
|
- }
|
|
|
- if (port_second_status != null) {
|
|
|
- checkPort(port_second_status, 2, imei, type);
|
|
|
- }
|
|
|
+ redisCache.setCacheObject(RedisConstant.DEVICE_PORT_STATUS + imei, data, 15, TimeUnit.MINUTES);
|
|
|
+ if (port_first_status != null) {
|
|
|
+ checkPort(port_first_status, 1, imei, type);
|
|
|
+ }
|
|
|
+ if (port_second_status != null) {
|
|
|
+ checkPort(port_second_status, 2, imei, type);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- } else if (NormalChargeConstant.PORT_STATUS.equals(type)) {
|
|
|
- //116端口详情也会变化
|
|
|
- JSONArray data = jsonObject.getJSONArray("data");
|
|
|
- checkPort(data.getInteger(4), data.getInteger(3), imei, type);
|
|
|
- } else if (NormalChargeConstant.KEY_PORT_STATUS.equals(type)) {
|
|
|
- //状态查询101
|
|
|
- JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
- Integer port_first_status = data.getInteger("port_first_status");
|
|
|
- Integer port_second_status = data.getInteger("port_second_status");
|
|
|
- if (port_first_status != null) {
|
|
|
- checkPort(port_first_status, 1, imei, type);
|
|
|
- }
|
|
|
- if (port_second_status != null) {
|
|
|
- checkPort(port_second_status, 2, imei, type);
|
|
|
- }
|
|
|
- } else if (NormalChargeConstant.KEY_STARTCHARGE.equals(type)) {
|
|
|
- //开启充电设备上报结果
|
|
|
- JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
- Integer result = data.getInteger("result");
|
|
|
- Integer port = data.getInteger("port");
|
|
|
- //TODO:上报云快充启动充电结果
|
|
|
+ if (NormalChargeConstant.PORT_STATUS.equals(type)) {
|
|
|
+ //116端口详情也会变化
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
+ checkPort(data.getInteger(4), data.getInteger(3), imei, type);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (NormalChargeConstant.KEY_PORT_STATUS.equals(type)) {
|
|
|
+ //状态查询101
|
|
|
+ JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
+ Integer port_first_status = data.getInteger("port_first_status");
|
|
|
+ Integer port_second_status = data.getInteger("port_second_status");
|
|
|
+ if (port_first_status != null) {
|
|
|
+ checkPort(port_first_status, 1, imei, type);
|
|
|
+ }
|
|
|
+ if (port_second_status != null) {
|
|
|
+ checkPort(port_second_status, 2, imei, type);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //104消息
|
|
|
+ if (NormalChargeConstant.KEY_STARTCHARGE.equals(type)) {
|
|
|
+ //开启充电设备上报结果
|
|
|
+ JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
+ Integer result = data.getInteger("result");
|
|
|
+ Integer port = data.getInteger("port");
|
|
|
+ //TODO:上报云快充启动充电结果
|
|
|
// QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
// orderStatusQueryWrapper.eq("imei",imei).eq("guns_code",port);
|
|
|
// OrderStatus one = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
@@ -253,201 +272,216 @@ public class DeviceMsgHandle {
|
|
|
// logger.info("开启充电未查到设备订单");
|
|
|
// return false;
|
|
|
// }
|
|
|
- QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
- orderStatusQueryWrapper.eq("device_imei", imei).eq("guns_code", port).orderByDesc("create_time").last("limit 1");
|
|
|
- OrderStatus statusServiceOne = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
- byte[] bytes = statusServiceOne.getTransOrder();
|
|
|
- logger.info(statusServiceOne.getPileCode() + ":设备开启充电流水号:" + DataConversion.bytesToHexString(bytes));
|
|
|
- DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(statusServiceOne.getPileCode());
|
|
|
- int reson = 0x00;
|
|
|
- if (result == 0x01) {
|
|
|
- //启充成功上报充电开启成功
|
|
|
- charngingPushFrame.startStatus(deviceConnection, bytes, port, result, 0x00);
|
|
|
-
|
|
|
- } else {
|
|
|
- //启机不成功,根据设备状态判断,并且要结束充电并上报订单
|
|
|
- if (port == 1) {
|
|
|
- if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_ONE)) {
|
|
|
- DeviceStatus oneStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, statusServiceOne.getPileCode());
|
|
|
- if (StatusConstant.FAULT == oneStatus.getGunStatus()) {
|
|
|
- reson = 0x03;
|
|
|
- } else if (StatusConstant.OFFLINE == oneStatus.getGunStatus()) {
|
|
|
- reson = 0x04;
|
|
|
- } else if (StatusConstant.CHARGING == oneStatus.getGunStatus()) {
|
|
|
- reson = 0x02;
|
|
|
- }
|
|
|
- charngingPushFrame.startStatus(deviceConnection, bytes, port, result, reson);
|
|
|
+ QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
+ orderStatusQueryWrapper.eq("device_imei", imei).eq("guns_code", port).orderByDesc("create_time").last("limit 1");
|
|
|
+ OrderStatus statusServiceOne = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
+ byte[] bytes = statusServiceOne.getTransOrder();
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":设备开启充电流水号:" + DataConversion.bytesToHexString(bytes));
|
|
|
+ DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(statusServiceOne.getPileCode());
|
|
|
+ int reson = 0x00;
|
|
|
+ if (result == 0x01) {
|
|
|
+ //启充成功上报充电开启成功
|
|
|
+ charngingPushFrame.startStatus(deviceConnection, bytes, port, result, 0x00);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //启机不成功,根据设备状态判断,并且要结束充电并上报订单
|
|
|
+ if (port == 1) {
|
|
|
+ if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_ONE)) {
|
|
|
+ DeviceStatus oneStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, statusServiceOne.getPileCode());
|
|
|
+ if (StatusConstant.FAULT == oneStatus.getGunStatus()) {
|
|
|
+ reson = 0x03;
|
|
|
+ } else if (StatusConstant.OFFLINE == oneStatus.getGunStatus()) {
|
|
|
+ reson = 0x04;
|
|
|
+ } else if (StatusConstant.CHARGING == oneStatus.getGunStatus()) {
|
|
|
+ reson = 0x02;
|
|
|
}
|
|
|
- } else if (port == 2) {
|
|
|
- if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_TWO)) {
|
|
|
- DeviceStatus oneStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, statusServiceOne.getPileCode());
|
|
|
- if (StatusConstant.FAULT == oneStatus.getGunStatus()) {
|
|
|
- reson = 0x03;
|
|
|
- } else if (StatusConstant.OFFLINE == oneStatus.getGunStatus()) {
|
|
|
- reson = 0x04;
|
|
|
- } else if (StatusConstant.CHARGING == oneStatus.getGunStatus()) {
|
|
|
- reson = 0x02;
|
|
|
- }
|
|
|
- charngingPushFrame.startStatus(deviceConnection, bytes, port, result, reson);
|
|
|
+ charngingPushFrame.startStatus(deviceConnection, bytes, port, result, reson);
|
|
|
+ }
|
|
|
+ } else if (port == 2) {
|
|
|
+ if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_TWO)) {
|
|
|
+ DeviceStatus oneStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, statusServiceOne.getPileCode());
|
|
|
+ if (StatusConstant.FAULT == oneStatus.getGunStatus()) {
|
|
|
+ reson = 0x03;
|
|
|
+ } else if (StatusConstant.OFFLINE == oneStatus.getGunStatus()) {
|
|
|
+ reson = 0x04;
|
|
|
+ } else if (StatusConstant.CHARGING == oneStatus.getGunStatus()) {
|
|
|
+ reson = 0x02;
|
|
|
}
|
|
|
+ charngingPushFrame.startStatus(deviceConnection, bytes, port, result, reson);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //发送一条103消息 等待状态上报
|
|
|
- try{
|
|
|
- DeviceParam dataParam = new DeviceParam();
|
|
|
- dataParam.setDeviceId(imei);
|
|
|
- dataParam.setCcid(imei);
|
|
|
- deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
- logger.info(statusServiceOne.getPileCode() + ":主动下发103消息");
|
|
|
- }catch (Exception e){
|
|
|
- logger.info(statusServiceOne.getPileCode() + ":主动下发103消息异常"+e.getMessage());
|
|
|
- }
|
|
|
+ //发送一条103消息 等待状态上报
|
|
|
+ try{
|
|
|
+ DeviceParam dataParam = new DeviceParam();
|
|
|
+ dataParam.setDeviceId(imei);
|
|
|
+ dataParam.setCcid(imei);
|
|
|
+ deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":主动下发103消息");
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":主动下发103消息异常"+e.getMessage());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- } else if (NormalChargeConstant.KEY_END_NOTICE.equals(type)) {
|
|
|
- //停止充电通知触发情况:1.急停,收到停充时主动要去发停充,所以这里不能处理急停的交易订单;2.手动停充,正常的远程停止指令
|
|
|
- // 1.设备已经在接收到云快充指令的时候进行了停充操作,2.结算订单,上报云快充停止回复
|
|
|
+ if (NormalChargeConstant.KEY_END_NOTICE.equals(type)) {
|
|
|
+ //停止充电通知触发情况:1.急停,收到停充时主动要去发停充,所以这里不能处理急停的交易订单;2.手动停充,正常的远程停止指令
|
|
|
+ // 1.设备已经在接收到云快充指令的时候进行了停充操作,2.结算订单,上报云快充停止回复
|
|
|
|
|
|
- try {
|
|
|
+ try {
|
|
|
|
|
|
- JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
- logger.info("接收到设备上送113停止充电msg>>" + jsonObject.toString());
|
|
|
- int port = data.getIntValue("port");
|
|
|
- byte reson = data.getByte("reason");
|
|
|
- QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
- orderStatusQueryWrapper.eq("device_imei", imei).eq("guns_code", port).orderByDesc("create_time").last("limit 1");
|
|
|
- OrderStatus statusServiceOne = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
- if (statusServiceOne.getReasonStopCharging() != TransConstant.APP_REMOTE_STOP) {
|
|
|
- DeviceParam dataParam = new DeviceParam();
|
|
|
- dataParam.setDeviceId(imei);
|
|
|
- dataParam.setCcid(imei);
|
|
|
- deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (statusServiceOne.getTransactionOrderReportingActionStatus()==StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK){
|
|
|
- return false;
|
|
|
- }
|
|
|
- //查询计费模板
|
|
|
- QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
|
|
|
- billingModelQueryWrapper.eq("device_imei", imei);
|
|
|
- BillingModel model = billingModelService.getOne(billingModelQueryWrapper);
|
|
|
- //收到停充回复
|
|
|
- DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(statusServiceOne.getPileCode());
|
|
|
- if (reson == 0x01) {
|
|
|
- if (redisCache.hasKey(RedisConstant.DEVICE_PORT_STATUS + imei)) {
|
|
|
- //拿缓存的103状态看现在的端口状态是急停不处理113停止充电
|
|
|
- JSONObject dataJson = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + imei);
|
|
|
- Integer port_first_status = dataJson.getInteger("port_first_status");
|
|
|
- Integer port_second_status = dataJson.getInteger("port_second_status");
|
|
|
- if (port_first_status == PortStatusConstant.EMERGENCY_STOP || port_second_status == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- if (statusServiceOne.getReasonStopCharging() == TransConstant.EMERGENCY_STOP_EXCEPTION_STOP || statusServiceOne.getStopChargingReply() == 1) {
|
|
|
- //1.急停停充的逻辑不处理停止充电记录 2.一个订单多次停止也不再次上报 3.充满不拔枪113结束通知会延迟所以充满时已经处理过交易上送
|
|
|
- return false;
|
|
|
- }
|
|
|
- //113进到这里说明需要记录结束时间(最优时间,尽量能让后台计费的103或113落库)
|
|
|
- statusServiceOne.setEndTime(System.currentTimeMillis());
|
|
|
- byte[] encrypt = new byte[0];
|
|
|
- //订单充电结束但是原因是0的一般是当手动停充处理
|
|
|
- if (statusServiceOne.getReasonStopCharging() == 0) {
|
|
|
- statusServiceOne.setReasonStopCharging(TransConstant.MANUAL_STOP);
|
|
|
- }
|
|
|
- ////计算电量费用后上报,手动停止和余额不足的情况
|
|
|
- // DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, statusServiceOne.getPileCode());
|
|
|
- Map<String, BigDecimal> map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
- logger.info(statusServiceOne.getPileCode() + ":停止充电上送交易记录" + DataConversion.bytesToHexString(statusServiceOne.getTransOrder()));
|
|
|
- encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 1, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, statusServiceOne.getReasonStopCharging());
|
|
|
- statusServiceOne.setOriginalText(encrypt);
|
|
|
- statusServiceOne.setStopChargingReply(StatusConstant.STOP_CHARGING_REPLY_OK);
|
|
|
- statusServiceOne.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
- statusServiceOne.setTransactionOrderReportingActionStatus(StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK);
|
|
|
- //statusServiceOne.setEndTime(endTime);
|
|
|
- orderStatusService.updateById(statusServiceOne);
|
|
|
- charngingPushFrame.endStatus(deviceConnection, port, 0x01, 0x00);
|
|
|
- } else if (reson == 0x00) {
|
|
|
- //余额用完停充
|
|
|
- logger.info(statusServiceOne.getPileCode() + ":设备余额不足>>>>>>停充>>>>");
|
|
|
- DeviceParam deviceParam = new DeviceParam();
|
|
|
- deviceParam.setDeviceId(statusServiceOne.getDeviceImei());
|
|
|
- deviceParam.setCcid(statusServiceOne.getDeviceImei());
|
|
|
- //deviceControlerService.sendPortDetailCmd(deviceParam);
|
|
|
- //deviceControlerService.stopCharge(statusServiceOne.getDeviceImei(), statusServiceOne.getDeviceImei(), 1);
|
|
|
- statusServiceOne.setEndTime(System.currentTimeMillis());
|
|
|
- byte[] encrypt = new byte[0];
|
|
|
- statusServiceOne.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
- //计算电量
|
|
|
- Map<String, BigDecimal> map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
- encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 2, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, statusServiceOne.getReasonStopCharging());
|
|
|
- statusServiceOne.setOriginalText(encrypt);
|
|
|
- statusServiceOne.setStopChargingReply(StatusConstant.STOP_CHARGING_REPLY_OK);
|
|
|
- statusServiceOne.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
- statusServiceOne.setTransactionOrderReportingActionStatus(StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK);
|
|
|
- orderStatusService.updateById(statusServiceOne);
|
|
|
- //return false;
|
|
|
- }
|
|
|
- //deviceControlerService.reset(imei, imei);
|
|
|
+ JSONObject data = jsonObject.getJSONObject("real_data");
|
|
|
+ logger.info("接收到设备上送113停止充电msg>>" + jsonObject.toString());
|
|
|
+ int port = data.getIntValue("port");
|
|
|
+ byte reson = data.getByte("reason");
|
|
|
+ QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
+ orderStatusQueryWrapper.eq("device_imei", imei).eq("guns_code", port).orderByDesc("create_time").last("limit 1");
|
|
|
+ OrderStatus statusServiceOne = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
+ if (statusServiceOne.getReasonStopCharging() != TransConstant.APP_REMOTE_STOP) {
|
|
|
+ //不是远程停止的 就给设备发送消息获取端口状态
|
|
|
DeviceParam dataParam = new DeviceParam();
|
|
|
dataParam.setDeviceId(imei);
|
|
|
dataParam.setCcid(imei);
|
|
|
deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
- } catch (Exception e) {
|
|
|
- //TODO:测试不上传订单,报个空闲设备状态
|
|
|
- DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(imei);
|
|
|
- realTimeStatusPushFrame.deviceStatusPush(deviceConnection, FrameDataSplicing.transactionNum(deviceConnection.getDeviceId(), deviceConnection.getMessageCount()), deviceConnection.getDeviceId(), (byte) 1, StatusConstant.FREE, StatusConstant.CHARGING_INIT_STATUS_OK, 0, 0, zero, zero, 0);
|
|
|
- e.printStackTrace();
|
|
|
+ return false;
|
|
|
}
|
|
|
- } else if (NormalChargeConstant.EMERGENCY_STOP_CHARGING.equals(type)) {
|
|
|
- //急停停充
|
|
|
- JSONArray data = jsonObject.getJSONArray("data");
|
|
|
- int port = data.getInteger(2);
|
|
|
- int status = data.getInteger(3);
|
|
|
- //关闭急停和急停完,停止充电,获取设备状态
|
|
|
- DeviceParam dataParam = new DeviceParam();
|
|
|
- dataParam.setDeviceId(imei);
|
|
|
- dataParam.setCcid(imei);
|
|
|
- deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
- deviceControlerService.stopCharge(imei, imei, port);
|
|
|
+ if (statusServiceOne.getTransactionOrderReportingActionStatus()==StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK){
|
|
|
+ //如果已上报停止状态就不再上报
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //远程停止
|
|
|
//查询计费模板
|
|
|
QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
|
|
|
billingModelQueryWrapper.eq("device_imei", imei);
|
|
|
BillingModel model = billingModelService.getOne(billingModelQueryWrapper);
|
|
|
- QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
- orderStatusQueryWrapper.eq("device_imei", imei)
|
|
|
- .eq("guns_code", port)
|
|
|
- .orderByDesc("create_time"
|
|
|
- ).last("limit 1");
|
|
|
- OrderStatus statusServiceOne = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
- statusServiceOne.setEndTime(System.currentTimeMillis());
|
|
|
+ //收到停充回复
|
|
|
DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(statusServiceOne.getPileCode());
|
|
|
- if (status == 1) {
|
|
|
+ if (reson == 0x01) {
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":用户主动停充>>>>>>停充>>>>");
|
|
|
+ //用户主动停止充电
|
|
|
+ if (redisCache.hasKey(RedisConstant.DEVICE_PORT_STATUS + imei)) {
|
|
|
+ //拿缓存的103状态看现在的端口状态是急停不处理113停止充电
|
|
|
+ JSONObject dataJson = redisCache.getCacheObject(RedisConstant.DEVICE_PORT_STATUS + imei);
|
|
|
+ Integer port_first_status = dataJson.getInteger("port_first_status");
|
|
|
+ Integer port_second_status = dataJson.getInteger("port_second_status");
|
|
|
+ if (port_first_status == PortStatusConstant.EMERGENCY_STOP || port_second_status == PortStatusConstant.EMERGENCY_STOP) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (statusServiceOne.getReasonStopCharging() == TransConstant.EMERGENCY_STOP_EXCEPTION_STOP || statusServiceOne.getStopChargingReply() == 1) {
|
|
|
+ //1.急停停充的逻辑不处理停止充电记录 2.一个订单多次停止也不再次上报 3.充满不拔枪113结束通知会延迟所以充满时已经处理过交易上送
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //113进到这里说明需要记录结束时间(最优时间,尽量能让后台计费的103或113落库)
|
|
|
+ statusServiceOne.setEndTime(System.currentTimeMillis());
|
|
|
byte[] encrypt = new byte[0];
|
|
|
- if (port == 1) {
|
|
|
- //急停停充:急停状态下:1.向设备发起结束充电,结算交易订单(交给结束充电处理;但是要考虑是急停的原因),2.上报的充电结束的订单式
|
|
|
-
|
|
|
- Map<String, BigDecimal> map = transMoney.compute(1, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
-
|
|
|
- logger.info(statusServiceOne.getPileCode() + ":急停停充>>>上报交易记录>>>");
|
|
|
- encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 1, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, TransConstant.EMERGENCY_STOP_EXCEPTION_STOP);
|
|
|
- } else if (port == 2) {
|
|
|
- //TODO:这里还是模拟数据上报
|
|
|
- DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, statusServiceOne.getPileCode());
|
|
|
-
|
|
|
- Map<String, BigDecimal> map = transMoney.compute(2, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
- //模拟3.5千瓦
|
|
|
- encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 2, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, TransConstant.EMERGENCY_STOP_EXCEPTION_STOP);
|
|
|
+ //订单充电结束但是原因是0的一般是当手动停充处理
|
|
|
+ if (statusServiceOne.getReasonStopCharging() == 0) {
|
|
|
+ statusServiceOne.setReasonStopCharging(TransConstant.MANUAL_STOP);
|
|
|
}
|
|
|
+ ////计算电量费用后上报,手动停止和余额不足的情况
|
|
|
+ // DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, statusServiceOne.getPileCode());
|
|
|
+ Map<String, BigDecimal> map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":停止充电上送交易记录" + DataConversion.bytesToHexString(statusServiceOne.getTransOrder()));
|
|
|
+ encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 1, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, statusServiceOne.getReasonStopCharging());
|
|
|
+ statusServiceOne.setOriginalText(encrypt);
|
|
|
+ statusServiceOne.setStopChargingReply(StatusConstant.STOP_CHARGING_REPLY_OK);
|
|
|
+ statusServiceOne.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
+ statusServiceOne.setTransactionOrderReportingActionStatus(StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK);
|
|
|
+ //statusServiceOne.setEndTime(endTime);
|
|
|
+ orderStatusService.updateById(statusServiceOne);
|
|
|
+ charngingPushFrame.endStatus(deviceConnection, port, 0x01, 0x00);
|
|
|
+ } else if (reson == 0x00) {
|
|
|
+ //余额用完停充
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":设备余额不足>>>>>>停充>>>>");
|
|
|
+ DeviceParam deviceParam = new DeviceParam();
|
|
|
+ deviceParam.setDeviceId(statusServiceOne.getDeviceImei());
|
|
|
+ deviceParam.setCcid(statusServiceOne.getDeviceImei());
|
|
|
+ //deviceControlerService.sendPortDetailCmd(deviceParam);
|
|
|
+ //deviceControlerService.stopCharge(statusServiceOne.getDeviceImei(), statusServiceOne.getDeviceImei(), 1);
|
|
|
+ statusServiceOne.setEndTime(System.currentTimeMillis());
|
|
|
+ byte[] encrypt = new byte[0];
|
|
|
+ statusServiceOne.setReasonStopCharging(TransConstant.INSUFFICIENT_BALANCE_EXCEPTION_STOP);
|
|
|
+ //计算电量
|
|
|
+ Map<String, BigDecimal> map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":余额用完充电上送交易记录" + DataConversion.bytesToHexString(statusServiceOne.getTransOrder()));
|
|
|
+ encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 2, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, statusServiceOne.getReasonStopCharging());
|
|
|
statusServiceOne.setOriginalText(encrypt);
|
|
|
- statusServiceOne.setReasonStopCharging(TransConstant.EMERGENCY_STOP_EXCEPTION_STOP);
|
|
|
statusServiceOne.setStopChargingReply(StatusConstant.STOP_CHARGING_REPLY_OK);
|
|
|
statusServiceOne.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
statusServiceOne.setTransactionOrderReportingActionStatus(StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK);
|
|
|
orderStatusService.updateById(statusServiceOne);
|
|
|
+ //return false;
|
|
|
}
|
|
|
+ //deviceControlerService.reset(imei, imei);
|
|
|
+ DeviceParam dataParam = new DeviceParam();
|
|
|
+ dataParam.setDeviceId(imei);
|
|
|
+ dataParam.setCcid(imei);
|
|
|
+ deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ //TODO:测试不上传订单,报个空闲设备状态
|
|
|
+ DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(imei);
|
|
|
+ realTimeStatusPushFrame.deviceStatusPush(deviceConnection, FrameDataSplicing.transactionNum(deviceConnection.getDeviceId(), deviceConnection.getMessageCount()), deviceConnection.getDeviceId(), (byte) 1, StatusConstant.FREE, StatusConstant.CHARGING_INIT_STATUS_OK, 0, 0, zero, zero, 0);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
+ //TODO:设备状态的修改这里进行监听变化 ,??
|
|
|
+ // 1.设备消息cmd:75960设备上报消息是的命令,只要设备报的不是离线当做设备在线
|
|
|
+ // 2.设备上报指令后根据type类型来分类处理消息包括:设备设为在线 是否插枪状态 枪状态(端口状态)
|
|
|
+ if (NormalChargeConstant.EMERGENCY_STOP_CHARGING.equals(type)) {
|
|
|
+ //急停停充
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
+ int port = data.getInteger(2);
|
|
|
+ int status = data.getInteger(3);
|
|
|
+ //关闭急停和急停完,停止充电,获取设备状态
|
|
|
+ DeviceParam dataParam = new DeviceParam();
|
|
|
+ dataParam.setDeviceId(imei);
|
|
|
+ dataParam.setCcid(imei);
|
|
|
+ deviceControlerService.sendPortDetailCmd(dataParam);
|
|
|
+ deviceControlerService.stopCharge(imei, imei, port);
|
|
|
+ //查询计费模板
|
|
|
+ QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
|
|
|
+ billingModelQueryWrapper.eq("device_imei", imei);
|
|
|
+ BillingModel model = billingModelService.getOne(billingModelQueryWrapper);
|
|
|
+ QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
|
|
|
+ orderStatusQueryWrapper.eq("device_imei", imei)
|
|
|
+ .eq("guns_code", port)
|
|
|
+ .orderByDesc("create_time"
|
|
|
+ ).last("limit 1");
|
|
|
+ OrderStatus statusServiceOne = orderStatusService.getOne(orderStatusQueryWrapper);
|
|
|
+ statusServiceOne.setEndTime(System.currentTimeMillis());
|
|
|
+ DeviceConnectionMsg deviceConnection = socketHandle.getDeviceConnection(statusServiceOne.getPileCode());
|
|
|
+ if (status == 1) {
|
|
|
+ byte[] encrypt = new byte[0];
|
|
|
+ if (port == 1) {
|
|
|
+ //急停停充:急停状态下:1.向设备发起结束充电,结算交易订单(交给结束充电处理;但是要考虑是急停的原因),2.上报的充电结束的订单式
|
|
|
+
|
|
|
+ Map<String, BigDecimal> map = transMoney.compute(1, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
+
|
|
|
+ logger.info(statusServiceOne.getPileCode() + ":急停停充>>>上报交易记录>>>");
|
|
|
+ encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 1, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, TransConstant.EMERGENCY_STOP_EXCEPTION_STOP);
|
|
|
+ } else if (port == 2) {
|
|
|
+ //TODO:这里还是模拟数据上报
|
|
|
+ DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, statusServiceOne.getPileCode());
|
|
|
+
|
|
|
+ Map<String, BigDecimal> map = transMoney.compute(2, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), true);
|
|
|
+ //模拟3.5千瓦
|
|
|
+ encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), (byte) 2, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, TransConstant.EMERGENCY_STOP_EXCEPTION_STOP);
|
|
|
+ }
|
|
|
+ statusServiceOne.setOriginalText(encrypt);
|
|
|
+ statusServiceOne.setReasonStopCharging(TransConstant.EMERGENCY_STOP_EXCEPTION_STOP);
|
|
|
+ statusServiceOne.setStopChargingReply(StatusConstant.STOP_CHARGING_REPLY_OK);
|
|
|
+ statusServiceOne.setNowOrderStatus(StatusConstant.NOW_ORDER_STATUS_CHARGING_ENDING);
|
|
|
+ statusServiceOne.setTransactionOrderReportingActionStatus(StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK);
|
|
|
+ orderStatusService.updateById(statusServiceOne);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- } else if (type == NormalChargeConstant.REPORT_PORT_STATUS) {
|
|
|
+ if (NormalChargeConstant.REPORT_PORT_STATUS.equals(type)) {
|
|
|
//114设备主动上报
|
|
|
JSONArray data = jsonObject.getJSONArray("data");
|
|
|
Integer integer = data.getInteger(2);
|
|
|
@@ -460,7 +494,6 @@ public class DeviceMsgHandle {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -546,7 +579,7 @@ public class DeviceMsgHandle {
|
|
|
return true;
|
|
|
}
|
|
|
//7状态:充电完成未拔枪会一直上报,只有当订单完成并回复解析订单成功,7状态当空闲状态上报
|
|
|
- if (one.getTransactionOrderReportingActionStatus()==StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK&&one.getTransactionOrderReportingActionStatus()==StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_SUCC){
|
|
|
+ if (one.getTransactionOrderReportingActionStatus()==StatusConstant.TRANSACTION_ORDER_REPORTING_ACTION_STATUS_OK&&one.getTransactionOrderReplyStatus()==StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_SUCC){
|
|
|
return false;
|
|
|
}
|
|
|
|