forked from rongchao/epmet-cloud-rizhao
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.
230 lines
8.3 KiB
230 lines
8.3 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.UserPointStatisticalDailyDao">
|
|
|
|
<resultMap type="com.epmet.entity.UserPointStatisticalDailyEntity" id="userPointStatisticalDailyMap">
|
|
<result property="id" column="ID"/>
|
|
<result property="userId" column="USER_ID" />
|
|
<result property="dateId" column="DATE_ID"/>
|
|
<result property="weekId" column="WEEK_ID"/>
|
|
<result property="monthId" column="MONTH_ID"/>
|
|
<result property="quarterId" column="QUARTER_ID"/>
|
|
<result property="yearId" column="YEAR_ID"/>
|
|
<result property="actionFlag" column="ACTION_FLAG"/>
|
|
<result property="customerId" column="CUSTOMER_ID"/>
|
|
<result property="pointChange" column="POINT_CHANGE"/>
|
|
<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 | 维度 | 维度值 -->
|
|
<!-- user_point_statistical_daily中的action_flag有三种key值,plus(获取),exchange(积分兑换),minus(调整、惩罚),当action_flag为minus时,point_change为负值,其余均为正数 -->
|
|
<select id="selectPointRankWithinTimeZone" resultType="com.epmet.dto.result.ResiPointRankResultDTO">
|
|
select * from (
|
|
|
|
SELECT IF ( @point > point.TOTAL_POINT,
|
|
@rank := @rank + 1,
|
|
@rank := @rank + 0
|
|
) AS rank,
|
|
point.user_id,
|
|
point.TOTAL_POINT,
|
|
@point := point.TOTAL_POINT
|
|
FROM
|
|
(
|
|
SELECT
|
|
total.USER_ID,
|
|
|
|
IF
|
|
( IFNULL( SUM( daily.POINT_CHANGE ), 0 ) <![CDATA[ < ]]> 0, 0, IFNULL( SUM( daily.POINT_CHANGE ), 0 ) ) AS
|
|
TOTAL_POINT
|
|
FROM
|
|
user_point_total total
|
|
LEFT JOIN user_point_statistical_daily daily ON daily.USER_ID = total.USER_ID
|
|
AND daily.DEL_FLAG = '0'
|
|
AND daily.USER_ID = total.USER_ID
|
|
AND daily.CUSTOMER_ID = #{customerId}
|
|
<if test='dimension == "week"'>
|
|
AND daily.WEEK_ID = #{dimensionId}
|
|
</if>
|
|
<if test='dimension == "month"'>
|
|
AND daily.MONTH_ID = #{dimensionId}
|
|
</if>
|
|
AND ( daily.ACTION_FLAG = 'plus' OR daily.ACTION_FLAG = 'minus' )
|
|
WHERE
|
|
total.DEL_FLAG = '0'
|
|
AND total.CUSTOMER_ID = #{customerId}
|
|
GROUP BY
|
|
total.USER_ID
|
|
ORDER BY
|
|
TOTAL_POINT DESC
|
|
) point,
|
|
( SELECT @point := NULL, @rank := 1 ) a
|
|
|
|
) temp
|
|
</select>
|
|
|
|
<!-- 查询有无指定日期的积分日统计 userId dateId actionFlag-->
|
|
<select id="selectIfExisted" resultType="com.epmet.entity.UserPointStatisticalDailyEntity" >
|
|
SELECT
|
|
id,
|
|
point_change
|
|
FROM
|
|
user_point_statistical_daily
|
|
WHERE
|
|
del_flag = '0'
|
|
AND
|
|
user_id = #{userId}
|
|
AND
|
|
date_id = #{dateId}
|
|
AND
|
|
action_flag = #{actionFlag}
|
|
</select>
|
|
|
|
|
|
<insert id="insertOrUpdate" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.epmet.entity.UserPointStatisticalDailyEntity">
|
|
|
|
<selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE">
|
|
SELECT replace(uuid(),'-','') AS ID
|
|
</selectKey>
|
|
|
|
INSERT INTO user_point_statistical_daily
|
|
(
|
|
id,
|
|
user_id,
|
|
date_id,
|
|
week_id,
|
|
month_id,
|
|
quarter_id,
|
|
year_id,
|
|
action_flag,
|
|
customer_id,
|
|
point_change,
|
|
del_flag,
|
|
revision,
|
|
created_by,
|
|
created_time,
|
|
updated_by,
|
|
updated_time
|
|
) VALUE (
|
|
#{id},
|
|
#{userId},
|
|
#{dateId},
|
|
#{weekId},
|
|
#{monthId},
|
|
#{quarterId},
|
|
#{yearId},
|
|
#{actionFlag},
|
|
#{customerId},
|
|
#{pointChange},
|
|
'0',
|
|
0,
|
|
#{createdBy},
|
|
now(),
|
|
#{createdBy},
|
|
now()
|
|
|
|
) ON DUPLICATE KEY UPDATE
|
|
POINT_CHANGE = (POINT_CHANGE + #{pointChange}),
|
|
UPDATED_TIME = NOW(),
|
|
UPDATED_BY = #{createdBy}
|
|
|
|
</insert>
|
|
|
|
<!-- 身边党员-积分排行 :按网格统计,对党员累计可用积分 排序 -->
|
|
<select id="selectListGridPartyRankByUsablePoint" resultType="com.epmet.dto.result.ResiAroundPartyPointRankResultDTO" >
|
|
SELECT
|
|
IF ( @point > p.USABLE_POINT,
|
|
@curRank := @curRank + 1,
|
|
@curRank := @curRank + 0
|
|
) AS ranking,
|
|
@point := IFNULL(p.USABLE_POINT, 0),
|
|
IFNULL(p.USABLE_POINT, 0) point,
|
|
p.USER_ID userId
|
|
FROM
|
|
user_point_total p, ( SELECT @curRank := #{pageNo} + 1 ) r
|
|
<if test="null != userIds and userIds.size() > 0">
|
|
WHERE p.USER_ID IN
|
|
<foreach collection="userIds" item="userId" open="(" separator="," close=" )">
|
|
#{userId}
|
|
</foreach>
|
|
</if>
|
|
ORDER BY IFNULL(p.USABLE_POINT, 0) DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<!-- 身边党员-积分排行 :按网格统计,对本月党员增加的积分 进行排序 -->
|
|
<select id="selectListGridPartyRankByMonth" resultType="com.epmet.dto.result.ResiAroundPartyPointRankResultDTO" >
|
|
SELECT
|
|
IF ( @point > p.point,
|
|
@curRank := @curRank + 1,
|
|
@curRank := @curRank + 0
|
|
) AS ranking,
|
|
@point := p.point,
|
|
P.userId,
|
|
P.point
|
|
FROM(
|
|
SELECT
|
|
pl.USER_ID userId,
|
|
SUM(PL.POINT) point
|
|
FROM user_point_action_log pl
|
|
WHERE pl.DEL_FLAG = '0' AND DATE_FORMAT(pl.CREATED_TIME, '%Y%m')= DATE_FORMAT( CURDATE( ) , '%Y%m' ) AND pl.action_flag = 'plus'
|
|
GROUP BY pl.USER_ID
|
|
) P, ( SELECT @curRank := #{pageNo} + 1 ) r
|
|
<if test="null != userIds and userIds.size() > 0">
|
|
WHERE userId IN
|
|
<foreach collection="userIds" item="userId" open="(" separator="," close=" )">
|
|
#{userId}
|
|
</foreach>
|
|
</if>
|
|
ORDER BY P.point DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<select id="selectListGridPartyNewRankByUsablePoint" resultType="com.epmet.dto.result.AllPartyResultDTO">
|
|
SET @curRank = 0;
|
|
SELECT
|
|
@curRank := @curRank + 1 AS ranking,
|
|
@point := IFNULL(p.USABLE_POINT, 0),
|
|
IFNULL(p.USABLE_POINT, 0) point,
|
|
p.USER_ID userId
|
|
FROM user_point_total p
|
|
<if test="null != userIds and userIds.size() > 0">
|
|
WHERE p.USER_ID IN
|
|
<foreach collection="userIds" item="userId" open="(" separator="," close=" )">
|
|
#{userId}
|
|
</foreach>
|
|
</if>
|
|
ORDER BY IFNULL(p.USABLE_POINT, 0) DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<select id="selectListGridPartyNewRankByMonth" resultType="com.epmet.dto.result.AllPartyResultDTO">
|
|
SET @curRank = 0;
|
|
SELECT
|
|
@curRank := @curRank + 1 AS ranking,
|
|
@point := p.point,
|
|
P.userId,
|
|
P.point
|
|
FROM(
|
|
SELECT
|
|
pl.USER_ID userId,
|
|
SUM(PL.POINT) point
|
|
FROM user_point_action_log pl
|
|
WHERE pl.DEL_FLAG = '0' AND DATE_FORMAT(pl.CREATED_TIME, '%Y%m')= DATE_FORMAT( CURDATE( ) , '%Y%m' ) AND pl.action_flag = 'plus'
|
|
GROUP BY pl.USER_ID
|
|
) P
|
|
<if test="null != userIds and userIds.size() > 0">
|
|
WHERE userId IN
|
|
<foreach collection="userIds" item="userId" open="(" separator="," close=" )">
|
|
#{userId}
|
|
</foreach>
|
|
</if>
|
|
ORDER BY P.point DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
</mapper>
|
|
|