QwSopSmsLogsMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.qw.mapper.QwSopSmsLogsMapper">
  6. <resultMap type="QwSopSmsLogs" id="QwSopSmsLogsResult">
  7. <result property="id" column="id" />
  8. <result property="sopId" column="sop_id" />
  9. <result property="sopLogId" column="sop_log_id" />
  10. <result property="qwUserId" column="qw_user_id" />
  11. <result property="companyId" column="company_id" />
  12. <result property="companyUserId" column="company_user_id" />
  13. <result property="contactId" column="contact_id" />
  14. <result property="fsUserId" column="fs_user_id" />
  15. <result property="phoneNumber" column="phone_number" />
  16. <result property="remark" column="remark" />
  17. <result property="content" column="content" />
  18. <result property="serverId" column="server_id" />
  19. <result property="status" column="status" />
  20. <result property="sendTime" column="send_time" />
  21. <result property="smsTemplateCode" column="sms_template_code" />
  22. <result property="createTime" column="create_time" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="smsIndex" column="sms_index"></result>
  25. </resultMap>
  26. <sql id="selectQwSopSmsLogsVo">
  27. select id, sop_id, sop_log_id, qw_user_id, company_id, company_user_id, contact_id, fs_user_id, phone_number, remark, content, server_id, status, send_time, sms_template_code, create_time, update_time,sms_index from qw_sop_sms_logs
  28. </sql>
  29. <select id="selectQwSopSmsLogsList" parameterType="QwSopSmsLogs" resultMap="QwSopSmsLogsResult">
  30. <include refid="selectQwSopSmsLogsVo"/>
  31. <where>
  32. <if test="sopId != null and sopId != ''"> and sop_id = #{sopId}</if>
  33. <if test="sopLogId != null "> and sop_log_id = #{sopLogId}</if>
  34. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  35. <if test="companyId != null "> and company_id = #{companyId}</if>
  36. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  37. <if test="contactId != null "> and contact_id = #{contactId}</if>
  38. <if test="fsUserId != null and fsUserId != ''"> and fs_user_id = #{fsUserId}</if>
  39. <if test="phoneNumber != null and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
  40. <if test="content != null and content != ''"> and content = #{content}</if>
  41. <if test="serverId != null "> and server_id = #{serverId}</if>
  42. <if test="status != null and status != ''"> and status = #{status}</if>
  43. <if test="sendTime != null "> and send_time = #{sendTime}</if>
  44. <if test="smsTemplateCode != null and smsTemplateCode != ''"> and sms_template_code = #{smsTemplateCode}</if>
  45. </where>
  46. </select>
  47. <select id="selectQwSopSmsLogsById" parameterType="Long" resultMap="QwSopSmsLogsResult">
  48. <include refid="selectQwSopSmsLogsVo"/>
  49. where id = #{id}
  50. </select>
  51. <insert id="insertQwSopSmsLogs" parameterType="QwSopSmsLogs" useGeneratedKeys="true" keyProperty="id">
  52. insert into qw_sop_sms_logs
  53. <trim prefix="(" suffix=")" suffixOverrides=",">
  54. <if test="sopId != null">sop_id,</if>
  55. <if test="sopLogId != null">sop_log_id,</if>
  56. <if test="qwUserId != null">qw_user_id,</if>
  57. <if test="companyId != null">company_id,</if>
  58. <if test="companyUserId != null">company_user_id,</if>
  59. <if test="contactId != null">contact_id,</if>
  60. <if test="fsUserId != null">fs_user_id,</if>
  61. <if test="phoneNumber != null">phone_number,</if>
  62. <if test="remark != null">remark,</if>
  63. <if test="content != null">content,</if>
  64. <if test="serverId != null">server_id,</if>
  65. <if test="status != null">status,</if>
  66. <if test="sendTime != null">send_time,</if>
  67. <if test="smsTemplateCode != null">sms_template_code,</if>
  68. <if test="createTime != null">create_time,</if>
  69. <if test="updateTime != null">update_time,</if>
  70. <if test="smsIndex != null">sms_index,</if>
  71. </trim>
  72. <trim prefix="values (" suffix=")" suffixOverrides=",">
  73. <if test="sopId != null">#{sopId},</if>
  74. <if test="sopLogId != null">#{sopLogId},</if>
  75. <if test="qwUserId != null">#{qwUserId},</if>
  76. <if test="companyId != null">#{companyId},</if>
  77. <if test="companyUserId != null">#{companyUserId},</if>
  78. <if test="contactId != null">#{contactId},</if>
  79. <if test="fsUserId != null">#{fsUserId},</if>
  80. <if test="phoneNumber != null">#{phoneNumber},</if>
  81. <if test="remark != null">#{remark},</if>
  82. <if test="content != null">#{content},</if>
  83. <if test="serverId != null">#{serverId},</if>
  84. <if test="status != null">#{status},</if>
  85. <if test="sendTime != null">#{sendTime},</if>
  86. <if test="smsTemplateCode != null">#{smsTemplateCode},</if>
  87. <if test="createTime != null">#{createTime},</if>
  88. <if test="updateTime != null">#{updateTime},</if>
  89. <if test="smsIndex != null">#{smsIndex},</if>
  90. </trim>
  91. </insert>
  92. <update id="updateQwSopSmsLogs" parameterType="QwSopSmsLogs">
  93. update qw_sop_sms_logs
  94. <trim prefix="SET" suffixOverrides=",">
  95. <if test="sopId != null">sop_id = #{sopId},</if>
  96. <if test="sopLogId != null">sop_log_id = #{sopLogId},</if>
  97. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  98. <if test="companyId != null">company_id = #{companyId},</if>
  99. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  100. <if test="contactId != null">contact_id = #{contactId},</if>
  101. <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
  102. <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
  103. <if test="remark != null">remark = #{remark},</if>
  104. <if test="content != null">content = #{content},</if>
  105. <if test="serverId != null">server_id = #{serverId},</if>
  106. <if test="status != null">status = #{status},</if>
  107. <if test="sendTime != null">send_time = #{sendTime},</if>
  108. <if test="smsTemplateCode != null">sms_template_code = #{smsTemplateCode},</if>
  109. <if test="createTime != null">create_time = #{createTime},</if>
  110. <if test="updateTime != null">update_time = #{updateTime},</if>
  111. <if test="smsIndex != null">sms_index = #{smsIndex},</if>
  112. </trim>
  113. where id = #{id}
  114. </update>
  115. <delete id="deleteQwSopSmsLogsById" parameterType="Long">
  116. delete from qw_sop_sms_logs where id = #{id}
  117. </delete>
  118. <delete id="deleteQwSopSmsLogsByIds" parameterType="String">
  119. delete from qw_sop_sms_logs where id in
  120. <foreach item="id" collection="array" open="(" separator="," close=")">
  121. #{id}
  122. </foreach>
  123. </delete>
  124. <!-- 查询待发送:例如 10点执行则查 当天 0 点 ~ 11 点之前。serverIds 为空时返回空结果。建议索引:(server_id, status, create_time) -->
  125. <select id="selectPendingSmsByServerAndTime" resultType="com.fs.qw.domain.QwSopSmsLogs">
  126. SELECT
  127. id,
  128. fs_user_id,
  129. content,
  130. sms_template_code
  131. FROM
  132. qw_sop_sms_logs
  133. <where>
  134. <choose>
  135. <when test="serverIds != null and serverIds.size() > 0">
  136. server_id IN
  137. <foreach collection="serverIds" item="serverId" open="(" separator="," close=")">
  138. #{serverId}
  139. </foreach>
  140. AND status = #{status}
  141. AND create_time &gt;= #{startTime}
  142. AND create_time &lt; #{endTime}
  143. </when>
  144. <otherwise>
  145. 1 = 0
  146. </otherwise>
  147. </choose>
  148. </where>
  149. </select>
  150. <!-- 分页查询待发送 OOM -->
  151. <select id="selectPendingSmsByServerAndTimePage" resultType="com.fs.qw.domain.QwSopSmsLogs">
  152. SELECT
  153. id,
  154. fs_user_id,
  155. content,
  156. sms_template_code,
  157. sop_log_id,
  158. server_id,
  159. sms_index
  160. FROM
  161. qw_sop_sms_logs
  162. <where>
  163. <choose>
  164. <when test="serverIds != null and serverIds.size() > 0">
  165. server_id IN
  166. <foreach collection="serverIds" item="serverId" open="(" separator="," close=")">
  167. #{serverId}
  168. </foreach>
  169. AND status = #{status}
  170. AND create_time &lt; #{endTime}
  171. </when>
  172. <otherwise>
  173. 1 = 0
  174. </otherwise>
  175. </choose>
  176. </where>
  177. LIMIT #{pageSize}
  178. </select>
  179. <update id="updateStatusByIds">
  180. UPDATE qw_sop_sms_logs SET status = #{status}, update_time = NOW() WHERE id IN
  181. <foreach collection="ids" item="id" open="(" separator="," close=")">
  182. #{id}
  183. </foreach>
  184. </update>
  185. <select id="selectQwSopSmsLogsByIdAndIndex" resultType="com.fs.qw.domain.QwSopSmsLogs">
  186. SELECT
  187. id,
  188. status,
  189. sms_index
  190. FROM
  191. qw_sop_sms_logs
  192. where id = #{id} and `index` = #{index}
  193. </select>
  194. <update id="updateSmsNotifyInfo" parameterType="QwSopSmsLogs">
  195. update qw_sop_sms_logs
  196. <trim prefix="SET" suffixOverrides=",">
  197. <if test="qwSopSmsLogs.remark != null">remark = #{qwSopSmsLogs.remark},</if>
  198. <if test="qwSopSmsLogs.status != null">status = #{qwSopSmsLogs.status},</if>
  199. <if test="qwSopSmsLogs.sendTime != null">send_time = #{qwSopSmsLogs.sendTime},</if>
  200. </trim>
  201. where sop_log_id = #{qwSopSmsLogs.sopLogId} AND sms_index = #{qwSopSmsLogs.smsIndex}
  202. </update>
  203. <insert id="batchInsertQwSopSmsLogsOneTouch" parameterType="java.util.List" useGeneratedKeys="false">
  204. INSERT INTO qw_sop_sms_logs
  205. (
  206. sop_id, sop_log_id, qw_user_id, company_id, company_user_id, contact_id, fs_user_id,
  207. content, server_id, status, send_time, sms_template_code, create_time,sms_index
  208. )
  209. VALUES
  210. <foreach collection="qwSopSmsLogs" item="log" separator=",">
  211. (
  212. #{log.sopId},
  213. #{log.sopLogId},
  214. #{log.qwUserId},
  215. #{log.companyId},
  216. #{log.companyUserId},
  217. #{log.contactId},
  218. #{log.fsUserId},
  219. #{log.content},
  220. #{log.serverId},
  221. #{log.status},
  222. #{log.sendTime},
  223. #{log.smsTemplateCode},
  224. #{log.createTime},
  225. #{log.smsIndex}
  226. )
  227. </foreach>
  228. </insert>
  229. </mapper>