Commit 1325d1e7 by 林永健

修复bug

1 parent 83a9e87d
......@@ -2,7 +2,6 @@ package cn.com.glsx.evbusiness.modules.mq.consumer;
import cn.com.glsx.charging.modules.model.gbt.ocpp16.tcp.HeartbeatReqMqData;
import cn.com.glsx.evbusiness.config.RabbitMQConfig;
import cn.com.glsx.evbusiness.modules.entity.ChargingGun;
import cn.com.glsx.evbusiness.modules.service.ChargingGunService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
......@@ -13,7 +12,6 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.Objects;
/**
......@@ -29,7 +27,7 @@ public class HeartBeatQueen {
@RabbitHandler
public void process(String jsonDataStr, Message message) {
log.debug("receiver mq message: {}", message);
log.info("receiver mq message: {}", message);
try {
HeartbeatReqMqData data = JSONObject.parseObject(jsonDataStr, HeartbeatReqMqData.class);
if (Objects.isNull(data)) {
......@@ -37,18 +35,7 @@ public class HeartBeatQueen {
}
// Date receiveTime = message.getMessageProperties().getTimestamp();
ChargingGun entity = gunService.getByPileIdAndGunNumber(data.getPileId(), data.getGunNumber());
if (Objects.isNull(entity)) {
entity = new ChargingGun();
entity.setCreatedTime(new Date());
}else {
entity.setUpdatedTime(new Date());
}
// 对比旧状态,发送变化才更新
if (!entity.getStatus().equals(data.getStatus().byteValue())) {
entity.setStatus(data.getStatus().byteValue());
gunService.saveOrUpdate(entity);
}
gunService.handleHeartbeat(data);
log.debug("接收到心跳包, message: {}", data);
} catch (Exception e) {
......
package cn.com.glsx.evbusiness.modules.mq.consumer;
import cn.com.glsx.evbusiness.config.RabbitMQConfig;
import cn.com.glsx.evbusiness.modules.entity.ChargingPile;
import cn.com.glsx.evbusiness.modules.model.ocpp16.LoginUploadData;
import cn.com.glsx.evbusiness.modules.service.ChargingPileService;
import cn.com.glsx.evbusiness.utils.CopyUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
......@@ -14,7 +12,6 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.Objects;
/**
......@@ -30,24 +27,15 @@ public class LoginQueen {
@RabbitHandler
public void process(String jsonDataStr, Message message) {
log.debug("receiver mq message: {}", message);
log.info("receiver mq message: {}", message);
try {
LoginUploadData data = JSONObject.parseObject(jsonDataStr, LoginUploadData.class);
if (Objects.isNull(data)) {
throw new RuntimeException("data is empty or parse fail, raw data is: " + JSON.toJSONString(jsonDataStr));
}
Date receiveTime = message.getMessageProperties().getTimestamp();
ChargingPile entity = pileService.getByPileId(data.getPileId());
if (Objects.isNull(entity)) {
entity = new ChargingPile();
entity.setUpdatedTime(receiveTime);
}else {
entity.setCreatedTime(receiveTime);
}
CopyUtils.copyPropertiesWithOutEmptyFields(data, entity);
pileService.saveOrUpdate(entity);
// Date receiveTime = message.getMessageProperties().getTimestamp();
pileService.handleLogin(data);
log.debug("登录认证处理成功, message: {}", data);
} catch (Exception e) {
e.printStackTrace();
......
......@@ -21,7 +21,7 @@ public class OpenPileQueen {
@RabbitHandler
public void process(String jsonDataStr, Message message) {
log.debug("receiver mq message: {}", message);
log.info("receiver mq message: {}", message);
try {
OrderCreateBO orderCreateBO = JSONObject.parseObject(jsonDataStr,
OrderCreateBO.class);
......
......@@ -32,7 +32,7 @@ public class RealTimeMonQueen {
@RabbitHandler
public void process(String jsonDataStr, Message message) {
log.debug("receiver mq message: {}", message);
log.info("receiver mq message: {}", message);
try {
RealTimeUploadMqData data = JSONObject.parseObject(jsonDataStr, RealTimeUploadMqData.class);
if (Objects.isNull(data)) {
......
......@@ -24,7 +24,7 @@ public class TransactionSettleQueen {
@RabbitHandler
public void process(String jsonDataStr, Message message) {
log.debug("receiver mq message: {}", message);
log.info("receiver mq message: {}", message);
try {
ChargingOrderDetail chargingOrderDetail = JSONObject.parseObject(jsonDataStr,
ChargingOrderDetail.class);
......
package cn.com.glsx.evbusiness.modules.service;
import cn.com.glsx.charging.modules.model.gbt.ocpp16.tcp.HeartbeatReqMqData;
import cn.com.glsx.charging.modules.model.gbt.ocpp16.tcp.RealTimeUploadMqData;
import cn.com.glsx.evbusiness.modules.converter.ChargingGunConverter;
import cn.com.glsx.evbusiness.modules.entity.ChargingGun;
......@@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
......@@ -114,9 +116,12 @@ public class ChargingGunService {
}
}
@Transactional
public void changeStatus(String pileId, Integer gunNumber, Byte statusCode) {
changeStatus(pileId, String.format("%02d", gunNumber), statusCode);
}
@Transactional
public void changeStatus(String pileId, String gunNumber, Byte statusCode) {
ChargingGun exist = getByPileIdAndGunNumber(pileId, gunNumber);
if (Objects.isNull(exist)) {
......@@ -126,4 +131,20 @@ public class ChargingGunService {
exist.setStatus(statusCode);
gunMapper.updateByPrimaryKey(exist);
}
@Transactional
public void handleHeartbeat(HeartbeatReqMqData data) {
ChargingGun entity = getByPileIdAndGunNumber(data.getPileId(), data.getGunNumber());
if (Objects.isNull(entity)) {
entity = new ChargingGun();
entity.setCreatedTime(new Date());
}else {
entity.setUpdatedTime(new Date());
}
// 对比旧状态,发送变化才更新
if (!entity.getStatus().equals(data.getStatus().byteValue())) {
entity.setStatus(data.getStatus().byteValue());
saveOrUpdate(entity);
}
}
}
......@@ -3,12 +3,16 @@ package cn.com.glsx.evbusiness.modules.service;
import cn.com.glsx.evbusiness.modules.converter.ChargingPileConverter;
import cn.com.glsx.evbusiness.modules.entity.ChargingPile;
import cn.com.glsx.evbusiness.modules.mapper.ChargingPileMapper;
import cn.com.glsx.evbusiness.modules.model.ocpp16.LoginUploadData;
import cn.com.glsx.evbusiness.modules.model.response.ChargingPileResponse;
import cn.com.glsx.evbusiness.utils.CopyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.Objects;
/**
......@@ -51,4 +55,17 @@ public class ChargingPileService {
log.debug("更新充电桩数据, entity: {}", entity);
}
}
@Transactional
public void handleLogin(LoginUploadData data) {
ChargingPile entity = getByPileId(data.getPileId());
if (Objects.isNull(entity)) {
entity = new ChargingPile();
entity.setUpdatedTime(new Date());
}else {
entity.setCreatedTime(new Date());
}
CopyUtils.copyPropertiesWithOutEmptyFields(data, entity);
saveOrUpdate(entity);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!