CompanySmsLogsMapper.xml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.company.mapper.CompanySmsLogsMapper">
  6. <resultMap type="CompanySmsLogs" id="CompanySmsLogsResult">
  7. <result property="logsId" column="logs_id" />
  8. <result property="companyId" column="company_id" />
  9. <result property="companyUserId" column="company_user_id" />
  10. <result property="customerId" column="customer_id" />
  11. <result property="tempId" column="temp_id" />
  12. <result property="tempCode" column="temp_code" />
  13. <result property="phone" column="phone" />
  14. <result property="content" column="content" />
  15. <result property="createTime" column="create_time" />
  16. <result property="sendTime" column="send_time" />
  17. <result property="status" column="status" />
  18. <result property="mid" column="mid" />
  19. <result property="stat" column="stat" />
  20. <result property="replyContent" column="reply_content" />
  21. <result property="number" column="number" />
  22. <result property="type" column="type" />
  23. <result property="sopSmsLogId" column="sop_sms_log_id" />
  24. <result property="smsIndex" column="sms_index" />
  25. </resultMap>
  26. <sql id="selectCompanySmsLogsVo">
  27. select logs_id, company_id,type, company_user_id, customer_id, temp_id, temp_code, phone, content,
  28. create_time, send_time, status,mid,stat,reply_content,number,sop_sms_log_id,sms_index
  29. from company_sms_logs
  30. </sql>
  31. <select id="selectCompanySmsLogsById" parameterType="Long" resultMap="CompanySmsLogsResult">
  32. <include refid="selectCompanySmsLogsVo"/>
  33. where logs_id = #{logsId}
  34. </select>
  35. <insert id="insertCompanySmsLogs" parameterType="CompanySmsLogs" useGeneratedKeys="true" keyProperty="logsId">
  36. insert into company_sms_logs
  37. <trim prefix="(" suffix=")" suffixOverrides=",">
  38. <if test="companyId != null">company_id,</if>
  39. <if test="companyUserId != null">company_user_id,</if>
  40. <if test="customerId != null">customer_id,</if>
  41. <if test="tempId != null">temp_id,</if>
  42. <if test="tempCode != null">temp_code,</if>
  43. <if test="phone != null">phone,</if>
  44. <if test="content != null">content,</if>
  45. <if test="createTime != null">create_time,</if>
  46. <if test="sendTime != null">send_time,</if>
  47. <if test="status != null">status,</if>
  48. <if test="mid != null">mid,</if>
  49. <if test="stat != null">stat,</if>
  50. <if test="replyContent != null">reply_content,</if>
  51. <if test="number != null">number,</if>
  52. <if test="type != null">type,</if>
  53. <if test="sopSmsLogId != null">sop_sms_log_id,</if>
  54. <if test="smsIndex != null">sms_index,</if>
  55. </trim>
  56. <trim prefix="values (" suffix=")" suffixOverrides=",">
  57. <if test="companyId != null">#{companyId},</if>
  58. <if test="companyUserId != null">#{companyUserId},</if>
  59. <if test="customerId != null">#{customerId},</if>
  60. <if test="tempId != null">#{tempId},</if>
  61. <if test="tempCode != null">#{tempCode},</if>
  62. <if test="phone != null">#{phone},</if>
  63. <if test="content != null">#{content},</if>
  64. <if test="createTime != null">#{createTime},</if>
  65. <if test="sendTime != null">#{sendTime},</if>
  66. <if test="status != null">#{status},</if>
  67. <if test="mid != null">#{mid},</if>
  68. <if test="stat != null">#{stat},</if>
  69. <if test="replyContent != null">#{replyContent},</if>
  70. <if test="number != null">#{number},</if>
  71. <if test="type != null">#{type},</if>
  72. <if test="sopSmsLogId != null">#{sopSmsLogId},</if>
  73. <if test="smsIndex != null">#{smsIndex},</if>
  74. </trim>
  75. </insert>
  76. <update id="updateCompanySmsLogs" parameterType="CompanySmsLogs">
  77. update company_sms_logs
  78. <trim prefix="SET" suffixOverrides=",">
  79. <if test="companyId != null">company_id = #{companyId},</if>
  80. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  81. <if test="customerId != null">customer_id = #{customerId},</if>
  82. <if test="tempId != null">temp_id = #{tempId},</if>
  83. <if test="tempCode != null">temp_code = #{tempCode},</if>
  84. <if test="phone != null">phone = #{phone},</if>
  85. <if test="content != null">content = #{content},</if>
  86. <if test="createTime != null">create_time = #{createTime},</if>
  87. <if test="sendTime != null">send_time = #{sendTime},</if>
  88. <if test="status != null">status = #{status},</if>
  89. <if test="mid != null">mid = #{mid},</if>
  90. <if test="stat != null">stat = #{stat},</if>
  91. <if test="replyContent != null">reply_content = #{replyContent},</if>
  92. <if test="number != null">number = #{number},</if>
  93. <if test="type != null">type = #{type},</if>
  94. <if test="sopSmsLogId != null">sop_sms_log_id = #{sopSmsLogId},</if>
  95. </trim>
  96. where logs_id = #{logsId}
  97. </update>
  98. <delete id="deleteCompanySmsLogsById" parameterType="Long">
  99. delete from company_sms_logs where logs_id = #{logsId}
  100. </delete>
  101. <delete id="deleteCompanySmsLogsByIds" parameterType="String">
  102. delete from company_sms_logs where logs_id in
  103. <foreach item="logsId" collection="array" open="(" separator="," close=")">
  104. #{logsId}
  105. </foreach>
  106. </delete>
  107. <select id="selectSmsLogsCounts" resultType="com.alibaba.fastjson.JSONObject">
  108. SELECT count(t.company_user_id ) AS smsCount,count( IF ( t.status =1,1, NULL ) ) AS successCount, t.type
  109. FROM
  110. (
  111. SELECT DATE_FORMAT( s.create_time, #{sqlDateFormat} ) AS type, s.company_user_id,s.status
  112. FROM
  113. company_sms_logs AS s
  114. WHERE
  115. (DATE_FORMAT(s.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
  116. AND s.company_user_id IN
  117. <foreach item="item" collection="userIds" open="(" separator="," close=")">
  118. #{item}
  119. </foreach>
  120. ) t
  121. GROUP BY t.type
  122. </select>
  123. <select id="selectCompanySmsLogsListQueryYsytg" resultType="com.fs.company.vo.CompanySmsLogsQueryVO">
  124. SELECT
  125. csl.logs_id AS logsId,
  126. c.company_name AS companyName,
  127. cu.user_name AS companyUserName,
  128. csl.temp_code AS tempCode,
  129. csl.phone AS phone,
  130. csl.number AS number,
  131. csl.type AS type,
  132. csl.content AS content,
  133. <!-- 根据optionType动态选择关联字段 -->
  134. <choose>
  135. <when test="dto.optionType == 1">
  136. fuc.course_name AS courseName,
  137. fucv.title AS videoTitle,
  138. </when>
  139. <otherwise>
  140. NULL AS courseName,
  141. NULL AS videoTitle,
  142. </otherwise>
  143. </choose>
  144. csl.create_time AS createTime,
  145. csl.send_time AS sendTime
  146. FROM
  147. company_sms_logs csl
  148. LEFT JOIN company c ON csl.company_id = c.company_id
  149. LEFT JOIN company_user cu ON csl.company_user_id = cu.user_id
  150. <!-- 根据optionType动态关联不同的表 -->
  151. <choose>
  152. <when test="dto.optionType == 1">
  153. LEFT JOIN qw_course_link_send_msg_log qclog ON csl.logs_id = qclog.company_sms_logs_id
  154. LEFT JOIN fs_user_course fuc ON fuc.course_id = qclog.course_id
  155. LEFT JOIN fs_user_course_video fucv ON fucv.video_id = qclog.video_id
  156. </when>
  157. <when test="dto.optionType == 2">
  158. LEFT JOIN qw_acquisition_send_msg_log qalog ON csl.logs_id = qalog.company_sms_logs_id
  159. </when>
  160. </choose>
  161. <where>
  162. <if test="dto.companyId != null">
  163. AND csl.company_id = #{dto.companyId}
  164. </if>
  165. <if test="dto.companyUserId != null">
  166. AND csl.company_user_id = #{dto.companyUserId}
  167. </if>
  168. <if test="dto.phone != null and dto.phone != ''">
  169. AND csl.phone LIKE CONCAT('%', #{dto.phone}, '%')
  170. </if>
  171. <if test="dto.tempCode != null and dto.tempCode != ''">
  172. AND csl.temp_code = #{dto.tempCode}
  173. </if>
  174. <if test="dto.type != null">
  175. AND csl.type = #{dto.type}
  176. </if>
  177. <if test="dto.beginCreateTime != null">
  178. AND csl.create_time >= #{dto.beginCreateTime}
  179. </if>
  180. <if test="dto.endCreateTime != null">
  181. AND csl.create_time &lt;= #{dto.endCreateTime}
  182. </if>
  183. <if test="dto.userIds != null and dto.userIds.size() > 0">
  184. AND csl.company_user_id IN
  185. <foreach collection="dto.userIds" item="userId" open="(" separator="," close=")">
  186. #{userId}
  187. </foreach>
  188. </if>
  189. <!-- 课程链接类型特有查询条件 -->
  190. <if test="dto.optionType == 1">
  191. <if test="dto.courseId != null">
  192. AND fuc.course_id = #{dto.courseId}
  193. </if>
  194. <if test="dto.videoId != null">
  195. AND fucv.video_id = #{dto.videoId}
  196. </if>
  197. </if>
  198. </where>
  199. ORDER BY csl.create_time DESC
  200. </select>
  201. </mapper>