add gao point

This commit is contained in:
Timi
2026-08-11 23:57:59 +08:00
parent 39ac73dc66
commit c6157db0de
26 changed files with 1534 additions and 1 deletions
@@ -0,0 +1,44 @@
<?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.imyeyu.api.modules.gao.mapper.GaoPointAccountMapper">
<select id="selectByStoreIdAndCustomerId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointAccount">
SELECT *
FROM `gao_point_account`
WHERE `store_id` = #{storeId}
AND `customer_id` = #{customerId}
AND `deleted_at` IS NULL
LIMIT 1
</select>
<insert id="insertIfAbsent">
INSERT INTO `gao_point_account` (
`id`, `store_id`, `customer_id`, `balance`, `total_earned`, `total_revoked`, `total_adjusted`, `version`, `created_at`, `updated_at`, `deleted_at`
) VALUES (
#{account.id}, #{account.storeId}, #{account.customerId}, #{account.balance}, #{account.totalEarned}, #{account.totalRevoked}, #{account.totalAdjusted}, #{account.version}, #{account.createdAt}, #{account.updatedAt}, #{account.deletedAt}
)
ON DUPLICATE KEY UPDATE `id` = `id`
</insert>
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointAccount">
SELECT *
FROM `gao_point_account`
WHERE `id` = #{id}
AND `deleted_at` IS NULL
LIMIT 1
FOR UPDATE
</select>
<update id="updateBalance">
UPDATE `gao_point_account`
SET
`balance` = `balance` + #{delta},
`total_earned` = `total_earned` + #{totalEarnedDelta},
`total_revoked` = `total_revoked` + #{totalRevokedDelta},
`total_adjusted` = `total_adjusted` + #{totalAdjustedDelta},
`version` = `version` + 1,
`updated_at` = #{updatedAt}
WHERE `id` = #{id}
AND `balance` + #{delta} &gt;= 0
AND `deleted_at` IS NULL
</update>
</mapper>
@@ -0,0 +1,68 @@
<?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.imyeyu.api.modules.gao.mapper.GaoPointLedgerMapper">
<select id="selectByIdempotencyKey" resultType="com.imyeyu.api.modules.gao.entity.GaoPointLedger">
SELECT *
FROM `gao_point_ledger`
WHERE `idempotency_key` = #{idempotencyKey}
AND `deleted_at` IS NULL
LIMIT 1
</select>
<select id="selectEarnByEventRecordId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointLedger">
SELECT *
FROM `gao_point_ledger`
WHERE `event_record_id` = #{eventRecordId}
AND `change_type` = 'EARN'
AND `deleted_at` IS NULL
ORDER BY `created_at` ASC, `id` ASC
</select>
<select id="selectByIdempotencyKeyList" resultType="com.imyeyu.api.modules.gao.entity.GaoPointLedger">
SELECT *
FROM `gao_point_ledger`
WHERE `deleted_at` IS NULL
AND `idempotency_key` IN
<foreach collection="idempotencyKeyList" item="idempotencyKey" open="(" separator="," close=")">
#{idempotencyKey}
</foreach>
</select>
<sql id="queryWhere">
`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">
AND `store_id` = #{storeId}
</if>
<if test="customerId != null and customerId != ''">
AND `customer_id` = #{customerId}
</if>
<if test="accountId != null and accountId != ''">
AND `account_id` = #{accountId}
</if>
<if test="changeType != null">
AND `change_type` = #{changeType}
</if>
<if test="beginAt != null">
AND `occurred_at` &gt;= #{beginAt}
</if>
<if test="endAt != null">
AND `occurred_at` &lt;= #{endAt}
</if>
</sql>
<select id="countByQuery" resultType="long">
SELECT COUNT(1)
FROM `gao_point_ledger`
WHERE
<include refid="queryWhere"/>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPointLedger">
SELECT *
FROM `gao_point_ledger`
WHERE
<include refid="queryWhere"/>
ORDER BY `occurred_at` DESC, `created_at` DESC
LIMIT #{offset}, #{limit}
</select>
</mapper>
@@ -0,0 +1,15 @@
<?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.imyeyu.api.modules.gao.mapper.GaoPointRuleMapper">
<select id="selectActiveByStoreIdAndEventId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRule">
SELECT *
FROM `gao_point_rule`
WHERE `store_id` = #{storeId}
AND `event_id` = #{eventId}
AND `status` = 'ACTIVE'
AND (`begin_at` IS NULL OR `begin_at` &lt;= #{now})
AND (`end_at` IS NULL OR #{now} &lt;= `end_at`)
AND `deleted_at` IS NULL
ORDER BY `priority` ASC, `created_at` ASC, `id` ASC
</select>
</mapper>