Commit 52de6995 authored by 陈嘉强's avatar 陈嘉强

初期存档,后续删除lombok依赖

parent c2a47fe8
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<description>test</description> <description>test</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-boot.mybatis>2.2.0</spring-boot.mybatis>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -41,6 +42,23 @@ ...@@ -41,6 +42,23 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId> <artifactId>spring-boot-starter-amqp</artifactId>
</dependency> </dependency>
<!-- Mybatis 依赖配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${spring-boot.mybatis}</version>
</dependency>
<!-- TODO:删除-->
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -24,8 +24,13 @@ public class RabbitmqMapper { ...@@ -24,8 +24,13 @@ public class RabbitmqMapper {
// } // }
public void sendTopic(){ public void sendTopic(){
String message = "ASYNUP|uploadParkingTradingRecord|{\"terminalId\": \"主终端\", \"plateNo\": \"豫H33333\", \"entryTime\": 1646639417620, \"entryId\": \"入口\", \"vehicleType\": \"小型车\", \"entryPhoto\":\"\", \"booking\": false, \"plateParseInfo\": \"{\\\"etcPlateNo\\\": [], \\\"videoPlateNo\\\": \\\"豫H33333\\\", \\\"state\\\": \\\"NORMAL\\\", \\\"idenType\\\": \\\"PLATE\\\"}\", \"parkingDetail\": {}, \"exitTime\": 1646639418573, \"requestId\": \"3bad40149deb11ec8f1ccaab5cf7fc68\", \"username\": \"ftp94\", \"password\": \"1\", \"parkUUID\": \"ypark2\", \"parkType\": \"路外\"}";
String message1 = "ASYNUP|uploadParkingTradingRecord|{\"plateNo\": \"豫H11111\", \"vehicleType\": \"小型车\", \"entryTime\": 1646373838476, \"entryId\": \"入口\", \"booking\": false, \"exitTime\": 1646373842172, \"exitId\": \"出口\", \"tradeTime\": 1646373842172, \"tollRateVersion\": \"\", \"tollCollectorName\": \"默认收费员\", \"tradeType\": \"FREE\", \"accounts\": 0, \"cash\": 0, \"entryPhoto\": null, \"exitPhoto\": null, \"plateParseInfo\": \"{\\\"etcPlateNo\\\": [], \\\"videoPlateNo\\\": \\\"豫H11111\\\", \\\"state\\\": \\\"NORMAL\\\", \\\"idenType\\\": \\\"PLATE\\\"}\", \"useType\": \"\", \"parkingDetail\": {\"couponList\": [], \"payList\": [], \"negotiate\": false, \"parkingFeeBeforeNegotiate\": 0}, \"terminalId\": \"主终端\", \"time\": 1646373845403, \"requestId\": \"e5bb7e809b8011ec88d6d64e40ddb35c\", \"username\": \"ftp94\", \"password\": \"1\", \"parkUUID\": \"ypark2\", \"parkType\": \"路外\"}";
rabbitTemplate.convertAndSend("global.parking.topic.exchange","ASYNUP.uploadParkingTradingRecord.ypark2",message1);
for (int i =0; i<10; i++){ for (int i =0; i<10; i++){
rabbitTemplate.convertAndSend("global.parking.topic.exchange","ASYNUP.uploadParkingTradingRecord.ypark2","测试发布订阅模型: " + i); // rabbitTemplate.convertAndSend("global.parking.topic.exchange","ASYNUP.uploadParkingTradingRecord.ypark2","测试发布订阅模型: " + i);
System.out.println("发布" + i);
} }
} }
......
package com.logwire.bhft.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.logwire.bhft.domain.InterfaceParkingGate;
/**
* @author 123
* @description 针对表【t01_interface_parking_gate(停车场道闸接口信息)】的数据库操作Mapper
* @createDate 2022-03-08 17:27:56
* @Entity com.logwire.bhft.domain.InterfaceParkingGate
*/
@Mapper
public interface InterfaceParkingGateMapper {
List<InterfaceParkingGate> selectAllByRequestIdOrExitRequestId(@Param("requestId") String requestId);
List<InterfaceParkingGate> selectByEntryTimeAndEntryId(@Param("entryTime") Object entryTime, @Param("entryId") String entryId);
int insertAll(InterfaceParkingGate interfaceParkingGate);
int updateExitInfo(InterfaceParkingGate interfaceParkingGate);
int updateExitId(@Param("exitId") String exitId);
}
package com.logwire.bhft.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class Infomation implements Serializable {
private static final long serialVersionUID = 1L;
private String parkUUID;
private Long requestTime;
private String terminalId;
private String requestId;
private String sign;
private String version;
private String service;
private String parkType;
private String plateNo;
private String vehicleType;
// 这是个对象
private String plateParseInfo;
private Long entryTime;
private String entryId;
private Long exitTime;
private String exitId;
private Long tradeTime;
private String tollRateVersion;
private String tradeType;
private float account;
private float cash;
private String entryPhoto;
private String exitPhoto;
private String tollCollectorName;
private String useType;
private String areaId;
private String slotId;
private Boolean booking;
// 这是个对象
private Object parkingDetail;
// 修改
}
package com.logwire.bhft.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 停车场道闸接口信息
* @TableName t01_interface_parking_gate
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class InterfaceParkingGate implements Serializable {
/**
* id
*/
private Object id;
/**
* 请求时间戳
*/
private Object requestTime;
/**
* 请求id
*/
private String requestId;
/**
* 出场请求时间戳
*/
private Object exitRequestTime;
/**
* 出场请求id
*/
private String exitRequestId;
/**
* 车牌号
*/
private String plateNo;
/**
* 设备类型
*/
private String vehicleType;
/**
* 车牌识别信息
*/
private String plateParseInfo;
/**
* 进场时间
*/
private Object entryTime;
/**
* 入口id
*/
private String entryId;
/**
* 出场时间
*/
private Object exitTime;
/**
* 出口id
*/
private String exitId;
/**
* 交易时间
*/
private Object tradeTime;
/**
* 费率版本
*/
private String tollRateVersion;
/**
* 交易类型
*/
private String tradeType;
/**
* 应收费用
*/
private BigDecimal account;
/**
* 现场收取现金
*/
private BigDecimal cash;
/**
* 收费员
*/
private String tollCollectorName;
/**
* 使用类型
*/
private String useType;
/**
* 区域类型
*/
private String areaId;
/**
* 车位id
*/
private String slotId;
/**
* 车位是否预定
*/
private Boolean booking;
/**
* 停车信息详情
*/
private String parkingDetail;
/**
* 出场使用标识
*/
private String exitFlagNum;
/**
* Domain Name
*/
private String domainName;
/**
* version
*/
private Object version;
/**
* deleted
*/
private Boolean deleted;
/**
* Insert User
*/
private String insertUser;
/**
* Insert Date
*/
private Date insertDate;
/**
* Update User
*/
private String updateUser;
/**
* Update Date
*/
private Date updateDate;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.logwire.bhft.listener; package com.logwire.bhft.listener;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.logwire.bhft.domain.Infomation;
import com.logwire.bhft.domain.InterfaceParkingGate;
import com.logwire.bhft.service.ParkingGateService;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
@Component @Component
public class TopicReceiveListener { public class TopicReceiveListener {
private Logger logger = LoggerFactory.getLogger(TopicReceiveListener.class);
@Resource
private ParkingGateService parkingGateService;
@RabbitListener(queues="queue_topic_ypark2") @RabbitListener(queues="queue_topic_ypark2")
public void receiveMessage(String msg, Channel channel, Message massage){ public void receiveMessage(String msg, Channel channel, Message massage){
System.out.println("接受到信息: " + msg); System.out.println("接受到信息: " + msg);
String[] data = msg.split("\\|"); String[] data = msg.split("\\|");
System.out.println("接受到信息体: " + data[2]); // System.out.println("接受到信息体: " + data[2]);
ObjectMapper om = new ObjectMapper();
try {
Infomation infomation = om.readValue(data[2], Infomation.class);
InterfaceParkingGate parkingGate = new InterfaceParkingGate();
// InterfaceParkingGate interfaceParkingGate = om.readValue(data[2], InterfaceParkingGate.class);
parkingGate.setAccount(BigDecimal.valueOf(infomation.getAccount()));
parkingGate.setAreaId(infomation.getAreaId());
parkingGate.setBooking(infomation.getBooking());
parkingGate.setCash(BigDecimal.valueOf(infomation.getCash()));
parkingGate.setDeleted(false);
parkingGate.setDomainName("interface");
parkingGate.setEntryId(infomation.getEntryId());
parkingGate.setExitId(infomation.getExitId());
parkingGate.setEntryTime(infomation.getEntryTime());
parkingGate.setExitTime(infomation.getExitTime());
parkingGate.setPlateNo(infomation.getPlateNo());
parkingGate.setPlateParseInfo(infomation.getPlateParseInfo());
parkingGate.setParkingDetail(infomation.getParkingDetail().toString());
parkingGate.setRequestId(infomation.getRequestId());
parkingGate.setRequestTime(infomation.getRequestTime());
parkingGate.setSlotId(infomation.getSlotId());
parkingGate.setTollRateVersion(infomation.getTollRateVersion());
parkingGate.setTollCollectorName(infomation.getTollCollectorName());
parkingGate.setUseType(infomation.getUseType());
// 出场标识,TODO:需要先判断是否有对应的数值
parkingGate.setExitFlagNum(infomation.getEntryTime()+infomation.getPlateNo());
// parkingGate.setVersion(0);
parkingGate.setVehicleType(infomation.getVehicleType());
logger.info(infomation.toString());
logger.info(parkingGate.toString());
parkingGateService.insertParkingGate(parkingGate);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
} }
} }
package com.logwire.bhft.service;
import com.logwire.bhft.domain.InterfaceParkingGate;
public interface ParkingGateService {
InterfaceParkingGate insertParkingGate(InterfaceParkingGate parkingGate);
}
package com.logwire.bhft.service.impl;
import com.logwire.bhft.dao.InterfaceParkingGateMapper;
import com.logwire.bhft.domain.Infomation;
import com.logwire.bhft.domain.InterfaceParkingGate;
import com.logwire.bhft.service.ParkingGateService;
import com.logwire.bhft.utils.SnowFlake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
@Service
public class ParkingGateServiceImpl implements ParkingGateService {
@Resource
InterfaceParkingGateMapper interfaceParkingGateMapper;
@Override
@Transactional
public InterfaceParkingGate insertParkingGate(InterfaceParkingGate parkingGate) {
// 根据唯一表示去查询数据库中是否有数据,避免重复消费
List<InterfaceParkingGate> hasRequestId = interfaceParkingGateMapper.selectAllByRequestIdOrExitRequestId(parkingGate.getRequestId());
if (hasRequestId.size()>0){
return null;
}
SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 判断是进站还是出站,进站新增,出站修改
if("".equals(parkingGate.getExitId()) || null == parkingGate.getExitId()){
// 进站逻辑
parkingGate.setId(SnowFlake.nextId());
parkingGate.setVersion(0);
parkingGate.setInsertUser("interface");
parkingGate.setInsertDate(new Date());
int id = interfaceParkingGateMapper.insertAll(parkingGate);
}else {
// 出站逻辑
List<InterfaceParkingGate> interfaceParkingGates = interfaceParkingGateMapper.selectByEntryTimeAndEntryId(parkingGate.getEntryTime(), parkingGate.getEntryId());
int i = interfaceParkingGateMapper.updateExitInfo(parkingGate);
}
parkingGate.setUpdateUser("cjq");
return null;
}
}
package com.logwire.bhft.utils;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class SnowFlake {
private final static long twepoch = 1L;
// 机器标识位数
private final static long workerIdBits = 5L;
// 数据中心标识位数
private final static long datacenterIdBits = 5L;
// 毫秒内自增位数
private final static long sequenceBits = 12L;
// 机器ID偏左移12位
private final static long workerIdShift = sequenceBits;
// 数据中心ID左移17位
private final static long datacenterIdShift = sequenceBits + workerIdBits;
// 时间毫秒左移22位
private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
//sequence掩码,确保sequnce不会超出上限
private final static long sequenceMask = -1L ^ (-1L << sequenceBits);
//上次时间戳
private static long lastTimestamp = -1L;
//序列
private long sequence = 0L;
//服务器ID
private long workerId = 1L;
private static long workerMask = -1L ^ (-1L << workerIdBits);
//进程编码
private long processId = 1L;
private static long processMask = -1L ^ (-1L << datacenterIdBits);
private static SnowFlake snowFlake = null;
static{
snowFlake = new SnowFlake();
}
public static synchronized long nextId(){
return snowFlake.getNextId();
}
private SnowFlake() {
//获取机器编码
this.workerId=this.getMachineNum();
//获取进程编码
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
this.processId=Long.valueOf(runtimeMXBean.getName().split("@")[0]).longValue();
//避免编码超出最大值
this.workerId=workerId & workerMask;
this.processId=processId & processMask;
}
public synchronized long getNextId() {
//获取时间戳
long timestamp = timeGen();
//如果时间戳小于上次时间戳则报错
if (timestamp < lastTimestamp) {
try {
throw new Exception("Clock moved backwards. Refusing to generate id for " + (lastTimestamp - timestamp) + " milliseconds");
} catch (Exception e) {
e.printStackTrace();
}
}
//如果时间戳与上次时间戳相同
if (lastTimestamp == timestamp) {
// 当前毫秒内,则+1,与sequenceMask确保sequence不会超出上限
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
// 当前毫秒内计数满了,则等待下一秒
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0;
}
lastTimestamp = timestamp;
// ID偏移组合生成最终的ID,并返回ID
long nextId = ((timestamp - twepoch) << timestampLeftShift) | (processId << datacenterIdShift) | (workerId << workerIdShift) | sequence;
return nextId;
}
/**
* 再次获取时间戳直到获取的时间戳与现有的不同
* @param lastTimestamp
* @return 下一个时间戳
*/
private long tilNextMillis(final long lastTimestamp) {
long timestamp = this.timeGen();
while (timestamp <= lastTimestamp) {
timestamp = this.timeGen();
}
return timestamp;
}
private long timeGen() {
return System.currentTimeMillis();
}
/**
* 获取机器编码
* @return
*/
private long getMachineNum(){
long machinePiece;
StringBuilder sb = new StringBuilder();
Enumeration<NetworkInterface> e = null;
try {
e = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e1) {
e1.printStackTrace();
}
while (e.hasMoreElements()) {
NetworkInterface ni = e.nextElement();
sb.append(ni.toString());
}
machinePiece = sb.toString().hashCode();
return machinePiece;
}
}
\ No newline at end of file
<?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">
<mapper namespace="com.logwire.bhft.dao.InterfaceParkingGateMapper">
<resultMap id="BaseResultMap" type="com.logwire.bhft.domain.InterfaceParkingGate">
<id property="id" column="id" jdbcType="OTHER"/>
<result property="requestTime" column="request_time" jdbcType="OTHER"/>
<result property="requestId" column="request_id" jdbcType="VARCHAR"/>
<result property="exitRequestTime" column="exit_request_time" jdbcType="OTHER"/>
<result property="exitRequestId" column="exit_request_id" jdbcType="VARCHAR"/>
<result property="plateNo" column="plate_no" jdbcType="VARCHAR"/>
<result property="vehicleType" column="vehicle_type" jdbcType="VARCHAR"/>
<result property="plateParseInfo" column="plate_parse_info" jdbcType="VARCHAR"/>
<result property="entryTime" column="entry_time" jdbcType="OTHER"/>
<result property="entryId" column="entry_id" jdbcType="VARCHAR"/>
<result property="exitTime" column="exit_time" jdbcType="OTHER"/>
<result property="exitId" column="exit_id" jdbcType="VARCHAR"/>
<result property="tradeTime" column="trade_time" jdbcType="OTHER"/>
<result property="tollRateVersion" column="toll_rate_version" jdbcType="VARCHAR"/>
<result property="tradeType" column="trade_type" jdbcType="VARCHAR"/>
<result property="account" column="account" jdbcType="NUMERIC"/>
<result property="cash" column="cash" jdbcType="NUMERIC"/>
<result property="tollCollectorName" column="toll_collector_name" jdbcType="VARCHAR"/>
<result property="useType" column="use_type" jdbcType="VARCHAR"/>
<result property="areaId" column="area_id" jdbcType="VARCHAR"/>
<result property="slotId" column="slot_id" jdbcType="VARCHAR"/>
<result property="booking" column="booking" jdbcType="BOOLEAN"/>
<result property="parkingDetail" column="parking_detail" jdbcType="VARCHAR"/>
<result property="exitFlagNum" column="exit_flag_num" jdbcType="VARCHAR"/>
<result property="domainName" column="domain_name" jdbcType="VARCHAR"/>
<result property="version" column="version" jdbcType="OTHER"/>
<result property="deleted" column="deleted" jdbcType="BOOLEAN"/>
<result property="insertUser" column="insert_user" jdbcType="VARCHAR"/>
<result property="insertDate" column="insert_date" jdbcType="TIMESTAMP"/>
<result property="updateUser" column="update_user" jdbcType="VARCHAR"/>
<result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,request_time,request_id,
plate_no,vehicle_type,plate_parse_info,
entry_time,entry_id,exit_time,
exit_id,trade_time,toll_rate_version,
trade_type,account,cash,
toll_collector_name,use_type,area_id,
slot_id,booking,parking_detail,
domain_name,version,deleted,
insert_user,insert_date,update_user,
update_date,exit_request_id,exit_request_time,exitFlagNum
</sql>
<insert id="insertAll">
insert into t01_interface_parking_gate
(id, request_time, request_id,
plate_no, vehicle_type, plate_parse_info,
entry_time, entry_id, exit_time,
exit_id, trade_time, toll_rate_version,
trade_type, account, cash,
toll_collector_name, use_type, area_id,
slot_id, booking, parking_detail,
domain_name, version, deleted,
insert_user, insert_date, exit_flag_num)
values (#{id}, #{requestTime}, #{requestId,jdbcType=VARCHAR},
#{plateNo,jdbcType=VARCHAR}, #{vehicleType,jdbcType=VARCHAR}, #{plateParseInfo,jdbcType=VARCHAR},
#{entryTime}, #{entryId,jdbcType=VARCHAR}, #{exitTime},
#{exitId,jdbcType=VARCHAR}, #{tradeTime}, #{tollRateVersion,jdbcType=VARCHAR},
#{tradeType,jdbcType=VARCHAR}, #{account,jdbcType=DECIMAL}, #{cash,jdbcType=DECIMAL},
#{tollCollectorName,jdbcType=VARCHAR}, #{useType,jdbcType=VARCHAR}, #{areaId,jdbcType=VARCHAR},
#{slotId,jdbcType=VARCHAR}, #{booking,jdbcType=BOOLEAN}, #{parkingDetail,jdbcType=VARCHAR},
#{domainName,jdbcType=VARCHAR}, #{version}, #{deleted,jdbcType=BOOLEAN},
#{insertUser,jdbcType=VARCHAR}, #{insertDate,jdbcType=TIMESTAMP}), #{exitFlagNum,jdbcType=VARCHAR}
</insert>
<update id="updateExitInfo" parameterType="interfaceParkingGate">
update t01_interface_parking_gate
<set>
update_user = #{updateUser}
</set>
where id = #{id}
</update>
<select id="selectByEntryTimeAndEntryId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t01_interface_parking_gate
where
entry_time = #{entryTime}
AND entry_id = #{entryId,jdbcType=VARCHAR}
</select>
<update id="updateExitId">
update t01_interface_parking_gate
set exit_id = #{exitId,jdbcType=VARCHAR}
</update>
<select id="selectAllByRequestIdOrExitRequestId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t01_interface_parking_gate
where
request_id = #{requestId,jdbcType=VARCHAR} OR exit_request_id = #{requestId,jdbcType=VARCHAR}
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment