| | |
| | | package com.sandu.ximon.admin.manager.iot.amqp.processor; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3CommonReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3ErrorCodeReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3HeartbeatReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3OperationReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3ChargingReportEnum; |
| | | import com.sandu.ximon.admin.service.C3ChargingService; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3ChargingEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3mRedisConstant; |
| | | import com.sandu.ximon.admin.service.*; |
| | | import com.sandu.ximon.admin.utils.LogUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.dao.domain.C3mCharging; |
| | | import com.sandu.ximon.dao.domain.C3mOrder; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.enums.OrderStatus; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @author ZZQ |
| | |
| | | |
| | | @Slf4j |
| | | public class c3ChargingProcessor implements IMessageProcessor { |
| | | @Autowired |
| | | private C3ChargingService c3ChargingService; |
| | | @Autowired |
| | | private PoleBindingService bindingService; |
| | | @Autowired |
| | | private PoleService poleService; |
| | | @Autowired |
| | | private C3mOrderService orderService; |
| | | |
| | | public c3ChargingProcessor() { |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void process(String productKey, String deviceName, CommonFrame frame) { |
| | | String functionCode = frame.getPayload().substring(2, 4); |
| | | if (C3ChargingReportEnum.HeartBeat_Data.getCode().equals(functionCode)) { |
| | | log.info("心跳相应——C3充电桩数据"+productKey+" ------- "+deviceName); |
| | | A5C3HeartbeatReportInnerFrame heartbeatReportInnerFrame = new A5C3HeartbeatReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_heartbeatReportInnerFrame"); |
| | | log.info(heartbeatReportInnerFrame.toString()); |
| | | //TODO |
| | | if (frame.getPayload().contains("0000048E") || frame.getPayload().contains("FEA5820018F040001000000000")) { |
| | | if (C3ChargingEnum.NETWORK_REQUEST.getCode().equals(functionCode)) { |
| | | A5C3CommonReportInnerFrame netRequestFrame = new A5C3CommonReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_netRequestFrame"); |
| | | log.info(netRequestFrame.toString()); |
| | | |
| | | SpringContextHolder.getBean(C3ChargingService.class).saveReportData(deviceName, heartbeatReportInnerFrame.getHeartBeatDataPackage()); |
| | | if (netRequestFrame.isValidate()) { |
| | | //保存充电桩硬件信息 |
| | | SpringContextHolder.getBean(C3ChargingService.class) |
| | | .saveReporEquipment(deviceName, netRequestFrame.getMcuUdid(), netRequestFrame.getDestinationAddress()); |
| | | } |
| | | } else if (C3ChargingEnum.QR_CODE_REQUEST.getCode().equals(functionCode)) { |
| | | // 网页操作二维码请求(41) |
| | | A5C3CommonReportInnerFrame codeRequestFrame = new A5C3CommonReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_codeRequestFrame"); |
| | | log.info(codeRequestFrame.toString()); |
| | | |
| | | if (codeRequestFrame.isValidate()) { |
| | | if (deviceName != null) { |
| | | //设置二维码 |
| | | Pole pole = SpringContextHolder.getBean(PoleService.class).getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName)); |
| | | if (pole != null) { |
| | | String testUrl = "http://www.ximonsmart.com/charge/#/charge/" + pole.getId() + "/" + System.currentTimeMillis(); |
| | | SpringContextHolder.getBean(C3ChargingService.class).QrCode(codeRequestFrame.getDestinationAddress(), testUrl); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } else if (C3ChargingEnum.HEART_BEAT.getCode().equals(functionCode)) { |
| | | log.info("心跳相应——C3充电桩数据" + productKey + " ------- " + deviceName); |
| | | A5C3HeartbeatReportInnerFrame heartbeatReportInnerFrame = new A5C3HeartbeatReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_heartbeatReportInnerFrame"); |
| | | log.info(heartbeatReportInnerFrame.toString()); |
| | | |
| | | if (heartbeatReportInnerFrame.isValidate()) { |
| | | SpringContextHolder.getBean(C3ChargingService.class).updateReportState(deviceName |
| | | , heartbeatReportInnerFrame.getHeartBeatDataPackage().getC3Mac() |
| | | , heartbeatReportInnerFrame.getHeartBeatDataPackage().getStatusBit() |
| | | , heartbeatReportInnerFrame.getHeartBeatDataPackage().getDeviceTemperature()); |
| | | //更新订单数据 |
| | | SpringContextHolder.getBean(C3mOrderService.class).updateOrderStatusByHeartbeat(heartbeatReportInnerFrame.getHeartBeatDataPackage()); |
| | | //存缓存 |
| | | RedisUtils.getBean().set(C3mRedisConstant.C3_STATUS.getCode() + heartbeatReportInnerFrame.getHeartBeatDataPackage().getC3Mac() |
| | | , heartbeatReportInnerFrame.getHeartBeatDataPackage(), 300L); |
| | | } |
| | | } else if (C3ChargingEnum.CHARGE_COMPLETE.getCode().equals(functionCode)) { |
| | | A5C3CommonReportInnerFrame completeRequestFrame = new A5C3CommonReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_completeRequestFrame"); |
| | | log.info(completeRequestFrame.toString()); |
| | | // 充电结束上报(43) |
| | | /** |
| | | * 读取心跳包,判断剩余金额和已充电量,统计到缓存中正在进行的订单。 |
| | | */ |
| | | if (completeRequestFrame != null) { |
| | | C3mCharging one = SpringContextHolder.getBean(C3ChargingService.class). |
| | | getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, completeRequestFrame.getMcuUdid()).last("limit 1")); |
| | | if (one == null) { |
| | | return; |
| | | } |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage aPackage = c3ChargingService.ReadTheHeartbeatPackage(one.getC3Id(), true); |
| | | if (aPackage == null) { |
| | | LogUtils.error("{ 充电桩(" + completeRequestFrame.getDestinationAddress() + ")充电结束上报读取心跳包失败,请检查充电桩是否出现故障! }"); |
| | | return; |
| | | } |
| | | orderService.stopCharingOrder(aPackage); |
| | | } |
| | | |
| | | |
| | | } else if (C3ChargingEnum.CHARGE_STOP.getCode().equals(functionCode)) { |
| | | log.info("心跳响应——充电中断"); |
| | | A5C3CommonReportInnerFrame stopRequestFrame = new A5C3CommonReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_stopRequestFrame"); |
| | | log.info(stopRequestFrame.toString()); |
| | | if (stopRequestFrame != null) { |
| | | C3mCharging one = SpringContextHolder.getBean(C3ChargingService.class). |
| | | getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, stopRequestFrame.getMcuUdid()).last("limit 1")); |
| | | if (one == null) { |
| | | return; |
| | | } |
| | | |
| | | /** |
| | | * 读取心跳包,判断剩余金额和已充电量,统计到缓存中正在进行的订单。 |
| | | */ |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage aPackage = c3ChargingService.ReadTheHeartbeatPackage(one.getC3Id(), true); |
| | | if (aPackage == null) { |
| | | LogUtils.error("{ 充电桩(" + stopRequestFrame.getDestinationAddress() + ")充电结束上报读取心跳包失败,请检查充电桩是否出现故障! }"); |
| | | return; |
| | | } |
| | | orderService.stopCharingOrder(aPackage); |
| | | } |
| | | |
| | | } else if (C3ChargingEnum.ERROR_CODE.getCode().equals(functionCode)) { |
| | | log.info("心跳响应——故障"); |
| | | A5C3ErrorCodeReportInnerFrame errorCodeRequestFrame = new A5C3ErrorCodeReportInnerFrame().transformFrame(frame.getPayload()); |
| | | log.info("C3充电桩上报处理_errorCodeRequestFrame"); |
| | | log.info(errorCodeRequestFrame.toString()); |
| | | |
| | | /** |
| | | * 保存C3充电桩故障数据 |
| | | */ |
| | | if (errorCodeRequestFrame.isValidate() && errorCodeRequestFrame.getErrorMessage() != null) { |
| | | //保存故障信息 |
| | | SpringContextHolder.getBean(C3mReportErrorService.class).saveReportError(errorCodeRequestFrame); |
| | | // //充电桩故障结束订单 |
| | | // A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage aPackage = c3ChargingService.ReadTheHeartbeatPackage(errorCodeRequestFrame.getDestinationAddress(), true); |
| | | // if (aPackage == null) { |
| | | // LogUtils.error("{ 充电桩(" + errorCodeRequestFrame.getDestinationAddress() + ")故障上报读取心跳包失败,请检查充电桩是否出现故障! }"); |
| | | // return; |
| | | // } |
| | | // orderService.stopCharingOrder(aPackage); |
| | | |
| | | } else { |
| | | System.out.println("数据校验异常!"); |
| | | } |
| | | } |
| | | } else { |
| | | log.info("不要处理0000048A之外的充电桩!"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |