|
|
|
<?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.elink.esua.epdc.dao.PointsLogsDao">
|
|
|
|
|
|
|
|
<resultMap type="com.elink.esua.epdc.entity.PointsLogsEntity" id="pointsLogsMap">
|
|
|
|
<result property="id" column="ID"/>
|
|
|
|
<result property="userId" column="USER_ID"/>
|
|
|
|
<result property="referenceId" column="REFERENCE_ID"/>
|
|
|
|
<result property="ruleCode" column="RULE_CODE"/>
|
|
|
|
<result property="behaviorCode" column="BEHAVIOR_CODE"/>
|
|
|
|
<result property="operationType" column="OPERATION_TYPE"/>
|
|
|
|
<result property="points" column="POINTS"/>
|
|
|
|
<result property="operationDesc" column="OPERATION_DESC"/>
|
|
|
|
<result property="operationTime" column="OPERATION_TIME"/>
|
|
|
|
<result property="operationMode" column="OPERATION_MODE"/>
|
|
|
|
<result property="lavePoints" column="LAVE_POINTS"/>
|
|
|
|
<result property="revision" column="REVISION"/>
|
|
|
|
<result property="delFlag" column="DEL_FLAG"/>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<select id="selectListPointsRecord" resultType="com.elink.esua.epdc.dto.result.EpdcAppPointsRecordResultDTO">
|
|
|
|
SELECT
|
|
|
|
l.ID id,
|
|
|
|
l.OPERATION_DESC ruleDesc,
|
|
|
|
l.OPERATION_TYPE operationType,
|
|
|
|
l.POINTS points,
|
|
|
|
l.OPERATION_TIME operationTime
|
|
|
|
FROM
|
|
|
|
epdc_points_logs l
|
|
|
|
WHERE l.DEL_FLAG = 0
|
|
|
|
AND l.USER_ID = #{userId}
|
|
|
|
ORDER BY
|
|
|
|
l.OPERATION_TIME DESC
|
|
|
|
LIMIT #{pageIndex}, #{pageSize}
|
|
|
|
</select>
|
|
|
|
<select id="selecOneLogsByBehaviorCodeAndUserIdAndReferenceId"
|
|
|
|
resultType="com.elink.esua.epdc.dto.result.PointsLogsResultDTO">
|
|
|
|
select ID,USER_ID,REFERENCE_ID,RULE_CODE,BEHAVIOR_CODE,POINTS,OPERATION_DESC,OPERATION_TIME,OPERATION_MODE
|
|
|
|
,LAVE_POINTS,REVISION,DEL_FLAG,CREATED_BY,CREATED_TIME,UPDATED_BY,UPDATED_TIME
|
|
|
|
from epdc_points_logs where DEL_FLAG ='0' and USER_ID = #{userId} and REFERENCE_ID = #{referenceId}
|
|
|
|
and RULE_CODE = #{ruleCode}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="getPointsSumByBehaviorCodeAndUserId" resultType="integer">
|
|
|
|
select sum(z) - sum(f) as total from(
|
|
|
|
select
|
|
|
|
case when OPERATION_TYPE =0 then sum(POINTS) else 0 end as f,
|
|
|
|
case when OPERATION_TYPE =1 then sum(POINTS) else 0 end as z,
|
|
|
|
BEHAVIOR_CODE
|
|
|
|
from epdc_points_logs where USER_ID = #{userId} and BEHAVIOR_CODE = #{behaviorCode}
|
|
|
|
<if test="operationFlag == 0">
|
|
|
|
and OPERATION_TIME between date_add(now() , interval -1 minute ) and now()
|
|
|
|
</if>
|
|
|
|
<if test="operationFlag == 1">
|
|
|
|
and OPERATION_TIME between date_add(now() , interval -1 hour ) and now()
|
|
|
|
</if>
|
|
|
|
<if test="operationFlag == 2">
|
|
|
|
and date_format(OPERATION_TIME,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
|
|
|
|
</if>
|
|
|
|
<if test="operationFlag == 3">
|
|
|
|
and date_format(OPERATION_TIME,'%Y-%m') = date_format(now(),'%Y-%m')
|
|
|
|
</if>
|
|
|
|
<if test="operationFlag == 4">
|
|
|
|
and date_format(OPERATION_TIME,'%Y') = date_format(now(),'%Y')
|
|
|
|
</if>
|
|
|
|
group by OPERATION_TYPE)a group by a.BEHAVIOR_CODE;
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="getLastPointLogs" resultType="com.elink.esua.epdc.dto.result.PointsLogsResultDTO">
|
|
|
|
select ID,USER_ID,REFERENCE_ID,RULE_CODE,BEHAVIOR_CODE,POINTS,OPERATION_DESC,OPERATION_TIME,OPERATION_MODE
|
|
|
|
,LAVE_POINTS,REVISION,DEL_FLAG,CREATED_BY,CREATED_TIME,UPDATED_BY,UPDATED_TIME
|
|
|
|
from epdc_points_logs where DEL_FLAG ='0' and USER_ID = #{userId}
|
|
|
|
and BEHAVIOR_CODE = #{behaviorCode} order by OPERATION_TIME desc limit 1
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectListPointsRanking" resultType="com.elink.esua.epdc.dto.result.EpdcAppPointsRankingTopTenDTO">
|
|
|
|
SELECT
|
|
|
|
tab.USER_ID userId,
|
|
|
|
(
|
|
|
|
SELECT NICKNAME
|
|
|
|
FROM epdc_points_logs
|
|
|
|
WHERE tab.USER_ID = USER_ID
|
|
|
|
ORDER BY CREATED_TIME DESC
|
|
|
|
limit 0,1
|
|
|
|
) nickName,
|
|
|
|
(tab.totalPointsAdd - tab.totalPointsDeducted) points
|
|
|
|
FROM(
|
|
|
|
SELECT
|
|
|
|
USER_ID,
|
|
|
|
SUM(case when OPERATION_TYPE = 0 then IFNULL(points,0) else 0 end) totalPointsDeducted,
|
|
|
|
SUM(case when OPERATION_TYPE = 1 then IFNULL(points,0) else 0 end) totalPointsAdd
|
|
|
|
FROM epdc_points_logs
|
|
|
|
WHERE DEL_FLAG = 0
|
|
|
|
<if test="rankingType != null and rankingType == 0">
|
|
|
|
AND YEARWEEK(date_format(OPERATION_TIME,'%Y-%m-%d')) = YEARWEEK(now())
|
|
|
|
</if>
|
|
|
|
<if test="rankingType != null and rankingType == 1">
|
|
|
|
AND DATE_FORMAT( OPERATION_TIME, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
|
|
|
|
</if>
|
|
|
|
GROUP BY USER_ID
|
|
|
|
) tab ORDER BY (tab.totalPointsAdd - tab.totalPointsDeducted) DESC
|
|
|
|
LIMIT #{pageIndex}, #{pageSize}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectListVolunteerPointsLog" resultType="com.elink.esua.epdc.dto.PointsLogsDTO">
|
|
|
|
SELECT
|
|
|
|
l.OPERATION_DESC operationDesc,
|
|
|
|
b.BEHAVIOR_DESC behaviorCode,
|
|
|
|
l.OPERATION_TIME operationTime,
|
|
|
|
l.POINTS points,
|
|
|
|
l.OPERATION_TYPE operationType,
|
|
|
|
l.LAVE_POINTS lavePoints
|
|
|
|
FROM
|
|
|
|
epdc_points_logs l
|
|
|
|
LEFT JOIN epdc_points_behavior b ON l.BEHAVIOR_CODE = b.BEHAVIOR_CODE AND b.DEL_FLAG = 0
|
|
|
|
WHERE
|
|
|
|
l.DEL_FLAG = 0
|
|
|
|
AND l.USER_ID = #{userId}
|
|
|
|
<if test="behaviorCode != null and behaviorCode != ''">
|
|
|
|
AND l.BEHAVIOR_CODE = #{behaviorCode}
|
|
|
|
</if>
|
|
|
|
ORDER BY
|
|
|
|
l.CREATED_TIME DESC
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectUserPointsRanking" resultType="com.elink.esua.epdc.dto.result.EpdcAppPointsRankingUserDTO">
|
|
|
|
SELECT
|
|
|
|
userRanking.rank,
|
|
|
|
userRanking.points
|
|
|
|
FROM(
|
|
|
|
SELECT
|
|
|
|
(@i:=@i+1) rank,
|
|
|
|
tab.USER_ID userId,
|
|
|
|
GROUP_CONCAT(tab.USER_ID SEPARATOR ',') pdtj,
|
|
|
|
tab.points
|
|
|
|
FROM(
|
|
|
|
SELECT
|
|
|
|
USER_ID,
|
|
|
|
(SUM(case when OPERATION_TYPE = 1 then IFNULL(points,0) else 0 end) - SUM(case when OPERATION_TYPE = 0 then IFNULL(points,0) else 0 end)) points
|
|
|
|
FROM epdc_points_logs
|
|
|
|
WHERE DEL_FLAG = 0
|
|
|
|
<if test="rankingType != null and rankingType == 0">
|
|
|
|
AND YEARWEEK(date_format(OPERATION_TIME,'%Y-%m-%d')) = YEARWEEK(now())
|
|
|
|
</if>
|
|
|
|
<if test="rankingType != null and rankingType == 1">
|
|
|
|
AND DATE_FORMAT( OPERATION_TIME, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
|
|
|
|
</if>
|
|
|
|
GROUP BY USER_ID
|
|
|
|
) tab ,(select @i:=0) t1
|
|
|
|
GROUP BY tab.points
|
|
|
|
ORDER BY tab.points DESC
|
|
|
|
) userRanking
|
|
|
|
WHERE instr(userRanking.pdtj , #{userId} ) > 0
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectCountPointsRanking" resultType="int">
|
|
|
|
SELECT
|
|
|
|
COUNT(1)
|
|
|
|
FROM(
|
|
|
|
SELECT
|
|
|
|
p.points
|
|
|
|
FROM(
|
|
|
|
SELECT
|
|
|
|
USER_ID,
|
|
|
|
(SUM(case when OPERATION_TYPE = 1 then IFNULL(points,0) else 0 end) - SUM(case when OPERATION_TYPE = 0 then IFNULL(points,0) else 0 end)) points
|
|
|
|
FROM epdc_points_logs
|
|
|
|
WHERE DEL_FLAG = 0
|
|
|
|
<if test="rankingType != null and rankingType == 0">
|
|
|
|
AND YEARWEEK(date_format(OPERATION_TIME,'%Y-%m-%d')) = YEARWEEK(now())
|
|
|
|
</if>
|
|
|
|
<if test="rankingType != null and rankingType == 1">
|
|
|
|
AND DATE_FORMAT( OPERATION_TIME, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
|
|
|
|
</if>
|
|
|
|
GROUP BY USER_ID
|
|
|
|
) p GROUP BY p.points
|
|
|
|
) tab
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectPointsList" resultType="com.elink.esua.epdc.dto.result.PointsStatisticsListResultDTO">
|
|
|
|
SELECT
|
|
|
|
SUM(
|
|
|
|
IF( lg.OPERATION_TYPE = '1', lg.POINTS, 0 )
|
|
|
|
) allPoints,
|
|
|
|
SUM(
|
|
|
|
IF( lg.OPERATION_TYPE = '0', lg.POINTS, 0 )
|
|
|
|
) residuePoints,
|
|
|
|
lg.OPERATION_DESC
|
|
|
|
FROM
|
|
|
|
epdc_points_logs lg
|
|
|
|
WHERE
|
|
|
|
lg.DEL_FLAG = '0'
|
|
|
|
<if test="ruleCode!= null and ruleCode !=''">
|
|
|
|
and lg.RULE_CODE = #{ruleCode}
|
|
|
|
</if>
|
|
|
|
<if test="startTime!= null and startTime !=''">
|
|
|
|
and lg.OPERATION_TIME between #{startTime} AND #{endTime}
|
|
|
|
</if>
|
|
|
|
|
|
|
|
GROUP BY
|
|
|
|
lg.RULE_CODE
|
|
|
|
ORDER BY allPoints DESC
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectPointsOverview" resultType="com.elink.esua.epdc.dto.result.PointsStatisticsListResultDTO">
|
|
|
|
SELECT
|
|
|
|
SUM(
|
|
|
|
IF( lg.OPERATION_TYPE = '1', lg.POINTS, 0 )
|
|
|
|
) allPoints,
|
|
|
|
SUM(
|
|
|
|
IF( lg.OPERATION_TYPE = '0', lg.POINTS, 0 )
|
|
|
|
) residuePoints
|
|
|
|
FROM
|
|
|
|
epdc_points_logs lg
|
|
|
|
WHERE
|
|
|
|
lg.DEL_FLAG = '0'
|
|
|
|
<if test="startTime!= null and startTime !=''">
|
|
|
|
and lg.OPERATION_TIME between #{startTime} AND #{endTime}
|
|
|
|
</if>
|
|
|
|
ORDER BY lg.OPERATION_TYPE DESC
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<insert id="insertBatchPointsResetLogs">
|
|
|
|
insert into epdc_points_logs(ID, USER_ID, NICKNAME, REFERENCE_ID, RULE_CODE, BEHAVIOR_CODE, OPERATION_TYPE, POINTS, OPERATION_DESC, OPERATION_TIME, OPERATION_MODE, LAVE_POINTS, REVISION, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, FACE_IMG, VOLUNTEER_ID, GRID_ID, GRID, ALL_DEPT_IDS, ALL_DEPT_NAMES, PARENT_DEPT_IDS, PARENT_DEPT_NAMES,REMARK, REAL_NAME) VALUES
|
|
|
|
<foreach collection="list" item="points" separator=",">
|
|
|
|
(MD5(UUID()),#{points.userId},#{points.nickname},#{points.referenceId},#{points.ruleCode},#{points.behaviorCode},#{points.operationType},#{points.points},#{points.operationDesc},#{points.operationTime},#{points.operationMode},#{points.lavePoints},0,0,0,now(),0,now(),#{points.faceImg},#{points.volunteerId},#{points.gridId},#{points.grid},#{points.allDeptIds},#{points.allDeptNames},#{points.parentDeptIds},#{points.parentDeptNames},#{points.remark},#{points.realName})
|
|
|
|
</foreach>
|
|
|
|
</insert>
|
|
|
|
</mapper>
|