QwSopLogsMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. <result property="qwUserKey" column="qw_user_key" />
  30. <result property="userLogsId" column="user_logs_id" />
  31. </resultMap>
  32. <sql id="selectQwSopLogsVo">
  33. 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
  34. </sql>
  35. <select id="selectQwSopLogsListVO" parameterType="QwSopLogs" resultMap="QwSopLogsResult">
  36. <include refid="selectQwSopLogsVo"/>
  37. <where>
  38. <if test="qwUserid != null "> and qw_userid = #{qwUserid}</if>
  39. <if test="externalUserId != null and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
  40. <if test="externalId != null and externalId != ''"> and external_id = #{externalId}</if>
  41. <if test="sendStatus != null "> and send_status = #{sendStatus}</if>
  42. <if test="corpId != null "> and corp_id = #{corpId}</if>
  43. </where>
  44. order by send_time desc
  45. </select>
  46. <select id="selectQwSopLogsList" parameterType="QwSopLogs" resultMap="QwSopLogsResult">
  47. <include refid="selectQwSopLogsVo"/>
  48. <where>
  49. <if test="qwUserid != null "> and qw_userid = #{qwUserid}</if>
  50. <if test="externalUserId != null and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
  51. <if test="externalId != null and externalId != ''"> and external_id = #{externalId}</if>
  52. <if test="externalUserName != null and externalUserName != ''"> and external_user_name = #{externalUserName}</if>
  53. <if test="logType != null and logType != ''"> and log_type = #{logType}</if>
  54. <if test="contentJson != null and contentJson != ''"> and content_json = #{contentJson}</if>
  55. <if test="sendStatus != null "> and send_status = #{sendStatus}</if>
  56. <if test="sendTime != null "> and send_time = #{sendTime}</if>
  57. <if test="realSendTime != null "> and real_send_time = #{realSendTime}</if>
  58. <if test="companyId != null "> and company_id = #{companyId}</if>
  59. <if test="receivingStatus != null "> and receiving_status = #{receivingStatus}</if>
  60. <if test="msgId != null "> and msg_id = #{msgId}</if>
  61. <if test="corpId != null "> and corp_id = #{corpId}</if>
  62. <if test="sendType != null "> and send_type = #{sendType}</if>
  63. <if test="sopId != null "> and sop_id = #{sopId}</if>
  64. <if test="remark != null "> and remark = #{remark}</if>
  65. <if test="customerId != null "> and customer_id = #{customerId}</if>
  66. <if test="fsUserId != null "> and fs_user_id = #{fsUserId}</if>
  67. <if test="takeRecords != null "> and take_records = #{takeRecords}</if>
  68. </where>
  69. </select>
  70. <select id="selectQwSopLogsById" parameterType="String" resultMap="QwSopLogsResult">
  71. <include refid="selectQwSopLogsVo"/>
  72. where id = #{id} order by send_time
  73. </select>
  74. <insert id="insertQwSopLogs" parameterType="QwSopLogs" useGeneratedKeys="false">
  75. insert into qw_sop_logs
  76. <trim prefix="(" suffix=")" suffixOverrides=",">
  77. <if test="data.qwUserid != null">qw_userid,</if>
  78. <if test="data.externalUserId != null">external_user_id,</if>
  79. <if test="data.externalId != null">external_id,</if>
  80. <if test="data.externalUserName != null">external_user_name,</if>
  81. <if test="data.logType != null">log_type,</if>
  82. <if test="data.contentJson != null">content_json,</if>
  83. <if test="data.sendStatus != null">send_status,</if>
  84. <if test="data.sendTime != null">send_time,</if>
  85. <if test="data.realSendTime != null">real_send_time,</if>
  86. <if test="data.sendType != null ">send_type,</if>
  87. <if test="data.companyId != null">company_id,</if>
  88. <if test="data.receivingStatus != null ">receiving_status,</if>
  89. <if test="data.msgId != null ">msg_id,</if>
  90. <if test="data.sopId != null ">sop_id,</if>
  91. <if test="data.remark != null ">remark,</if>
  92. <if test="data.corpId != null">corp_id,</if>
  93. <if test="data.customerId != null">customer_id,</if>
  94. <if test="data.fsUserId != null">fs_user_id,</if>
  95. <if test="data.takeRecords != null">take_records,</if>
  96. <if test="data.sort != null">sort,</if>
  97. <if test="data.userLogsId != null">user_logs_id,</if>
  98. <if test="data.qwUserKey != null">qw_user_key,</if>
  99. </trim>
  100. <trim prefix="values (" suffix=")" suffixOverrides=",">
  101. <if test="data.qwUserid != null">#{data.qwUserid},</if>
  102. <if test="data.externalUserId != null">#{data.externalUserId},</if>
  103. <if test="data.externalId != null">#{data.externalId},</if>
  104. <if test="data.externalUserName != null">#{data.externalUserName},</if>
  105. <if test="data.logType != null">#{data.logType},</if>
  106. <if test="data.contentJson != null">#{data.contentJson},</if>
  107. <if test="data.sendStatus != null">#{data.sendStatus},</if>
  108. <if test="data.sendTime != null">#{data.sendTime},</if>
  109. <if test="data.realSendTime != null">#{data.realSendTime},</if>
  110. <if test="data.sendType != null ">#{data.sendType},</if>
  111. <if test="data.companyId != null">#{data.companyId},</if>
  112. <if test="data.receivingStatus != null "> #{data.receivingStatus},</if>
  113. <if test="data.msgId != null ">#{data.msgId},</if>
  114. <if test="data.sopId != null ">#{data.sopId},</if>
  115. <if test="data.remark != null ">#{data.remark},</if>
  116. <if test="data.corpId != null">#{data.corpId},</if>
  117. <if test="data.customerId != null">#{data.customerId},</if>
  118. <if test="data.fsUserId != null">#{data.fsUserId},</if>
  119. <if test="data.takeRecords != null">#{data.takeRecords},</if>
  120. <if test="data.sort != null">#{data.sort},</if>
  121. <if test="data.userLogsId != null">#{data.userLogsId},</if>
  122. <if test="data.qwUserKey != null">#{data.qwUserKey},</if>
  123. </trim>
  124. </insert>
  125. <update id="updateQwSopLogs" parameterType="QwSopLogs" >
  126. update qw_sop_logs
  127. <trim prefix="SET" suffixOverrides=",">
  128. <if test="data.externalUserName != null">external_user_name = #{data.externalUserName},</if>
  129. <if test="data.logType != null">log_type = #{data.logType},</if>
  130. <if test="data.contentJson != null">content_json = #{data.contentJson},</if>
  131. <if test="data.sendStatus != null">send_status = #{data.sendStatus},</if>
  132. <if test="data.sendTime != null">send_time = #{data.sendTime},</if>
  133. <if test="data.realSendTime != null">real_send_time = #{data.realSendTime},</if>
  134. <if test="data.companyId != null">company_id = #{data.companyId},</if>
  135. <if test="data.receivingStatus != null ">receiving_status = #{data.receivingStatus},</if>
  136. <if test="data.msgId != null ">msg_id = #{data.msgId},</if>
  137. <if test="data.sendType != null ">send_type = #{data.sendType},</if>
  138. <if test="data.sopId != null ">sop_id = #{data.sopId},</if>
  139. <if test="data.customerId != null ">customer_id = #{data.customerId},</if>
  140. <if test="data.remark != null ">remark = #{data.remark},</if>
  141. <if test="data.fsUserId != null ">fs_user_id = #{data.fsUserId},</if>
  142. <if test="data.sort != null ">sort = #{data.sort},</if>
  143. <if test="data.qwUserKey != null ">qw_user_key = #{data.qwUserKey},</if>
  144. </trim>
  145. where id = #{data.id}
  146. </update>
  147. <select id="selectQwSopLogsDoSendList" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  148. <![CDATA[
  149. select ql.id as id,
  150. ql.qw_userid,
  151. ql.external_user_id,
  152. ql.external_id,
  153. ql.external_user_name,
  154. qs.name,
  155. ql.content_json,
  156. ql.send_time,
  157. ql.fs_user_id,
  158. qs.expiry_time as expiryTime
  159. from qw_sop_logs ql
  160. INNER join qw_sop qs on qs.id = ql.sop_id
  161. where ql.qw_userid=#{qwUserId} and ql.corp_id=#{corpId}
  162. and ql.log_type = 2
  163. and ql.send_type = 2
  164. and ql.send_status = 3
  165. and ql.send_time <= now()
  166. order by ql.send_time desc
  167. limit 5
  168. ]]>
  169. </select>
  170. <select id="selectQwSopLogsListByQwSopId" parameterType="com.fs.sop.params.QwSopLogsParam" resultType="com.fs.sop.vo.QwSopLogsListCVO" >
  171. SELECT * FROM qw_sop_logs
  172. <where>
  173. <if test="map.sopId != null">sop_id = #{map.sopId}</if>
  174. <if test="map.corpId != null">AND corp_id = #{map.corpId}</if>
  175. <if test="map.sendType != null">AND send_type = #{map.sendType}</if>
  176. <if test="map.sendStatus != null">AND send_status = #{map.sendStatus}</if>
  177. <if test="map.receivingStatus != null">AND receiving_status = #{map.receivingStatus}</if>
  178. <if test="map.qwUserid != null and map.qwUserid !='' ">AND qw_userid = #{map.qwUserid}</if>
  179. <if test="map.externalUserName != null and map.externalUserName!= '' ">AND external_user_name = #{map.externalUserName}</if>
  180. <if test="map.scheduleStartTime != null">AND send_time &gt;= #{map.scheduleStartTime}</if>
  181. <if test="map.scheduleEndTime != null">AND send_time &lt;= #{map.scheduleEndTime}</if>
  182. <if test="map.qwUseridByList != null">AND qw_userid IN
  183. <foreach collection="map.qwUseridByList" item="item" open="(" separator="," close=")">
  184. #{item}
  185. </foreach>
  186. </if>
  187. <if test="map.qwUseridList != null and map.qwUseridList.size() > 0">
  188. AND qw_userid IN
  189. <foreach collection="map.qwUseridList" item="item" open="(" separator="," close=")">
  190. #{item}
  191. </foreach>
  192. </if>
  193. <if test="map.qwUserKeyList != null and !map.qwUserKeyList.isEmpty() ">
  194. AND qw_user_key IN
  195. <foreach collection='map.qwUserKeyList' item='item' open='(' separator=',' close=')'>
  196. #{item}
  197. </foreach>
  198. </if>
  199. </where>
  200. ORDER BY send_time desc,real_send_time desc
  201. </select>
  202. <update id="updateQwSopLogsByWatchLogType" >
  203. UPDATE qw_sop_logs
  204. SET
  205. send_status = 5,
  206. receiving_status = 4,
  207. remark = #{remark},
  208. real_send_time = NOW()
  209. WHERE
  210. id = #{id}
  211. </update>
  212. <update id="updateQwSopLogsBycollectIds" useGeneratedKeys="false" keyProperty="id" >
  213. UPDATE qw_sop_logs SET
  214. send_status = #{sendStatus},
  215. msg_id = #{msgId},
  216. real_send_time = NOW()
  217. WHERE id IN
  218. <foreach collection="collectIds" item="id" open="(" separator="," close=")">
  219. #{id}
  220. </foreach>
  221. </update>
  222. <update id="batchUpdateStatus" parameterType="java.util.List" >
  223. UPDATE qw_sop_logs
  224. SET send_status = CASE
  225. <foreach collection="list" item="item">
  226. WHEN id = #{item.id} THEN #{item.sendStatus}
  227. </foreach>
  228. else send_status
  229. END,
  230. msg_id = CASE
  231. <foreach collection="list" item="item">
  232. WHEN id = #{item.id} AND #{item.msgId} IS NOT NULL THEN #{item.msgId}
  233. </foreach>
  234. ELSE msg_id
  235. END,
  236. send_type = CASE
  237. <foreach collection="list" item="item">
  238. WHEN id = #{item.id} AND #{item.sendType} IS NOT NULL THEN #{item.sendType}
  239. </foreach>
  240. ELSE send_type
  241. END,
  242. send_time = CASE
  243. <foreach collection="list" item="item">
  244. WHEN id = #{item.id} AND #{item.sendTime} IS NOT NULL THEN #{item.sendTime}
  245. </foreach>
  246. ELSE send_time
  247. END,
  248. receiving_status = CASE
  249. <foreach collection="list" item="item">
  250. WHEN id = #{item.id} AND #{item.receivingStatus} IS NOT NULL THEN #{item.receivingStatus}
  251. </foreach>
  252. ELSE receiving_status
  253. END,
  254. qw_user_key = CASE
  255. <foreach collection="list" item="item">
  256. WHEN id = #{item.id} AND #{item.qwUserKey} IS NOT NULL THEN #{item.qwUserKey}
  257. </foreach>
  258. ELSE qw_user_key
  259. END,
  260. remark = CASE
  261. <foreach collection="list" item="item">
  262. WHEN id = #{item.id} AND #{item.remark} IS NOT NULL THEN #{item.remark}
  263. </foreach>
  264. ELSE remark
  265. END,
  266. sort = CASE
  267. <foreach collection="list" item="item">
  268. WHEN id = #{item.id} AND #{item.sort} IS NOT NULL THEN #{item.sort}
  269. </foreach>
  270. ELSE sort
  271. END,
  272. real_send_time = NOW()
  273. WHERE id IN
  274. <foreach collection="list" item="item" open="(" separator="," close=")">
  275. #{item.id}
  276. </foreach>
  277. </update>
  278. <update id="batchUpdateStatusByQwResult" parameterType="java.util.List" >
  279. UPDATE qw_sop_logs
  280. SET
  281. send_status = CASE
  282. <foreach collection="list" item="item">
  283. WHEN id = #{item.id} AND #{item.sendStatus} IS NOT NULL THEN #{item.sendStatus}
  284. </foreach>
  285. ELSE send_status
  286. END,
  287. send_type = CASE
  288. <foreach collection="list" item="item">
  289. WHEN id = #{item.id} AND #{item.sendType} IS NOT NULL THEN #{item.sendType}
  290. </foreach>
  291. ELSE send_type
  292. END,
  293. send_time = CASE
  294. <foreach collection="list" item="item">
  295. WHEN id = #{item.id} AND #{item.sendTime} IS NOT NULL THEN #{item.sendTime}
  296. </foreach>
  297. ELSE send_time
  298. END,
  299. qw_user_key = CASE
  300. <foreach collection="list" item="item">
  301. WHEN id = #{item.id} AND #{item.qwUserKey} IS NOT NULL THEN #{item.qwUserKey}
  302. </foreach>
  303. ELSE qw_user_key
  304. END,
  305. receiving_status = CASE
  306. <foreach collection="list" item="item">
  307. WHEN id = #{item.id} AND #{item.receivingStatus} IS NOT NULL THEN #{item.receivingStatus}
  308. </foreach>
  309. ELSE receiving_status
  310. END,
  311. remark = CASE
  312. <foreach collection="list" item="item">
  313. WHEN id = #{item.id} AND #{item.remark} IS NOT NULL THEN #{item.remark}
  314. </foreach>
  315. ELSE remark
  316. END
  317. WHERE id IN
  318. <foreach collection="list" item="item" open="(" separator="," close=")">
  319. #{item.id}
  320. </foreach>
  321. </update>
  322. <update id="editCourseQwSopLogs" parameterType="String">
  323. update qw_sop_logs
  324. SET send_status = 3, receiving_status = 0 , remark='再次补发记录', send_time = NOW(),real_send_time =null
  325. where id in
  326. <foreach item="id" collection="array" open="(" separator="," close=")">
  327. #{id}
  328. </foreach>
  329. </update>
  330. <delete id="deleteQwSopLogsById" parameterType="String">
  331. delete from qw_sop_logs where id = #{id}
  332. </delete>
  333. <delete id="deleteQwSopLogsByIds" parameterType="String">
  334. delete from qw_sop_logs
  335. where id in
  336. <foreach item="id" collection="array" open="(" separator="," close=")">
  337. #{id}
  338. </foreach>
  339. </delete>
  340. <update id="deleteQwSopLogsBySopID" parameterType="String">
  341. update qw_sop_logs
  342. SET send_status = 5, receiving_status = 2 , remark='已删除' where sop_id in
  343. <foreach item="id" collection="array" open="(" separator="," close=")">
  344. #{id}
  345. </foreach>
  346. </update>
  347. <update id="updateQwSopLogsBySendStatus">
  348. <![CDATA[
  349. update qw_sop_logs
  350. set
  351. send_status = 5,
  352. receiving_status = 4,
  353. remark = '已过期,不发送',
  354. real_send_time = NOW()
  355. WHERE
  356. send_status = '3'
  357. AND send_time <= NOW() - INTERVAL (
  358. SELECT expiry_time
  359. FROM qw_sop
  360. WHERE id IN (SELECT sop_id FROM qw_sop_logs WHERE send_status = '3')
  361. LIMIT 1
  362. ) HOUR
  363. ]]>
  364. </update>
  365. <select id="checkQwSopLogs" resultType="QwSopLogs" >
  366. <![CDATA[
  367. select * from qw_sop_logs where log_type=2 and send_status=3 and send_type=1 and send_time <= NOW()
  368. ]]>
  369. </select>
  370. <select id="createCorpMassSending" parameterType="String" resultType="QwSopLogs" >
  371. <![CDATA[
  372. select * from qw_sop_logs
  373. where log_type=2
  374. and send_status=3
  375. and send_type=1
  376. and send_time >= #{date}
  377. AND take_records = 1
  378. ]]>
  379. </select>
  380. <select id="selectSopLogsByCreateCorpMassSending" parameterType="String" resultType="QwSopLogs" >
  381. <![CDATA[
  382. select * from qw_sop_logs
  383. where log_type=2
  384. and send_status=3
  385. and send_type=1
  386. AND send_time >= #{taskStartTime}
  387. AND send_time <= #{taskEndTime}
  388. AND take_records = 0
  389. ]]>
  390. </select>
  391. <select id="selectSopLogsByCreateCorpMassSendResult" resultType="QwSopLogs" >
  392. <![CDATA[
  393. SELECT
  394. *
  395. FROM
  396. qw_sop_logs
  397. WHERE
  398. log_type = 2
  399. AND send_type = 1
  400. AND send_status = 1
  401. AND receiving_status = 0
  402. AND msg_id IS NOT NULL
  403. AND send_time BETWEEN DATE_SUB( NOW(), INTERVAL 1 DAY )
  404. AND NOW()
  405. order by msg_id,send_time
  406. ]]>
  407. </select>
  408. <select id="qwSopLogsResult" resultType="QwSopLogs">
  409. <![CDATA[
  410. select * from qw_sop_logs
  411. where log_type=2
  412. and send_type=1
  413. and send_status=1
  414. and receiving_status=0
  415. AND send_time BETWEEN DATE_SUB(NOW(), INTERVAL 3 DAY) AND NOW()
  416. ]]>
  417. </select>
  418. <select id="getQwSopLogsByJsApiAll" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  419. <![CDATA[
  420. select ql.id as id,
  421. ql.qw_userid,
  422. ql.external_user_id,
  423. ql.external_id,
  424. ql.external_user_name,
  425. qs.name,
  426. ql.content_json,
  427. ql.send_time,
  428. ql.fs_user_id,
  429. ql.send_type,
  430. qs.expiry_time as expiryTime
  431. from qw_sop_logs ql
  432. left join qw_sop qs on qs.id = ql.sop_id
  433. where ql.qw_userid=#{data.qwUserId}
  434. and ql.corp_id=#{data.corpId}
  435. and ql.external_user_id =#{data.externalUserId}
  436. and ql.log_type = 2
  437. and ql.send_status = 3
  438. and ql.send_type != 1
  439. and ql.receiving_status = 0
  440. and ql.send_time <= now()
  441. order by ql.sort DESC ,ql.send_time asc
  442. LIMIT 2
  443. ]]>
  444. </select>
  445. <select id="getQwSopLogsByJsApi" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  446. <![CDATA[
  447. select ql.id as id,
  448. ql.qw_userid,
  449. ql.external_user_id,
  450. ql.external_id,
  451. ql.external_user_name,
  452. qs.name,
  453. ql.content_json,
  454. ql.send_time,
  455. ql.fs_user_id,
  456. qs.expiry_time as expiryTime
  457. from qw_sop_logs ql
  458. left join qw_sop qs on qs.id = ql.sop_id
  459. where ql.qw_userid=#{data.qwUserId}
  460. and ql.corp_id=#{data.corpId}
  461. and ql.external_user_id =#{data.externalUserId}
  462. and ql.log_type = 2
  463. and ql.send_type in (2,5,7)
  464. and ql.send_status = 3
  465. and ql.receiving_status = 0
  466. and ql.send_time <= now()
  467. order by ql.sort DESC ,ql.send_time asc
  468. ]]>
  469. </select>
  470. <select id="getQwSopLogsByJsApiOver" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  471. <![CDATA[
  472. select ql.id as id,
  473. ql.qw_userid,
  474. ql.external_user_id,
  475. ql.external_id,
  476. ql.external_user_name,
  477. ql.content_json,
  478. ql.send_time,
  479. ql.fs_user_id
  480. from qw_sop_logs ql
  481. where ql.qw_userid=#{data.qwUserId}
  482. and ql.corp_id=#{data.corpId}
  483. and ql.external_user_id =#{data.externalUserId}
  484. and ql.log_type = 2
  485. and ql.send_type = 3
  486. and ql.send_status = 3
  487. and ql.receiving_status = 0
  488. and ql.send_time <= now()
  489. order by ql.sort DESC ,ql.send_time asc
  490. ]]>
  491. </select>
  492. <select id="getExpiredMessagesByQwSopLogs" resultType="com.fs.sop.vo.QwSopLogsDoSendListTVO">
  493. <![CDATA[
  494. SELECT
  495. ql.id
  496. FROM
  497. qw_sop_logs ql
  498. LEFT JOIN qw_sop qs ON qs.id = ql.sop_id
  499. WHERE
  500. ql.log_type = 2
  501. AND ql.send_type IN (2,5,11)
  502. AND ql.send_status = 3
  503. AND ql.receiving_status = 0
  504. AND ql.send_time <= now()
  505. AND (qs.expiry_time IS NOT NULL AND ql.send_time <= now() - interval qs.expiry_time hour)
  506. ORDER BY
  507. ql.sort DESC,
  508. ql.send_time asc;
  509. ]]>
  510. </select>
  511. <select id="getQwSopLogsByJsApiNext" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" resultType="QwSopLogs">
  512. <![CDATA[
  513. SELECT external_user_id,external_id,send_type
  514. FROM qw_sop_logs
  515. WHERE qw_userid = #{data.qwUserId}
  516. AND corp_id = #{data.corpId}
  517. AND external_user_id != #{data.externalUserId}
  518. AND log_type = 2
  519. AND send_status = 3
  520. AND send_type != 1
  521. AND receiving_status = 0
  522. AND send_time <= now()
  523. ORDER BY sort DESC,send_time ASC, rand()
  524. LIMIT 1
  525. ]]>
  526. </select>
  527. <delete id="deleteQwSopLogsByJsApi" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" >
  528. delete FROM qw_sop_logs
  529. where qw_userid = #{data.qwUserId}
  530. AND corp_id = #{data.corpId}
  531. AND external_user_id = #{data.externalUserId}
  532. </delete>
  533. <delete id="deleteQwSopLogsByRemoveSop" parameterType="String" >
  534. delete FROM qw_sop_logs
  535. where qw_userid = #{qwUserId}
  536. AND corp_id = #{corpId}
  537. AND sop_id = #{sopId}
  538. </delete>
  539. <delete id="deleteQwSopLogsByExternalUserIdList" parameterType="com.fs.sop.params.DeleteQwSopParam" >
  540. delete FROM qw_sop_logs
  541. where qw_userid = #{data.qwUserId}
  542. AND corp_id = #{data.corpId}
  543. AND external_user_id IN
  544. <foreach collection="data.externalUserIds" item="extId" open="(" separator="," close=")">
  545. #{extId}
  546. </foreach>
  547. </delete>
  548. <insert id="batchInsertQwSopLogsOneTouch" parameterType="java.util.List" useGeneratedKeys="false">
  549. INSERT INTO qw_sop_logs
  550. (
  551. qw_userid, external_user_id,external_id, external_user_name, log_type,
  552. content_json, send_status, send_time, real_send_time, send_type,
  553. company_id, receiving_status, msg_id, sop_id, remark,
  554. corp_id, customer_id,fs_user_id,sort,qw_user_key
  555. )
  556. VALUES
  557. <foreach collection="qwSopLogs" item="log" separator=",">
  558. (
  559. #{log.qwUserid},
  560. #{log.externalUserId},
  561. #{log.externalId},
  562. #{log.externalUserName},
  563. #{log.logType},
  564. #{log.contentJson},
  565. #{log.sendStatus},
  566. #{log.sendTime},
  567. #{log.realSendTime},
  568. #{log.sendType},
  569. #{log.companyId},
  570. #{log.receivingStatus},
  571. #{log.msgId},
  572. #{log.sopId},
  573. #{log.remark},
  574. #{log.corpId},
  575. #{log.customerId},
  576. #{log.fsUserId},
  577. #{log.sort},
  578. #{log.qwUserKey}
  579. )
  580. </foreach>
  581. </insert>
  582. <!-- 批量插入 QwSopLogs -->
  583. <insert id="batchInsertQwSopLogs" parameterType="java.util.List" useGeneratedKeys="false">
  584. INSERT INTO qw_sop_logs
  585. (
  586. qw_userid, external_user_id,external_id, external_user_name, log_type,
  587. content_json, send_status, send_time, real_send_time, send_type,
  588. company_id, receiving_status, msg_id, sop_id, remark,
  589. corp_id, customer_id, fs_user_id, expiration_time,sort,user_logs_id,take_records,qw_user_key
  590. )
  591. VALUES
  592. <foreach collection="qwSopLogs" item="log" separator=",">
  593. (
  594. #{log.qwUserid},
  595. #{log.externalUserId},
  596. #{log.externalId},
  597. #{log.externalUserName},
  598. #{log.logType},
  599. #{log.contentJson},
  600. #{log.sendStatus},
  601. #{log.sendTime},
  602. #{log.realSendTime},
  603. #{log.sendType},
  604. #{log.companyId},
  605. #{log.receivingStatus},
  606. #{log.msgId},
  607. #{log.sopId},
  608. #{log.remark},
  609. #{log.corpId},
  610. #{log.customerId},
  611. #{log.fsUserId},
  612. #{log.expirationTime},
  613. #{log.sort},
  614. #{log.userLogsId},
  615. #{log.takeRecords},
  616. #{log.qwUserKey}
  617. )
  618. </foreach>
  619. </insert>
  620. <!-- 批量更新 QwSopLogs -->
  621. <update id="batchUpdateQwSopLogsByTakeRecordsList" parameterType="java.util.List" useGeneratedKeys="false">
  622. UPDATE qw_sop_logs
  623. SET take_records = 1
  624. WHERE id IN
  625. <foreach collection="data" item="log" open="(" separator="," close=")">
  626. #{log.id}
  627. </foreach>
  628. </update>
  629. <update id="updateQwSopLogsByDeleted" parameterType="com.fs.sop.params.GetQwSopLogsByJsApiParam" useGeneratedKeys="false">
  630. <![CDATA[
  631. UPDATE qw_sop_logs
  632. SET
  633. send_status = 5,
  634. receiving_status = 4,
  635. remark = '非外部联系人',
  636. real_send_time = NOW()
  637. WHERE qw_userid = #{data.qwUserId}
  638. AND corp_id = #{data.corpId}
  639. AND external_user_id = #{data.externalUserId}
  640. AND send_time <= now()
  641. ]]>
  642. </update>
  643. <!-- 批量更新 QwSopLogs -->
  644. <update id="batchUpdateQwSopLogsBySendTime" parameterType="java.util.List" useGeneratedKeys="false">
  645. UPDATE qw_sop_logs
  646. SET
  647. send_status = 5,
  648. receiving_status = 4,
  649. remark = '已过期,不发送',
  650. real_send_time = NOW()
  651. WHERE id IN
  652. <foreach collection="data" item="log" open="(" separator="," close=")">
  653. #{log.id}
  654. </foreach>
  655. </update>
  656. <select id="selectQwSopLogsByCancel" resultMap="QwSopLogsResult">
  657. <include refid="selectQwSopLogsVo"/>
  658. <![CDATA[
  659. WHERE send_type = 3
  660. AND send_status = 5
  661. AND receiving_status = 4
  662. AND remark = '已过期,不发送'
  663. AND real_send_time >= now() - INTERVAL 1 HOUR
  664. AND real_send_time < now()
  665. ]]>
  666. </select>
  667. <select id="getWxMsgByAccountId" resultType="com.fs.sop.domain.QwSopLogs">
  668. 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")
  669. </select>
  670. <!-- 批量更新 QwSopLogs -->
  671. <update id="batchUpdateQwSopLogsByCancel" parameterType="java.util.List" useGeneratedKeys="false">
  672. UPDATE qw_sop_logs
  673. SET
  674. send_status = 3,
  675. receiving_status = 0,
  676. remark = null,
  677. real_send_time = null,
  678. send_time = DATE_ADD(now(), INTERVAL 30 MINUTE)
  679. WHERE id IN
  680. <foreach collection="data" item="log" open="(" separator="," close=")">
  681. #{log.id}
  682. </foreach>
  683. </update>
  684. <delete id="deleteQwSopLogsByDate" >
  685. <![CDATA[
  686. DELETE FROM qw_sop_logs WHERE DATE(send_time) < CURDATE() - INTERVAL 2 DAY;
  687. ]]>
  688. </delete>
  689. <update id="updateQwSopLogsByDayBefore" useGeneratedKeys="false">
  690. UPDATE qw_sop_logs
  691. SET send_status = 5,
  692. remark = '清除跨天待发送'
  693. WHERE send_time &lt; CURRENT_DATE() and send_status=3
  694. </update>
  695. <select id="selectQwSopLogsListByChatSopId" resultType="com.fs.sop.vo.QwSopLogsListCVO">
  696. SELECT * FROM qw_sop_logs
  697. <where>
  698. <if test="map.sopId != null">sop_id = #{map.sopId}</if>
  699. <if test="map.corpId != null">AND corp_id = #{map.corpId}</if>
  700. <if test="map.sendType != null">AND send_type = #{map.sendType}</if>
  701. <if test="map.sendStatus != null">AND send_status = #{map.sendStatus}</if>
  702. <if test="map.receivingStatus != null">AND receiving_status = #{map.receivingStatus}</if>
  703. <if test="map.qwUserid != null and map.qwUserid !='' ">AND qw_userid = #{map.qwUserid}</if>
  704. <if test="map.externalUserName != null and map.externalUserName!= '' ">AND external_user_name = #{map.externalUserName}</if>
  705. <if test="map.scheduleStartTime != null">AND send_time &gt;= #{map.scheduleStartTime}</if>
  706. <if test="map.scheduleEndTime != null">AND send_time &lt;= #{map.scheduleEndTime}</if>
  707. </where>
  708. ORDER BY send_time desc
  709. </select>
  710. <select id="queryPeriodNameById" resultType="java.lang.String">
  711. select concat(qw_user_id,'-',start_time) from sop_user_logs where id=#{periodId}
  712. </select>
  713. <select id="queryAllPeriod" resultType="com.fs.sop.domain.QwSopLogs">
  714. select id,concat(qw_user_id,'-',start_time) as sop_title from sop_user_logs
  715. </select>
  716. <select id="selectQwSopLogsCountByQwUserId" resultType="java.lang.Long">
  717. select count(1) from qw_sop_logs
  718. <where>
  719. AND type = '0'
  720. AND send_status = '1'
  721. AND DATE(real_send_time) = #{previousDay}
  722. AND user_logs_id = #{periodId}
  723. <if test="data != null and data.size() > 0">
  724. AND qw_userid in
  725. <foreach collection="data" item="item" open="(" close=")" separator=",">
  726. #{item}
  727. </foreach>
  728. </if>
  729. </where>
  730. </select>
  731. <select id="selectByQwUserIdIn" resultType="com.fs.sop.domain.QwSopLogs">
  732. select ql.*,
  733. qs.name,
  734. qs.expiry_time as expiryTime
  735. from qw_sop_logs ql
  736. left join qw_sop qs on qs.id = ql.sop_id
  737. where ql.qw_user_key in <foreach collection="qwUserIds" item="item" open="(" close=")" separator=",">#{item}</foreach>
  738. and ql.log_type = 2
  739. and ql.send_status = 3
  740. and ql.send_type != 1
  741. <![CDATA[
  742. and ql.send_time <= #{startTime}
  743. ]]>
  744. order by ql.sort DESC ,ql.send_time asc
  745. </select>
  746. <update id="batchUpdateQwSopLogsIpadSendStatus">
  747. update qw_sop_logs
  748. SET send_status = 6,receiving_status = 0
  749. where id in <foreach collection="ids" open="(" close=")" separator="," item="item">#{item}</foreach>
  750. </update>
  751. <select id="selectIpadByCorpId" resultType="com.fs.sop.domain.QwSopLogs">
  752. select ql.*,
  753. qs.name,
  754. qs.expiry_time as expiryTime
  755. from qw_sop_logs ql
  756. left join qw_sop qs on qs.id = ql.sop_id
  757. where ql.corp_id = #{corpId}
  758. and ql.qw_user_key is not null
  759. and ql.log_type = 2
  760. and ql.send_status in (3,6)
  761. and ql.send_type != 1
  762. <![CDATA[
  763. and ql.send_time <= #{now}
  764. ]]>
  765. order by ql.sort DESC ,ql.send_time asc
  766. </select>
  767. <update id="batchUpdateQwSopLogsById" parameterType="java.util.List" useGeneratedKeys="false">
  768. UPDATE qw_sop_logs
  769. SET
  770. send_status = 5,
  771. remark = 'ai回复超时过期'
  772. WHERE id IN
  773. <foreach collection="data" item="log" open="(" separator="," close=")">
  774. #{log.id}
  775. </foreach>
  776. </update>
  777. <update id="batchUpdateQwSopLogsNewUserById">
  778. UPDATE qw_sop_logs
  779. SET
  780. send_status = 5,
  781. remark = '新客对话已回复'
  782. WHERE id IN
  783. <foreach collection="data" item="log" open="(" separator="," close=")">
  784. #{log.id}
  785. </foreach>
  786. </update>
  787. <select id="selectByQwUserId" resultType="com.fs.sop.domain.QwSopLogs">
  788. select ql.*,
  789. qs.name,
  790. qs.expiry_time as expiryTime
  791. from qw_sop_logs ql
  792. left join qw_sop qs on qs.id = ql.sop_id
  793. where ql.qw_user_key = #{id}
  794. and ql.log_type = 2
  795. and ql.send_status = 3
  796. and ql.send_type != 1
  797. <![CDATA[
  798. and ql.send_time <= now()
  799. ]]>
  800. order by ql.sort DESC ,ql.send_time asc limit 50
  801. </select>
  802. </mapper>