Commit 1325d1e7 by 林永健

修复bug

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