FsCourseTrafficLogMapper.xml 15 KB

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