FsUserWatchStatisticsMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.course.mapper.FsUserWatchStatisticsMapper">
  6. <resultMap type="FsUserWatchStatistics" id="FsUserWatchStatisticsResult">
  7. <result property="id" column="id" />
  8. <result property="periodId" column="period_id" />
  9. <result property="periodName" column="period_name" />
  10. <result property="periodStartingTime" column="period_starting_time" />
  11. <result property="companyId" column="company_id" />
  12. <result property="companyName" column="company_name" />
  13. <result property="newUserNum" column="new_user_num" />
  14. <result property="userNum" column="user_num" />
  15. <result property="watchNum" column="watch_num" />
  16. <result property="completeWatchNum" column="complete_watch_num" />
  17. <result property="onlineRate" column="online_rate" />
  18. <result property="completeWatchRate" column="complete_watch_rate" />
  19. <result property="companyBelongOwner" column="company_belong_owner" />
  20. </resultMap>
  21. <sql id="selectFsUserWatchStatisticsVo">
  22. select id, period_id, period_name, period_starting_time, new_user_num, user_num, watch_num, complete_watch_num, online_rate, complete_watch_rate, company_id, company_name,company_belong_owner from fs_user_watch_statistics
  23. </sql>
  24. <select id="selectFsUserWatchStatisticsList" parameterType="FsUserWatchStatistics" resultMap="FsUserWatchStatisticsResult">
  25. <include refid="selectFsUserWatchStatisticsVo"/>
  26. <where>
  27. <if test="periodId != null "> and period_id = #{periodId}</if>
  28. <if test="periodName != null and periodName != ''"> and period_name like concat('%', #{periodName}, '%')</if>
  29. <if test="periodStartingTime != null "> and period_starting_time = #{periodStartingTime}</if>
  30. <if test="companyId != null and companyId !='' "> and company_id = #{companyId}</if>
  31. <if test="companyName != null and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
  32. <if test="newUserNum != null "> and new_user_num = #{newUserNum}</if>
  33. <if test="userNum != null "> and user_num = #{userNum}</if>
  34. <if test="watchNum != null "> and watch_num = #{watchNum}</if>
  35. <if test="completeWatchNum != null "> and complete_watch_num = #{completeWatchNum}</if>
  36. <if test="completeWatchRate != null "> and complete_watch_rate = #{completeWatchRate}</if>
  37. <if test="companyBelongOwner != null "> and company_belong_owner like concat('%', #{companyBelongOwner}, '%')</if>
  38. </where>
  39. </select>
  40. <select id="selectFsUserWatchStatisticsById" parameterType="Long" resultMap="FsUserWatchStatisticsResult">
  41. <include refid="selectFsUserWatchStatisticsVo"/>
  42. where id = #{id}
  43. </select>
  44. <insert id="insertFsUserWatchStatistics" parameterType="FsUserWatchStatistics" useGeneratedKeys="true" keyProperty="id">
  45. insert into fs_user_watch_statistics
  46. <trim prefix="(" suffix=")" suffixOverrides=",">
  47. <if test="periodId != null">period_id,</if>
  48. <if test="periodName != null">period_name,</if>
  49. <if test="periodStartingTime != null">period_starting_time,</if>
  50. <if test="companyId != null and companyId !='' ">company_id,</if>
  51. <if test="companyName != null">company_name,</if>
  52. <if test="newUserNum != null">new_user_num,</if>
  53. <if test="userNum != null">user_num,</if>
  54. <if test="watchNum != null">watch_num,</if>
  55. <if test="completeWatchNum != null">complete_watch_num,</if>
  56. <if test="onlineRate != null">online_rate,</if>
  57. <if test="completeWatchRate != null">complete_watch_rate,</if>
  58. </trim>
  59. <trim prefix="values (" suffix=")" suffixOverrides=",">
  60. <if test="periodId != null">#{periodId},</if>
  61. <if test="periodName != null">#{periodName},</if>
  62. <if test="periodStartingTime != null">#{periodStartingTime},</if>
  63. <if test="companyId != null and companyId !='' ">#{companyId},</if>
  64. <if test="companyName != null">#{companyName},</if>
  65. <if test="newUserNum != null">#{newUserNum},</if>
  66. <if test="userNum != null">#{userNum},</if>
  67. <if test="watchNum != null">#{watchNum},</if>
  68. <if test="completeWatchNum != null">#{completeWatchNum},</if>
  69. <if test="onlineRate != null">#{onlineRate},</if>
  70. <if test="completeWatchRate != null">#{completeWatchRate},</if>
  71. </trim>
  72. </insert>
  73. <update id="updateFsUserWatchStatistics" parameterType="FsUserWatchStatistics">
  74. update fs_user_watch_statistics
  75. <trim prefix="SET" suffixOverrides=",">
  76. <if test="periodId != null">period_id = #{periodId},</if>
  77. <if test="periodName != null">period_name = #{periodName},</if>
  78. <if test="periodStartingTime != null">period_starting_time = #{periodStartingTime},</if>
  79. <if test="companyId != null and companyId !='' ">company_id = #{companyId},</if>
  80. <if test="companyName != null">company_name = #{companyName},</if>
  81. <if test="newUserNum != null">new_user_num = #{newUserNum},</if>
  82. <if test="userNum != null">user_num = #{userNum},</if>
  83. <if test="watchNum != null">watch_num = #{watchNum},</if>
  84. <if test="completeWatchNum != null">complete_watch_num = #{completeWatchNum},</if>
  85. <if test="onlineRate != null">online_rate = #{onlineRate},</if>
  86. <if test="completeWatchRate != null">complete_watch_rate = #{completeWatchRate},</if>
  87. </trim>
  88. where id = #{id}
  89. </update>
  90. <delete id="deleteFsUserWatchStatisticsById" parameterType="Long">
  91. delete from fs_user_watch_statistics where id = #{id}
  92. </delete>
  93. <delete id="deleteFsUserWatchStatisticsByIds" parameterType="String">
  94. delete from fs_user_watch_statistics where id in
  95. <foreach item="id" collection="array" open="(" separator="," close=")">
  96. #{id}
  97. </foreach>
  98. </delete>
  99. <select id="getCourseWatchStatistics" resultType="FsUserWatchStatistics">
  100. SELECT
  101. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  102. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  103. ifnull(
  104. ROUND(
  105. (
  106. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END )) * 100,
  107. 2
  108. ),
  109. 0
  110. ) AS completeWatchRate,
  111. fwl.period_id,
  112. fwl.company_id
  113. FROM
  114. fs_course_watch_log fwl
  115. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
  116. WHERE
  117. fwl.send_type = 1
  118. AND fs_user_company_user.`status` = 1
  119. GROUP BY
  120. fwl.period_id, fwl.company_id
  121. </select>
  122. <insert id="insertFsUserWatchStatisticsTask" parameterType="FsUserWatchStatistics" useGeneratedKeys="true" keyProperty="id">
  123. insert into fs_user_watch_statistics
  124. <trim prefix="(" suffix=")" suffixOverrides=",">
  125. <if test="periodId != null">period_id,</if>
  126. <if test="periodName != null">period_name,</if>
  127. <if test="periodStartingTime != null">period_starting_time,</if>
  128. <if test="companyId != null and companyId !='' ">company_id,</if>
  129. <if test="companyName != null">company_name,</if>
  130. <if test="newUserNum != null">new_user_num,</if>
  131. <if test="userNum != null">user_num,</if>
  132. <if test="watchNum != null">watch_num,</if>
  133. <if test="completeWatchNum != null">complete_watch_num,</if>
  134. <if test="completeWatchRate != null">complete_watch_rate,</if>
  135. <if test="onlineRate != null">online_rate,</if>
  136. <if test="createTime != null">create_time,</if>
  137. <if test="companyBelongOwner != null">company_belong_owner,</if>
  138. </trim>
  139. <trim prefix="values (" suffix=")" suffixOverrides=",">
  140. <if test="periodId != null">#{periodId},</if>
  141. <if test="periodName != null">#{periodName},</if>
  142. <if test="periodStartingTime != null">#{periodStartingTime},</if>
  143. <if test="companyId != null and companyId !='' ">#{companyId},</if>
  144. <if test="companyName != null">#{companyName},</if>
  145. <if test="newUserNum != null">#{newUserNum},</if>
  146. <if test="userNum != null">#{userNum},</if>
  147. <if test="watchNum != null">#{watchNum},</if>
  148. <if test="completeWatchNum != null">#{completeWatchNum},</if>
  149. <if test="onlineRate != null">#{onlineRate},</if>
  150. <if test="completeWatchRate != null">#{completeWatchRate},</if>
  151. <if test="createTime != null">#{createTime},</if>
  152. <if test="companyBelongOwner != null">#{companyBelongOwner},</if>
  153. </trim>
  154. on duplicate key update
  155. <trim suffixOverrides=",">
  156. <if test="periodId != null">period_id = #{periodId},</if>
  157. <if test="periodName != null">period_name = #{periodName},</if>
  158. <if test="periodStartingTime != null">period_starting_time = #{periodStartingTime},</if>
  159. <if test="companyId != null and companyId !='' ">company_id = #{companyId},</if>
  160. <if test="companyName != null">company_name = #{companyName},</if>
  161. <if test="newUserNum != null">new_user_num = #{newUserNum},</if>
  162. <if test="userNum != null">user_num = #{userNum},</if>
  163. <if test="watchNum != null">watch_num = #{watchNum},</if>
  164. <if test="completeWatchNum != null">complete_watch_num = #{completeWatchNum},</if>
  165. <if test="onlineRate != null">online_rate = #{onlineRate},</if>
  166. <if test="completeWatchRate != null">complete_watch_rate = #{completeWatchRate},</if>
  167. <if test="updateTime != null">update_time = #{updateTime},</if>
  168. <if test="companyBelongOwner != null">company_belong_owner=#{companyBelongOwner},</if>
  169. </trim>
  170. </insert>
  171. </mapper>