SopUserLogsMapper.xml 18 KB

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