QwSopLogsMapper.xml 40 KB

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