QwSopLogsMapper.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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.sop.mapper.QwSopLogsMapper">
  6. <resultMap type="QwSopLogs" id="QwSopLogsResult">
  7. <result property="id" column="id" />
  8. <result property="qwUserid" column="qw_userid" />
  9. <result property="externalUserId" column="external_user_id" />
  10. <result property="externalId" column="external_id" />
  11. <result property="externalUserName" column="external_user_name" />
  12. <result property="logType" column="log_type" />
  13. <result property="contentJson" column="content_json" />
  14. <result property="sendStatus" column="send_status" />
  15. <result property="sendTime" column="send_time" jdbcType="VARCHAR" />
  16. <result property="realSendTime" column="real_send_time" jdbcType="VARCHAR" />
  17. <result property="companyId" column="company_id" />
  18. <result property="receivingStatus" column="receiving_status" />
  19. <result property="msgId" column="msg_id" />
  20. <result property="sendType" column="send_type" />
  21. <result property="sopId" column="sop_id" />
  22. <result property="remark" column="remark" />
  23. <result property="createTime" column="create_time" />
  24. <result property="corpId" column="corp_id" />
  25. <result property="customerId" column="customer_id" />
  26. <result property="fsUserId" column="fs_user_id" />
  27. <result property="takeRecords" column="take_records" />
  28. <result property="sort" column="sort" />
  29. </resultMap>
  30. <sql id="selectQwSopLogsVo">
  31. select id,sop_id,customer_id, qw_userid,corp_id,external_user_id,external_id,external_user_name, log_type, content_json, send_status,receiving_status,msg_id, send_time, real_send_time, company_id, send_type,remark,fs_user_id,take_records from qw_sop_logs
  32. </sql>
  33. <select id="selectQwSopLogsListVO" parameterType="QwSopLogs" resultMap="QwSopLogsResult">
  34. <include refid="selectQwSopLogsVo"/>
  35. <where>
  36. <if test="qwUserid != null "> and qw_userid = #{qwUserid}</if>
  37. <if test="externalUserId != null and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
  38. <if test="externalId != null and externalId != ''"> and external_id = #{externalId}</if>
  39. <if test="sendStatus != null "> and send_status = #{sendStatus}</if>
  40. <if test="corpId != null "> and corp_id = #{corpId}</if>
  41. </where>
  42. order by send_time desc
  43. </select>
  44. <select id="selectQwSopLogsList" parameterType="QwSopLogs" resultMap="QwSopLogsResult">
  45. <include refid="selectQwSopLogsVo"/>
  46. <where>
  47. <if test="qwUserid != null "> and qw_userid = #{qwUserid}</if>
  48. <if test="externalUserId != null and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
  49. <if test="externalId != null and externalId != ''"> and external_id = #{externalId}</if>
  50. <if test="externalUserName != null and externalUserName != ''"> and external_user_name = #{externalUserName}</if>
  51. <if test="logType != null and logType != ''"> and log_type = #{logType}</if>
  52. <if test="contentJson != null and contentJson != ''"> and content_json = #{contentJson}</if>
  53. <if test="sendStatus != null "> and send_status = #{sendStatus}</if>
  54. <if test="sendTime != null "> and send_time = #{sendTime}</if>
  55. <if test="realSendTime != null "> and real_send_time = #{realSendTime}</if>
  56. <if test="companyId != null "> and company_id = #{companyId}</if>
  57. <if test="receivingStatus != null "> and receiving_status = #{receivingStatus}</if>
  58. <if test="msgId != null "> and msg_id = #{msgId}</if>
  59. <if test="corpId != null "> and corp_id = #{corpId}</if>
  60. <if test="sendType != null "> and send_type = #{sendType}</if>
  61. <if test="sopId != null "> and sop_id = #{sopId}</if>
  62. <if test="remark != null "> and remark = #{remark}</if>
  63. <if test="customerId != null "> and customer_id = #{customerId}</if>
  64. <if test="fsUserId != null "> and fs_user_id = #{fsUserId}</if>
  65. <if test="takeRecords != null "> and take_records = #{takeRecords}</if>
  66. </where>
  67. </select>
  68. <select id="selectQwSopLogsById" parameterType="String" resultMap="QwSopLogsResult">
  69. <include refid="selectQwSopLogsVo"/>
  70. where id = #{id} order by send_time
  71. </select>
  72. <insert id="insertQwSopLogs" parameterType="QwSopLogs" useGeneratedKeys="false">
  73. insert into qw_sop_logs
  74. <trim prefix="(" suffix=")" suffixOverrides=",">
  75. <if test="data.qwUserid != null">qw_userid,</if>
  76. <if test="data.externalUserId != null">external_user_id,</if>
  77. <if test="data.externalId != null">external_id,</if>
  78. <if test="data.externalUserName != null">external_user_name,</if>
  79. <if test="data.logType != null">log_type,</if>
  80. <if test="data.contentJson != null">content_json,</if>
  81. <if test="data.sendStatus != null">send_status,</if>
  82. <if test="data.sendTime != null">send_time,</if>
  83. <if test="data.realSendTime != null">real_send_time,</if>
  84. <if test="data.sendType != null ">send_type,</if>
  85. <if test="data.companyId != null">company_id,</if>
  86. <if test="data.receivingStatus != null ">receiving_status,</if>
  87. <if test="data.msgId != null ">msg_id,</if>
  88. <if test="data.sopId != null ">sop_id,</if>
  89. <if test="data.remark != null ">remark,</if>
  90. <if test="data.corpId != null">corp_id,</if>
  91. <if test="data.customerId != null">customer_id,</if>
  92. <if test="data.fsUserId != null">fs_user_id,</if>
  93. <if test="data.takeRecords != null">take_records,</if>
  94. <if test="data.sort != null">sort,</if>
  95. </trim>
  96. <trim prefix="values (" suffix=")" suffixOverrides=",">
  97. <if test="data.qwUserid != null">#{data.qwUserid},</if>
  98. <if test="data.externalUserId != null">#{data.externalUserId},</if>
  99. <if test="data.externalId != null">#{data.externalId},</if>
  100. <if test="data.externalUserName != null">#{data.externalUserName},</if>
  101. <if test="data.logType != null">#{data.logType},</if>
  102. <if test="data.contentJson != null">#{data.contentJson},</if>
  103. <if test="data.sendStatus != null">#{data.sendStatus},</if>
  104. <if test="data.sendTime != null">#{data.sendTime},</if>
  105. <if test="data.realSendTime != null">#{data.realSendTime},</if>
  106. <if test="data.sendType != null ">#{data.sendType},</if>
  107. <if test="data.companyId != null">#{data.companyId},</if>
  108. <if test="data.receivingStatus != null "> #{data.receivingStatus},</if>
  109. <if test="data.msgId != null ">#{data.msgId},</if>
  110. <if test="data.sopId != null ">#{data.sopId},</if>
  111. <if test="data.remark != null ">#{data.remark},</if>
  112. <if test="data.corpId != null">#{data.corpId},</if>
  113. <if test="data.customerId != null">#{data.customerId},</if>
  114. <if test="data.fsUserId != null">#{data.fsUserId},</if>
  115. <if test="data.takeRecords != null">#{data.takeRecords},</if>
  116. <if test="data.sort != null">#{data.sort},</if>
  117. </trim>
  118. </insert>
  119. <update id="updateQwSopLogs" parameterType="QwSopLogs" >
  120. update qw_sop_logs
  121. <trim prefix="SET" suffixOverrides=",">
  122. <if test="data.externalUserName != null">external_user_name = #{data.externalUserName},</if>
  123. <if test="data.logType != null">log_type = #{data.logType},</if>
  124. <if test="data.contentJson != null">content_json = #{data.contentJson},</if>
  125. <if test="data.sendStatus != null">send_status = #{data.sendStatus},</if>
  126. <if test="data.sendTime != null">send_time = #{data.sendTime},</if>
  127. <if test="data.realSendTime != null">real_send_time = #{data.realSendTime},</if>
  128. <if test="data.companyId != null">company_id = #{data.companyId},</if>
  129. <if test="data.receivingStatus != null ">receiving_status = #{data.receivingStatus},</if>
  130. <if test="data.msgId != null ">msg_id = #{data.msgId},</if>
  131. <if test="data.sendType != null ">send_type = #{data.sendType},</if>
  132. <if test="data.sopId != null ">sop_id = #{data.sopId},</if>
  133. <if test="data.customerId != null ">customer_id = #{data.customerId},</if>
  134. <if test="data.remark != null ">remark = #{data.remark},</if>
  135. <if test="data.fsUserId != null ">fs_user_id = #{data.fsUserId},</if>
  136. <if test="data.sort != null ">sort = #{data.sort},</if>
  137. </trim>
  138. where id = #{data.id}
  139. </update>
  140. <select id="selectQwSopLogsDoSendList" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  141. <![CDATA[
  142. select ql.id as id,
  143. ql.qw_userid,
  144. ql.external_user_id,
  145. ql.external_id,
  146. ql.external_user_name,
  147. qs.name,
  148. ql.content_json,
  149. ql.send_time,
  150. ql.fs_user_id,
  151. qs.expiry_time as expiryTime
  152. from qw_sop_logs ql
  153. INNER join qw_sop qs on qs.id = ql.sop_id
  154. where ql.qw_userid=#{qwUserId} and ql.corp_id=#{corpId}
  155. and ql.log_type = 2
  156. and ql.send_type = 2
  157. and ql.send_status = 3
  158. and ql.send_time <= now()
  159. order by ql.send_time desc
  160. limit 5
  161. ]]>
  162. </select>
  163. <select id="selectQwSopLogsListByQwSopId" parameterType="com.fs.sop.params.QwSopLogsParam" resultType="com.fs.sop.vo.QwSopLogsListCVO" >
  164. SELECT * FROM qw_sop_logs
  165. <where>
  166. <if test="map.sopId != null">sop_id = #{map.sopId}</if>
  167. <if test="map.corpId != null">AND corp_id = #{map.corpId}</if>
  168. <if test="map.sendType != null">AND send_type = #{map.sendType}</if>
  169. <if test="map.sendStatus != null">AND send_status = #{map.sendStatus}</if>
  170. <if test="map.receivingStatus != null">AND receiving_status = #{map.receivingStatus}</if>
  171. <if test="map.qwUserid != null and map.qwUserid !='' ">AND qw_userid = #{map.qwUserid}</if>
  172. <if test="map.externalUserName != null and map.externalUserName!= '' ">AND external_user_name = #{map.externalUserName}</if>
  173. <if test="map.scheduleStartTime != null">AND send_time &gt;= #{map.scheduleStartTime}</if>
  174. <if test="map.scheduleEndTime != null">AND send_time &lt;= #{map.scheduleEndTime}</if>
  175. <if test="map.qwUseridByList != null">AND qw_userid IN
  176. <foreach collection="map.qwUseridByList" item="item" open="(" separator="," close=")">
  177. #{item}
  178. </foreach></if>
  179. </where>
  180. ORDER BY send_time desc,real_send_time desc
  181. </select>
  182. <update id="updateQwSopLogsByWatchLogType" >
  183. UPDATE qw_sop_logs
  184. SET
  185. send_status = 5,
  186. receiving_status = 4,
  187. remark = #{remark},
  188. real_send_time = NOW()
  189. WHERE
  190. id = #{id}
  191. </update>
  192. <update id="updateQwSopLogsBycollectIds" useGeneratedKeys="false" keyProperty="id" >
  193. UPDATE qw_sop_logs SET
  194. send_status = #{sendStatus},
  195. msg_id = #{msgId},
  196. real_send_time = NOW()
  197. WHERE id IN
  198. <foreach collection="collectIds" item="id" open="(" separator="," close=")">
  199. #{id}
  200. </foreach>
  201. </update>
  202. <update id="batchUpdateStatus" parameterType="java.util.List" >
  203. UPDATE qw_sop_logs
  204. SET send_status = CASE
  205. <foreach collection="list" item="item">
  206. WHEN id = #{item.id} THEN #{item.sendStatus}
  207. </foreach>
  208. END,
  209. msg_id = CASE
  210. <foreach collection="list" item="item">
  211. WHEN id = #{item.id} THEN #{item.msgId}
  212. </foreach>
  213. END,
  214. real_send_time = NOW()
  215. WHERE id IN
  216. <foreach collection="list" item="item" open="(" separator="," close=")">
  217. #{item.id}
  218. </foreach>
  219. </update>
  220. <update id="batchUpdateStatusByQwResult" parameterType="java.util.List" >
  221. UPDATE qw_sop_logs
  222. SET
  223. send_status = CASE
  224. <foreach collection="list" item="item">
  225. WHEN id = #{item.id} AND #{item.sendStatus} IS NOT NULL THEN #{item.sendStatus}
  226. </foreach>
  227. ELSE send_status
  228. END,
  229. send_type = CASE
  230. <foreach collection="list" item="item">
  231. WHEN id = #{item.id} AND #{item.sendType} IS NOT NULL THEN #{item.sendType}
  232. </foreach>
  233. ELSE send_type
  234. END,
  235. send_time = CASE
  236. <foreach collection="list" item="item">
  237. WHEN id = #{item.id} AND #{item.sendTime} IS NOT NULL THEN #{item.sendTime}
  238. </foreach>
  239. ELSE send_time
  240. END,
  241. receiving_status = CASE
  242. <foreach collection="list" item="item">
  243. WHEN id = #{item.id} AND #{item.receivingStatus} IS NOT NULL THEN #{item.receivingStatus}
  244. </foreach>
  245. ELSE receiving_status
  246. END,
  247. remark = CASE
  248. <foreach collection="list" item="item">
  249. WHEN id = #{item.id} AND #{item.remark} IS NOT NULL THEN #{item.remark}
  250. </foreach>
  251. ELSE remark
  252. END
  253. WHERE id IN
  254. <foreach collection="list" item="item" open="(" separator="," close=")">
  255. #{item.id}
  256. </foreach>
  257. </update>
  258. <update id="editCourseQwSopLogs" parameterType="String">
  259. update qw_sop_logs
  260. SET send_status = 3, receiving_status = 0 , remark='再次补发记录', send_time = NOW(),real_send_time =null
  261. where id in
  262. <foreach item="id" collection="array" open="(" separator="," close=")">
  263. #{id}
  264. </foreach>
  265. </update>
  266. <delete id="deleteQwSopLogsById" parameterType="String">
  267. delete from qw_sop_logs where id = #{id}
  268. </delete>
  269. <delete id="deleteQwSopLogsByIds" parameterType="String">
  270. delete from qw_sop_logs
  271. where id in
  272. <foreach item="id" collection="array" open="(" separator="," close=")">
  273. #{id}
  274. </foreach>
  275. </delete>
  276. <update id="deleteQwSopLogsBySopID" parameterType="String">
  277. update qw_sop_logs
  278. SET send_status = 5, receiving_status = 2 , remark='已删除' where sop_id in
  279. <foreach item="id" collection="array" open="(" separator="," close=")">
  280. #{id}
  281. </foreach>
  282. </update>
  283. <update id="updateQwSopLogsBySendStatus">
  284. <![CDATA[
  285. update qw_sop_logs
  286. set
  287. send_status = 5,
  288. receiving_status = 4,
  289. remark = '已过期,不发送',
  290. real_send_time = NOW()
  291. WHERE
  292. send_status = '3'
  293. AND send_time <= NOW() - INTERVAL (
  294. SELECT expiry_time
  295. FROM qw_sop
  296. WHERE id IN (SELECT sop_id FROM qw_sop_logs WHERE send_status = '3')
  297. LIMIT 1
  298. ) HOUR
  299. ]]>
  300. </update>
  301. <select id="checkQwSopLogs" resultType="QwSopLogs" >
  302. <![CDATA[
  303. select * from qw_sop_logs where log_type=2 and send_status=3 and send_type=1 and send_time <= NOW()
  304. ]]>
  305. </select>
  306. <select id="selectSopLogsByCreateCorpMassSending" parameterType="String" resultType="QwSopLogs" >
  307. <![CDATA[
  308. select * from qw_sop_logs where log_type=2 and send_status=3 and send_type=1 and send_time >= #{date}
  309. ]]>
  310. </select>
  311. <select id="selectSopLogsByCreateCorpMassSendResult" resultType="QwSopLogs" >
  312. <![CDATA[
  313. SELECT
  314. *
  315. FROM
  316. qw_sop_logs
  317. WHERE
  318. log_type = 2
  319. AND send_type = 1
  320. AND send_status = 1
  321. AND receiving_status = 0
  322. AND msg_id IS NOT NULL
  323. AND send_time BETWEEN DATE_SUB( NOW(), INTERVAL 1 DAY )
  324. AND NOW()
  325. ]]>
  326. </select>
  327. <select id="qwSopLogsResult" resultType="QwSopLogs">
  328. <![CDATA[
  329. select * from qw_sop_logs
  330. where log_type=2
  331. and send_type=1
  332. and send_status=1
  333. and receiving_status=0
  334. AND send_time BETWEEN DATE_SUB(NOW(), INTERVAL 3 DAY) AND NOW()
  335. ]]>
  336. </select>
  337. <select id="getQwSopLogsByJsApiAll" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  338. <![CDATA[
  339. select ql.id as id,
  340. ql.qw_userid,
  341. ql.external_user_id,
  342. ql.external_id,
  343. ql.external_user_name,
  344. qs.name,
  345. ql.content_json,
  346. ql.send_time,
  347. ql.fs_user_id,
  348. ql.send_type,
  349. qs.expiry_time as expiryTime
  350. from qw_sop_logs ql
  351. left join qw_sop qs on qs.id = ql.sop_id
  352. where ql.qw_userid=#{data.qwUserId}
  353. and ql.corp_id=#{data.corpId}
  354. and ql.external_user_id =#{data.externalUserId}
  355. and ql.log_type = 2
  356. and ql.send_status = 3
  357. and ql.send_type != 1
  358. and ql.receiving_status = 0
  359. and ql.send_time <= now()
  360. order by ql.sort DESC ,ql.send_time asc
  361. LIMIT 2
  362. ]]>
  363. </select>
  364. <select id="getQwSopLogsByJsApi" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  365. <![CDATA[
  366. select ql.id as id,
  367. ql.qw_userid,
  368. ql.external_user_id,
  369. ql.external_id,
  370. ql.external_user_name,
  371. qs.name,
  372. ql.content_json,
  373. ql.send_time,
  374. ql.fs_user_id,
  375. qs.expiry_time as expiryTime
  376. from qw_sop_logs ql
  377. left join qw_sop qs on qs.id = ql.sop_id
  378. where ql.qw_userid=#{data.qwUserId}
  379. and ql.corp_id=#{data.corpId}
  380. and ql.external_user_id =#{data.externalUserId}
  381. and ql.log_type = 2
  382. and ql.send_type in (2,5,7)
  383. and ql.send_status = 3
  384. and ql.receiving_status = 0
  385. and ql.send_time <= now()
  386. order by ql.sort DESC ,ql.send_time asc
  387. ]]>
  388. </select>
  389. <select id="getQwSopLogsByJsApiOver" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  390. <![CDATA[
  391. select ql.id as id,
  392. ql.qw_userid,
  393. ql.external_user_id,
  394. ql.external_id,
  395. ql.external_user_name,
  396. ql.content_json,
  397. ql.send_time,
  398. ql.fs_user_id
  399. from qw_sop_logs ql
  400. where ql.qw_userid=#{data.qwUserId}
  401. and ql.corp_id=#{data.corpId}
  402. and ql.external_user_id =#{data.externalUserId}
  403. and ql.log_type = 2
  404. and ql.send_type = 3
  405. and ql.send_status = 3
  406. and ql.receiving_status = 0
  407. and ql.send_time <= now()
  408. order by ql.sort DESC ,ql.send_time asc
  409. ]]>
  410. </select>
  411. <select id="getExpiredMessagesByQwSopLogs" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  412. <![CDATA[
  413. SELECT
  414. ql.id
  415. FROM
  416. qw_sop_logs ql
  417. LEFT JOIN qw_sop qs ON qs.id = ql.sop_id
  418. WHERE
  419. ql.log_type = 2
  420. AND ql.send_type IN (2, 5)
  421. AND ql.send_status = 3
  422. AND ql.receiving_status = 0
  423. AND ql.send_time <= now()
  424. AND (qs.expiry_time IS NOT NULL AND ql.send_time <= now() - interval qs.expiry_time hour)
  425. ORDER BY
  426. ql.sort DESC,
  427. ql.send_time asc;
  428. ]]>
  429. </select>
  430. <select id="getQwSopLogsByJsApiNext" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="QwSopLogs">
  431. <![CDATA[
  432. SELECT external_user_id,external_id,send_type
  433. FROM qw_sop_logs
  434. WHERE qw_userid = #{data.qwUserId}
  435. AND corp_id = #{data.corpId}
  436. AND external_user_id != #{data.externalUserId}
  437. AND log_type = 2
  438. AND send_status = 3
  439. AND send_type != 1
  440. AND receiving_status = 0
  441. AND send_time <= now()
  442. ORDER BY sort DESC,send_time ASC, rand()
  443. LIMIT 1
  444. ]]>
  445. </select>
  446. <delete id="deleteQwSopLogsByJsApi" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" >
  447. delete FROM qw_sop_logs
  448. where qw_userid = #{data.qwUserId}
  449. AND corp_id = #{data.corpId}
  450. AND external_user_id = #{data.externalUserId}
  451. </delete>
  452. <delete id="deleteQwSopLogsByRemoveSop" parameterType="String" >
  453. delete FROM qw_sop_logs
  454. where qw_userid = #{qwUserId}
  455. AND corp_id = #{corpId}
  456. AND sop_id = #{sopId}
  457. </delete>
  458. <delete id="deleteQwSopLogsByExternalUserIdList" parameterType="com.fs.sop.params.DeleteQwSopParam" >
  459. delete FROM qw_sop_logs
  460. where qw_userid = #{data.qwUserId}
  461. AND corp_id = #{data.corpId}
  462. AND external_user_id IN
  463. <foreach collection="data.externalUserIds" item="extId" open="(" separator="," close=")">
  464. #{extId}
  465. </foreach>
  466. </delete>
  467. <insert id="batchInsertQwSopLogsOneTouch" parameterType="java.util.List" useGeneratedKeys="false">
  468. INSERT INTO qw_sop_logs
  469. (
  470. qw_userid, external_user_id,external_id, external_user_name, log_type,
  471. content_json, send_status, send_time, real_send_time, send_type,
  472. company_id, receiving_status, msg_id, sop_id, remark,
  473. corp_id, customer_id, fs_user_id,sort
  474. )
  475. VALUES
  476. <foreach collection="qwSopLogs" item="log" separator=",">
  477. (
  478. #{log.qwUserid},
  479. #{log.externalUserId},
  480. #{log.externalId},
  481. #{log.externalUserName},
  482. #{log.logType},
  483. #{log.contentJson},
  484. #{log.sendStatus},
  485. #{log.sendTime},
  486. #{log.realSendTime},
  487. #{log.sendType},
  488. #{log.companyId},
  489. #{log.receivingStatus},
  490. #{log.msgId},
  491. #{log.sopId},
  492. #{log.remark},
  493. #{log.corpId},
  494. #{log.customerId},
  495. #{log.fsUserId},
  496. #{log.sort}
  497. )
  498. </foreach>
  499. </insert>
  500. <!-- 批量插入 QwSopLogs -->
  501. <insert id="batchInsertQwSopLogs" parameterType="java.util.List" useGeneratedKeys="false">
  502. INSERT INTO qw_sop_logs
  503. (
  504. qw_userid, external_user_id,external_id, external_user_name, log_type,
  505. content_json, send_status, send_time, real_send_time, send_type,
  506. company_id, receiving_status, msg_id, sop_id, remark,
  507. corp_id, customer_id, fs_user_id, expiration_time
  508. )
  509. VALUES
  510. <foreach collection="qwSopLogs" item="log" separator=",">
  511. (
  512. #{log.qwUserid},
  513. #{log.externalUserId},
  514. #{log.externalId},
  515. #{log.externalUserName},
  516. #{log.logType},
  517. #{log.contentJson},
  518. #{log.sendStatus},
  519. #{log.sendTime},
  520. #{log.realSendTime},
  521. #{log.sendType},
  522. #{log.companyId},
  523. #{log.receivingStatus},
  524. #{log.msgId},
  525. #{log.sopId},
  526. #{log.remark},
  527. #{log.corpId},
  528. #{log.customerId},
  529. #{log.fsUserId},
  530. #{log.expirationTime}
  531. )
  532. </foreach>
  533. </insert>
  534. <!-- 批量更新 QwSopLogs -->
  535. <update id="batchUpdateQwSopLogsByTakeRecordsList" parameterType="java.util.List" useGeneratedKeys="false">
  536. UPDATE qw_sop_logs
  537. SET take_records = 1
  538. WHERE id IN
  539. <foreach collection="data" item="log" open="(" separator="," close=")">
  540. #{log.id}
  541. </foreach>
  542. </update>
  543. <update id="updateQwSopLogsByDeleted" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" useGeneratedKeys="false">
  544. <![CDATA[
  545. UPDATE qw_sop_logs
  546. SET
  547. send_status = 5,
  548. receiving_status = 4,
  549. remark = '非外部联系人',
  550. real_send_time = NOW()
  551. WHERE qw_userid = #{data.qwUserId}
  552. AND corp_id = #{data.corpId}
  553. AND external_user_id = #{data.externalUserId}
  554. AND send_time <= now()
  555. ]]>
  556. </update>
  557. <!-- 批量更新 QwSopLogs -->
  558. <update id="batchUpdateQwSopLogsBySendTime" parameterType="java.util.List" useGeneratedKeys="false">
  559. UPDATE qw_sop_logs
  560. SET
  561. send_status = 5,
  562. receiving_status = 4,
  563. remark = '已过期,不发送',
  564. real_send_time = NOW()
  565. WHERE id IN
  566. <foreach collection="data" item="log" open="(" separator="," close=")">
  567. #{log.id}
  568. </foreach>
  569. </update>
  570. <select id="selectQwSopLogsByCancel" resultMap="QwSopLogsResult">
  571. <include refid="selectQwSopLogsVo"/>
  572. <![CDATA[
  573. WHERE send_type = 3
  574. AND send_status = 5
  575. AND receiving_status = 4
  576. AND remark = '已过期,不发送'
  577. AND real_send_time >= now() - INTERVAL 1 HOUR
  578. AND real_send_time < now()
  579. ]]>
  580. </select>
  581. <select id="getWxMsgByAccountId" resultType="com.fs.sop.domain.QwSopLogs">
  582. SELECT * FROM `qw_sop_logs` where log_type = 1 and qw_userid = #{accountId} and DATE_FORMAT(send_time, "%Y-%m-%d") = DATE_FORMAT(now(), "%Y-%m-%d")
  583. </select>
  584. <!-- 批量更新 QwSopLogs -->
  585. <update id="batchUpdateQwSopLogsByCancel" parameterType="java.util.List" useGeneratedKeys="false">
  586. UPDATE qw_sop_logs
  587. SET
  588. send_status = 3,
  589. receiving_status = 0,
  590. remark = null,
  591. real_send_time = null,
  592. send_time = DATE_ADD(now(), INTERVAL 30 MINUTE)
  593. WHERE id IN
  594. <foreach collection="data" item="log" open="(" separator="," close=")">
  595. #{log.id}
  596. </foreach>
  597. </update>
  598. <delete id="deleteQwSopLogsByDate" >
  599. <![CDATA[
  600. DELETE FROM qw_sop_logs WHERE DATE(send_time) < CURDATE() - INTERVAL 2 DAY;
  601. ]]>
  602. </delete>
  603. <select id="selectQwSopLogsListByChatSopId" resultType="com.fs.sop.vo.QwSopLogsListCVO">
  604. SELECT * FROM qw_sop_logs
  605. <where>
  606. <if test="map.sopId != null">sop_id = #{map.sopId}</if>
  607. <if test="map.corpId != null">AND corp_id = #{map.corpId}</if>
  608. <if test="map.sendType != null">AND send_type = #{map.sendType}</if>
  609. <if test="map.sendStatus != null">AND send_status = #{map.sendStatus}</if>
  610. <if test="map.receivingStatus != null">AND receiving_status = #{map.receivingStatus}</if>
  611. <if test="map.qwUserid != null and map.qwUserid !='' ">AND qw_userid = #{map.qwUserid}</if>
  612. <if test="map.externalUserName != null and map.externalUserName!= '' ">AND external_user_name = #{map.externalUserName}</if>
  613. <if test="map.scheduleStartTime != null">AND send_time &gt;= #{map.scheduleStartTime}</if>
  614. <if test="map.scheduleEndTime != null">AND send_time &lt;= #{map.scheduleEndTime}</if>
  615. </where>
  616. ORDER BY send_time desc
  617. </select>
  618. </mapper>