LiveWatchUserMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.live.mapper.LiveWatchUserMapper">
  6. <resultMap type="LiveWatchUser" id="LiveWatchUserResult">
  7. <result property="id" column="id" />
  8. <result property="liveId" column="live_id" />
  9. <result property="userId" column="user_id" />
  10. <result property="msgStatus" column="msg_status" />
  11. <result property="online" column="online" />
  12. <result property="createTime" column="create_time" />
  13. <result property="createBy" column="create_by" />
  14. <result property="updateBy" column="update_by" />
  15. <result property="updateTime" column="update_time" />
  16. <result property="remark" column="remark" />
  17. <result property="onlineSeconds" column="online_seconds" />
  18. <result property="globalVisible" column="global_visible" />
  19. <result property="singleVisible" column="single_visible" />
  20. <result property="liveFlag" column="live_flag" />
  21. <result property="replayFlag" column="replay_flag" />
  22. <result property="location" column="location" />
  23. </resultMap>
  24. <sql id="selectLiveWatchUserVo">
  25. select id, live_id,user_id, msg_status, online, create_time, create_by, update_by, update_time, remark,online_seconds,global_visible,single_visible,live_flag,replay_flag,location from live_watch_user
  26. </sql>
  27. <select id="selectLiveWatchUserList" parameterType="LiveWatchUser" resultMap="LiveWatchUserResult">
  28. <include refid="selectLiveWatchUserVo"/>
  29. <where>
  30. <if test="liveId != null "> and live_id = #{liveId}</if>
  31. <if test="userId != null "> and user_id = #{userId}</if>
  32. <if test="liveFlag != null "> and live_flag = #{liveFlag}</if>
  33. <if test="replayFlag != null "> and replay_flag = #{replayFlag}</if>
  34. <if test="msgStatus != null "> and msg_status = #{msgStatus}</if>
  35. <if test="online != null "> and online = #{online}</if>
  36. <if test="onlineSeconds != null "> and online_seconds = #{onlineSeconds}</if>
  37. </where>
  38. </select>
  39. <select id="selectLiveWatchUserById" parameterType="Long" resultMap="LiveWatchUserResult">
  40. <include refid="selectLiveWatchUserVo"/>
  41. where id = #{id}
  42. </select>
  43. <select id="selectWatchUserListAllByLiveId" resultType="com.fs.live.vo.LiveWatchUserVO">
  44. select
  45. lwu.live_id liveId,
  46. lwu.user_id userId,
  47. lwu.msg_status msgStatus,
  48. lwu.online online,
  49. fu.nick_name nickName,
  50. fu.avatar avatar,
  51. lwu.global_visible globalVisible,
  52. lwu.single_visible singleVisible
  53. from live_watch_user lwu
  54. left join fs_user fu on lwu.user_id = fu.user_id
  55. where lwu.live_id = #{params.liveId} and fu.status = 1
  56. <if test="params.liveFlag != null "> and lwu.live_flag = #{params.liveFlag}</if>
  57. <if test="params.replayFlag != null "> and lwu.replay_flag = #{params.replayFlag}</if>
  58. <if test="params.userName != null and params.userName != ''"> and fu.nick_name like concat('%',#{params.userName},'%')</if>
  59. order by lwu.create_time desc
  60. </select>
  61. <select id="selectWatchUserListByLiveId" resultType="com.fs.live.vo.LiveWatchUserVO">
  62. select
  63. lwu.live_id liveId,
  64. lwu.user_id userId,
  65. lwu.msg_status msgStatus,
  66. lwu.online online,
  67. fu.nick_name nickName,
  68. fu.avatar avatar,
  69. lwu.global_visible globalVisible,
  70. lwu.single_visible singleVisible
  71. from live_watch_user lwu
  72. left join fs_user fu on lwu.user_id = fu.user_id
  73. where lwu.live_id = #{params.liveId} and fu.status = 1
  74. <if test="params.liveFlag != null "> and lwu.live_flag = #{params.liveFlag}</if>
  75. <if test="params.replayFlag != null "> and lwu.replay_flag = #{params.replayFlag}</if>
  76. <if test="params.msgStatus != null "> and msg_status = #{params.msgStatus}</if>
  77. <if test="params.online != null "> and online = #{params.online}</if>
  78. <if test="params.userName != null and params.userName != ''"> and fu.nick_name like concat('%',#{params.userName},'%')</if>
  79. order by lwu.create_time desc
  80. </select>
  81. <select id="selectLiveWatchUserByIdAndCompanyIdAndCompanyUserId" resultMap="LiveWatchUserResult">
  82. <include refid="selectLiveWatchUserVo"/>
  83. where id = #{id} and company_id = #{companyId} and company_user_id = #{companyUserId}
  84. </select>
  85. <select id="selectWatchUserByLiveIdAndUserId" resultType="com.fs.live.vo.LiveWatchUserVO">
  86. select
  87. lwu.live_id liveId,
  88. lwu.user_id userId,
  89. lwu.msg_status msgStatus,
  90. lwu.online online,
  91. fu.nickname nickName,
  92. fu.avatar avatar
  93. lwu.global_visible globalVisible,
  94. lwu.single_visible singleVisible
  95. from live_watch_user lwu
  96. left join fs_user fu on lwu.user_id = fu.user_id
  97. where lwu.live_id = #{liveId} and lwu.user_id = #{userId}
  98. <if test="liveFlag != null "> and lwu.live_flag = #{liveFlag}</if>
  99. <if test="replayFlag != null "> and lwu.replay_flag = #{replayFlag}</if>
  100. </select>
  101. <select id="selectOnlineUserList" parameterType="LiveWatchUser" resultType="com.fs.live.vo.LiveWatchUserVO">
  102. select lwu.*,
  103. fu.nickname nickName,
  104. fu.avatar avatar
  105. from live_watch_user lwu
  106. left join fs_user fu on lwu.user_id = fu.user_id
  107. <where>
  108. <if test="liveId != null "> and live_id = #{liveId}</if>
  109. <if test="liveFlag != null "> and live_flag = #{liveFlag}</if>
  110. <if test="replayFlag != null "> and replay_flag = #{replayFlag}</if>
  111. <if test="online != null "> and online = #{online}</if>
  112. </where>
  113. </select>
  114. <insert id="insertLiveWatchUser" parameterType="LiveWatchUser" useGeneratedKeys="true" keyProperty="id">
  115. insert into live_watch_user
  116. <trim prefix="(" suffix=")" suffixOverrides=",">
  117. <if test="liveId != null">live_id,</if>
  118. <if test="userId != null">user_id,</if>
  119. <if test="msgStatus != null">msg_status,</if>
  120. <if test="online != null">online,</if>
  121. <if test="createTime != null">create_time,</if>
  122. <if test="createBy != null">create_by,</if>
  123. <if test="updateBy != null">update_by,</if>
  124. <if test="updateTime != null">update_time,</if>
  125. <if test="remark != null">remark,</if>
  126. <if test="onlineSeconds != null">online_seconds,</if>
  127. <if test="globalVisible != null">global_visible,</if>
  128. <if test="singleVisible != null">single_visible,</if>
  129. <if test="liveFlag != null">live_flag,</if>
  130. <if test="replayFlag != null">replay_flag,</if>
  131. <if test="location != null">location,</if>
  132. </trim>
  133. <trim prefix="values (" suffix=")" suffixOverrides=",">
  134. <if test="liveId != null">#{liveId},</if>
  135. <if test="userId != null">#{userId},</if>
  136. <if test="msgStatus != null">#{msgStatus},</if>
  137. <if test="online != null">#{online},</if>
  138. <if test="createTime != null">#{createTime},</if>
  139. <if test="createBy != null">#{createBy},</if>
  140. <if test="updateBy != null">#{updateBy},</if>
  141. <if test="updateTime != null">#{updateTime},</if>
  142. <if test="remark != null">#{remark},</if>
  143. <if test="onlineSeconds != null">#{onlineSeconds},</if>
  144. <if test="globalVisible != null">#{globalVisible},</if>
  145. <if test="singleVisible != null">#{singleVisible},</if>
  146. <if test="liveFlag != null">#{liveFlag},</if>
  147. <if test="replayFlag != null">#{replayFlag},</if>
  148. <if test="location != null">#{location},</if>
  149. </trim>
  150. </insert>
  151. <update id="updateLiveWatchUser" parameterType="LiveWatchUser">
  152. update live_watch_user
  153. <trim prefix="SET" suffixOverrides=",">
  154. <if test="liveId != null">live_id = #{liveId},</if>
  155. <if test="userId != null">user_id = #{userId},</if>
  156. <if test="msgStatus != null">msg_status = #{msgStatus},</if>
  157. <if test="online != null">online = #{online},</if>
  158. <if test="createTime != null">create_time = #{createTime},</if>
  159. <if test="createBy != null">create_by = #{createBy},</if>
  160. <if test="updateBy != null">update_by = #{updateBy},</if>
  161. <if test="updateTime != null">update_time = #{updateTime},</if>
  162. <if test="remark != null">remark = #{remark},</if>
  163. <if test="onlineSeconds != null">online_seconds = #{onlineSeconds},</if>
  164. <if test="globalVisible != null">global_visible = #{globalVisible},</if>
  165. <if test="singleVisible != null">single_visible = #{singleVisible},</if>
  166. <if test="liveFlag != null">live_flag = #{liveFlag},</if>
  167. <if test="replayFlag != null">replay_flag = #{replayFlag},</if>
  168. <if test="location != null">location = #{location},</if>
  169. </trim>
  170. where id = #{id}
  171. </update>
  172. <delete id="deleteLiveWatchUserById" parameterType="Long">
  173. delete from live_watch_user where id = #{id}
  174. </delete>
  175. <delete id="deleteLiveWatchUserByIds" parameterType="String">
  176. delete from live_watch_user where id in
  177. <foreach item="id" collection="array" open="(" separator="," close=")">
  178. #{id}
  179. </foreach>
  180. </delete>
  181. <select id="checkOnlineNoRewardUser" resultType="com.fs.live.domain.LiveWatchUser">
  182. SELECT lwu.*
  183. FROM live_watch_user lwu
  184. WHERE lwu.live_id = #{liveId}
  185. AND lwu.online = 0
  186. AND NOT EXISTS (
  187. SELECT 1
  188. FROM live_reward_record lrr
  189. WHERE lrr.user_id = lwu.user_id
  190. AND lrr.live_id = lwu.live_id
  191. and lrr.source_type = 3
  192. AND DATE(lrr.create_time) = DATE(#{now})
  193. )
  194. </select>
  195. <!-- 根据唯一索引查询:live_id, user_id, live_flag, replay_flag -->
  196. <select id="selectByUniqueIndex" resultMap="LiveWatchUserResult">
  197. <include refid="selectLiveWatchUserVo"/>
  198. WHERE live_id = #{liveId}
  199. AND user_id = #{userId}
  200. AND live_flag = #{liveFlag}
  201. AND replay_flag = #{replayFlag}
  202. LIMIT 1
  203. </select>
  204. <!-- 根据唯一索引插入或更新(ON DUPLICATE KEY UPDATE) -->
  205. <insert id="insertOrUpdateByUniqueIndex" parameterType="LiveWatchUser">
  206. INSERT INTO live_watch_user (
  207. live_id, user_id, live_flag, replay_flag,
  208. msg_status, online, location,
  209. create_time, update_time
  210. ) VALUES (
  211. #{liveId}, #{userId}, #{liveFlag}, #{replayFlag},
  212. #{msgStatus}, #{online}, #{location},
  213. #{createTime}, #{updateTime}
  214. )
  215. ON DUPLICATE KEY UPDATE
  216. msg_status = VALUES(msg_status),
  217. online = VALUES(online),
  218. location = VALUES(location),
  219. update_time = VALUES(update_time)
  220. </insert>
  221. </mapper>