SopUserLogsMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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.SopUserLogsMapper">
  6. <resultMap type="SopUserLogs" id="SopUserLogsResult">
  7. <result property="id" column="id" />
  8. <result property="sopId" column="sop_id" />
  9. <result property="sopTempId" column="sop_temp_id" />
  10. <result property="qwUserId" column="qw_user_id" />
  11. <result property="actualQwUserId" column="actual_user_id" />
  12. <result property="corpId" column="corp_id" />
  13. <result property="startTime" column="start_time" jdbcType="TIMESTAMP" />
  14. <result property="status" column="status" />
  15. <result property="userId" column="user_id" />
  16. <result property="chatId" column="chat_id" />
  17. <result property="countDays" column="count_days" />
  18. </resultMap>
  19. <sql id="selectSopUserLogsVo">
  20. SELECT
  21. id,
  22. sop_id,
  23. sop_temp_id,
  24. qw_user_id,
  25. corp_id,
  26. start_time,
  27. chat_id,
  28. status,
  29. user_id,
  30. DATEDIFF(CURRENT_DATE, start_time) + 1 AS count_days
  31. FROM sop_user_logs
  32. </sql>
  33. <select id="selectSopUserLogsList" parameterType="com.fs.sop.domain.SopUserLogs" resultMap="SopUserLogsResult">
  34. <include refid="selectSopUserLogsVo"/>
  35. <where>
  36. <if test="id != null "> and id = #{id}</if>
  37. <if test="sopId != null "> and sop_id = #{sopId}</if>
  38. <if test="sopTempId != null "> and sop_temp_id = #{sopTempId}</if>
  39. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  40. <if test="corpId != null "> and corp_id = #{corpId}</if>
  41. <if test="startTime != null "> and start_time = #{startTime}</if>
  42. <if test="status != null "> and status = #{status}</if>
  43. <if test="userId != null "> and user_id = #{userId}</if>
  44. </where>
  45. order by start_time desc
  46. </select>
  47. <!-- 根据ID删除记录 -->
  48. <delete id="deleteSopUserLogsById" parameterType="String">
  49. DELETE FROM sop_user_logs WHERE id = #{id}
  50. </delete>
  51. <delete id="deleteSopUserLogsByIds" parameterType="String">
  52. delete from sop_user_logs where id in
  53. <foreach item="id" collection="array" open="(" separator="," close=")">
  54. #{id}
  55. </foreach>
  56. </delete>
  57. <insert id="insertSopUserLogsByDate" parameterType="com.fs.sop.params.SopUserLogsParamByDate" useGeneratedKeys="false" >
  58. insert into sop_user_logs
  59. <trim prefix="(" suffix=")" suffixOverrides=",">
  60. <if test="data.id != null ">id,</if>
  61. <if test="data.sopId != null ">sop_id,</if>
  62. <if test="data.sopTempId != null ">sop_temp_id,</if>
  63. <if test="data.qwUserId != null ">qw_user_id,</if>
  64. <if test="data.corpId != null ">corp_id,</if>
  65. <if test="data.startTime != null ">start_time,</if>
  66. <if test="data.status != null ">status,</if>
  67. <if test="data.userId != null ">user_id,</if>
  68. </trim>
  69. <trim prefix="values (" suffix=")" suffixOverrides=",">
  70. <if test="data.id != null ">#{data.id},</if>
  71. <if test="data.sopId != null ">#{data.sopId},</if>
  72. <if test="data.sopTempId != null ">#{data.sopTempId},</if>
  73. <if test="data.qwUserId != null ">#{data.qwUserId},</if>
  74. <if test="data.corpId != null ">#{data.corpId},</if>
  75. <if test="data.startTime != null ">#{data.startTime},</if>
  76. <if test="data.status != null ">#{data.status},</if>
  77. <if test="data.userId != null ">#{data.userId},</if>
  78. </trim>
  79. </insert>
  80. <select id="selectSopUserLogsById" parameterType="String" resultMap="SopUserLogsResult">
  81. <include refid="selectSopUserLogsVo"/>
  82. where id = #{id}
  83. </select>
  84. <select id="selectSopUserLogsBySopId" parameterType="String" resultMap="SopUserLogsResult">
  85. <include refid="selectSopUserLogsVo"/>
  86. where sop_id = #{sopId}
  87. </select>
  88. <insert id="insertSopUserLogsByList" parameterType="com.fs.sop.params.SopUserLogsList" useGeneratedKeys="false" >
  89. insert into sop_user_logs
  90. <trim prefix="(" suffix=")" suffixOverrides=",">
  91. <if test="data.id != null ">id,</if>
  92. <if test="data.sopId != null ">sop_id,</if>
  93. <if test="data.sopTempId != null ">sop_temp_id,</if>
  94. <if test="data.qwUserId != null ">qw_user_id,</if>
  95. <if test="data.corpId != null ">corp_id,</if>
  96. <if test="data.startTime != null ">start_time,</if>
  97. <if test="data.status != null ">status,</if>
  98. <if test="data.userId != null ">user_id,</if>
  99. </trim>
  100. <trim prefix="values (" suffix=")" suffixOverrides=",">
  101. <if test="data.id != null ">#{data.id},</if>
  102. <if test="data.sopId != null ">#{data.sopId},</if>
  103. <if test="data.sopTempId != null ">#{data.sopTempId},</if>
  104. <if test="data.qwUserId != null ">#{data.qwUserId},</if>
  105. <if test="data.corpId != null ">#{data.corpId},</if>
  106. <if test="data.startTime != null ">#{data.startTime},</if>
  107. <if test="data.status != null ">#{data.status},</if>
  108. <if test="data.userId != null ">#{data.userId},</if>
  109. </trim>
  110. </insert>
  111. <insert id="batchInsertSopUserLogs">
  112. INSERT INTO sop_user_logs
  113. (
  114. sop_id, sop_temp_id, qw_user_id,chat_id,corp_id, start_time,
  115. status, user_id
  116. )
  117. VALUES
  118. <foreach collection="list" item="log" separator=",">
  119. (
  120. #{log.sopId},
  121. #{log.sopTempId},
  122. #{log.qwUserId},
  123. #{log.chatId},
  124. #{log.corpId},
  125. #{log.startTime},
  126. #{log.status},
  127. #{log.userId}
  128. )
  129. </foreach>
  130. </insert>
  131. <update id="updateSopUserLogsByTempId" parameterType="String">
  132. update sop_user_logs
  133. SET sop_temp_id = #{sopTempId} where sop_id = #{sopId}
  134. </update>
  135. <update id="deleteSopUserLogsBySopId" parameterType="String">
  136. update sop_user_logs
  137. SET status = 0 where sop_id = #{sopId}
  138. </update>
  139. <update id="deleteSopUserLogsByRemoveSop" parameterType="String">
  140. update sop_user_logs
  141. SET status = 0
  142. where sop_id = #{sopId} and qw_user_id=#{qwUserId} and corp_id=#{corpId}
  143. </update>
  144. <update id="deleteSopUserLogsBySopIds" parameterType="String">
  145. update sop_user_logs
  146. SET status = 0 where sop_id in
  147. <foreach item="id" collection="sopIds" open="(" separator="," close=")">
  148. #{id}
  149. </foreach>
  150. </update>
  151. <update id="updateSopUserLogsByStatus" parameterType="SopUserLogs" useGeneratedKeys="false" keyProperty="id" >
  152. UPDATE sop_user_logs
  153. SET status= #{data.status}
  154. WHERE sop_id = #{data.sopId}
  155. </update>
  156. <update id="updateSopUserLogsByStartTime" parameterType="SopUserLogs" useGeneratedKeys="false" keyProperty="id" >
  157. UPDATE sop_user_logs
  158. SET status= #{data.status},start_time = #{data.startTime}
  159. where id = #{data.id}
  160. </update>
  161. <update id="updateSopUserLogsByCompanyInfo" parameterType="SopUserLogs" useGeneratedKeys="false" keyProperty="id" >
  162. UPDATE sop_user_logs
  163. SET user_id= #{data.userId}
  164. where id = #{data.id}
  165. </update>
  166. <update id="updateSopuserLogsDateById">
  167. update sop_user_logs
  168. set start_time = #{date}
  169. where id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>
  170. </update>
  171. <select id="repairSopUserLogsList" resultType="com.fs.sop.domain.SopUserLogs">
  172. select id,qw_user_id,corp_id,user_id from sop_user_logs where status=1 and user_id like '%null%'
  173. </select>
  174. <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">
  175. select a.*,
  176. b.min_conversion_day,
  177. b.max_conversion_day,
  178. b.min_send,
  179. b.max_send,
  180. b.is_fixed,
  181. b.is_register,
  182. b.chat_id,
  183. b.filter_mode,
  184. b.is_samp_send
  185. from sop_user_logs a
  186. inner join qw_sop b on a.sop_id = b.id
  187. inner join qw_sop_temp c on b.temp_id = c.id
  188. where a.start_time &lt;= Now()
  189. and a.status = 1
  190. and b.send_type != 4 and b.status in (2,3)
  191. and c.`status` = 1
  192. <if test="sopIds != null and !sopIds.isEmpty()">
  193. and a.sop_id in
  194. <foreach collection="sopIds" open="(" close=")" index="index" item="item" separator=",">#{item}</foreach>
  195. </if>
  196. </select>
  197. <select id="meetsTheRatingByUserInfo" resultMap="SopUserLogsResult">
  198. SELECT
  199. ul.id,
  200. ul.sop_id,
  201. ul.sop_temp_id,
  202. ul.qw_user_id,
  203. ul.corp_id,
  204. ul.start_time,
  205. ul.`status`,
  206. ul.user_id,
  207. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  208. FROM
  209. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  210. WHERE
  211. ul.`status` = '1'
  212. and qs.is_rating=1
  213. and qs.`status` in (2,3)
  214. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) % 7 = 0
  215. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) &gt; 0
  216. </select>
  217. <select id="meetsTheRatingByUserInfoWithPagination" resultType="Integer" resultMap="SopUserLogsResult">
  218. SELECT
  219. ul.id,
  220. ul.sop_id,
  221. ul.sop_temp_id,
  222. ul.qw_user_id,
  223. ul.corp_id,
  224. ul.start_time,
  225. ul.`status`,
  226. ul.user_id,
  227. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  228. FROM
  229. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  230. WHERE
  231. ul.`status` = '1'
  232. and qs.is_rating=1
  233. and qs.type=2
  234. and qs.send_type=2
  235. and qs.`status` in (2,3)
  236. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  237. ORDER BY id ASC
  238. LIMIT #{offset}, #{pageSize}
  239. </select>
  240. <select id="meetsTheRatingByUserInfoWithPaginationStudyDays" resultType="Integer" resultMap="SopUserLogsResult">
  241. SELECT
  242. ul.id,
  243. ul.sop_id,
  244. ul.sop_temp_id,
  245. ul.qw_user_id,
  246. ul.corp_id,
  247. ul.start_time,
  248. ul.`status`,
  249. ul.user_id,
  250. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  251. FROM
  252. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  253. WHERE
  254. ul.`status` = '1'
  255. and qs.type=2
  256. and qs.send_type=2
  257. and qs.`status` in (2,3)
  258. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= #{notStudyDays}
  259. ORDER BY id ASC
  260. LIMIT #{offset}, #{pageSize}
  261. </select>
  262. <select id="meetsTherestoreByIsDaysNotStudy" resultType="Integer" resultMap="SopUserLogsResult">
  263. SELECT
  264. ul.id,
  265. ul.sop_id
  266. FROM
  267. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  268. WHERE
  269. ul.`status` = '1'
  270. and qs.type=2
  271. and qs.send_type=2
  272. and qs.`status` in (2,3)
  273. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) &lt; #{notStudyDays}
  274. ORDER BY id ASC
  275. LIMIT #{offset}, #{pageSize}
  276. </select>
  277. <select id="meetsTheRatingByUserInfoBySopId" resultType="String" resultMap="SopUserLogsResult">
  278. SELECT
  279. ul.id,
  280. ul.sop_id,
  281. ul.sop_temp_id,
  282. ul.qw_user_id,
  283. ul.corp_id,
  284. ul.start_time,
  285. ul.`status`,
  286. ul.user_id,
  287. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  288. FROM
  289. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  290. WHERE
  291. ul.`status` = '1'
  292. and qs.is_rating=1
  293. and qs.type=2
  294. and qs.send_type=2
  295. and qs.`status` in (2,3)
  296. and ul.sop_id= #{sopId}
  297. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  298. </select>
  299. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  300. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  301. <!-- inner join qw_sop b on a.sop_id = b.id-->
  302. <!-- where b.id="23d77d16-2967-4760-940c-bdce4ca78b59"-->
  303. <!-- </select>-->
  304. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  305. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  306. <!-- inner join qw_sop b on a.sop_id = b.id-->
  307. <!-- where a.id="2263eef1-f037-4db8-875a-b29d717929ef"-->
  308. <!-- </select>-->
  309. <select id="selectSopUserLogsListByTest" resultType="com.fs.sop.vo.SopUserLogsVo">
  310. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a
  311. inner join qw_sop b on a.sop_id = b.id
  312. where a.sop_id = '343bbcae-07cf-11f0-b693-96e1ac939c1f' and a.start_time &lt;= Now() and a.status = 1 and b.send_type != 4
  313. </select>
  314. <select id="selectSopUserLogsByUnionSopId" resultType="String" parameterType="SopUserLogs">
  315. SELECT id
  316. FROM sop_user_logs
  317. WHERE sop_id = #{data.sopId}
  318. AND sop_temp_id = #{data.sopTempId}
  319. AND qw_user_id = #{data.qwUserId}
  320. AND corp_id = #{data.corpId}
  321. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  322. AND status = #{data.status}
  323. limit 1
  324. </select>
  325. <select id="selectSopUserLogsByUpdate" resultType="String" parameterType="SopUserLogs">
  326. SELECT id
  327. FROM sop_user_logs
  328. WHERE sop_id = #{data.sopId}
  329. AND qw_user_id = #{data.qwUserId}
  330. AND corp_id = #{data.corpId}
  331. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  332. AND status = #{data.status}
  333. limit 1
  334. </select>
  335. <select id="selectSopUserLogsInfoListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  336. select
  337. c.id sopId,
  338. b.id sopLogsId,
  339. a.id sopLogsInfoId,
  340. a.external_id externalId,
  341. a.create_time createTime,a.qw_user_id qwUserId,a.corp_id corpId,a.fs_user_id fsUserId,a.external_user_name externalUserName,
  342. c.min_conversion_day minConversionDay,c.max_conversion_day maxConversionDay,c.min_send minSend,c.max_send maxSend
  343. from sop_user_logs_info a
  344. inner join sop_user_logs b on a.user_logs_id = b.id
  345. inner join qw_sop c on b.sop_id = c.id
  346. where a.create_time &lt; CURDATE() and b.status = 1 and c.min_conversion_day is not null and c.max_conversion_day is not null and (c.min_send = 0 or c.max_send = 0)
  347. </select>
  348. <select id="selectSopUserLogsListBySopId" resultMap="SopUserLogsResult">
  349. select
  350. id,
  351. sop_id,
  352. sop_temp_id,
  353. qw_user_id,
  354. corp_id,
  355. start_time,
  356. status,
  357. user_id
  358. from sop_user_logs where sop_id = #{data.sopId} order by start_time desc
  359. </select>
  360. <select id="selectSopUserInfoLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  361. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs_info_chat a
  362. inner join qw_sop b on a.sop_id = b.id
  363. where a.start_time &lt;= Now() and a.status = 1
  364. </select>
  365. <select id="selectSopUserLogsByDate" resultType="String">
  366. SELECT id
  367. FROM sop_user_logs
  368. WHERE start_time BETWEEN STR_TO_DATE(#{scheduleStartTime}, '%Y-%m-%d') AND STR_TO_DATE(#{scheduleEndTime}, '%Y-%m-%d')
  369. </select>
  370. <select id="selectQwSopLogsMessSendList" resultType="com.fs.qw.param.SopUserLogsVO">
  371. <include refid="selectSopUserLogsVo"/>
  372. <where>
  373. count_days = 1
  374. <if test="sopIds != null and sopIds.size() > 0">
  375. and sop_id in
  376. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  377. #{sopId}
  378. </foreach>
  379. </if>
  380. </where>
  381. order by send_time desc
  382. </select>
  383. <select id="selectSopUserLogsByDateAndIds" resultType="com.fs.sop.domain.SopUserLogs" >
  384. select * from sop_user_logs where sop_id=#{sopId} and sop_temp_id=#{sopTempId} and qw_user_id=#{qwUserId} and corp_id=#{corpId} and start_time=#{startTime}
  385. </select>
  386. <select id="queryExecuteLogBySopId" resultType="com.fs.sop.domain.SopUserLogs">
  387. select *
  388. from
  389. sop_user_logs
  390. where sop_id=#{sopId}
  391. </select>
  392. <select id="selectSopUserLogsByQwUserIds" resultType="java.lang.String">
  393. select id from sop_user_logs
  394. <where>
  395. qw_user_id in
  396. <foreach collection="qwUserIds" item="item" open="(" close=")" separator=",">
  397. #{item}
  398. </foreach>
  399. </where>
  400. </select>
  401. <select id="selectSopUserLogsListByIds" resultType="java.util.Map">
  402. select
  403. id,
  404. sop_id,
  405. qw_user_id,
  406. corp_id,
  407. start_time,
  408. status
  409. from sop_user_logs
  410. <where>
  411. status = 0
  412. <if test="ids != null and ids.size() > 0">
  413. and id in
  414. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  415. #{item}
  416. </foreach>
  417. </if>
  418. </where>
  419. order by start_time desc
  420. </select>
  421. <select id="querySopUserLogsByParam" resultType="com.fs.sop.domain.SopUserLogs">
  422. SELECT DISTINCT log.id as id,
  423. log.qw_user_id as qw_user_id,
  424. log.start_time as start_time,
  425. log.sop_id as sop_id
  426. FROM sop_user_logs log
  427. LEFT JOIN qw_sop ON log.sop_id = qw_sop.id
  428. <where>
  429. <![CDATA[
  430. log.start_time <= CURDATE()
  431. ]]>
  432. AND log.status = 1
  433. AND qw_sop.status in(2,3)
  434. <if test="startDate != null and endDate != null">
  435. AND (
  436. <![CDATA[
  437. log.start_time >= #{startDate}
  438. AND log.start_time <= #{endDate}
  439. ]]>
  440. )
  441. </if>
  442. </where>
  443. ORDER BY log.start_time DESC
  444. </select>
  445. <select id="getSopUserLogsInfoById" resultType="com.fs.sop.domain.SopUserLogs">
  446. select * from sop_user_logs where id IN <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
  447. </select>
  448. </mapper>