93 lines
3.2 KiB
XML
93 lines
3.2 KiB
XML
<?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>
|
|
|
|
<select id="selectByIdAndStoreId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointAccount">
|
|
SELECT *
|
|
FROM `gao_point_account`
|
|
WHERE `id` = #{id}
|
|
<if test="storeId != null and storeId != ''">
|
|
AND `store_id` = #{storeId}
|
|
</if>
|
|
AND `deleted_at` IS NULL
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<sql id="queryWhere">
|
|
`a`.`deleted_at` IS NULL
|
|
AND `c`.`deleted_at` IS NULL
|
|
<if test="storeId != null and storeId != ''">
|
|
AND `a`.`store_id` = #{storeId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
AND (
|
|
`c`.`code` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`name` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`telephone` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%')
|
|
OR `c`.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%')
|
|
OR `c`.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%')
|
|
)
|
|
</if>
|
|
</sql>
|
|
|
|
<select id="countByQuery" resultType="long">
|
|
SELECT COUNT(1)
|
|
FROM `gao_point_account` `a`
|
|
INNER JOIN `gao_customer` `c` ON `c`.`id` = `a`.`customer_id` AND `c`.`store_id` = `a`.`store_id`
|
|
WHERE
|
|
<include refid="queryWhere"/>
|
|
</select>
|
|
|
|
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPointAccount">
|
|
SELECT `a`.*
|
|
FROM `gao_point_account` `a`
|
|
INNER JOIN `gao_customer` `c` ON `c`.`id` = `a`.`customer_id` AND `c`.`store_id` = `a`.`store_id`
|
|
WHERE
|
|
<include refid="queryWhere"/>
|
|
ORDER BY `a`.`created_at` DESC, `a`.`id` DESC
|
|
LIMIT #{offset}, #{limit}
|
|
</select>
|
|
|
|
<insert id="insertIfAbsent">
|
|
INSERT INTO `gao_point_account` (
|
|
`id`, `store_id`, `customer_id`, `balance`, `total_earned`, `total_consumed`, `total_revoked`, `total_adjusted`, `version`, `created_at`, `updated_at`, `deleted_at`
|
|
) VALUES (
|
|
#{account.id}, #{account.storeId}, #{account.customerId}, #{account.balance}, #{account.totalEarned}, #{account.totalConsumed}, #{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_consumed` = `total_consumed` + #{totalConsumedDelta},
|
|
`total_revoked` = `total_revoked` + #{totalRevokedDelta},
|
|
`total_adjusted` = `total_adjusted` + #{totalAdjustedDelta},
|
|
`version` = `version` + 1,
|
|
`updated_at` = #{updatedAt}
|
|
WHERE `id` = #{id}
|
|
AND `balance` + #{delta} >= 0
|
|
AND `deleted_at` IS NULL
|
|
</update>
|
|
</mapper>
|