QwSopLogsMapper.xml 36 KB

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