通过交易流水号查询订单信息

This commit is contained in:
2023-03-13 16:06:18 +08:00
parent 9a0692a0f6
commit 6f74b99fb3
7 changed files with 50 additions and 8 deletions

View File

@@ -30,6 +30,8 @@ public class CacheConstants {
*/
public static final String GET_ORDER_INFO_BY_ORDER_CODE = "get_order_info_by_order_code:";
public static final String GET_ORDER_INFO_BY_TRANSACTION_CODE = "get_order_info_by_transaction_code:";
/**
* 充电枪口实时监控数据
*/

View File

@@ -18,9 +18,10 @@ import org.apache.commons.lang3.builder.ToStringStyle;
@AllArgsConstructor
@Builder
public class TransactionRecordsData {
// private String orderCode;
// 交易流水号
private String orderCode;
private String transactionCode;
// 桩编码
private String pileSn;
@@ -121,7 +122,7 @@ public class TransactionRecordsData {
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
.append("orderCode", orderCode)
.append("transactionCode", transactionCode)
.append("pileSn", pileSn)
.append("connectorCode", connectorCode)
.append("startTime", startTime)

View File

@@ -260,7 +260,7 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
// 交易流水号
byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String orderCode = BytesUtil.bcd2Str(orderCodeByteArr);
String transactionCode = BytesUtil.bcd2Str(orderCodeByteArr);
// 桩编码
startIndex += length;
@@ -442,14 +442,15 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
"峰单价:{}, 峰电量:{}, 计损峰电量:{}, 峰金额:{}, 平单价:{}, 平电量:{}, 计损平电量:{}, 平金额:{}, " +
"谷单价:{}, 谷电量:{}, 计损谷电量:{}, 谷金额:{}, 电表总起值:{}, 电表总止值:{}, 总电量:{}, 计损总电量:{}, 消费金额:{}, " +
"电动汽车唯一标识:{}, 交易标识:{}, 交易日期、时间:{}, 停止原因码:{}, 停止原因描述:{}, 物理卡号:{}",
orderCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectricity, sharpAmount,
transactionCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectricity, sharpAmount,
peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount,
valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity,
consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard);
// 交易记录封装到对象里
TransactionRecordsData data = TransactionRecordsData.builder()
.orderCode(orderCode)
// .orderCode(transactionCode)
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.startTime(startTime)
@@ -487,7 +488,7 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
pileMsgRecordService.save(pileSn, pileSn + connectorCode, type, jsonMsg, ykcDataProtocol.getHEXString());
// 处理订单加锁
String lockKey = "settle_order_" + orderCode;
String lockKey = "settle_order_" + transactionCode;
String uuid = IdUtils.fastUUID();
try {
// redis锁
@@ -517,9 +518,12 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
}
private void processOrder(TransactionRecordsData data) {
String orderCode = data.getOrderCode();
// String orderCode = data.getOrderCode();
String transactionCode = data.getTransactionCode();
// 根据订单号查询订单信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
// OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
// 根据交易流水号查询订单信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderBasicInfo != null) {
// 平台存在订单
orderBasicInfo.setReason(data.getStopReasonMsg());

View File

@@ -109,6 +109,8 @@ public interface OrderBasicInfoMapper {
*/
OrderBasicInfo getOrderInfoByOrderCode(String orderCode);
OrderBasicInfo getOrderInfoByTransactionCode(String transactionCode);
/**
* 根据桩编号和枪口号查询某状态订单
*
@@ -182,4 +184,5 @@ public interface OrderBasicInfoMapper {
* @return
*/
List<PersonPileConnectorSumInfoVO> getAccumulativeInfo(QueryPersonPileDTO dto);
}

View File

@@ -78,6 +78,8 @@ public interface IOrderBasicInfoService {
*/
OrderBasicInfo getOrderInfoByOrderCode(String orderCode);
OrderBasicInfo getOrderInfoByTransactionCode(String transactionCode);
/**
* 通过桩号和枪口号查询充电中的状态
* @param pileSn 桩编号
@@ -198,4 +200,6 @@ public interface IOrderBasicInfoService {
* @param pileSn
*/
void updateOrderStatusAsAbnormal(String pileSn);
}

View File

@@ -389,6 +389,25 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
return orderBasicInfo;
}
@Override
public OrderBasicInfo getOrderInfoByTransactionCode(String transactionCode) {
if (StringUtils.equals("00000000000000000000000000000000", transactionCode)) {
return null;
}
String redisKey = CacheConstants.GET_ORDER_INFO_BY_TRANSACTION_CODE + transactionCode;
OrderBasicInfo orderBasicInfo = redisCache.getCacheObject(redisKey);
if (orderBasicInfo == null) {
// 查数据库
orderBasicInfo = orderBasicInfoMapper.getOrderInfoByTransactionCode(transactionCode);
// 放缓存
if (orderBasicInfo != null) {
redisCache.setCacheObject(redisKey, orderBasicInfo, 5, TimeUnit.MINUTES);
}
}
logger.info("通过交易流水号:{}, 查询订单信息:{}", transactionCode, JSON.toJSONString(orderBasicInfo));
return orderBasicInfo;
}
/**
* 根据充电桩编号和枪口号查询正在充电中的订单
*

View File

@@ -655,6 +655,14 @@
and del_flag = '0'
</select>
<select id="getOrderInfoByTransactionCode" resultMap="OrderBasicInfoResult">
select
<include refid="Base_Column_List"/>
from order_basic_info
where del_flag = '0'
and transaction_code = #{transactionCode,jdbcType=VARCHAR}
</select>
<select id="queryOrderBasicInfo" resultMap="OrderBasicInfoResult">
select
<include refid="Base_Column_List"/>
@@ -830,4 +838,5 @@
AND t1.order_status = '6'
AND t1.del_flag = '0'
</select>
</mapper>