SopUserLogsMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send,b.is_fixed,b.is_register,b.chat_id from sop_user_logs a
  162. inner join qw_sop b on a.sop_id = b.id
  163. where a.start_time &lt;= Now() and a.status = 1 and b.send_type != 4 and b.status in (2,3)
  164. </select>
  165. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  166. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  167. <!-- inner join qw_sop b on a.sop_id = b.id-->
  168. <!-- where b.id="23d77d16-2967-4760-940c-bdce4ca78b59"-->
  169. <!-- </select>-->
  170. <!-- <select id="selectSopUserLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsVo">-->
  171. <!-- select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a-->
  172. <!-- inner join qw_sop b on a.sop_id = b.id-->
  173. <!-- where a.id="2263eef1-f037-4db8-875a-b29d717929ef"-->
  174. <!-- </select>-->
  175. <select id="selectSopUserLogsListByTest" resultType="com.fs.sop.vo.SopUserLogsVo">
  176. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs a
  177. inner join qw_sop b on a.sop_id = b.id
  178. where a.sop_id = '1d3aedf1-91f0-4cd2-85ef-47be5e8bcacb' and a.start_time &lt;= Now() and a.status = 1 and b.send_type != 4
  179. </select>
  180. <select id="selectSopUserLogsByUnionSopId" resultType="String" parameterType="SopUserLogs">
  181. SELECT id
  182. FROM sop_user_logs
  183. WHERE sop_id = #{data.sopId}
  184. AND sop_temp_id = #{data.sopTempId}
  185. AND qw_user_id = #{data.qwUserId}
  186. AND corp_id = #{data.corpId}
  187. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  188. AND status = #{data.status}
  189. limit 1
  190. </select>
  191. <select id="selectSopUserLogsByUpdate" resultType="String" parameterType="SopUserLogs">
  192. SELECT id
  193. FROM sop_user_logs
  194. WHERE sop_id = #{data.sopId}
  195. AND qw_user_id = #{data.qwUserId}
  196. AND corp_id = #{data.corpId}
  197. AND start_time = STR_TO_DATE(#{data.startTime}, '%Y-%m-%d')
  198. AND status = #{data.status}
  199. limit 1
  200. </select>
  201. <select id="selectSopUserLogsInfoListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  202. select
  203. c.id sopId,
  204. b.id sopLogsId,
  205. a.id sopLogsInfoId,
  206. a.external_id externalId,
  207. a.create_time createTime,a.qw_user_id qwUserId,a.corp_id corpId,a.fs_user_id fsUserId,a.external_user_name externalUserName,
  208. c.min_conversion_day minConversionDay,c.max_conversion_day maxConversionDay,c.min_send minSend,c.max_send maxSend
  209. from sop_user_logs_info a
  210. inner join sop_user_logs b on a.user_logs_id = b.id
  211. inner join qw_sop c on b.sop_id = c.id
  212. 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)
  213. </select>
  214. <select id="selectSopUserLogsListBySopId" resultMap="SopUserLogsResult">
  215. select
  216. id,
  217. sop_id,
  218. sop_temp_id,
  219. qw_user_id,
  220. corp_id,
  221. start_time,
  222. status,
  223. user_id
  224. from sop_user_logs where sop_id = #{data.sopId} order by start_time desc
  225. </select>
  226. <select id="selectSopUserInfoLogsListByTime" resultType="com.fs.sop.vo.SopUserLogsInfoVo">
  227. select a.*,b.min_conversion_day,b.max_conversion_day,b.min_send,b.max_send from sop_user_logs_info_chat a
  228. inner join qw_sop b on a.sop_id = b.id
  229. where a.start_time &lt;= Now() and a.status = 1
  230. </select>
  231. <select id="selectSopUserLogsByDate" resultType="String">
  232. SELECT id
  233. FROM sop_user_logs
  234. WHERE start_time BETWEEN STR_TO_DATE(#{scheduleStartTime}, '%Y-%m-%d') AND STR_TO_DATE(#{scheduleEndTime}, '%Y-%m-%d')
  235. </select>
  236. <select id="selectQwSopLogsMessSendList" resultType="com.fs.qw.param.SopUserLogsVO">
  237. <include refid="selectSopUserLogsVo"/>
  238. <where>
  239. count_days = 1
  240. <if test="sopIds != null and sopIds.size() > 0">
  241. and sop_id in
  242. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  243. #{sopId}
  244. </foreach>
  245. </if>
  246. </where>
  247. order by send_time desc
  248. </select>
  249. <select id="selectSopUserLogsByDateAndIds" resultType="com.fs.sop.domain.SopUserLogs" >
  250. 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}
  251. </select>
  252. <select id="selectSopUserLogByChatIds" resultType="com.fs.sop.domain.SopUserLogs">
  253. select * from sop_user_logs where chat_id in <foreach collection="ids" open="(" separator="," close=")" item="item">#{item}</foreach>
  254. </select>
  255. </mapper>