SopUserLogsMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. <if test="sopIds != null and !sopIds.isEmpty()">
  189. and a.sop_id in
  190. <foreach collection="sopIds" open="(" close=")" index="index" item="item" separator=",">#{item}</foreach>
  191. </if>
  192. </select>
  193. <select id="meetsTheRatingByUserInfo" resultMap="SopUserLogsResult">
  194. SELECT
  195. ul.id,
  196. ul.sop_id,
  197. ul.sop_temp_id,
  198. ul.qw_user_id,
  199. ul.corp_id,
  200. ul.start_time,
  201. ul.`status`,
  202. ul.user_id,
  203. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  204. FROM
  205. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  206. WHERE
  207. ul.`status` = '1'
  208. and qs.is_rating=1
  209. and qs.`status` in (2,3)
  210. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) % 7 = 0
  211. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) &gt; 0
  212. </select>
  213. <select id="meetsTheRatingByUserInfoWithPagination" resultType="Integer" resultMap="SopUserLogsResult">
  214. SELECT
  215. ul.id,
  216. ul.sop_id,
  217. ul.sop_temp_id,
  218. ul.qw_user_id,
  219. ul.corp_id,
  220. ul.start_time,
  221. ul.`status`,
  222. ul.user_id,
  223. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  224. FROM
  225. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  226. WHERE
  227. ul.`status` = '1'
  228. and qs.is_rating=1
  229. and qs.type=2
  230. <if test="isAllratingRating == null || !isAllratingRating">
  231. and qs.send_type=2
  232. </if>
  233. and qs.`status` in (2,3)
  234. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  235. ORDER BY id ASC
  236. LIMIT #{offset}, #{pageSize}
  237. </select>
  238. <select id="meetsTheRatingByUserInfoWithPaginationStudyDays" resultType="Integer" resultMap="SopUserLogsResult">
  239. SELECT
  240. ul.id,
  241. ul.sop_id,
  242. ul.sop_temp_id,
  243. ul.qw_user_id,
  244. ul.corp_id,
  245. ul.start_time,
  246. ul.`status`,
  247. ul.user_id,
  248. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  249. FROM
  250. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  251. WHERE
  252. ul.`status` = '1'
  253. and qs.type=2
  254. and qs.send_type=2
  255. and qs.`status` in (2,3)
  256. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= #{notStudyDays}
  257. ORDER BY id ASC
  258. LIMIT #{offset}, #{pageSize}
  259. </select>
  260. <select id="meetsTherestoreByIsDaysNotStudy" resultType="Integer" resultMap="SopUserLogsResult">
  261. SELECT
  262. ul.id,
  263. ul.sop_id
  264. FROM
  265. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  266. WHERE
  267. ul.`status` = '1'
  268. and qs.type=2
  269. and qs.send_type=2
  270. and qs.`status` in (2,3)
  271. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) &lt; #{notStudyDays}
  272. ORDER BY id ASC
  273. LIMIT #{offset}, #{pageSize}
  274. </select>
  275. <select id="meetsTheRatingByUserInfoBySopId" resultType="String" resultMap="SopUserLogsResult">
  276. SELECT
  277. ul.id,
  278. ul.sop_id,
  279. ul.sop_temp_id,
  280. ul.qw_user_id,
  281. ul.corp_id,
  282. ul.start_time,
  283. ul.`status`,
  284. ul.user_id,
  285. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  286. FROM
  287. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  288. WHERE
  289. ul.`status` = '1'
  290. and qs.is_rating=1
  291. and qs.type=2
  292. and qs.send_type=2
  293. and qs.`status` in (2,3)
  294. and ul.sop_id= #{sopId}
  295. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  296. </select>
  297. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  298. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  299. <!-- inner join qw_sop b on a.sop_id = b.id-->
  300. <!-- where b.id="23d77d16-2967-4760-940c-bdce4ca78b59"-->
  301. <!-- </select>-->
  302. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  303. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  304. <!-- inner join qw_sop b on a.sop_id = b.id-->
  305. <!-- where a.id="2263eef1-f037-4db8-875a-b29d717929ef"-->
  306. <!-- </select>-->
  307. <select id="selectSopUserLogsListByTest" resultType="com.fs.sop.vo.SopUserLogsVo">
  308. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a
  309. inner join qw_sop b on a.sop_id = b.id
  310. where a.sop_id = '343bbcae-07cf-11f0-b693-96e1ac939c1f' and a.start_time &lt;= Now() and a.status = 1 and b.send_type != 4
  311. </select>
  312. <select id="selectSopUserLogsByUnionSopId" resultType="String" parameterType="SopUserLogs">
  313. SELECT id
  314. FROM sop_user_logs
  315. WHERE sop_id = #{data.sopId}
  316. AND sop_temp_id = #{data.sopTempId}
  317. AND qw_user_id = #{data.qwUserId}
  318. AND corp_id = #{data.corpId}
  319. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  320. AND status = #{data.status}
  321. limit 1
  322. </select>
  323. <select id="selectSopUserLogsByUpdate" resultType="String" parameterType="SopUserLogs">
  324. SELECT id
  325. FROM sop_user_logs
  326. WHERE sop_id = #{data.sopId}
  327. AND qw_user_id = #{data.qwUserId}
  328. AND corp_id = #{data.corpId}
  329. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  330. AND status = #{data.status}
  331. limit 1
  332. </select>
  333. <select id="selectSopUserLogsInfoListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  334. select
  335. c.id sopId,
  336. b.id sopLogsId,
  337. a.id sopLogsInfoId,
  338. a.external_id externalId,
  339. a.create_time createTime,a.qw_user_id qwUserId,a.corp_id corpId,a.fs_user_id fsUserId,a.external_user_name externalUserName,
  340. c.min_conversion_day minConversionDay,c.max_conversion_day maxConversionDay,c.min_send minSend,c.max_send maxSend
  341. from sop_user_logs_info a
  342. inner join sop_user_logs b on a.user_logs_id = b.id
  343. inner join qw_sop c on b.sop_id = c.id
  344. 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)
  345. </select>
  346. <select id="selectSopUserLogsListBySopId" resultMap="SopUserLogsResult">
  347. select
  348. id,
  349. sop_id,
  350. sop_temp_id,
  351. qw_user_id,
  352. corp_id,
  353. start_time,
  354. status,
  355. user_id
  356. from sop_user_logs where sop_id = #{data.sopId} order by start_time desc
  357. </select>
  358. <select id="selectSopUserInfoLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  359. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs_info_chat a
  360. inner join qw_sop b on a.sop_id = b.id
  361. where a.start_time &lt;= Now() and a.status = 1
  362. </select>
  363. <select id="selectSopUserLogsByDate" resultType="String">
  364. SELECT id
  365. FROM sop_user_logs
  366. WHERE start_time BETWEEN STR_TO_DATE(#{scheduleStartTime}, '%Y-%m-%d') AND STR_TO_DATE(#{scheduleEndTime}, '%Y-%m-%d')
  367. </select>
  368. <select id="selectQwSopLogsMessSendList" resultType="com.fs.qw.param.SopUserLogsVO">
  369. <include refid="selectSopUserLogsVo"/>
  370. <where>
  371. count_days = 1
  372. <if test="sopIds != null and sopIds.size() > 0">
  373. and sop_id in
  374. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  375. #{sopId}
  376. </foreach>
  377. </if>
  378. </where>
  379. order by send_time desc
  380. </select>
  381. <select id="selectSopUserLogsByDateAndIds" resultType="com.fs.sop.domain.SopUserLogs" >
  382. 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}
  383. </select>
  384. <select id="queryExecuteLogBySopId" resultType="com.fs.sop.domain.SopUserLogs">
  385. select *
  386. from
  387. sop_user_logs
  388. where sop_id=#{sopId}
  389. </select>
  390. <select id="selectSopUserLogsByQwUserIds" resultType="java.lang.String">
  391. select id from sop_user_logs
  392. <where>
  393. qw_user_id in
  394. <foreach collection="qwUserIds" item="item" open="(" close=")" separator=",">
  395. #{item}
  396. </foreach>
  397. </where>
  398. </select>
  399. <select id="querySopUserLogsByParam" resultType="com.fs.sop.domain.SopUserLogs">
  400. SELECT DISTINCT log.id as id,
  401. log.qw_user_id as qw_user_id,
  402. log.start_time as start_time,
  403. log.sop_id as sop_id
  404. FROM sop_user_logs log
  405. LEFT JOIN qw_sop ON log.sop_id = qw_sop.id
  406. <where>
  407. <![CDATA[
  408. log.start_time <= CURDATE()
  409. ]]>
  410. AND log.status = 1
  411. AND qw_sop.status in(2,3)
  412. <if test="startDate != null and endDate != null">
  413. AND (
  414. <![CDATA[
  415. log.start_time >= #{startDate}
  416. AND log.start_time <= #{endDate}
  417. ]]>
  418. )
  419. </if>
  420. </where>
  421. ORDER BY log.start_time DESC
  422. </select>
  423. <select id="getSopUserLogsInfoById" resultType="com.fs.sop.domain.SopUserLogs">
  424. select * from sop_user_logs where id IN <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
  425. </select>
  426. </mapper>