add 积分系统功能

This commit is contained in:
Guoqs
2025-12-24 15:41:11 +08:00
parent c2a1ae1966
commit e135db56b0
11 changed files with 917 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?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.jsowell.pile.mapper.MemberPointsInfoMapper">
<resultMap id="BaseResultMap" type="com.jsowell.pile.domain.MemberPointsInfo">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="member_id" jdbcType="VARCHAR" property="memberId"/>
<result column="total_points" jdbcType="DECIMAL" property="totalPoints"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
</resultMap>
<sql id="Base_Column_List">
id, member_id, total_points, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from member_points_info
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectByMemberId" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from member_points_info
where member_id = #{memberId,jdbcType=VARCHAR}
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberPointsInfo"
useGeneratedKeys="true">
insert into member_points_info (member_id, total_points, update_time)
values (#{memberId,jdbcType=VARCHAR}, #{totalPoints,jdbcType=DECIMAL}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="com.jsowell.pile.domain.MemberPointsInfo" useGeneratedKeys="true">
insert into member_points_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="memberId != null">
member_id,
</if>
<if test="totalPoints != null">
total_points,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="memberId != null">
#{memberId,jdbcType=VARCHAR},
</if>
<if test="totalPoints != null">
#{totalPoints,jdbcType=DECIMAL},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKey" parameterType="com.jsowell.pile.domain.MemberPointsInfo">
update member_points_info
set member_id = #{memberId,jdbcType=VARCHAR},
total_points = #{totalPoints,jdbcType=DECIMAL},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.jsowell.pile.domain.MemberPointsInfo">
update member_points_info
<set>
<if test="memberId != null">
member_id = #{memberId,jdbcType=VARCHAR},
</if>
<if test="totalPoints != null">
total_points = #{totalPoints,jdbcType=DECIMAL},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<!-- 原子性增加积分 -->
<update id="addPoints">
update member_points_info
set total_points = total_points + #{points,jdbcType=DECIMAL},
update_time = NOW()
where member_id = #{memberId,jdbcType=VARCHAR}
</update>
<!-- 原子性扣减积分(确保积分不会变为负数) -->
<update id="deductPoints">
update member_points_info
set total_points = total_points - #{points,jdbcType=DECIMAL},
update_time = NOW()
where member_id = #{memberId,jdbcType=VARCHAR}
and total_points >= #{points,jdbcType=DECIMAL}
</update>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from member_points_info
where id = #{id,jdbcType=BIGINT}
</delete>
</mapper>

View File

@@ -0,0 +1,153 @@
<?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.jsowell.pile.mapper.MemberPointsRecordMapper">
<resultMap id="BaseResultMap" type="com.jsowell.pile.domain.MemberPointsRecord">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="member_id" jdbcType="VARCHAR" property="memberId"/>
<result column="points" jdbcType="DECIMAL" property="points"/>
<result column="type" jdbcType="TINYINT" property="type"/>
<result column="order_code" jdbcType="VARCHAR" property="orderCode"/>
<result column="before_points" jdbcType="DECIMAL" property="beforePoints"/>
<result column="after_points" jdbcType="DECIMAL" property="afterPoints"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
</resultMap>
<sql id="Base_Column_List">
id, member_id, points, type, order_code, before_points, after_points, create_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from member_points_record
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectByMemberId" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from member_points_record
where member_id = #{memberId,jdbcType=VARCHAR}
order by create_time desc
</select>
<select id="selectByMemberIdWithPage" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from member_points_record
where member_id = #{memberId,jdbcType=VARCHAR}
order by create_time desc
</select>
<select id="selectByOrderCode" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from member_points_record
where order_code = #{orderCode,jdbcType=VARCHAR}
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberPointsRecord"
useGeneratedKeys="true">
insert into member_points_record (member_id, points, type, order_code, before_points, after_points, create_time)
values (#{memberId,jdbcType=VARCHAR}, #{points,jdbcType=DECIMAL}, #{type,jdbcType=TINYINT},
#{orderCode,jdbcType=VARCHAR}, #{beforePoints,jdbcType=DECIMAL}, #{afterPoints,jdbcType=DECIMAL},
#{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="com.jsowell.pile.domain.MemberPointsRecord" useGeneratedKeys="true">
insert into member_points_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="memberId != null">
member_id,
</if>
<if test="points != null">
points,
</if>
<if test="type != null">
type,
</if>
<if test="orderCode != null">
order_code,
</if>
<if test="beforePoints != null">
before_points,
</if>
<if test="afterPoints != null">
after_points,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="memberId != null">
#{memberId,jdbcType=VARCHAR},
</if>
<if test="points != null">
#{points,jdbcType=DECIMAL},
</if>
<if test="type != null">
#{type,jdbcType=TINYINT},
</if>
<if test="orderCode != null">
#{orderCode,jdbcType=VARCHAR},
</if>
<if test="beforePoints != null">
#{beforePoints,jdbcType=DECIMAL},
</if>
<if test="afterPoints != null">
#{afterPoints,jdbcType=DECIMAL},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKey" parameterType="com.jsowell.pile.domain.MemberPointsRecord">
update member_points_record
set member_id = #{memberId,jdbcType=VARCHAR},
points = #{points,jdbcType=DECIMAL},
type = #{type,jdbcType=TINYINT},
order_code = #{orderCode,jdbcType=VARCHAR},
before_points = #{beforePoints,jdbcType=DECIMAL},
after_points = #{afterPoints,jdbcType=DECIMAL},
create_time = #{createTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.jsowell.pile.domain.MemberPointsRecord">
update member_points_record
<set>
<if test="memberId != null">
member_id = #{memberId,jdbcType=VARCHAR},
</if>
<if test="points != null">
points = #{points,jdbcType=DECIMAL},
</if>
<if test="type != null">
type = #{type,jdbcType=TINYINT},
</if>
<if test="orderCode != null">
order_code = #{orderCode,jdbcType=VARCHAR},
</if>
<if test="beforePoints != null">
before_points = #{beforePoints,jdbcType=DECIMAL},
</if>
<if test="afterPoints != null">
after_points = #{afterPoints,jdbcType=DECIMAL},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from member_points_record
where id = #{id,jdbcType=BIGINT}
</delete>
</mapper>