SopUserLogsMapper.xml 18 KB

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