You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.9 KiB
112 lines
3.9 KiB
<?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.epmet.dao.UserPointTotalDao">
|
|
|
|
<resultMap type="com.epmet.entity.UserPointTotalEntity" id="userPointTotalMap">
|
|
<result property="id" column="ID"/>
|
|
<result property="userId" column="USER_ID"/>
|
|
<result property="customerId" column="CUSTOMER_ID"/>
|
|
<result property="usedPoint" column="USED_POINT"/>
|
|
<result property="usablePoint" column="USABLE_POINT"/>
|
|
<result property="totalPoint" column="TOTAL_POINT"/>
|
|
<result property="delFlag" column="DEL_FLAG"/>
|
|
<result property="revision" column="REVISION"/>
|
|
<result property="createdBy" column="CREATED_BY"/>
|
|
<result property="createdTime" column="CREATED_TIME"/>
|
|
<result property="updatedBy" column="UPDATED_BY"/>
|
|
<result property="updatedTime" column="UPDATED_TIME"/>
|
|
</resultMap>
|
|
|
|
<!-- 根据用户Id查询该用户的可用积分和累计积分 -->
|
|
<select id="selectPointByUserId" resultType="com.epmet.dto.result.ResiPointDetailResultDTO">
|
|
SELECT
|
|
USABLE_POINT AS usablePoint,
|
|
TOTAL_POINT AS accumulatedPoint
|
|
FROM
|
|
USER_POINT_TOTAL
|
|
WHERE
|
|
DEL_FLAG = '0'
|
|
AND
|
|
USER_ID = #{userId}
|
|
</select>
|
|
|
|
<!-- 根据用户Id和客户Id查询他的累计积分以及可用积分 -->
|
|
<select id="selectPointByCustomerUserId" resultType="com.epmet.dto.result.ResiPointDetailResultDTO">
|
|
SELECT
|
|
USABLE_POINT AS usablePoint,
|
|
TOTAL_POINT AS accumulatedPoint
|
|
FROM
|
|
USER_POINT_TOTAL
|
|
WHERE
|
|
DEL_FLAG = '0'
|
|
AND
|
|
CUSTOMER_ID = #{customerId}
|
|
AND
|
|
USER_ID = #{userId}
|
|
</select>
|
|
|
|
<!-- 查询客户下的用户积分排行,分页 传参:customerId -->
|
|
<select id="selectUserPointRank" resultType="com.epmet.dto.result.ResiPointRankResultDTO">
|
|
SELECT
|
|
IF ( @point > point.total_point, @rank := @rank + 1, @rank := @rank + 0 ) AS rank,
|
|
point.user_id,
|
|
point.customer_id,
|
|
point.total_point,
|
|
@point := point.total_point
|
|
FROM
|
|
( SELECT * FROM user_point_total WHERE CUSTOMER_ID = #{customerId} ORDER BY total_point DESC ) point,
|
|
( SELECT @point := NULL, @rank := 1 ) a
|
|
</select>
|
|
|
|
<!-- 根据userId查找是否存在数据 -->
|
|
<select id="selectIfExisted" resultType="com.epmet.entity.UserPointTotalEntity">
|
|
SELECT
|
|
ID,
|
|
USED_POINT,
|
|
USABLE_POINT,
|
|
TOTAL_POINT
|
|
FROM
|
|
user_point_total
|
|
WHERE
|
|
del_flag = '0'
|
|
AND
|
|
user_id = #{userId}
|
|
</select>
|
|
|
|
<insert id="insertOrUpdate" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.epmet.entity.UserPointTotalEntity">
|
|
<selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE">
|
|
SELECT replace(uuid(),'-','') AS ID
|
|
</selectKey>
|
|
INSERT INTO user_point_total
|
|
(
|
|
id,
|
|
user_id,
|
|
customer_id,
|
|
used_point,
|
|
usable_point,
|
|
total_point,
|
|
created_by,
|
|
created_time,
|
|
updated_by,
|
|
updated_time
|
|
) VALUE (
|
|
#{id},
|
|
#{userId},
|
|
#{customerId},
|
|
#{usedPoint},
|
|
#{usablePoint},
|
|
#{totalPoint},
|
|
#{createdBy},
|
|
now(),
|
|
#{createdBy},
|
|
now()
|
|
) ON DUPLICATE KEY UPDATE
|
|
USED_POINT = (USED_POINT + #{usedPoint}),
|
|
USABLE_POINT = (USABLE_POINT + #{usablePoint}),
|
|
TOTAL_POINT = (TOTAL_POINT + #{totalPoint}),
|
|
UPDATED_TIME = NOW(),
|
|
UPDATED_BY = #{createdBy}
|
|
</insert>
|
|
|
|
</mapper>
|