SopUserLogsMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. <insert id="insertSopUserLogsByDate" parameterType="com.fs.sop.params.SopUserLogsParamByDate" useGeneratedKeys="false" >
  49. insert into sop_user_logs
  50. <trim prefix="(" suffix=")" suffixOverrides=",">
  51. <if test="data.id != null ">id,</if>
  52. <if test="data.sopId != null ">sop_id,</if>
  53. <if test="data.sopTempId != null ">sop_temp_id,</if>
  54. <if test="data.qwUserId != null ">qw_user_id,</if>
  55. <if test="data.corpId != null ">corp_id,</if>
  56. <if test="data.startTime != null ">start_time,</if>
  57. <if test="data.status != null ">status,</if>
  58. <if test="data.userId != null ">user_id,</if>
  59. </trim>
  60. <trim prefix="values (" suffix=")" suffixOverrides=",">
  61. <if test="data.id != null ">#{data.id},</if>
  62. <if test="data.sopId != null ">#{data.sopId},</if>
  63. <if test="data.sopTempId != null ">#{data.sopTempId},</if>
  64. <if test="data.qwUserId != null ">#{data.qwUserId},</if>
  65. <if test="data.corpId != null ">#{data.corpId},</if>
  66. <if test="data.startTime != null ">#{data.startTime},</if>
  67. <if test="data.status != null ">#{data.status},</if>
  68. <if test="data.userId != null ">#{data.userId},</if>
  69. </trim>
  70. </insert>
  71. <select id="selectSopUserLogsById" parameterType="String" resultMap="SopUserLogsResult">
  72. <include refid="selectSopUserLogsVo"/>
  73. where id = #{id}
  74. </select>
  75. <select id="selectSopUserLogsBySopId" parameterType="String" resultMap="SopUserLogsResult">
  76. <include refid="selectSopUserLogsVo"/>
  77. where sop_id = #{sopId}
  78. </select>
  79. <insert id="insertSopUserLogsByList" parameterType="com.fs.sop.params.SopUserLogsList" useGeneratedKeys="false" >
  80. insert into sop_user_logs
  81. <trim prefix="(" suffix=")" suffixOverrides=",">
  82. <if test="data.id != null ">id,</if>
  83. <if test="data.sopId != null ">sop_id,</if>
  84. <if test="data.sopTempId != null ">sop_temp_id,</if>
  85. <if test="data.qwUserId != null ">qw_user_id,</if>
  86. <if test="data.corpId != null ">corp_id,</if>
  87. <if test="data.startTime != null ">start_time,</if>
  88. <if test="data.status != null ">status,</if>
  89. <if test="data.userId != null ">user_id,</if>
  90. </trim>
  91. <trim prefix="values (" suffix=")" suffixOverrides=",">
  92. <if test="data.id != null ">#{data.id},</if>
  93. <if test="data.sopId != null ">#{data.sopId},</if>
  94. <if test="data.sopTempId != null ">#{data.sopTempId},</if>
  95. <if test="data.qwUserId != null ">#{data.qwUserId},</if>
  96. <if test="data.corpId != null ">#{data.corpId},</if>
  97. <if test="data.startTime != null ">#{data.startTime},</if>
  98. <if test="data.status != null ">#{data.status},</if>
  99. <if test="data.userId != null ">#{data.userId},</if>
  100. </trim>
  101. </insert>
  102. <insert id="batchInsertSopUserLogs">
  103. INSERT INTO sop_user_logs
  104. (
  105. sop_id, sop_temp_id, qw_user_id,chat_id,corp_id, start_time,
  106. status, user_id
  107. )
  108. VALUES
  109. <foreach collection="list" item="log" separator=",">
  110. (
  111. #{log.sopId},
  112. #{log.sopTempId},
  113. #{log.qwUserId},
  114. #{log.chatId},
  115. #{log.corpId},
  116. #{log.startTime},
  117. #{log.status},
  118. #{log.userId}
  119. )
  120. </foreach>
  121. </insert>
  122. <update id="updateSopUserLogsByTempId" parameterType="String">
  123. update sop_user_logs
  124. SET sop_temp_id = #{sopTempId} where sop_id = #{sopId}
  125. </update>
  126. <update id="deleteSopUserLogsBySopId" parameterType="String">
  127. update sop_user_logs
  128. SET status = 0 where sop_id = #{sopId}
  129. </update>
  130. <update id="deleteSopUserLogsByRemoveSop" parameterType="String">
  131. update sop_user_logs
  132. SET status = 0
  133. where sop_id = #{sopId} and qw_user_id=#{qwUserId} and corp_id=#{corpId}
  134. </update>
  135. <update id="deleteSopUserLogsBySopIds" parameterType="String">
  136. update sop_user_logs
  137. SET status = 0 where sop_id in
  138. <foreach item="id" collection="sopIds" open="(" separator="," close=")">
  139. #{id}
  140. </foreach>
  141. </update>
  142. <update id="updateSopUserLogsByStatus" parameterType="SopUserLogs" useGeneratedKeys="false" keyProperty="id" >
  143. UPDATE sop_user_logs
  144. SET status= #{data.status}
  145. WHERE sop_id = #{data.sopId}
  146. </update>
  147. <update id="updateSopUserLogsByStartTime" parameterType="SopUserLogs" useGeneratedKeys="false" keyProperty="id" >
  148. UPDATE sop_user_logs
  149. SET status= #{data.status},start_time = #{data.startTime}
  150. where id = #{data.id}
  151. </update>
  152. <update id="updateSopUserLogsByCompanyInfo" parameterType="SopUserLogs" useGeneratedKeys="false" keyProperty="id" >
  153. UPDATE sop_user_logs
  154. SET user_id= #{data.userId}
  155. where id = #{data.id}
  156. </update>
  157. <select id="repairSopUserLogsList" resultType="com.fs.sop.domain.SopUserLogs">
  158. select id,qw_user_id,corp_id,user_id from sop_user_logs where status=1 and user_id like '%null%'
  159. </select>
  160. <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">
  161. select a.*,
  162. b.min_conversion_day,
  163. b.max_conversion_day,
  164. b.min_send,
  165. b.max_send,
  166. b.is_fixed,
  167. b.is_register,
  168. b.chat_id,
  169. b.filter_mode
  170. from sop_user_logs a
  171. inner join qw_sop b on a.sop_id = b.id
  172. where a.start_time &lt;= Now()
  173. and a.status = 1
  174. and b.send_type != 4 and b.status in (2,3)
  175. </select>
  176. <select id="meetsTheRatingByUserInfo" resultMap="SopUserLogsResult">
  177. SELECT
  178. ul.id,
  179. ul.sop_id,
  180. ul.sop_temp_id,
  181. ul.qw_user_id,
  182. ul.corp_id,
  183. ul.start_time,
  184. ul.`status`,
  185. ul.user_id,
  186. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  187. FROM
  188. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  189. WHERE
  190. ul.`status` = '1'
  191. and qs.is_rating=1
  192. and qs.`status` in (2,3)
  193. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) % 7 = 0
  194. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) &gt; 0
  195. </select>
  196. <select id="meetsTheRatingByUserInfoWithPagination" resultType="Integer" resultMap="SopUserLogsResult">
  197. SELECT
  198. ul.id,
  199. ul.sop_id,
  200. ul.sop_temp_id,
  201. ul.qw_user_id,
  202. ul.corp_id,
  203. ul.start_time,
  204. ul.`status`,
  205. ul.user_id,
  206. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  207. FROM
  208. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  209. WHERE
  210. ul.`status` = '1'
  211. and qs.is_rating=1
  212. and qs.type=2
  213. and qs.send_type=2
  214. and qs.`status` in (2,3)
  215. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  216. ORDER BY id ASC
  217. LIMIT #{offset}, #{pageSize}
  218. </select>
  219. <select id="meetsTheRatingByUserInfoBySopId" resultType="String" resultMap="SopUserLogsResult">
  220. SELECT
  221. ul.id,
  222. ul.sop_id,
  223. ul.sop_temp_id,
  224. ul.qw_user_id,
  225. ul.corp_id,
  226. ul.start_time,
  227. ul.`status`,
  228. ul.user_id,
  229. DATEDIFF( CURRENT_DATE, ul.start_time ) AS count_days
  230. FROM
  231. sop_user_logs ul LEFT JOIN qw_sop qs on ul.sop_id=qs.id
  232. WHERE
  233. ul.`status` = '1'
  234. and qs.is_rating=1
  235. and qs.type=2
  236. and qs.send_type=2
  237. and qs.`status` in (2,3)
  238. and ul.sop_id= #{sopId}
  239. AND ( DATEDIFF( CURRENT_DATE, ul.start_time ) ) >= 7
  240. </select>
  241. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  242. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  243. <!-- inner join qw_sop b on a.sop_id = b.id-->
  244. <!-- where b.id="23d77d16-2967-4760-940c-bdce4ca78b59"-->
  245. <!-- </select>-->
  246. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  247. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  248. <!-- inner join qw_sop b on a.sop_id = b.id-->
  249. <!-- where a.id="2263eef1-f037-4db8-875a-b29d717929ef"-->
  250. <!-- </select>-->
  251. <select id="selectSopUserLogsListByTest" resultType="com.fs.sop.vo.SopUserLogsVo">
  252. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a
  253. inner join qw_sop b on a.sop_id = b.id
  254. where a.sop_id = '343bbcae-07cf-11f0-b693-96e1ac939c1f' and a.start_time &lt;= Now() and a.status = 1 and b.send_type != 4
  255. </select>
  256. <select id="selectSopUserLogsByUnionSopId" resultType="String" parameterType="SopUserLogs">
  257. SELECT id
  258. FROM sop_user_logs
  259. WHERE sop_id = #{data.sopId}
  260. AND sop_temp_id = #{data.sopTempId}
  261. AND qw_user_id = #{data.qwUserId}
  262. AND corp_id = #{data.corpId}
  263. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  264. AND status = #{data.status}
  265. limit 1
  266. </select>
  267. <select id="selectSopUserLogsByUpdate" resultType="String" parameterType="SopUserLogs">
  268. SELECT id
  269. FROM sop_user_logs
  270. WHERE sop_id = #{data.sopId}
  271. AND qw_user_id = #{data.qwUserId}
  272. AND corp_id = #{data.corpId}
  273. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  274. AND status = #{data.status}
  275. limit 1
  276. </select>
  277. <select id="selectSopUserLogsInfoListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  278. select
  279. c.id sopId,
  280. b.id sopLogsId,
  281. a.id sopLogsInfoId,
  282. a.external_id externalId,
  283. a.create_time createTime,a.qw_user_id qwUserId,a.corp_id corpId,a.fs_user_id fsUserId,a.external_user_name externalUserName,
  284. c.min_conversion_day minConversionDay,c.max_conversion_day maxConversionDay,c.min_send minSend,c.max_send maxSend
  285. from sop_user_logs_info a
  286. inner join sop_user_logs b on a.user_logs_id = b.id
  287. inner join qw_sop c on b.sop_id = c.id
  288. 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)
  289. </select>
  290. <select id="selectSopUserLogsListBySopId" resultMap="SopUserLogsResult">
  291. select
  292. id,
  293. sop_id,
  294. sop_temp_id,
  295. qw_user_id,
  296. corp_id,
  297. start_time,
  298. status,
  299. user_id
  300. from sop_user_logs where sop_id = #{data.sopId} order by start_time desc
  301. </select>
  302. <select id="selectSopUserInfoLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  303. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs_info_chat a
  304. inner join qw_sop b on a.sop_id = b.id
  305. where a.start_time &lt;= Now() and a.status = 1
  306. </select>
  307. <select id="selectSopUserLogsByDate" resultType="String">
  308. SELECT id
  309. FROM sop_user_logs
  310. WHERE start_time BETWEEN STR_TO_DATE(#{scheduleStartTime}, '%Y-%m-%d') AND STR_TO_DATE(#{scheduleEndTime}, '%Y-%m-%d')
  311. </select>
  312. <select id="selectQwSopLogsMessSendList" resultType="com.fs.qw.param.SopUserLogsVO">
  313. <include refid="selectSopUserLogsVo"/>
  314. <where>
  315. count_days = 1
  316. <if test="sopIds != null and sopIds.size() > 0">
  317. and sop_id in
  318. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  319. #{sopId}
  320. </foreach>
  321. </if>
  322. </where>
  323. order by send_time desc
  324. </select>
  325. <select id="selectSopUserLogsByDateAndIds" resultType="com.fs.sop.domain.SopUserLogs" >
  326. 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}
  327. </select>
  328. </mapper>