FsImMsgSendLogMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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.im.mapper.FsImMsgSendLogMapper">
  6. <resultMap type="FsImMsgSendLog" id="FsImMsgSendLogResult">
  7. <result property="logId" column="log_id" />
  8. <result property="companyUserId" column="company_user_id" />
  9. <result property="companyId" column="company_id" />
  10. <result property="courseId" column="course_id" />
  11. <result property="courseName" column="course_name" />
  12. <result property="videoId" column="video_id" />
  13. <result property="videoName" column="video_name" />
  14. <result property="periodId" column="period_id" />
  15. <result property="sendTitle" column="send_title" />
  16. <result property="planSendTime" column="plan_send_time" />
  17. <result property="sendType" column="send_type" />
  18. <result property="sendMode" column="send_mode" />
  19. <result property="sendStatus" column="send_status" />
  20. <result property="isUrgeCourse" column="is_urge_course" />
  21. <result property="msgType" column="msg_type" />
  22. <result property="createTime" column="create_time" />
  23. <result property="createBy" column="create_by" />
  24. <result property="updateTime" column="update_time" />
  25. <result property="sendUnionId" column="send_union_id" />
  26. <result property="tagIds" column="tag_ids" />
  27. <result property="tagNames" column="tag_names" />
  28. <result property="projectId" column="project_id" />
  29. <result property="periodDaysId" column="period_days_id" />
  30. </resultMap>
  31. <sql id="selectFsImMsgSendLogVo">
  32. select log_id, company_user_id, company_id, course_id, course_name, video_id, video_name, period_id, send_title, plan_send_time, send_type, send_mode, send_status, is_urge_course, msg_type, create_time, create_by, update_time, send_union_id, tag_ids,
  33. tag_names, project_id, period_days_id from fs_im_msg_send_log
  34. </sql>
  35. <select id="selectFsImMsgSendLogList" parameterType="FsImMsgSendLog" resultMap="FsImMsgSendLogResult">
  36. <include refid="selectFsImMsgSendLogVo"/>
  37. <where>
  38. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  39. <if test="companyId != null "> and company_id = #{companyId}</if>
  40. <if test="courseId != null "> and course_id = #{courseId}</if>
  41. <if test="courseName != null and courseName != ''"> and course_name like concat('%', #{courseName}, '%')</if>
  42. <if test="videoId != null "> and video_id = #{videoId}</if>
  43. <if test="videoName != null and videoName != ''"> and video_name like concat('%', #{videoName}, '%')</if>
  44. <if test="periodId != null "> and period_id = #{periodId}</if>
  45. <if test="sendTitle != null and sendTitle != ''"> and send_title = #{sendTitle}</if>
  46. <if test="planSendTime != null "> and plan_send_time = #{planSendTime}</if>
  47. <if test="sendType != null "> and send_type = #{sendType}</if>
  48. <if test="sendMode != null "> and send_mode = #{sendMode}</if>
  49. <if test="sendStatus != null "> and send_status = #{sendStatus}</if>
  50. <if test="isUrgeCourse != null "> and is_urge_course = #{isUrgeCourse}</if>
  51. <if test="msgType != null "> and msg_type = #{msgType}</if>
  52. <if test="sendUnionId != null and sendUnionId != ''"> and send_union_id = #{sendUnionId}</if>
  53. <if test="tagIds != null and tagIds != ''"> and tag_ids = #{tagIds}</if>
  54. <if test="tagNames != null and tagNames != ''"> and tag_names = #{tagNames}</if>
  55. <if test="projectId != null and projectId != ''"> and project_id = #{projectId}</if>
  56. <if test="periodDaysId != null and periodDaysId != ''"> and period_days_id = #{periodDaysId}</if>
  57. </where>
  58. </select>
  59. <select id="selectFsImMsgSendLogByLogId" parameterType="Long" resultMap="FsImMsgSendLogResult">
  60. <include refid="selectFsImMsgSendLogVo"/>
  61. where log_id = #{logId}
  62. </select>
  63. <insert id="insertFsImMsgSendLog" parameterType="FsImMsgSendLog" useGeneratedKeys="true" keyProperty="logId">
  64. insert into fs_im_msg_send_log
  65. <trim prefix="(" suffix=")" suffixOverrides=",">
  66. <if test="companyUserId != null">company_user_id,</if>
  67. <if test="companyId != null">company_id,</if>
  68. <if test="courseId != null">course_id,</if>
  69. <if test="courseName != null">course_name,</if>
  70. <if test="videoId != null">video_id,</if>
  71. <if test="videoName != null">video_name,</if>
  72. <if test="periodId != null">period_id,</if>
  73. <if test="sendTitle != null">send_title,</if>
  74. <if test="planSendTime != null">plan_send_time,</if>
  75. <if test="sendType != null">send_type,</if>
  76. <if test="sendMode != null">send_mode,</if>
  77. <if test="sendStatus != null">send_status,</if>
  78. <if test="isUrgeCourse != null">is_urge_course,</if>
  79. <if test="msgType != null">msg_type,</if>
  80. <if test="createTime != null">create_time,</if>
  81. <if test="createBy != null">create_by,</if>
  82. <if test="updateTime != null">update_time,</if>
  83. <if test="sendUnionId != null">send_union_id,</if>
  84. <if test="tagIds != null">tag_ids,</if>
  85. <if test="tagNames != null">tag_names,</if>
  86. <if test="projectId != null">project_id,</if>
  87. <if test="periodDaysId != null">period_days_id,</if>
  88. </trim>
  89. <trim prefix="values (" suffix=")" suffixOverrides=",">
  90. <if test="companyUserId != null">#{companyUserId},</if>
  91. <if test="companyId != null">#{companyId},</if>
  92. <if test="courseId != null">#{courseId},</if>
  93. <if test="courseName != null">#{courseName},</if>
  94. <if test="videoId != null">#{videoId},</if>
  95. <if test="videoName != null">#{videoName},</if>
  96. <if test="periodId != null">#{periodId},</if>
  97. <if test="sendTitle != null">#{sendTitle},</if>
  98. <if test="planSendTime != null">#{planSendTime},</if>
  99. <if test="sendType != null">#{sendType},</if>
  100. <if test="sendMode != null">#{sendMode},</if>
  101. <if test="sendStatus != null">#{sendStatus},</if>
  102. <if test="isUrgeCourse != null">#{isUrgeCourse},</if>
  103. <if test="msgType != null">#{msgType},</if>
  104. <if test="createTime != null">#{createTime},</if>
  105. <if test="createBy != null">#{createBy},</if>
  106. <if test="updateTime != null">#{updateTime},</if>
  107. <if test="sendUnionId != null">#{sendUnionId},</if>
  108. <if test="tagIds != null">#{tagIds},</if>
  109. <if test="tagNames != null">#{tagNames},</if>
  110. <if test="projectId != null">#{projectId},</if>
  111. <if test="periodDaysId != null">#{periodDaysId},</if>
  112. </trim>
  113. </insert>
  114. <update id="updateFsImMsgSendLog" parameterType="FsImMsgSendLog">
  115. update fs_im_msg_send_log
  116. <trim prefix="SET" suffixOverrides=",">
  117. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  118. <if test="companyId != null">company_id = #{companyId},</if>
  119. <if test="courseId != null">course_id = #{courseId},</if>
  120. <if test="courseName != null">course_name = #{courseName},</if>
  121. <if test="videoId != null">video_id = #{videoId},</if>
  122. <if test="videoName != null">video_name = #{videoName},</if>
  123. <if test="periodId != null">period_id = #{periodId},</if>
  124. <if test="sendTitle != null">send_title = #{sendTitle},</if>
  125. <if test="planSendTime != null">plan_send_time = #{planSendTime},</if>
  126. <if test="sendType != null">send_type = #{sendType},</if>
  127. <if test="sendMode != null">send_mode = #{sendMode},</if>
  128. <if test="sendStatus != null">send_status = #{sendStatus},</if>
  129. <if test="isUrgeCourse != null">is_urge_course = #{isUrgeCourse},</if>
  130. <if test="msgType != null">msg_type = #{msgType},</if>
  131. <if test="createTime != null">create_time = #{createTime},</if>
  132. <if test="createBy != null">create_by = #{createBy},</if>
  133. <if test="updateTime != null">update_time = #{updateTime},</if>
  134. <if test="sendUnionId != null">send_union_id = #{sendUnionId},</if>
  135. <if test="tagIds != null">tag_ids = #{tagIds},</if>
  136. <if test="tagNames != null">tag_names = #{tagNames},</if>
  137. <if test="projectId != null">project_id = #{projectId},</if>
  138. <if test="periodDaysId != null">period_days_id = #{periodDaysId},</if>
  139. </trim>
  140. where log_id = #{logId}
  141. </update>
  142. <delete id="deleteFsImMsgSendLogByLogId" parameterType="Long">
  143. delete from fs_im_msg_send_log where log_id = #{logId}
  144. </delete>
  145. <delete id="deleteFsImMsgSendLogByLogIds" parameterType="String">
  146. delete from fs_im_msg_send_log where log_id in
  147. <foreach item="logId" collection="array" open="(" separator="," close=")">
  148. #{logId}
  149. </foreach>
  150. </delete>
  151. <select id="selectFsImSendLogList" resultType="com.fs.course.vo.newfs.FsImSendLogVO">
  152. SELECT
  153. log.log_id,
  154. log.company_user_id,
  155. log.company_id,
  156. log.course_id,
  157. log.course_name,
  158. log.video_id,
  159. log.video_name,
  160. log.send_title,
  161. log.plan_send_time,
  162. log.send_type,
  163. log.send_mode,
  164. log.send_status,
  165. log.is_urge_course,
  166. log.msg_type,
  167. log.create_time,
  168. log.send_union_id,
  169. log.tag_ids,
  170. log.tag_names,
  171. log2.send_title as urgeSendTitle,
  172. GROUP_CONCAT( DISTINCT detail.user_id ) AS userIds,
  173. GROUP_CONCAT( DISTINCT fs_user.nick_name ) AS nickNames
  174. FROM
  175. fs_im_msg_send_log log
  176. LEFT JOIN fs_im_msg_send_detail detail ON detail.log_id = log.log_id
  177. LEFT JOIN fs_user ON fs_user.user_id = detail.user_id
  178. LEFT JOIN fs_im_msg_send_log log2 on log2.send_union_id = log.send_union_id and log2.msg_type = 2
  179. WHERE
  180. log.msg_type = 1
  181. AND log.company_user_id = #{params.companyUserId}
  182. AND log.company_id = #{params.companyId}
  183. <if test="params.keyword != null and params.keyword !='' ">
  184. AND log.send_title like concat('%',#{params.keyword},'%')
  185. </if>
  186. GROUP BY
  187. log.log_id
  188. ORDER BY
  189. log.create_time DESC
  190. </select>
  191. <select id="selectSendLogListByDetailId" resultType="FsImMsgSendLog">
  192. SELECT DISTINCT log.*
  193. FROM
  194. fs_im_msg_send_log log
  195. LEFT JOIN fs_im_msg_send_detail detail ON detail.log_id = log.log_id
  196. WHERE
  197. detail.log_detail_id IN
  198. <foreach item="logDetailId" collection="params.logDetailIds" open="(" separator="," close=")">
  199. #{logDetailId}
  200. </foreach>
  201. </select>
  202. <select id="selectFsImMsgSendLogInfoList" resultType="com.fs.app.service.param.FsImMsgSendLogResponse">
  203. SELECT
  204. d.log_id AS logId,
  205. l.company_user_id AS companyUserId,
  206. l.company_id AS companyId,
  207. l.course_id AS courseId,
  208. l.course_name AS courseName,
  209. l.video_id AS videoId,
  210. l.video_name AS videoName,
  211. l.project_id AS projectId,
  212. l.send_title AS sendTitle,
  213. l.plan_send_time AS planSendTime,
  214. l.send_type AS sendType,
  215. l.send_mode AS sendMode,
  216. l.is_urge_course AS isUrgeCourse,
  217. l.msg_type AS msgType,
  218. l.send_status AS sendStatus,
  219. l.count AS count,
  220. l.create_time AS createTime,
  221. d.user_id AS userId,
  222. d.status AS status,
  223. d.exception_info AS exceptionInfo
  224. FROM fs_im_msg_send_detail d
  225. LEFT JOIN fs_im_msg_send_log l ON l.log_id = d.log_id
  226. <where>
  227. <if test="companyUserId != null"> AND l.company_user_id = #{companyUserId}</if>
  228. <if test="companyId != null"> AND l.company_id = #{companyId}</if>
  229. <if test="courseId != null"> AND l.course_id = #{courseId}</if>
  230. <if test="courseName != null and courseName != ''"> AND l.course_name like concat('%', #{courseName}, '%')</if>
  231. <if test="videoId != null"> AND l.video_id = #{videoId}</if>
  232. <if test="videoName != null and videoName != ''"> AND l.video_name like concat('%', #{videoName}, '%')</if>
  233. <if test="sendTitle != null and sendTitle != ''"> AND l.send_title like concat('%', #{sendTitle}, '%')</if>
  234. <if test="planSendStartTime != null and planSendEndTime != null">
  235. AND l.plan_send_time between #{planSendStartTime} and #{planSendEndTime}
  236. </if>
  237. <if test="sendType != null"> AND l.send_type = #{sendType}</if>
  238. <if test="sendMode != null"> AND l.send_mode = #{sendMode}</if>
  239. <if test="sendStatus != null"> AND l.send_status = #{sendStatus}</if>
  240. <if test="msgType != null"> AND l.msg_type = #{msgType}</if>
  241. <if test="projectId != null"> AND l.project_id = #{projectId}</if>
  242. <if test="createTimeStartTime != null and createTimeEndTime != null">
  243. AND d.create_time between #{createTimeStartTime} and #{createTimeEndTime}
  244. </if>
  245. <if test="status != null"> AND d.status = #{status}</if>
  246. </where>
  247. ORDER BY l.create_time DESC
  248. </select>
  249. <select id="getFsImMsgSendStatistics" resultType="com.fs.app.service.param.FsImMsgSendLogStatisticsResponse">
  250. SELECT
  251. count(d.log_detail_id) as total,
  252. sum(case when d.status = 0 then 1 else 0 end) as sent,
  253. sum(case when d.send_status = 2 then 1 else 0 end) as pending,
  254. sum(case when d.status = 1 then 1 else 0 end) as failed
  255. FROM fs_im_msg_send_detail d
  256. LEFT JOIN fs_im_msg_send_log l ON l.log_id = d.log_id
  257. <where>
  258. <if test="companyUserId != null"> AND l.company_user_id = #{companyUserId}</if>
  259. <if test="companyId != null"> AND l.company_id = #{companyId}</if>
  260. <if test="courseId != null"> AND l.course_id = #{courseId}</if>
  261. <if test="courseName != null and courseName != ''"> AND l.course_name like concat('%', #{courseName}, '%')</if>
  262. <if test="videoId != null"> AND l.video_id = #{videoId}</if>
  263. <if test="videoName != null and videoName != ''"> AND l.video_name like concat('%', #{videoName}, '%')</if>
  264. <if test="sendTitle != null and sendTitle != ''"> AND l.send_title like concat('%', #{sendTitle}, '%')</if>
  265. <if test="planSendStartTime != null and planSendEndTime != null">
  266. AND l.plan_send_time between #{planSendStartTime} and #{planSendEndTime}
  267. </if>
  268. <if test="sendType != null"> AND l.send_type = #{sendType}</if>
  269. <if test="sendMode != null"> AND l.send_mode = #{sendMode}</if>
  270. <if test="msgType != null"> AND l.msg_type = #{msgType}</if>
  271. <if test="projectId != null"> AND l.project_id = #{projectId}</if>
  272. <if test="createTimeStartTime != null and createTimeEndTime != null">
  273. AND d.create_time between #{createTimeStartTime} and #{createTimeEndTime}
  274. </if>
  275. </where>
  276. </select>
  277. </mapper>