QwWatchLogMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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.qw.mapper.QwWatchLogMapper">
  6. <resultMap type="QwWatchLog" id="QwWatchLogResult">
  7. <result property="id" column="id" />
  8. <result property="extId" column="ext_id" />
  9. <result property="qwUserId" column="qw_user_id" />
  10. <result property="status" column="status" />
  11. <result property="day" column="day" />
  12. <result property="project" column="project" />
  13. <result property="createTime" column="create_time" />
  14. <result property="lineTime" column="line_time" />
  15. </resultMap>
  16. <sql id="selectQwWatchLogVo">
  17. select id, ext_id, qw_user_id,line_time, status, day, project, create_time from qw_watch_log
  18. </sql>
  19. <select id="selectQwWatchLogList" parameterType="QwWatchLog" resultMap="QwWatchLogResult">
  20. <include refid="selectQwWatchLogVo"/>
  21. <where>
  22. <if test="extId != null "> and ext_id = #{extId}</if>
  23. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  24. <if test="status != null "> and status = #{status}</if>
  25. <if test="day != null "> and day = #{day}</if>
  26. <if test="project != null "> and project = #{project}</if>
  27. </where>
  28. </select>
  29. <select id="selectQwWatchLogById" parameterType="Long" resultMap="QwWatchLogResult">
  30. <include refid="selectQwWatchLogVo"/>
  31. where id = #{id}
  32. </select>
  33. <select id="selectQwWatchLogAllStatisticsListVONew"
  34. resultType="com.fs.qw.vo.QwWatchLogAllStatisticsListVO">
  35. select
  36. any_value(company_id) as company_id,
  37. company_user_id,MIN(line_time) as create_time,
  38. COUNT(CASE WHEN day = 0 and status in (1,2) THEN 1 END) AS firstOnline,
  39. COUNT(CASE WHEN day = 0 and status=2 THEN 1 END) AS firstOver,
  40. COUNT(CASE WHEN day = 1 and status in (1,2) THEN 1 END) AS d1Online,
  41. COUNT(CASE WHEN day = 1 and status=2 THEN 1 END) AS d1Over,
  42. COUNT(CASE WHEN day = 2 and status in (1,2) THEN 1 END) AS d2Online,
  43. COUNT(CASE WHEN day = 2 and status=2 THEN 1 END) AS d2Over,
  44. COUNT(CASE WHEN day = 3 and status in (1,2) THEN 1 END) AS d3Online,
  45. COUNT(CASE WHEN day = 3 and status=2 THEN 1 END) AS d3Over,
  46. COUNT(CASE WHEN day = 4 and status in (1,2) THEN 1 END) AS d4Online,
  47. COUNT(CASE WHEN day = 4 and status=2 THEN 1 END) AS d4Over,
  48. COUNT(CASE WHEN day = 5 and status in (1,2) THEN 1 END) AS d5Online,
  49. COUNT(CASE WHEN day = 5 and status=2 THEN 1 END) AS d5Over,
  50. COUNT(CASE WHEN day = 6 and status in (1,2) THEN 1 END) AS d6Online,
  51. COUNT(CASE WHEN day = 6 and status=2 THEN 1 END) AS d6Over,
  52. COUNT(CASE WHEN day = 7 and status in (1,2) THEN 1 END) AS d7Online,
  53. COUNT(CASE WHEN day = 7 and status=2 THEN 1 END) AS d7Over,
  54. COUNT(CASE WHEN day = 8 and status in (1,2) THEN 1 END) AS d8Online,
  55. COUNT(CASE WHEN day = 8 and status=2 THEN 1 END) AS d8Over,
  56. COUNT(CASE WHEN day = 9 and status in (1,2) THEN 1 END) AS d9Online,
  57. COUNT(CASE WHEN day = 9 and status=2 THEN 1 END) AS d9Over,
  58. COUNT(CASE WHEN day = 10 and status in (1,2) THEN 1 END) AS d10Online,
  59. COUNT(CASE WHEN day = 10 and status=2 THEN 1 END) AS d10Over,
  60. COUNT(CASE WHEN day = 11 and status in (1,2) THEN 1 END) AS d11Online,
  61. COUNT(CASE WHEN day = 11 and status=2 THEN 1 END) AS d11Over,
  62. COUNT(CASE WHEN day = 12 and status in (1,2) THEN 1 END) AS d12Online,
  63. COUNT(CASE WHEN day = 12 and status=2 THEN 1 END) AS d12Over,
  64. COUNT(CASE WHEN day = 13 and status in (1,2) THEN 1 END) AS d13Online,
  65. COUNT(CASE WHEN day = 13 and status=2 THEN 1 END) AS d13Over,
  66. COUNT(CASE WHEN day = 14 and status in (1,2) THEN 1 END) AS d14Online,
  67. COUNT(CASE WHEN day = 14 and status=2 THEN 1 END) AS d14Over,
  68. COUNT(CASE WHEN day = 15 and status in (1,2) THEN 1 END) AS d15Online,
  69. COUNT(CASE WHEN day = 15 and status=2 THEN 1 END) AS d15Over,
  70. COUNT(CASE WHEN day = 16 and status in (1,2) THEN 1 END) AS d16Online,
  71. COUNT(CASE WHEN day = 16 and status=2 THEN 1 END) AS d16Over,
  72. COUNT(CASE WHEN day = 17 and status in (1,2) THEN 1 END) AS d17Online,
  73. COUNT(CASE WHEN day = 17 and status=2 THEN 1 END) AS d17Over,
  74. COUNT(CASE WHEN day = 18 and status in (1,2) THEN 1 END) AS d18Online,
  75. COUNT(CASE WHEN day = 18 and status=2 THEN 1 END) AS d18Over,
  76. COUNT(CASE WHEN day = 19 and status in (1,2) THEN 1 END) AS d19Online,
  77. COUNT(CASE WHEN day = 19 and status=2 THEN 1 END) AS d19Over,
  78. COUNT(CASE WHEN day = 20 and status in (1,2) THEN 1 END) AS d20Online,
  79. COUNT(CASE WHEN day = 20 and status=2 THEN 1 END) AS d20Over,
  80. COUNT(CASE WHEN day = 21 and status in (1,2) THEN 1 END) AS d21Online,
  81. COUNT(CASE WHEN day = 21 and status=2 THEN 1 END) AS d21Over,
  82. COUNT(CASE WHEN day = 22 and status in (1,2) THEN 1 END) AS d22Online,
  83. COUNT(CASE WHEN day = 22 and status=2 THEN 1 END) AS d22Over,
  84. COUNT(CASE WHEN day = 23 and status in (1,2) THEN 1 END) AS d23Online,
  85. COUNT(CASE WHEN day = 23 and status=2 THEN 1 END) AS d23Over,
  86. COUNT(CASE WHEN day = 24 and status in (1,2) THEN 1 END) AS d24Online,
  87. COUNT(CASE WHEN day = 24 and status=2 THEN 1 END) AS d24Over,
  88. COUNT(CASE WHEN day = 25 and status in (1,2) THEN 1 END) AS d25Online,
  89. COUNT(CASE WHEN day = 25 and status=2 THEN 1 END) AS d25Over,
  90. COUNT(CASE WHEN day = 26 and status in (1,2) THEN 1 END) AS d26Online,
  91. COUNT(CASE WHEN day = 26 and status=2 THEN 1 END) AS d26Over,
  92. COUNT(CASE WHEN day = 27 and status in (1,2) THEN 1 END) AS d27Online,
  93. COUNT(CASE WHEN day = 27 and status=2 THEN 1 END) AS d27Over,
  94. COUNT(CASE WHEN day = 28 and status in (1,2) THEN 1 END) AS d28Online,
  95. COUNT(CASE WHEN day = 28 and status=2 THEN 1 END) AS d28Over,
  96. COUNT(CASE WHEN day = 29 and status in (1,2) THEN 1 END) AS d29Online,
  97. COUNT(CASE WHEN day = 29 and status=2 THEN 1 END) AS d29Over,
  98. COUNT(CASE WHEN day = 30 and status in (1,2) THEN 1 END) AS d30Online,
  99. COUNT(CASE WHEN day = 30 and status=2 THEN 1 END) AS d30Over,
  100. COUNT(1) AS line,project,course_id,video_id
  101. from hy_watch_log
  102. <where>
  103. <if test="companyUserIds != null and companyUserIds.size() != 0">
  104. and company_user_id in
  105. <foreach collection="companyUserIds" item="item" open="(" close=")" separator=",">
  106. ${item}
  107. </foreach>
  108. </if>
  109. <if test="project != null">
  110. and project = #{project}
  111. </if>
  112. <if test="courseId != null">
  113. and course_id = #{courseId}
  114. </if>
  115. <if test="videoId != null">
  116. and video_id =#{videoId}
  117. </if>
  118. and DATE(line_time) between #{sDate} AND #{eDate} group by project,course_id,video_id,company_user_id
  119. </where>
  120. </select>
  121. <select id="selectQwWatchLogAllStatisticsListVONewCount" resultType="java.lang.Long">
  122. select count(*) from(
  123. select
  124. 1
  125. from hy_watch_log
  126. <where>
  127. <if test="companyUserIds != null">
  128. and company_user_id in
  129. <foreach collection="companyUserIds" item="item" open="(" close=")" separator=",">
  130. ${item}
  131. </foreach>
  132. </if>
  133. <if test="project != null">
  134. and project = #{project}
  135. </if>
  136. <if test="courseId != null">
  137. and course_id = #{courseId}
  138. </if>
  139. <if test="videoId != null">
  140. and video_id =#{videoId}
  141. </if>
  142. and DATE(line_time) between #{sDate} AND #{eDate} group by project,course_id,video_id
  143. </where>
  144. )t
  145. </select>
  146. <select id="selectQwWatchLogByCompanyUserId" resultType="com.fs.qw.vo.QwWatchLogStatisticsListVO">
  147. select
  148. COUNT(CASE WHEN day = 0 and status in (1,2) THEN 1 END) AS firstOnline,
  149. COUNT(CASE WHEN day = 0 and status=2 THEN 1 END) AS firstOver,
  150. COUNT(CASE WHEN day = 1 and status in (1,2) THEN 1 END) AS d1Online,
  151. COUNT(CASE WHEN day = 1 and status=2 THEN 1 END) AS d1Over,
  152. COUNT(1) AS line,project,course_id,video_id,company_id,company_user_id
  153. from hy_watch_log
  154. <where>
  155. <if test="companyUserIds != null and companyUserIds.size() != 0">
  156. and company_user_id in
  157. <foreach collection="companyUserIds" item="item" open="(" close=")" separator=",">
  158. ${item}
  159. </foreach>
  160. </if>
  161. <if test="project != null">
  162. and project=#{project}
  163. </if>
  164. <if test="courseId != null">
  165. and course_id=#{courseId}
  166. </if>
  167. <if test="videoId != null">
  168. and video_id=#{videoId}
  169. </if>
  170. and DATE(line_time) between #{sTime} and #{dTime}
  171. </where>
  172. group by project,course_id,video_id
  173. limit ${(pageNum-1)*pageSize},${pageSize}
  174. </select>
  175. <select id="selectQwWatchLogByCompanyUserIdCount" resultType="java.lang.Long">
  176. SELECT COUNT(*)
  177. FROM (
  178. SELECT 1
  179. FROM hy_watch_log
  180. <where>
  181. <if test="companyUserIds != null and companyUserIds.size() != 0">
  182. and company_user_id in
  183. <foreach collection="companyUserIds" item="item" open="(" close=")" separator=",">
  184. #{item}
  185. </foreach>
  186. </if>
  187. <if test="project != null">
  188. and project=#{project}
  189. </if>
  190. <if test="courseId != null">
  191. and course_id=#{courseId}
  192. </if>
  193. <if test="videoId != null">
  194. and video_id=#{videoId}
  195. </if>
  196. and DATE(line_time) between #{sTime} and #{dTime}
  197. </where>
  198. GROUP BY project, course_id, video_id,company_user_id
  199. ) AS count_temp_table
  200. </select>
  201. <select id="selectQwExtCountByDayAndCount" resultType="java.lang.Long">
  202. SELECT COUNT(*) AS total_count
  203. FROM (
  204. SELECT 1
  205. FROM
  206. qw_external_contact qec
  207. JOIN
  208. qw_user qu ON qec.qw_user_id = qu.id
  209. WHERE
  210. DATE(qec.create_time) &gt;= DATE(#{sTime})
  211. AND DATE(qec.create_time) &lt;= DATE(#{eTime})
  212. AND qec.company_id = #{companyId}
  213. <if test='nickName != null and nickName != ""'>
  214. AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
  215. </if>
  216. <if test='idsList != null and !idsList.isEmpty()'>
  217. AND qec.qw_user_id IN
  218. <foreach item="item" index="index" collection="idsList" open="(" separator="," close=")">
  219. #{item}
  220. </foreach>
  221. </if>
  222. GROUP BY
  223. qec.qw_user_id, DATE(qec.create_time)
  224. ) AS grouped_data
  225. </select>
  226. <insert id="insertQwWatchLog" parameterType="QwWatchLog" useGeneratedKeys="true" keyProperty="id">
  227. insert into qw_watch_log
  228. <trim prefix="(" suffix=")" suffixOverrides=",">
  229. <if test="extId != null">ext_id,</if>
  230. <if test="qwUserId != null">qw_user_id,</if>
  231. <if test="status != null">status,</if>
  232. <if test="day != null">day,</if>
  233. <if test="project != null">project,</if>
  234. <if test="createTime != null">create_time,</if>
  235. <if test="lineTime != null">line_time,</if>
  236. </trim>
  237. <trim prefix="values (" suffix=")" suffixOverrides=",">
  238. <if test="extId != null">#{extId},</if>
  239. <if test="qwUserId != null">#{qwUserId},</if>
  240. <if test="status != null">#{status},</if>
  241. <if test="day != null">#{day},</if>
  242. <if test="project != null">#{project},</if>
  243. <if test="createTime != null">#{createTime},</if>
  244. <if test="lineTime != null">#{lineTime},</if>
  245. </trim>
  246. </insert>
  247. <insert id="insertQwWatchLogBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
  248. INSERT INTO qw_watch_log (
  249. ext_id,
  250. qw_user_id,
  251. status,
  252. day,
  253. project,
  254. create_time,
  255. line_time
  256. )
  257. VALUES
  258. <foreach collection="watchLogs" item="log" separator=",">
  259. (
  260. #{log.extId},
  261. #{log.qwUserId},
  262. #{log.status},
  263. #{log.day},
  264. #{log.project},
  265. #{log.createTime},
  266. #{log.lineTime}
  267. )
  268. </foreach>
  269. </insert>
  270. <update id="updateQwWatchLog" parameterType="QwWatchLog">
  271. update qw_watch_log
  272. <trim prefix="SET" suffixOverrides=",">
  273. <if test="extId != null">ext_id = #{extId},</if>
  274. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  275. <if test="status != null">status = #{status},</if>
  276. <if test="day != null">day = #{day},</if>
  277. <if test="project != null">project = #{project},</if>
  278. <if test="createTime != null">create_time = #{createTime},</if>
  279. <if test="lineTime != null">line_time = #{lineTime},</if>
  280. </trim>
  281. where id = #{id}
  282. </update>
  283. <delete id="deleteQwWatchLogById" parameterType="Long">
  284. delete from qw_watch_log where id = #{id}
  285. </delete>
  286. <delete id="deleteQwWatchLogByIds" parameterType="String">
  287. delete from qw_watch_log where id in
  288. <foreach item="id" collection="array" open="(" separator="," close=")">
  289. #{id}
  290. </foreach>
  291. </delete>
  292. </mapper>