SopUserLogsMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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="meetsTheRatingByUserInfoBySopId" resultType="String" 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.is_rating=1
  247. and qs.type=2
  248. and qs.send_type=2
  249. and qs.`status` in (2,3)
  250. and ul.sop_id= #{sopId}
  251. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  252. </select>
  253. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  254. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  255. <!-- inner join qw_sop b on a.sop_id = b.id-->
  256. <!-- where b.id="23d77d16-2967-4760-940c-bdce4ca78b59"-->
  257. <!-- </select>-->
  258. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  259. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  260. <!-- inner join qw_sop b on a.sop_id = b.id-->
  261. <!-- where a.id="2263eef1-f037-4db8-875a-b29d717929ef"-->
  262. <!-- </select>-->
  263. <select id="selectSopUserLogsListByTest" resultType="com.fs.sop.vo.SopUserLogsVo">
  264. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a
  265. inner join qw_sop b on a.sop_id = b.id
  266. where a.sop_id = '343bbcae-07cf-11f0-b693-96e1ac939c1f' and a.start_time &lt;= Now() and a.status = 1 and b.send_type != 4
  267. </select>
  268. <select id="selectSopUserLogsByUnionSopId" resultType="String" parameterType="SopUserLogs">
  269. SELECT id
  270. FROM sop_user_logs
  271. WHERE sop_id = #{data.sopId}
  272. AND sop_temp_id = #{data.sopTempId}
  273. AND qw_user_id = #{data.qwUserId}
  274. AND corp_id = #{data.corpId}
  275. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  276. AND status = #{data.status}
  277. limit 1
  278. </select>
  279. <select id="selectSopUserLogsByUpdate" resultType="String" parameterType="SopUserLogs">
  280. SELECT id
  281. FROM sop_user_logs
  282. WHERE sop_id = #{data.sopId}
  283. AND qw_user_id = #{data.qwUserId}
  284. AND corp_id = #{data.corpId}
  285. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  286. AND status = #{data.status}
  287. limit 1
  288. </select>
  289. <select id="selectSopUserLogsInfoListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  290. select
  291. c.id sopId,
  292. b.id sopLogsId,
  293. a.id sopLogsInfoId,
  294. a.external_id externalId,
  295. a.create_time createTime,a.qw_user_id qwUserId,a.corp_id corpId,a.fs_user_id fsUserId,a.external_user_name externalUserName,
  296. c.min_conversion_day minConversionDay,c.max_conversion_day maxConversionDay,c.min_send minSend,c.max_send maxSend
  297. from sop_user_logs_info a
  298. inner join sop_user_logs b on a.user_logs_id = b.id
  299. inner join qw_sop c on b.sop_id = c.id
  300. 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)
  301. </select>
  302. <select id="selectSopUserLogsListBySopId" resultMap="SopUserLogsResult">
  303. select
  304. id,
  305. sop_id,
  306. sop_temp_id,
  307. qw_user_id,
  308. corp_id,
  309. start_time,
  310. status,
  311. user_id
  312. from sop_user_logs where sop_id = #{data.sopId} order by start_time desc
  313. </select>
  314. <select id="selectSopUserInfoLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  315. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs_info_chat a
  316. inner join qw_sop b on a.sop_id = b.id
  317. where a.start_time &lt;= Now() and a.status = 1
  318. </select>
  319. <select id="selectSopUserLogsByDate" resultType="String">
  320. SELECT id
  321. FROM sop_user_logs
  322. WHERE start_time BETWEEN STR_TO_DATE(#{scheduleStartTime}, '%Y-%m-%d') AND STR_TO_DATE(#{scheduleEndTime}, '%Y-%m-%d')
  323. </select>
  324. <select id="selectQwSopLogsMessSendList" resultType="com.fs.qw.param.SopUserLogsVO">
  325. <include refid="selectSopUserLogsVo"/>
  326. <where>
  327. count_days = 1
  328. <if test="sopIds != null and sopIds.size() > 0">
  329. and sop_id in
  330. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  331. #{sopId}
  332. </foreach>
  333. </if>
  334. </where>
  335. order by send_time desc
  336. </select>
  337. <select id="selectSopUserLogsByDateAndIds" resultType="com.fs.sop.domain.SopUserLogs" >
  338. 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}
  339. </select>
  340. </mapper>