| 
					
				 | 
			
			
				@@ -135,8 +135,72 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         </foreach> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     </delete> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    <insert id="insertFsUserCourseCountTask" useGeneratedKeys="true" keyProperty="id"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <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, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            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 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        </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> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        </trim> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |