mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-01-26 19:20:27 +08:00
交易下单2-添加sequence_info表并自动生成Mapper
This commit is contained in:
parent
d44db6d5be
commit
e3917d1ff1
@ -11,7 +11,7 @@
|
|||||||
Target Server Version : 50726
|
Target Server Version : 50726
|
||||||
File Encoding : 65001
|
File Encoding : 65001
|
||||||
|
|
||||||
Date: 03/03/2022 22:01:38
|
Date: 03/03/2022 23:08:26
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
@ -100,6 +100,22 @@ CREATE TABLE `order_info` (
|
|||||||
-- Records of order_info
|
-- Records of order_info
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for sequence_info
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `sequence_info`;
|
||||||
|
CREATE TABLE `sequence_info` (
|
||||||
|
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||||
|
`current_value` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`step` int(11) NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (`name`) USING BTREE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Records of sequence_info
|
||||||
|
-- ----------------------------
|
||||||
|
INSERT INTO `sequence_info` VALUES ('order_info', 0, 1);
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for user_info
|
-- Table structure for user_info
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package com.cxyxiaomo.flashsale.dao;
|
||||||
|
|
||||||
|
import com.cxyxiaomo.flashsale.dataobject.SequenceDO;
|
||||||
|
|
||||||
|
public interface SequenceDOMapper {
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method corresponds to the database table sequence_info
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
int deleteByPrimaryKey(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method corresponds to the database table sequence_info
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
int insert(SequenceDO record);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method corresponds to the database table sequence_info
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
int insertSelective(SequenceDO record);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method corresponds to the database table sequence_info
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
SequenceDO selectByPrimaryKey(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method corresponds to the database table sequence_info
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
int updateByPrimaryKeySelective(SequenceDO record);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method corresponds to the database table sequence_info
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
int updateByPrimaryKey(SequenceDO record);
|
||||||
|
}
|
102
src/main/java/com/cxyxiaomo/flashsale/dataobject/SequenceDO.java
Normal file
102
src/main/java/com/cxyxiaomo/flashsale/dataobject/SequenceDO.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package com.cxyxiaomo.flashsale.dataobject;
|
||||||
|
|
||||||
|
public class SequenceDO {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This field was generated by MyBatis Generator.
|
||||||
|
* This field corresponds to the database column sequence_info.name
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This field was generated by MyBatis Generator.
|
||||||
|
* This field corresponds to the database column sequence_info.current_value
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
private Integer currentValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This field was generated by MyBatis Generator.
|
||||||
|
* This field corresponds to the database column sequence_info.step
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
private Integer step;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method returns the value of the database column sequence_info.name
|
||||||
|
*
|
||||||
|
* @return the value of sequence_info.name
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method sets the value of the database column sequence_info.name
|
||||||
|
*
|
||||||
|
* @param name the value for sequence_info.name
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name == null ? null : name.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method returns the value of the database column sequence_info.current_value
|
||||||
|
*
|
||||||
|
* @return the value of sequence_info.current_value
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
public Integer getCurrentValue() {
|
||||||
|
return currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method sets the value of the database column sequence_info.current_value
|
||||||
|
*
|
||||||
|
* @param currentValue the value for sequence_info.current_value
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
public void setCurrentValue(Integer currentValue) {
|
||||||
|
this.currentValue = currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method returns the value of the database column sequence_info.step
|
||||||
|
*
|
||||||
|
* @return the value of sequence_info.step
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
public Integer getStep() {
|
||||||
|
return step;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method was generated by MyBatis Generator.
|
||||||
|
* This method sets the value of the database column sequence_info.step
|
||||||
|
*
|
||||||
|
* @param step the value for sequence_info.step
|
||||||
|
*
|
||||||
|
* @mbg.generated Thu Mar 03 23:07:17 CST 2022
|
||||||
|
*/
|
||||||
|
public void setStep(Integer step) {
|
||||||
|
this.step = step;
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class OrderServiceImpl implements OrderService {
|
public class OrderServiceImpl implements OrderService {
|
||||||
@ -83,13 +85,19 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成交易流水号,订单号
|
// 生成交易流水号,订单号
|
||||||
private String generateOderNo(){
|
private String generateOrderNo() {
|
||||||
// 订单号为16位
|
// 订单号为16位
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
// 前8位为时间信息(年月日)
|
// 前8位为时间信息(年月日)
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
String nowDate = now.format(DateTimeFormatter.ISO_DATE).replace("-", "");
|
||||||
|
stringBuilder.append(nowDate);
|
||||||
|
|
||||||
// 中间6位为自增序列
|
// 中间6位为自增序列
|
||||||
|
|
||||||
// 最后2位为分库分表位
|
// 最后2位为分库分表位
|
||||||
|
stringBuilder.append("00"); // 暂时写死
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
111
src/main/resources/mapping/SequenceDOMapper.xml
Normal file
111
src/main/resources/mapping/SequenceDOMapper.xml
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?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.cxyxiaomo.flashsale.dao.SequenceDOMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.cxyxiaomo.flashsale.dataobject.SequenceDO">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
<id column="name" jdbcType="VARCHAR" property="name" />
|
||||||
|
<result column="current_value" jdbcType="INTEGER" property="currentValue" />
|
||||||
|
<result column="step" jdbcType="INTEGER" property="step" />
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
name, current_value, step
|
||||||
|
</sql>
|
||||||
|
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from sequence_info
|
||||||
|
where name = #{name,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
delete from sequence_info
|
||||||
|
where name = #{name,jdbcType=VARCHAR}
|
||||||
|
</delete>
|
||||||
|
<insert id="insert" parameterType="com.cxyxiaomo.flashsale.dataobject.SequenceDO">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
insert into sequence_info (name, current_value, step
|
||||||
|
)
|
||||||
|
values (#{name,jdbcType=VARCHAR}, #{currentValue,jdbcType=INTEGER}, #{step,jdbcType=INTEGER}
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.SequenceDO">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
insert into sequence_info
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="name != null">
|
||||||
|
name,
|
||||||
|
</if>
|
||||||
|
<if test="currentValue != null">
|
||||||
|
current_value,
|
||||||
|
</if>
|
||||||
|
<if test="step != null">
|
||||||
|
step,
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="name != null">
|
||||||
|
#{name,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="currentValue != null">
|
||||||
|
#{currentValue,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="step != null">
|
||||||
|
#{step,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
<update id="updateByPrimaryKeySelective" parameterType="com.cxyxiaomo.flashsale.dataobject.SequenceDO">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
update sequence_info
|
||||||
|
<set>
|
||||||
|
<if test="currentValue != null">
|
||||||
|
current_value = #{currentValue,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="step != null">
|
||||||
|
step = #{step,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where name = #{name,jdbcType=VARCHAR}
|
||||||
|
</update>
|
||||||
|
<update id="updateByPrimaryKey" parameterType="com.cxyxiaomo.flashsale.dataobject.SequenceDO">
|
||||||
|
<!--
|
||||||
|
WARNING - @mbg.generated
|
||||||
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
|
This element was generated on Thu Mar 03 23:07:17 CST 2022.
|
||||||
|
-->
|
||||||
|
update sequence_info
|
||||||
|
set current_value = #{currentValue,jdbcType=INTEGER},
|
||||||
|
step = #{step,jdbcType=INTEGER}
|
||||||
|
where name = #{name,jdbcType=VARCHAR}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
@ -56,6 +56,9 @@
|
|||||||
<!--<table tableName="order_info" domainObjectName="OrderDO" enableCountByExample="false"-->
|
<!--<table tableName="order_info" domainObjectName="OrderDO" enableCountByExample="false"-->
|
||||||
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->
|
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->
|
||||||
<!-- selectByExampleQueryId="false"></table>-->
|
<!-- selectByExampleQueryId="false"></table>-->
|
||||||
|
<!--<table tableName="sequence_info" domainObjectName="SequenceDO" enableCountByExample="false"-->
|
||||||
|
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->
|
||||||
|
<!-- selectByExampleQueryId="false"></table>-->
|
||||||
|
|
||||||
</context>
|
</context>
|
||||||
</generatorConfiguration>
|
</generatorConfiguration>
|
Loading…
x
Reference in New Issue
Block a user