FsCourseTrafficLogMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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.FsCourseTrafficLogMapper">
  6. <resultMap type="FsCourseTrafficLog" id="FsCourseTrafficLogResult">
  7. <result property="logId" column="log_id" />
  8. <result property="userId" column="user_id" />
  9. <result property="videoId" column="video_id" />
  10. <result property="createTime" column="create_time" />
  11. <result property="qwExternalContactId" column="qw_external_contact_id" />
  12. <result property="internetTraffic" column="internet_traffic" />
  13. <result property="qwUserId" column="qw_user_id" />
  14. <result property="companyUserId" column="company_user_id" />
  15. <result property="companyId" column="company_id" />
  16. <result property="courseId" column="course_id" />
  17. <result property="uuId" column="uu_id" />
  18. <result property="periodId" column="period_id" />
  19. <result property="project" column="project" />
  20. </resultMap>
  21. <sql id="selectFsCourseTrafficLogVo">
  22. select log_id,
  23. user_id,
  24. video_id,
  25. create_time,
  26. qw_external_contact_id,
  27. internet_traffic,
  28. qw_user_id,
  29. company_user_id,
  30. company_id,
  31. course_id,
  32. uu_id,
  33. project,
  34. period_id from fs_course_traffic_log
  35. </sql>
  36. <select id="selectFsCourseTrafficLogList" parameterType="FsCourseTrafficLog" resultMap="FsCourseTrafficLogResult">
  37. <include refid="selectFsCourseTrafficLogVo"/>
  38. <where>
  39. <if test="userId != null "> and user_id = #{userId}</if>
  40. <if test="videoId != null "> and video_id = #{videoId}</if>
  41. <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
  42. <if test="internetTraffic != null "> and internet_traffic = #{internetTraffic}</if>
  43. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  44. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  45. <if test="companyId != null "> and company_id = #{companyId}</if>
  46. <if test="courseId != null "> and course_id = #{courseId}</if>
  47. </where>
  48. </select>
  49. <select id="selectFsCourseTrafficLogByLogId" parameterType="Long" resultMap="FsCourseTrafficLogResult">
  50. <include refid="selectFsCourseTrafficLogVo"/>
  51. where log_id = #{logId}
  52. </select>
  53. <select id="getTodayTrafficLogCompanyId" resultType="java.lang.Long">
  54. SELECT
  55. COALESCE(SUM(internet_traffic), 0) AS today_traffic_bytes
  56. FROM
  57. fs_course_traffic_log
  58. <where>
  59. <!-- DATE(create_time) = CURDATE() -->
  60. create_time >= CURDATE()
  61. AND create_time &lt; CURDATE() + INTERVAL 1 DAY
  62. <if test="companyId != null">
  63. AND company_id = ${companyId}
  64. </if>
  65. </where>
  66. </select>
  67. <select id="getYesterdayTrafficLogCompanyId" resultType="java.lang.Long">
  68. SELECT
  69. COALESCE(SUM(internet_traffic), 0) AS yesterday_traffic_bytes
  70. FROM
  71. fs_course_traffic_log
  72. <where>
  73. create_time &gt;= CURDATE() - INTERVAL 1 DAY
  74. AND create_time &lt; CURDATE()
  75. <if test="companyId != null">
  76. AND company_id = ${companyId}
  77. </if>
  78. </where>
  79. </select>
  80. <select id="getMonthTrafficLogCompanyId" resultType="java.lang.Long">
  81. SELECT
  82. COALESCE(SUM(internet_traffic), 0) AS month_traffic_bytes
  83. FROM
  84. fs_course_traffic_log
  85. <where>
  86. <!-- YEAR(create_time) = YEAR(CURDATE()) -->
  87. <!-- AND MONTH(create_time) = MONTH(CURDATE()) -->
  88. create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
  89. AND create_time &lt; DATE_FORMAT(CURDATE() + INTERVAL 1 MONTH, '%Y-%m-01')
  90. <if test="companyId != null">
  91. AND company_id = ${companyId}
  92. </if>
  93. </where>
  94. </select>
  95. <select id="getTodayTrafficLog" resultType="java.lang.Long">
  96. SELECT
  97. COALESCE(SUM(internet_traffic), 0) AS today_traffic_bytes
  98. FROM
  99. fs_course_traffic_log
  100. WHERE
  101. DATE(create_time) = CURDATE()
  102. </select>
  103. <select id="getYesterdayTrafficLog" resultType="java.lang.Long">
  104. SELECT
  105. COALESCE(SUM(internet_traffic), 0) AS yesterday_traffic_bytes
  106. FROM
  107. fs_course_traffic_log
  108. WHERE
  109. DATE(create_time) = CURDATE() - INTERVAL 1 DAY
  110. </select>
  111. <select id="getMonthTrafficLog" resultType="java.lang.Long">
  112. SELECT
  113. COALESCE(SUM(internet_traffic), 0) AS month_traffic_bytes
  114. FROM
  115. fs_course_traffic_log
  116. WHERE
  117. <!-- YEAR(create_time) = YEAR(CURDATE()) -->
  118. <!-- AND MONTH(create_time) = MONTH(CURDATE()) -->
  119. create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
  120. AND create_time &lt; DATE_FORMAT(CURDATE() + INTERVAL 1 MONTH, '%Y-%m-01')
  121. </select>
  122. <insert id="insertFsCourseTrafficLog" parameterType="FsCourseTrafficLog" useGeneratedKeys="true" keyProperty="logId">
  123. insert into fs_course_traffic_log
  124. <trim prefix="(" suffix=")" suffixOverrides=",">
  125. <if test="userId != null">user_id,</if>
  126. <if test="videoId != null">video_id,</if>
  127. <if test="createTime != null">create_time,</if>
  128. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  129. <if test="internetTraffic != null">internet_traffic,</if>
  130. <if test="qwUserId != null">qw_user_id,</if>
  131. <if test="companyUserId != null">company_user_id,</if>
  132. <if test="companyId != null">company_id,</if>
  133. <if test="courseId != null">course_id,</if>
  134. <if test="uuId != null">uu_id,</if>
  135. </trim>
  136. <trim prefix="values (" suffix=")" suffixOverrides=",">
  137. <if test="userId != null">#{userId},</if>
  138. <if test="videoId != null">#{videoId},</if>
  139. <if test="createTime != null">#{createTime},</if>
  140. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  141. <if test="internetTraffic != null">#{internetTraffic},</if>
  142. <if test="qwUserId != null">#{qwUserId},</if>
  143. <if test="companyUserId != null">#{companyUserId},</if>
  144. <if test="companyId != null">#{companyId},</if>
  145. <if test="courseId != null">#{courseId},</if>
  146. <if test="uuId != null">#{uuId},</if>
  147. </trim>
  148. </insert>
  149. <insert id="insertOrUpdateTrafficLog" parameterType="FsCourseTrafficLog" useGeneratedKeys="true" keyProperty="logId">
  150. insert into fs_course_traffic_log
  151. <trim prefix="(" suffix=")" suffixOverrides=",">
  152. <if test="userId != null">user_id,</if>
  153. <if test="videoId != null">video_id,</if>
  154. <if test="createTime != null">create_time,</if>
  155. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  156. <if test="internetTraffic != null">internet_traffic,</if>
  157. <if test="qwUserId != null">qw_user_id,</if>
  158. <if test="companyUserId != null">company_user_id,</if>
  159. <if test="companyId != null">company_id,</if>
  160. <if test="courseId != null">course_id,</if>
  161. <if test="uuId != null">uu_id,</if>
  162. <if test="project != null">project,</if>
  163. </trim>
  164. <trim prefix="values (" suffix=")" suffixOverrides=",">
  165. <if test="userId != null">#{userId},</if>
  166. <if test="videoId != null">#{videoId},</if>
  167. <if test="createTime != null">#{createTime},</if>
  168. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  169. <if test="internetTraffic != null">#{internetTraffic},</if>
  170. <if test="qwUserId != null">#{qwUserId},</if>
  171. <if test="companyUserId != null">#{companyUserId},</if>
  172. <if test="companyId != null">#{companyId},</if>
  173. <if test="courseId != null">#{courseId},</if>
  174. <if test="uuId != null">#{uuId},</if>
  175. <if test="project != null">#{project},</if>
  176. </trim>
  177. on duplicate key update
  178. <trim suffixOverrides=",">
  179. <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
  180. </trim>
  181. </insert>
  182. <update id="updateFsCourseTrafficLog" parameterType="FsCourseTrafficLog">
  183. update fs_course_traffic_log
  184. <trim prefix="SET" suffixOverrides=",">
  185. <if test="userId != null">user_id = #{userId},</if>
  186. <if test="videoId != null">video_id = #{videoId},</if>
  187. <if test="createTime != null">create_time = #{createTime},</if>
  188. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  189. <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
  190. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  191. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  192. <if test="companyId != null">company_id = #{companyId},</if>
  193. <if test="courseId != null">course_id = #{courseId},</if>
  194. <if test="uuId != null">uu_id = #{uuId},</if>
  195. </trim>
  196. where log_id = #{logId}
  197. </update>
  198. <delete id="deleteFsCourseTrafficLogByLogId" parameterType="Long">
  199. delete from fs_course_traffic_log where log_id = #{logId}
  200. </delete>
  201. <delete id="deleteFsCourseTrafficLogByLogIds" parameterType="String">
  202. delete from fs_course_traffic_log where log_id in
  203. <foreach item="logId" collection="array" open="(" separator="," close=")">
  204. #{logId}
  205. </foreach>
  206. </delete>
  207. <select id="selectCourseTrafficLogByTwoDaysLater" resultMap="FsCourseTrafficLogResult">
  208. <![CDATA[
  209. SELECT
  210. l.log_id,
  211. l.user_id,
  212. l.video_id,
  213. l.create_time,
  214. l.qw_external_contact_id,
  215. l.internet_traffic,
  216. l.qw_user_id,
  217. l.company_user_id,
  218. l.company_id,
  219. l.course_id,
  220. l.uu_id,
  221. l.project, l.period_id
  222. FROM
  223. fs_course_traffic_log l
  224. WHERE
  225. l.create_time < DATE_SUB( NOW( ), INTERVAL 2 DAY )
  226. ORDER BY l.log_id limit #{offset},#{limit} ]]>
  227. </select>
  228. <insert id="insertCourseTrafficLogByTwoDaysLaterBatch" useGeneratedKeys="false">
  229. insert into fs_course_traffic_log (
  230. log_id, user_id, video_id, create_time, qw_external_contact_id, internet_traffic, qw_user_id, company_user_id, company_id, course_id, uu_id, project, period_id ) values
  231. <foreach collection="list" item="item" separator=",">
  232. (#{item.logId},#{item.userId},#{item.videoId},#{item.createTime},#{item.qwExternalContactId},#{item.internetTraffic},#{item.qwUserId}
  233. ,#{item.companyUserId},#{item.companyId},#{item.courseId},#{item.uuId},#{item.project},#{item.periodId})
  234. </foreach>
  235. </insert>
  236. <select id="selectTrafficNew" resultType="com.fs.course.vo.FsCourseTrafficLogListVO">
  237. select company_id,project,course_id,SUM(internet_traffic) AS total_internet_traffic
  238. ,DATE_FORMAT(create_time, '%Y-%m-%d') AS `month` from fs_course_traffic_log
  239. <where>
  240. <if test="startDate != null and endDate != null">
  241. and DATE_FORMAT(create_time, '%Y-%m-%d') between #{startDate} AND #{endDate}
  242. </if>
  243. <if test="companyId !=null">
  244. and company_id = #{companyId}
  245. </if>
  246. <if test="courseId != null">
  247. and course_id = ${courseId}
  248. </if>
  249. <if test="project != null">
  250. and project = ${project}
  251. </if>
  252. <if test="common == null">
  253. AND company_id IS not NULL
  254. </if>
  255. <if test="common != null ">
  256. AND company_id IS NULL
  257. </if>
  258. </where>
  259. <if test="tabType==null or tabType==''">
  260. group by company_id,`month`,course_id,project
  261. </if>
  262. <if test="tabType!=null and tabType=='project'">
  263. group by project,`month`
  264. </if>
  265. <if test="tabType!=null and tabType=='course'">
  266. group by course_id,`month`
  267. </if>
  268. <if test="tabType!=null and tabType=='company'">
  269. group by company_id,`month`
  270. </if>
  271. <if test="tabType!=null and tabType=='common'">
  272. group by course_id,`month`
  273. </if>
  274. <!-- <choose>-->
  275. <!-- &lt;!&ndash; 按公司+日期分组 &ndash;&gt;-->
  276. <!-- <when test="tabType == 'company'">-->
  277. <!-- GROUP BY company_id, `month`-->
  278. <!-- </when>-->
  279. <!-- &lt;!&ndash; 按项目+日期分组 &ndash;&gt;-->
  280. <!-- <when test="tabType == 'project'">-->
  281. <!-- GROUP BY project, `month`-->
  282. <!-- </when>-->
  283. <!-- &lt;!&ndash; 按课程+日期分组 &ndash;&gt;-->
  284. <!-- <when test="tabType == 'course'">-->
  285. <!-- GROUP BY course_id, `month`-->
  286. <!-- </when>-->
  287. <!-- &lt;!&ndash; common模式:按课程+日期分组 &ndash;&gt;-->
  288. <!-- <when test="tabType == 'common'">-->
  289. <!-- GROUP BY course_id, `month`-->
  290. <!-- </when>-->
  291. <!-- &lt;!&ndash; 默认:所有维度都分组 &ndash;&gt;-->
  292. <!-- <otherwise>-->
  293. <!-- GROUP BY company_id, project, course_id, `month`-->
  294. <!-- </otherwise>-->
  295. <!-- </choose>-->
  296. </select>
  297. <select id="selectTrafficByCompany" parameterType="com.fs.course.param.FsCourseTrafficLogParam"
  298. resultType="com.fs.course.vo.FsCourseTrafficLogListVO">
  299. SELECT
  300. c.company_name AS companyName,
  301. l.company_id AS companyId,
  302. '' AS courseName,
  303. 0 AS courseId,
  304. '' AS projectName,
  305. 0 AS project,
  306. SUM(l.internet_traffic) AS totalInternetTraffic,
  307. DATE_FORMAT(l.create_time, '%Y-%m') AS month
  308. FROM fs_course_traffic_log l
  309. LEFT JOIN company c ON c.company_id = l.company_id
  310. <where>
  311. <if test="startDate != null and startDate != ''">
  312. AND l.create_time >= STR_TO_DATE(#{startDate}, '%Y-%m-%d %H:%i:%s')
  313. </if>
  314. <if test="endDate != null and endDate != ''">
  315. AND l.create_time &lt;= STR_TO_DATE(#{endDate}, '%Y-%m-%d %H:%i:%s')
  316. </if>
  317. <if test="companyId != null">
  318. AND l.company_id = #{companyId}
  319. </if>
  320. <if test="common == null">
  321. AND l.company_id IS NOT NULL
  322. </if>
  323. <if test="common != null">
  324. AND l.company_id IS NULL
  325. </if>
  326. </where>
  327. GROUP BY l.company_id, DATE_FORMAT(l.create_time, '%Y-%m')
  328. </select>
  329. <select id="selectExpireLinkIds" resultType="java.lang.Long">
  330. <![CDATA[
  331. SELECT log_id
  332. FROM fs_course_traffic_log
  333. WHERE create_time < #{createTime}
  334. ORDER BY log_id ASC
  335. LIMIT #{limit} OFFSET #{offset}
  336. ]]>
  337. </select>
  338. <delete id="batchDeleteByIds">
  339. DELETE FROM fs_course_traffic_log
  340. WHERE log_id IN
  341. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  342. #{id}
  343. </foreach>
  344. </delete>
  345. <select id="countExpireLink" resultType="java.lang.Long">
  346. <![CDATA[
  347. SELECT COUNT(*)
  348. FROM fs_course_traffic_log
  349. WHERE create_time < #{createTime}
  350. ]]>
  351. </select>
  352. </mapper>