FsCourseTrafficLogMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. <if test="companyId != null">
  61. AND company_id = ${companyId}
  62. </if>
  63. </where>
  64. </select>
  65. <select id="getYesterdayTrafficLogCompanyId" resultType="java.lang.Long">
  66. SELECT
  67. COALESCE(SUM(internet_traffic), 0) AS yesterday_traffic_bytes
  68. FROM
  69. fs_course_traffic_log
  70. <where>
  71. DATE(create_time) = CURDATE() - INTERVAL 1 DAY
  72. <if test="companyId != null">
  73. AND company_id = ${companyId}
  74. </if>
  75. </where>
  76. </select>
  77. <select id="getMonthTrafficLogCompanyId" resultType="java.lang.Long">
  78. SELECT
  79. COALESCE(SUM(internet_traffic), 0) AS month_traffic_bytes
  80. FROM
  81. fs_course_traffic_log
  82. <where>
  83. YEAR(create_time) = YEAR(CURDATE())
  84. AND MONTH(create_time) = MONTH(CURDATE())
  85. <if test="companyId != null">
  86. AND company_id = ${companyId}
  87. </if>
  88. </where>
  89. </select>
  90. <select id="getTodayTrafficLog" resultType="java.lang.Long">
  91. SELECT
  92. COALESCE(SUM(internet_traffic), 0) AS today_traffic_bytes
  93. FROM
  94. fs_course_traffic_log
  95. WHERE
  96. DATE(create_time) = CURDATE()
  97. </select>
  98. <select id="getYesterdayTrafficLog" resultType="java.lang.Long">
  99. SELECT
  100. COALESCE(SUM(internet_traffic), 0) AS yesterday_traffic_bytes
  101. FROM
  102. fs_course_traffic_log
  103. WHERE
  104. DATE(create_time) = CURDATE() - INTERVAL 1 DAY
  105. </select>
  106. <select id="getMonthTrafficLog" resultType="java.lang.Long">
  107. SELECT
  108. COALESCE(SUM(internet_traffic), 0) AS month_traffic_bytes
  109. FROM
  110. fs_course_traffic_log
  111. WHERE
  112. YEAR(create_time) = YEAR(CURDATE())
  113. AND MONTH(create_time) = MONTH(CURDATE())
  114. </select>
  115. <insert id="insertFsCourseTrafficLog" parameterType="FsCourseTrafficLog" useGeneratedKeys="true" keyProperty="logId">
  116. insert into fs_course_traffic_log
  117. <trim prefix="(" suffix=")" suffixOverrides=",">
  118. <if test="userId != null">user_id,</if>
  119. <if test="videoId != null">video_id,</if>
  120. <if test="createTime != null">create_time,</if>
  121. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  122. <if test="internetTraffic != null">internet_traffic,</if>
  123. <if test="qwUserId != null">qw_user_id,</if>
  124. <if test="companyUserId != null">company_user_id,</if>
  125. <if test="companyId != null">company_id,</if>
  126. <if test="courseId != null">course_id,</if>
  127. <if test="uuId != null">uu_id,</if>
  128. </trim>
  129. <trim prefix="values (" suffix=")" suffixOverrides=",">
  130. <if test="userId != null">#{userId},</if>
  131. <if test="videoId != null">#{videoId},</if>
  132. <if test="createTime != null">#{createTime},</if>
  133. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  134. <if test="internetTraffic != null">#{internetTraffic},</if>
  135. <if test="qwUserId != null">#{qwUserId},</if>
  136. <if test="companyUserId != null">#{companyUserId},</if>
  137. <if test="companyId != null">#{companyId},</if>
  138. <if test="courseId != null">#{courseId},</if>
  139. <if test="uuId != null">#{uuId},</if>
  140. </trim>
  141. </insert>
  142. <insert id="insertOrUpdateTrafficLog" parameterType="FsCourseTrafficLog" useGeneratedKeys="true" keyProperty="logId">
  143. insert into fs_course_traffic_log
  144. <trim prefix="(" suffix=")" suffixOverrides=",">
  145. <if test="userId != null">user_id,</if>
  146. <if test="videoId != null">video_id,</if>
  147. <if test="createTime != null">create_time,</if>
  148. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  149. <if test="internetTraffic != null">internet_traffic,</if>
  150. <if test="qwUserId != null">qw_user_id,</if>
  151. <if test="companyUserId != null">company_user_id,</if>
  152. <if test="companyId != null">company_id,</if>
  153. <if test="courseId != null">course_id,</if>
  154. <if test="uuId != null">uu_id,</if>
  155. </trim>
  156. <trim prefix="values (" suffix=")" suffixOverrides=",">
  157. <if test="userId != null">#{userId},</if>
  158. <if test="videoId != null">#{videoId},</if>
  159. <if test="createTime != null">#{createTime},</if>
  160. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  161. <if test="internetTraffic != null">#{internetTraffic},</if>
  162. <if test="qwUserId != null">#{qwUserId},</if>
  163. <if test="companyUserId != null">#{companyUserId},</if>
  164. <if test="companyId != null">#{companyId},</if>
  165. <if test="courseId != null">#{courseId},</if>
  166. <if test="uuId != null">#{uuId},</if>
  167. </trim>
  168. on duplicate key update
  169. <trim suffixOverrides=",">
  170. <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
  171. </trim>
  172. </insert>
  173. <update id="updateFsCourseTrafficLog" parameterType="FsCourseTrafficLog">
  174. update fs_course_traffic_log
  175. <trim prefix="SET" suffixOverrides=",">
  176. <if test="userId != null">user_id = #{userId},</if>
  177. <if test="videoId != null">video_id = #{videoId},</if>
  178. <if test="createTime != null">create_time = #{createTime},</if>
  179. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  180. <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
  181. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  182. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  183. <if test="companyId != null">company_id = #{companyId},</if>
  184. <if test="courseId != null">course_id = #{courseId},</if>
  185. <if test="uuId != null">uu_id = #{uuId},</if>
  186. </trim>
  187. where log_id = #{logId}
  188. </update>
  189. <delete id="deleteFsCourseTrafficLogByLogId" parameterType="Long">
  190. delete from fs_course_traffic_log where log_id = #{logId}
  191. </delete>
  192. <delete id="deleteFsCourseTrafficLogByLogIds" parameterType="String">
  193. delete from fs_course_traffic_log where log_id in
  194. <foreach item="logId" collection="array" open="(" separator="," close=")">
  195. #{logId}
  196. </foreach>
  197. </delete>
  198. <select id="selectCourseTrafficLogByTwoDaysLater" resultMap="FsCourseTrafficLogResult">
  199. <![CDATA[
  200. SELECT
  201. l.log_id,
  202. l.user_id,
  203. l.video_id,
  204. l.create_time,
  205. l.qw_external_contact_id,
  206. l.internet_traffic,
  207. l.qw_user_id,
  208. l.company_user_id,
  209. l.company_id,
  210. l.course_id,
  211. l.uu_id,
  212. l.project, l.period_id
  213. FROM
  214. fs_course_traffic_log l
  215. WHERE
  216. l.create_time < DATE_SUB( NOW( ), INTERVAL 2 DAY )
  217. ORDER BY l.log_id limit #{offset},#{limit} ]]>
  218. </select>
  219. <insert id="insertCourseTrafficLogByTwoDaysLaterBatch" useGeneratedKeys="false">
  220. insert into fs_course_traffic_log (
  221. 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
  222. <foreach collection="list" item="item" separator=",">
  223. (#{item.logId},#{item.userId},#{item.videoId},#{item.createTime},#{item.qwExternalContactId},#{item.internetTraffic},#{item.qwUserId}
  224. ,#{item.companyUserId},#{item.companyId},#{item.courseId},#{item.uuId},#{item.project},#{item.periodId})
  225. </foreach>
  226. </insert>
  227. <select id="selectTrafficNew" resultType="com.fs.course.vo.FsCourseTrafficLogListVO">
  228. select company_id,project,course_id,SUM(internet_traffic) AS total_internet_traffic
  229. ,DATE_FORMAT(create_time, '%Y-%m-%d') AS `month` from fs_course_traffic_log
  230. <where>
  231. <if test="startDate != null and endDate != null">
  232. and DATE_FORMAT(create_time, '%Y-%m-%d') between #{startDate} AND #{endDate}
  233. </if>
  234. <if test='companyId !=null'>
  235. and company_id = #{companyId}
  236. </if>
  237. <if test="courseId != null">
  238. and course_id = ${courseId}
  239. </if>
  240. <if test="project != null">
  241. and project = ${project}
  242. </if>
  243. </where>
  244. <if test="tabType==null or tabType==''">
  245. group by company_id,`month`,course_id,project
  246. </if>
  247. <if test="tabType!=null and tabType=='project'">
  248. group by project,`month`
  249. </if>
  250. <if test="tabType!=null and tabType=='course'">
  251. group by course_id,`month`
  252. </if>
  253. <if test="tabType!=null and tabType=='company'">
  254. group by company_id,`month`
  255. </if>
  256. </select>
  257. </mapper>