|
@@ -0,0 +1,221 @@
|
|
|
+<?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.fs.store.mapper.FsUserCourseCountMapper">
|
|
|
+
|
|
|
+ <resultMap type="FsUserCourseCount" id="FsUserCourseCountResult">
|
|
|
+ <result property="id" column="id" />
|
|
|
+ <result property="userId" column="user_id" />
|
|
|
+ <result property="watchCourseCount" column="watch_course_count" />
|
|
|
+ <result property="missCourseCount" column="miss_course_count" />
|
|
|
+ <result property="missCourseStatus" column="miss_course_status" />
|
|
|
+ <result property="missCourseDays" column="miss_course_days" />
|
|
|
+ <result property="courseIds" column="course_idss" />
|
|
|
+ <result property="partCourseCount" column="part_course_count" />
|
|
|
+ <result property="lastWatchDate" column="last_watch_date" />
|
|
|
+ <result property="status" column="status" />
|
|
|
+ <result property="stopWatchDays" column="stop_watch_days" />
|
|
|
+ <result property="createTime" column="create_time" />
|
|
|
+ <result property="updateTime" column="update_time" />
|
|
|
+ <result property="createBy" column="create_by" />
|
|
|
+ <result property="updateBy" column="update_by" />
|
|
|
+ <result property="completeWatchDate" column="complete_watch_date" />
|
|
|
+ <result property="completeWatchCount" column="complete_watch_count" />
|
|
|
+ <result property="watchTimes" column="watch_times" />
|
|
|
+ <result property="createDate" column="create_date" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <sql id="selectFsUserCourseCountVo">
|
|
|
+ select id, user_id, watch_course_count, miss_course_count, miss_course_status, miss_course_days, course_ids, part_course_count, last_watch_date, status, stop_watch_days, create_time, update_time, create_by, update_by, complete_watch_date, complete_watch_count, watch_times, create_date from fs_user_course_count
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <select id="selectFsUserCourseCountList" parameterType="FsUserCourseCount" resultMap="FsUserCourseCountResult">
|
|
|
+ <include refid="selectFsUserCourseCountVo"/>
|
|
|
+ <where>
|
|
|
+ <if test="userId != null "> and user_id = #{userId}</if>
|
|
|
+ <if test="watchCourseCount != null "> and watch_course_count = #{watchCourseCount}</if>
|
|
|
+ <if test="missCourseCount != null "> and miss_course_count = #{missCourseCount}</if>
|
|
|
+ <if test="missCourseStatus != null "> and miss_course_status = #{missCourseStatus}</if>
|
|
|
+ <if test="missCourseDays != null "> and miss_course_days = #{missCourseDays}</if>
|
|
|
+ <if test="courseIds != null "> and course_ids = #{courseIds}</if>
|
|
|
+ <if test="partCourseCount != null and partCourseCount != ''"> and part_course_count = #{partCourseCount}</if>
|
|
|
+ <if test="lastWatchDate != null "> and last_watch_date = #{lastWatchDate}</if>
|
|
|
+ <if test="status != null "> and status = #{status}</if>
|
|
|
+ <if test="stopWatchDays != null "> and stop_watch_days = #{stopWatchDays}</if>
|
|
|
+ <if test="completeWatchDate != null "> and complete_watch_date = #{completeWatchDate}</if>
|
|
|
+ <if test="completeWatchCount != null "> and complete_watch_count = #{completeWatchCount}</if>
|
|
|
+ <if test="watchTimes != null "> and watch_times = #{watchTimes}</if>
|
|
|
+ <if test="createDate != null "> and create_date = #{createDate}</if>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectFsUserCourseCountById" parameterType="Long" resultMap="FsUserCourseCountResult">
|
|
|
+ <include refid="selectFsUserCourseCountVo"/>
|
|
|
+ where id = #{id}
|
|
|
+ </select>
|
|
|
+ <select id="findByUserId" resultType="com.fs.store.domain.FsUserCourseCount">
|
|
|
+ select * from fs_user_course_count where user_id = ${userId} limit 1
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <insert id="insertFsUserCourseCount" parameterType="FsUserCourseCount">
|
|
|
+ insert into fs_user_course_count
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">id,</if>
|
|
|
+ <if test="userId != null">user_id,</if>
|
|
|
+ <if test="watchCourseCount != null">watch_course_count,</if>
|
|
|
+ <if test="missCourseCount != null">miss_course_count,</if>
|
|
|
+ <if test="missCourseStatus != null">miss_course_status,</if>
|
|
|
+ <if test="missCourseDays != null">miss_course_days,</if>
|
|
|
+ <if test="courseIds != null">course_ids,</if>
|
|
|
+ <if test="partCourseCount != null">part_course_count,</if>
|
|
|
+ <if test="lastWatchDate != null">last_watch_date,</if>
|
|
|
+ <if test="status != null">status,</if>
|
|
|
+ <if test="stopWatchDays != null">stop_watch_days,</if>
|
|
|
+ <if test="createTime != null">create_time,</if>
|
|
|
+ <if test="updateTime != null">update_time,</if>
|
|
|
+ <if test="createBy != null">create_by,</if>
|
|
|
+ <if test="updateBy != null">update_by,</if>
|
|
|
+ <if test="completeWatchDate != null">complete_watch_date,</if>
|
|
|
+ <if test="completeWatchCount != null">complete_watch_count,</if>
|
|
|
+ <if test="watchTimes != null">watch_times,</if>
|
|
|
+ <if test="createDate != null">create_date,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">#{id},</if>
|
|
|
+ <if test="userId != null">#{userId},</if>
|
|
|
+ <if test="watchCourseCount != null">#{watchCourseCount},</if>
|
|
|
+ <if test="missCourseCount != null">#{missCourseCount},</if>
|
|
|
+ <if test="missCourseStatus != null">#{missCourseStatus},</if>
|
|
|
+ <if test="missCourseDays != null">#{missCourseDays},</if>
|
|
|
+ <if test="courseIds != null">#{courseIds},</if>
|
|
|
+ <if test="partCourseCount != null">#{partCourseCount},</if>
|
|
|
+ <if test="lastWatchDate != null">#{lastWatchDate},</if>
|
|
|
+ <if test="status != null">#{status},</if>
|
|
|
+ <if test="stopWatchDays != null">#{stopWatchDays},</if>
|
|
|
+ <if test="createTime != null">#{createTime},</if>
|
|
|
+ <if test="updateTime != null">#{updateTime},</if>
|
|
|
+ <if test="createBy != null">#{createBy},</if>
|
|
|
+ <if test="updateBy != null">#{updateBy},</if>
|
|
|
+ <if test="completeWatchDate != null">#{completeWatchDate},</if>
|
|
|
+ <if test="completeWatchCount != null">#{completeWatchCount},</if>
|
|
|
+ <if test="watchTimes != null">#{watchTimes},</if>
|
|
|
+ <if test="createDate != null">#{createDate},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <update id="updateFsUserCourseCount" parameterType="FsUserCourseCount">
|
|
|
+ update fs_user_course_count
|
|
|
+ <trim prefix="SET" suffixOverrides=",">
|
|
|
+ <if test="userId != null">user_id = #{userId},</if>
|
|
|
+ <if test="watchCourseCount != null">watch_course_count = #{watchCourseCount},</if>
|
|
|
+ <if test="missCourseCount != null">miss_course_count = #{missCourseCount},</if>
|
|
|
+ <if test="missCourseStatus != null">miss_course_status = #{missCourseStatus},</if>
|
|
|
+ <if test="missCourseDays != null">miss_course_days = #{missCourseDays},</if>
|
|
|
+ <if test="courseIds != null">course_ids = #{courseIds},</if>
|
|
|
+ <if test="partCourseCount != null">part_course_count = #{partCourseCount},</if>
|
|
|
+ <if test="lastWatchDate != null">last_watch_date = #{lastWatchDate},</if>
|
|
|
+ <if test="status != null">status = #{status},</if>
|
|
|
+ <if test="stopWatchDays != null">stop_watch_days = #{stopWatchDays},</if>
|
|
|
+ <if test="createTime != null">create_time = #{createTime},</if>
|
|
|
+ <if test="updateTime != null">update_time = #{updateTime},</if>
|
|
|
+ <if test="createBy != null">create_by = #{createBy},</if>
|
|
|
+ <if test="updateBy != null">update_by = #{updateBy},</if>
|
|
|
+ <if test="completeWatchDate != null">complete_watch_date = #{completeWatchDate},</if>
|
|
|
+ <if test="completeWatchCount != null">complete_watch_count = #{completeWatchCount},</if>
|
|
|
+ <if test="watchTimes != null">watch_times = #{watchTimes},</if>
|
|
|
+ <if test="createDate != null">create_date = #{createDate},</if>
|
|
|
+ </trim>
|
|
|
+ where id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <delete id="deleteFsUserCourseCountById" parameterType="Long">
|
|
|
+ delete from fs_user_course_count where id = #{id}
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <delete id="deleteFsUserCourseCountByIds" parameterType="String">
|
|
|
+ delete from fs_user_course_count where id in
|
|
|
+ <foreach item="id" collection="array" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <select id="getCountResult" resultType="FsUserCourseCount">
|
|
|
+ SELECT
|
|
|
+ fwl.user_id,
|
|
|
+ count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.video_id END ) AS watchCourseCount,
|
|
|
+ count( DISTINCT CASE WHEN fwl.log_type = 3 THEN fwl.video_id END ) AS missCourseCount,
|
|
|
+ IF
|
|
|
+ ( count( DISTINCT CASE WHEN fwl.log_type = 3 THEN fwl.video_id END ) > 0, 1, 2 ) AS missCourseStatus,
|
|
|
+ GROUP_CONCAT( DISTINCT fwl.period_id ) AS courseIds,
|
|
|
+ count(DISTINCT fwl.period_id ) AS partCourseCount,
|
|
|
+ a.last_heartbeat_time AS lastWatchDate,
|
|
|
+ CASE
|
|
|
+ WHEN a.log_type = 1
|
|
|
+ OR a.log_type = 2 THEN
|
|
|
+ 1
|
|
|
+ WHEN a.log_type = 4 THEN
|
|
|
+ 2
|
|
|
+ WHEN a.log_type = 3 THEN
|
|
|
+ 3
|
|
|
+ END AS STATUS,
|
|
|
+ DATEDIFF(DATE_FORMAT(NOW(),'%Y-%m-%d'),DATE_FORMAT(a.last_heartbeat_time,'%Y-%m-%d')) as stop_watch_days,
|
|
|
+ max( CASE WHEN fwl.log_type = 2 THEN fwl.last_heartbeat_time END ) AS completeWatchDate,
|
|
|
+ count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS completeWatchCount,
|
|
|
+ count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS watch_times,
|
|
|
+ NOW() AS create_time,
|
|
|
+ NOW() AS updateTime,
|
|
|
+ curdate() AS create_date
|
|
|
+ FROM
|
|
|
+ ( SELECT fs_course_watch_log.user_id, Max( fs_course_watch_log.last_heartbeat_time ) AS last_heartbeat_time, log_type FROM fs_course_watch_log GROUP BY fs_course_watch_log.user_id ) a
|
|
|
+ INNER JOIN fs_course_watch_log fwl ON fwl.user_id = a.user_id
|
|
|
+ GROUP BY
|
|
|
+ fwl.user_id
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <insert id="insertFsUserCourseCountTask" parameterType="FsUserCourseCount" useGeneratedKeys="true" keyProperty="id">
|
|
|
+ insert into fs_user_course_count
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="userId != null">user_id,</if>
|
|
|
+ <if test="watchCourseCount != null">watch_course_count,</if>
|
|
|
+ <if test="missCourseCount != null">miss_course_count,</if>
|
|
|
+ <if test="missCourseStatus != null">miss_course_status,</if>
|
|
|
+ <if test="courseIds != null">course_ids,</if>
|
|
|
+ <if test="partCourseCount != null">part_course_count,</if>
|
|
|
+ <if test="lastWatchDate != null">last_watch_date,</if>
|
|
|
+ <if test="status != null">status,</if>
|
|
|
+ <if test="createTime != null">create_time,</if>
|
|
|
+ <if test="updateTime != null">update_time,</if>
|
|
|
+ <if test="createBy != null">create_by,</if>
|
|
|
+ <if test="updateBy != null">update_by,</if>
|
|
|
+ <if test="completeWatchDate != null">complete_watch_date,</if>
|
|
|
+ <if test="completeWatchCount != null">complete_watch_count,</if>
|
|
|
+ <if test="watchTimes != null">watch_times,</if>
|
|
|
+ <if test="createDate != null">create_date,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="userId != null">#{userId},</if>
|
|
|
+ <if test="watchCourseCount != null">#{watchCourseCount},</if>
|
|
|
+ <if test="missCourseCount != null">#{missCourseCount},</if>
|
|
|
+ <if test="missCourseStatus != null">#{missCourseStatus},</if>
|
|
|
+ <if test="courseIds != null">#{courseIds},</if>
|
|
|
+ <if test="partCourseCount != null">#{partCourseCount},</if>
|
|
|
+ <if test="lastWatchDate != null">#{lastWatchDate},</if>
|
|
|
+ <if test="status != null">#{status},</if>
|
|
|
+ <if test="createTime != null">#{createTime},</if>
|
|
|
+ <if test="updateTime != null">#{updateTime},</if>
|
|
|
+ <if test="createBy != null">#{createBy},</if>
|
|
|
+ <if test="updateBy != null">#{updateBy},</if>
|
|
|
+ <if test="completeWatchDate != null">#{completeWatchDate},</if>
|
|
|
+ <if test="completeWatchCount != null">#{completeWatchCount},</if>
|
|
|
+ <if test="watchTimes != null">#{watchTimes},</if>
|
|
|
+ <if test="createDate != null">#{createDate},</if>
|
|
|
+ </trim>
|
|
|
+ on duplicate key update
|
|
|
+ <trim suffixOverrides=",">
|
|
|
+ <if test="updateTime != null">update_time = #{updateTime},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+
|
|
|
+</mapper>
|