Commit 95273885 by 林永健

消费交易流程入库

1 parent 10b6b033
package cn.com.glsx.evbusiness.modules.entity; package cn.com.glsx.evbusiness.modules.entity;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Date; import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*; import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
@Table(name = "charging_order_detail") @Table(name = "charging_order_detail")
@Data
@NoArgsConstructor
public class ChargingOrderDetail { public class ChargingOrderDetail {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id; private Integer id;
/** /**
* 充电时段 * 交易流水号
*/ */
@Column(name = "period_of_time") @Column(name = "order_code")
@Schema(description = "充电时段") @Schema(description = "交易流水号")
private String periodOfTime; private String orderCode;
/** /**
* 度数 * 桩编号
*/ */
@Column(name = "total_degrees") @Column(name = "pile_id")
@Schema(description = "度数") @Schema(description = "桩编号")
private Double totalDegrees; private String pileId;
/** /**
* 电费 * 枪号
*/ */
@Column(name = "electric_charge") @Column(name = "gun_number")
@Schema(description = "电费") @Schema(description = "枪号")
private Double electricCharge; private String gunNumber;
/** /**
* 服务费 * 开始时间
*/ */
@Column(name = "service_charge") @Column(name = "start_time")
@Schema(description = "服务费") @Schema(description = "开始时间")
private Double serviceCharge; private Date startTime;
/** /**
* 平均电费 * 结束时间
*/ */
@Column(name = "average_ele_charge") @Column(name = "end_time")
@Schema(description = "平均电费") @Schema(description = "结束时间")
private Double averageEleCharge; private Date endTime;
/** /**
* 平均服务费 * 尖单价
*/ */
@Column(name = "average_service_charge") @Column(name = "peak_unit_price")
@Schema(description = "平均服务费") @Schema(description = "尖单价")
private Double averageServiceCharge; private BigDecimal peakUnitPrice;
/** /**
* 订单号 * 尖电量
*/ */
@Column(name = "order_code") @Column(name = "peak_electricity")
@Schema(description = "订单号") @Schema(description = "尖电量")
private String orderCode; private BigDecimal peakElectricity;
@Column(name = "created_time") /**
private Date createdTime; * 计损尖电量
*/
@Column(name = "peak_electricity_loss")
@Schema(description = "计损尖电量")
private BigDecimal peakElectricityLoss;
/** /**
* @return id * 尖金额
*/ */
public Integer getId() { @Column(name = "peak_amount")
return id; @Schema(description = "尖单价")
} private BigDecimal peakAmount;
/**
* 峰单价
*/
@Column(name = "top_unit_price")
@Schema(description = "峰单价")
private BigDecimal topUnitPrice;
/** /**
* @param id * 峰电量
*/ */
public void setId(Integer id) { @Column(name = "top_electricity")
this.id = id; @Schema(description = "峰电量")
} private BigDecimal topElectricity;
/** /**
* 获取充电时段 * 计损峰电量
*
* @return period_of_time - 充电时段
*/ */
public String getPeriodOfTime() { @Column(name = "top_electricity_loss")
return periodOfTime; @Schema(description = "计损峰电量")
} private BigDecimal topElectricityLoss;
/** /**
* 设置充电时段 * 峰金额
*
* @param periodOfTime 充电时段
*/ */
public void setPeriodOfTime(String periodOfTime) { @Column(name = "top_amount")
this.periodOfTime = periodOfTime == null ? null : periodOfTime.trim(); @Schema(description = "峰金额")
} private BigDecimal topAmount;
/** /**
* 获取度数 * 平单价
*
* @return total_degrees - 度数
*/ */
public Double getTotalDegrees() { @Column(name = "flat_unit_price")
return totalDegrees; @Schema(description = "平单价")
} private BigDecimal flatUnitPrice;
/** /**
* 设置度数 * 平电量
*
* @param totalDegrees 度数
*/ */
public void setTotalDegrees(Double totalDegrees) { @Column(name = "flat_electricity")
this.totalDegrees = totalDegrees; @Schema(description = "平电量")
} private BigDecimal flatElectricity;
/** /**
* 获取电费 * 计损平电量
*
* @return electric_charge - 电费
*/ */
public Double getElectricCharge() { @Column(name = "flat_electricity_loss")
return electricCharge; @Schema(description = "计损平电量")
} private BigDecimal flatElectricityLoss;
/** /**
* 设置电费 * 平金额
*
* @param electricCharge 电费
*/ */
public void setElectricCharge(Double electricCharge) { @Column(name = "flat_amount")
this.electricCharge = electricCharge; @Schema(description = "平金额")
} private BigDecimal flatAmount;
/**
* 谷单价
*/
@Column(name = "valley_unit_price")
@Schema(description = "谷单价")
private BigDecimal valleyUnitPrice;
/** /**
* 获取服务费 * 谷电量
*
* @return service_charge - 服务费
*/ */
public Double getServiceCharge() { @Column(name = "valley_electricity")
return serviceCharge; @Schema(description = "谷电量")
} private BigDecimal valleyElectricity;
/** /**
* 设置服务费 * 计损谷电量
*
* @param serviceCharge 服务费
*/ */
public void setServiceCharge(Double serviceCharge) { @Column(name = "valley_electricity_loss")
this.serviceCharge = serviceCharge; @Schema(description = "计损谷电量")
} private BigDecimal valleyElectricityLoss;
/** /**
* 获取平均电费 * 谷金额
*
* @return average_ele_charge - 平均电费
*/ */
public Double getAverageEleCharge() { @Column(name = "valley_amount")
return averageEleCharge; @Schema(description = "谷金额")
} private BigDecimal valleyAmount;
/** /**
* 设置平均电费 * 电表总起值
*
* @param averageEleCharge 平均电费
*/ */
public void setAverageEleCharge(Double averageEleCharge) { @Column(name = "total_start_value")
this.averageEleCharge = averageEleCharge; @Schema(description = "电表总起值")
} private BigDecimal totalStartValue;
/** /**
* 获取平均服务费 * 电表总止值
*
* @return average_service_charge - 平均服务费
*/ */
public Double getAverageServiceCharge() { @Column(name = "total_end_value")
return averageServiceCharge; @Schema(description = "电表总止值")
} private BigDecimal totalEndValue;
/** /**
* 设置平均服务费 * 总电量
*
* @param averageServiceCharge 平均服务费
*/ */
public void setAverageServiceCharge(Double averageServiceCharge) { @Column(name = "total_electricity")
this.averageServiceCharge = averageServiceCharge; @Schema(description = "总电量")
} private BigDecimal totalElectricity;
/** /**
* 获取订单号 * 计损总电量
*
* @return order_code - 订单号
*/ */
public String getOrderCode() { @Column(name = "total_electricity_loss")
return orderCode; @Schema(description = "计损总电量")
} private BigDecimal totalElectricityLoss;
/** /**
* 设置订单号 * 消费金额
*
* @param orderCode 订单号
*/ */
public void setOrderCode(String orderCode) { @Column(name = "total_amount")
this.orderCode = orderCode == null ? null : orderCode.trim(); @Schema(description = "消费金额")
} private BigDecimal totalAmount;
/** /**
* @return created_time * 电动汽车唯一标识
*/ */
public Date getCreatedTime() { @Column(name = "vehicle_identifier")
return createdTime; @Schema(description = "电动汽车唯一标识")
} private String vehicleIdentifier;
/** /**
* @param createdTime * 交易标识
*/ */
public void setCreatedTime(Date createdTime) { @Column(name = "transaction_identifier")
this.createdTime = createdTime; @Schema(description = "交易标识")
} private byte transactionIdentifier;
/**
* 交易日期、时间
*/
@Column(name = "transaction_datetime")
@Schema(description = "交易日期、时间")
private Date transactionDateTime;
/**
* 停止原因
*/
@Column(name = "stop_reason")
@Schema(description = "停止原因")
private byte stopReason;
/**
* 物理卡号
*/
@Column(name = "physical_card_number")
@Schema(description = "物理卡号")
private String physicalCardNumber;
/**
* 创建时间
*/
@Column(name = "created_time")
@Schema(description = "创建时间")
private Date createdTime;
public ChargingOrderDetail(String orderCode) { public ChargingOrderDetail(String orderCode) {
this.orderCode = orderCode; this.orderCode = orderCode;
} }
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.evbusiness.modules.mq.consumer; package cn.com.glsx.evbusiness.modules.mq.consumer;
import cn.com.glsx.charging.modules.model.gbt.ocpp16.tcp.TransactionRecordsMqData;
import cn.com.glsx.evbusiness.config.RabbitMQConfig; import cn.com.glsx.evbusiness.config.RabbitMQConfig;
import cn.com.glsx.evbusiness.modules.entity.ChargingOrderDetail; import cn.com.glsx.evbusiness.modules.entity.ChargingOrderDetail;
import cn.com.glsx.evbusiness.modules.service.OrderService; import cn.com.glsx.evbusiness.modules.service.OrderService;
import cn.com.glsx.evbusiness.utils.CopyUtils;
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;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
...@@ -11,6 +14,9 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener; ...@@ -11,6 +14,9 @@ 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;
/** /**
* 交易结算消息 * 交易结算消息
*/ */
...@@ -27,9 +33,15 @@ public class TransactionSettleQueen { ...@@ -27,9 +33,15 @@ public class TransactionSettleQueen {
log.info("receiver mq message: {}", message); log.info("receiver mq message: {}", message);
log.info("receiver mq payload: {}", jsonDataStr); log.info("receiver mq payload: {}", jsonDataStr);
try { try {
ChargingOrderDetail chargingOrderDetail = JSONObject.parseObject(jsonDataStr, TransactionRecordsMqData data = JSONObject.parseObject(jsonDataStr, TransactionRecordsMqData.class);
ChargingOrderDetail.class); if (Objects.isNull(data)) {
orderService.updateOrder(chargingOrderDetail); throw new RuntimeException("data is empty or parse fail, raw data is: " + JSON.toJSONString(jsonDataStr));
}
ChargingOrderDetail entity = new ChargingOrderDetail(data.getTransactionSerialNumber());
CopyUtils.copyPropertiesWithOutEmptyFields(data, entity);
entity.setCreatedTime(new Date());
orderService.updateOrder(entity);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.info("交易结算异常{}",e.getMessage()); log.info("交易结算异常{}",e.getMessage());
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.evbusiness.modules.mapper.ChargingOrderDetailMapper"> <mapper namespace="cn.com.glsx.evbusiness.modules.mapper.ChargingOrderDetailMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.evbusiness.modules.entity.ChargingOrderDetail"> <resultMap id="BaseResultMap" type="cn.com.glsx.evbusiness.modules.entity.ChargingOrderDetail">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="period_of_time" jdbcType="VARCHAR" property="periodOfTime" /> <result column="order_code" jdbcType="VARCHAR" property="orderCode"/>
<result column="total_degrees" jdbcType="DOUBLE" property="totalDegrees" /> <result column="pile_id" jdbcType="VARCHAR" property="pileId"/>
<result column="electric_charge" jdbcType="DOUBLE" property="electricCharge" /> <result column="gun_number" jdbcType="VARCHAR" property="gunNumber"/>
<result column="service_charge" jdbcType="DOUBLE" property="serviceCharge" /> <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
<result column="average_ele_charge" jdbcType="DOUBLE" property="averageEleCharge" /> <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
<result column="average_service_charge" jdbcType="DOUBLE" property="averageServiceCharge" /> <result column="peak_unit_price" jdbcType="DECIMAL" property="peakUnitPrice"/>
<result column="order_code" jdbcType="VARCHAR" property="orderCode" /> <result column="peak_electricity" jdbcType="DECIMAL" property="peakElectricity"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime" /> <result column="peak_electricity_loss" jdbcType="DECIMAL" property="peakElectricityLoss"/>
</resultMap> <result column="peak_amount" jdbcType="DECIMAL" property="peakAmount"/>
<sql id="Base_Column_List"> <result column="top_unit_price" jdbcType="DECIMAL" property="topUnitPrice"/>
<!-- <result column="top_electricity" jdbcType="DECIMAL" property="topElectricity"/>
WARNING - @mbg.generated <result column="top_electricity_loss" jdbcType="DECIMAL" property="topElectricityLoss"/>
--> <result column="top_amount" jdbcType="DECIMAL" property="topAmount"/>
id, period_of_time, total_degrees, electric_charge, service_charge, average_ele_charge, <result column="flat_unit_price" jdbcType="DECIMAL" property="flatUnitPrice"/>
average_service_charge, order_code, created_time <result column="flat_electricity" jdbcType="DECIMAL" property="flatElectricity"/>
</sql> <result column="flat_electricity_loss" jdbcType="DECIMAL" property="flatElectricityLoss"/>
<result column="flat_amount" jdbcType="DECIMAL" property="flatAmount"/>
<result column="valley_unit_price" jdbcType="DECIMAL" property="valleyUnitPrice"/>
<result column="valley_electricity" jdbcType="DECIMAL" property="valleyElectricity"/>
<result column="valley_electricity_loss" jdbcType="DECIMAL" property="valleyElectricityLoss"/>
<result column="valley_amount" jdbcType="DECIMAL" property="valleyAmount"/>
<result column="total_start_value" jdbcType="DECIMAL" property="totalStartValue"/>
<result column="total_end_value" jdbcType="DECIMAL" property="totalEndValue"/>
<result column="total_electricity" jdbcType="DECIMAL" property="totalElectricity"/>
<result column="total_electricity_loss" jdbcType="DECIMAL" property="totalElectricityLoss"/>
<result column="total_amount" jdbcType="DECIMAL" property="totalAmount"/>
<result column="vehicle_identifier" jdbcType="VARCHAR" property="vehicleIdentifier"/>
<result column="transaction_identifier" jdbcType="TINYINT" property="transactionIdentifier"/>
<result column="transaction_datetime" jdbcType="TIMESTAMP" property="transactionDateTime"/>
<result column="stop_reason" jdbcType="TINYINT" property="stopReason"/>
<result column="physical_card_number" jdbcType="VARCHAR" property="physicalCardNumber"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, order_code, pile_id, gun_number, start_time, end_time, peak_unit_price, peak_electricity,
peak_electricity_loss, peak_amount, top_unit_price, top_electricity, top_electricity_loss, top_amount,
flat_unit_price, flat_electricity, flat_electricity_loss, flat_amount, valley_unit_price, valley_electricity,
valley_electricity_loss, valley_amount, total_start_value, total_end_value, total_electricity,
total_electricity_loss, total_amount, vehicle_identifier, transaction_identifier, transaction_datetime,
stop_reason, physical_card_number, created_time
</sql>
<select id="findByOrderCode" resultMap="BaseResultMap"> <select id="findByOrderCode" resultMap="BaseResultMap">
select * from charging_order_detail select *
where order_code = #{orderCode} from charging_order_detail
</select> where order_code = #{orderCode}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.evbusiness.modules.mq.consumer;
import cn.com.glsx.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class QueenProcessTest {
@Autowired
TransactionSettleQueen transactionSettleQueen;
@Test
public void transactionSettleTest(){
String msg = "{\"endTime\":1700456189000,\"flatAmount\":0.0000,\"flatElectricity\":0.0000,\"flatElectricityLoss\":0.0000,\"flatUnitPrice\":0.0000,\"gunNumber\":\"01\",\"peakAmount\":0.0000,\"peakElectricity\":0.0000,\"peakElectricityLoss\":0.0000,\"peakUnitPrice\":0.00000,\"physicalCardNumber\":\"175A000000000000\",\"pileId\":\"00000002100023\",\"startTime\":1700456189000,\"stopReason\":11,\"topAmount\":0.0000,\"topElectricity\":0.0000,\"topElectricityLoss\":0.0000,\"topUnitPrice\":16.4152,\"totalAmount\":0.0000,\"totalElectricity\":0.0000,\"totalElectricityLoss\":0.0000,\"totalEndValue\":847.3600,\"totalStartValue\":3.3100,\"transactionDateTime\":2618644080000,\"transactionIdentifier\":0,\"transactionSerialNumber\":\"32010200000000111511161555350261\",\"valleyAmount\":0.0000,\"valleyElectricity\":0.0000,\"valleyElectricityLoss\":0.0000,\"valleyUnitPrice\":0.0000,\"vehicleIdentifier\":\"\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\"}";
transactionSettleQueen.process(msg, null);
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!