FsCourseTrafficLogMapper.xml 17 KB

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