FsCourseTrafficLogMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. <if test="project != null">project,</if>
  136. </trim>
  137. <trim prefix="values (" suffix=")" suffixOverrides=",">
  138. <if test="userId != null">#{userId},</if>
  139. <if test="videoId != null">#{videoId},</if>
  140. <if test="createTime != null">#{createTime},</if>
  141. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  142. <if test="internetTraffic != null">#{internetTraffic},</if>
  143. <if test="qwUserId != null">#{qwUserId},</if>
  144. <if test="companyUserId != null">#{companyUserId},</if>
  145. <if test="companyId != null">#{companyId},</if>
  146. <if test="courseId != null">#{courseId},</if>
  147. <if test="uuId != null">#{uuId},</if>
  148. <if test="project != null">#{project},</if>
  149. </trim>
  150. </insert>
  151. <insert id="insertOrUpdateTrafficLog" parameterType="FsCourseTrafficLog" useGeneratedKeys="true" keyProperty="logId">
  152. insert into fs_course_traffic_log
  153. <trim prefix="(" suffix=")" suffixOverrides=",">
  154. <if test="userId != null">user_id,</if>
  155. <if test="videoId != null">video_id,</if>
  156. <if test="createTime != null">create_time,</if>
  157. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  158. <if test="internetTraffic != null">internet_traffic,</if>
  159. <if test="qwUserId != null">qw_user_id,</if>
  160. <if test="companyUserId != null">company_user_id,</if>
  161. <if test="companyId != null">company_id,</if>
  162. <if test="courseId != null">course_id,</if>
  163. <if test="uuId != null">uu_id,</if>
  164. <if test="project != null">project,</if>
  165. </trim>
  166. <trim prefix="values (" suffix=")" suffixOverrides=",">
  167. <if test="userId != null">#{userId},</if>
  168. <if test="videoId != null">#{videoId},</if>
  169. <if test="createTime != null">#{createTime},</if>
  170. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  171. <if test="internetTraffic != null">#{internetTraffic},</if>
  172. <if test="qwUserId != null">#{qwUserId},</if>
  173. <if test="companyUserId != null">#{companyUserId},</if>
  174. <if test="companyId != null">#{companyId},</if>
  175. <if test="courseId != null">#{courseId},</if>
  176. <if test="uuId != null">#{uuId},</if>
  177. <if test="project != null">#{project},</if>
  178. </trim>
  179. on duplicate key update
  180. <trim suffixOverrides=",">
  181. <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
  182. </trim>
  183. </insert>
  184. <update id="updateFsCourseTrafficLog" parameterType="FsCourseTrafficLog">
  185. update fs_course_traffic_log
  186. <trim prefix="SET" suffixOverrides=",">
  187. <if test="userId != null">user_id = #{userId},</if>
  188. <if test="videoId != null">video_id = #{videoId},</if>
  189. <if test="createTime != null">create_time = #{createTime},</if>
  190. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  191. <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
  192. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  193. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  194. <if test="companyId != null">company_id = #{companyId},</if>
  195. <if test="courseId != null">course_id = #{courseId},</if>
  196. <if test="uuId != null">uu_id = #{uuId},</if>
  197. </trim>
  198. where log_id = #{logId}
  199. </update>
  200. <delete id="deleteFsCourseTrafficLogByLogId" parameterType="Long">
  201. delete from fs_course_traffic_log where log_id = #{logId}
  202. </delete>
  203. <delete id="deleteFsCourseTrafficLogByLogIds" parameterType="String">
  204. delete from fs_course_traffic_log where log_id in
  205. <foreach item="logId" collection="array" open="(" separator="," close=")">
  206. #{logId}
  207. </foreach>
  208. </delete>
  209. <select id="selectCourseTrafficLogByTwoDaysLater" resultMap="FsCourseTrafficLogResult">
  210. <![CDATA[
  211. SELECT
  212. l.log_id,
  213. l.user_id,
  214. l.video_id,
  215. l.create_time,
  216. l.qw_external_contact_id,
  217. l.internet_traffic,
  218. l.qw_user_id,
  219. l.company_user_id,
  220. l.company_id,
  221. l.course_id,
  222. l.uu_id,
  223. l.project, l.period_id
  224. FROM
  225. fs_course_traffic_log l
  226. WHERE
  227. l.create_time < DATE_SUB( NOW( ), INTERVAL 2 DAY )
  228. ORDER BY l.log_id limit #{offset},#{limit} ]]>
  229. </select>
  230. <insert id="insertCourseTrafficLogByTwoDaysLaterBatch" useGeneratedKeys="false">
  231. insert into fs_course_traffic_log (
  232. 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
  233. <foreach collection="list" item="item" separator=",">
  234. (#{item.logId},#{item.userId},#{item.videoId},#{item.createTime},#{item.qwExternalContactId},#{item.internetTraffic},#{item.qwUserId}
  235. ,#{item.companyUserId},#{item.companyId},#{item.courseId},#{item.uuId},#{item.project},#{item.periodId})
  236. </foreach>
  237. </insert>
  238. <select id="selectTrafficNew" resultType="com.fs.course.vo.FsCourseTrafficLogListVO">
  239. select a.company_id,
  240. <if test="tabType!=null and tabType=='project'">
  241. b.project,
  242. </if>
  243. a.course_id,SUM(a.internet_traffic) AS total_internet_traffic
  244. ,DATE_FORMAT(a.create_time, '%Y-%m-%d') AS `month` from fs_course_traffic_log a
  245. <if test="tabType!=null and tabType=='project'">
  246. left join fs_user_course b on a.course_id = b.course_id
  247. </if>
  248. <where>
  249. <if test="startDate != null and endDate != null">
  250. and DATE_FORMAT(a.create_time, '%Y-%m-%d') between #{startDate} AND #{endDate}
  251. </if>
  252. <if test="companyId !=null">
  253. and a.company_id = #{companyId}
  254. </if>
  255. <if test="courseId != null">
  256. and a.course_id = ${courseId}
  257. </if>
  258. <if test="project != null">
  259. and b.project = ${project}
  260. </if>
  261. <if test="common == null">
  262. AND a.company_id IS not NULL
  263. </if>
  264. <if test="common != null ">
  265. AND a.company_id IS NULL
  266. </if>
  267. </where>
  268. <if test="tabType==null or tabType==''">
  269. group by company_id,`month`,course_id,project
  270. </if>
  271. <if test="tabType!=null and tabType=='project'">
  272. group by b.project,`month`
  273. </if>
  274. <if test="tabType!=null and tabType=='course'">
  275. group by course_id,`month`
  276. </if>
  277. <if test="tabType!=null and tabType=='company'">
  278. group by company_id,`month`
  279. </if>
  280. <if test="tabType!=null and tabType=='common'">
  281. group by course_id,`month`
  282. </if>
  283. </select>
  284. <select id="selectTrafficByCompany" parameterType="com.fs.course.param.FsCourseTrafficLogParam"
  285. resultType="com.fs.course.vo.FsCourseTrafficLogListVO">
  286. SELECT
  287. c.company_name AS companyName,
  288. l.company_id AS companyId,
  289. '' AS courseName,
  290. 0 AS courseId,
  291. '' AS projectName,
  292. 0 AS project,
  293. SUM(l.internet_traffic) AS totalInternetTraffic,
  294. DATE_FORMAT(l.create_time, '%Y-%m') AS month
  295. FROM fs_course_traffic_log l
  296. LEFT JOIN company c ON c.company_id = l.company_id
  297. <where>
  298. <if test="startDate != null and startDate != ''">
  299. AND l.create_time >= STR_TO_DATE(#{startDate}, '%Y-%m-%d %H:%i:%s')
  300. </if>
  301. <if test="endDate != null and endDate != ''">
  302. AND l.create_time &lt;= STR_TO_DATE(#{endDate}, '%Y-%m-%d %H:%i:%s')
  303. </if>
  304. <if test="companyId != null">
  305. AND l.company_id = #{companyId}
  306. </if>
  307. <if test="common == null">
  308. AND l.company_id IS NOT NULL
  309. </if>
  310. <if test="common != null">
  311. AND l.company_id IS NULL
  312. </if>
  313. </where>
  314. GROUP BY l.company_id, DATE_FORMAT(l.create_time, '%Y-%m')
  315. </select>
  316. <select id="selectExpireLinkIds" resultType="java.lang.Long">
  317. <![CDATA[
  318. SELECT log_id
  319. FROM fs_course_traffic_log
  320. WHERE create_time < #{createTime}
  321. ORDER BY log_id ASC
  322. LIMIT #{limit} OFFSET #{offset}
  323. ]]>
  324. </select>
  325. <delete id="batchDeleteByIds">
  326. DELETE FROM fs_course_traffic_log
  327. WHERE log_id IN
  328. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  329. #{id}
  330. </foreach>
  331. </delete>
  332. <select id="countExpireLink" resultType="java.lang.Long">
  333. <![CDATA[
  334. SELECT COUNT(*)
  335. FROM fs_course_traffic_log
  336. WHERE create_time < #{createTime}
  337. ]]>
  338. </select>
  339. </mapper>