FsUserOnlineStateMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.store.mapper.FsUserOnlineStateMapper">
  6. <resultMap type="FsUserOnlineState" id="FsUserOnlineStateResult">
  7. <result property="id" column="id" />
  8. <result property="userId" column="user_id" />
  9. <result property="nickname" column="nickname" />
  10. <result property="avatar" column="avatar" />
  11. <result property="phone" column="phone" />
  12. <result property="createTime" column="create_time" />
  13. <result property="maOpenId" column="ma_open_id" />
  14. <result property="mpOpenId" column="mp_open_id" />
  15. <result property="unionId" column="union_id" />
  16. <result property="status" column="status" />
  17. <result property="companyId" column="company_id" />
  18. <result property="companyUserId" column="company_user_id" />
  19. <result property="companyName" column="company_name" />
  20. <result property="companyUserName" column="company_user_name" />
  21. <result property="onlineStatus" column="online_status" />
  22. <result property="onlineTime" column="online_time" />
  23. <result property="watchCourseCount" column="watch_course_count" />
  24. <result property="partCourseCount" column="part_course_count" />
  25. <result property="lastWatchDate" column="last_watch_date" />
  26. <result property="updateTime" column="update_time" />
  27. </resultMap>
  28. <sql id="selectFsUserOnlineStateVo">
  29. select id, user_id, nickname, avatar, phone, create_time, ma_open_id, mp_open_id, union_id, status, company_id, company_user_id, company_name, company_user_name, online_status, online_time, watch_course_count, part_course_count, last_watch_date, update_time from fs_user_online_state
  30. </sql>
  31. <select id="selectFsUserOnlineStateList" parameterType="FsUserOnlineState" resultMap="FsUserOnlineStateResult">
  32. <include refid="selectFsUserOnlineStateVo"/>
  33. <where>
  34. <if test="nickname != null and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
  35. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  36. <if test="phone != null and phone != ''"> and phone like concat ('%', #{phone}, '%')</if>
  37. <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
  38. <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
  39. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  40. <if test="status != null "> and status = #{status}</if>
  41. <if test="companyId != null "> and company_id = #{companyId}</if>
  42. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  43. <if test="companyName != null and companyName !='' "> and company_name like concat('%', #{companyName}, '%')</if>
  44. <if test="companyUserName != null and companyUserName !='' "> and company_user_name like concat('%', #{companyUserName}, '%')</if>
  45. <if test="onlineStatus != null "> and online_status = #{onlineStatus}</if>
  46. <if test="onlineTime != null "> and online_time = #{onlineTime}</if>
  47. <if test="watchCourseCount != null "> and watch_course_count = #{watchCourseCount}</if>
  48. <if test="partCourseCount != null "> and part_course_count = #{partCourseCount}</if>
  49. <if test="lastWatchDate != null "> and last_watch_date = #{lastWatchDate}</if>
  50. <if test="updateTime != null "> and update_time = #{updateTime}</if>
  51. </where>
  52. </select>
  53. <select id="selectFsUserOnlineStateById" parameterType="Long" resultMap="FsUserOnlineStateResult">
  54. <include refid="selectFsUserOnlineStateVo"/>
  55. where id = #{id}
  56. </select>
  57. <insert id="insertFsUserOnlineState" parameterType="FsUserOnlineState" useGeneratedKeys="true" keyProperty="id">
  58. insert into fs_user_online_state
  59. <trim prefix="(" suffix=")" suffixOverrides=",">
  60. <if test="userId != null">user_id,</if>
  61. <if test="nickname != null">nickname,</if>
  62. <if test="avatar != null">avatar,</if>
  63. <if test="phone != null">phone,</if>
  64. <if test="createTime != null">create_time,</if>
  65. <if test="maOpenId != null">ma_open_id,</if>
  66. <if test="mpOpenId != null">mp_open_id,</if>
  67. <if test="unionId != null">union_id,</if>
  68. <if test="status != null">status,</if>
  69. <if test="companyId != null">company_id,</if>
  70. <if test="companyUserId != null">company_user_id,</if>
  71. <if test="companyName != null">company_name,</if>
  72. <if test="companyUserName != null">company_user_name,</if>
  73. <if test="onlineStatus != null">online_status,</if>
  74. <if test="onlineTime != null">online_time,</if>
  75. <if test="watchCourseCount != null">watch_course_count,</if>
  76. <if test="partCourseCount != null">part_course_count,</if>
  77. <if test="lastWatchDate != null">last_watch_date,</if>
  78. <if test="updateTime != null ">update_time,</if>
  79. </trim>
  80. <trim prefix="values (" suffix=")" suffixOverrides=",">
  81. <if test="userId != null">#{userId},</if>
  82. <if test="nickname != null">#{nickname},</if>
  83. <if test="avatar != null">#{avatar},</if>
  84. <if test="phone != null">#{phone},</if>
  85. <if test="createTime != null">#{createTime},</if>
  86. <if test="maOpenId != null">#{maOpenId},</if>
  87. <if test="mpOpenId != null">#{mpOpenId},</if>
  88. <if test="unionId != null">#{unionId},</if>
  89. <if test="status != null">#{status},</if>
  90. <if test="companyId != null">#{companyId},</if>
  91. <if test="companyUserId != null">#{companyUserId},</if>
  92. <if test="companyName != null">#{companyName},</if>
  93. <if test="companyUserName != null">#{companyUserName},</if>
  94. <if test="onlineStatus != null">#{onlineStatus},</if>
  95. <if test="onlineTime != null">#{onlineTime},</if>
  96. <if test="watchCourseCount != null">#{watchCourseCount},</if>
  97. <if test="partCourseCount != null">#{partCourseCount},</if>
  98. <if test="lastWatchDate != null">#{lastWatchDate},</if>
  99. <if test="updateTime != null ">#{updateTime},</if>
  100. </trim>
  101. on duplicate key update
  102. <trim suffixOverrides=",">
  103. <if test="companyId != null">company_id = #{companyId},</if>
  104. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  105. <if test="companyName != null">company_Name = #{companyName},</if>
  106. <if test="companyUserName != null">company_user_name = #{companyUserName},</if>
  107. <if test="updateTime != null ">update_time = #{updateTime}</if>
  108. </trim>
  109. </insert>
  110. <update id="updateFsUserOnlineState" parameterType="FsUserOnlineState">
  111. update fs_user_online_state
  112. <trim prefix="SET" suffixOverrides=",">
  113. <if test="userId != null">user_id = #{userId},</if>
  114. <if test="nickname != null">nickname = #{nickname},</if>
  115. <if test="avatar != null">avatar = #{avatar},</if>
  116. <if test="phone != null">phone = #{phone},</if>
  117. <if test="createTime != null">create_time = #{createTime},</if>
  118. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  119. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  120. <if test="unionId != null">union_id = #{unionId},</if>
  121. <if test="status != null">status = #{status},</if>
  122. <if test="companyId != null">company_id = #{companyId},</if>
  123. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  124. <if test="companyName != null">company_Name = #{companyName},</if>
  125. <if test="companyUserName != null">company_user_name = #{companyUserName},</if>
  126. <if test="onlineStatus != null">online_status = #{onlineStatus},</if>
  127. <if test="onlineTime != null">online_time = #{onlineTime},</if>
  128. <if test="watchCourseCount != null">watch_course_count = #{watchCourseCount},</if>
  129. <if test="partCourseCount != null">part_course_count = #{partCourseCount},</if>
  130. <if test="lastWatchDate != null">last_watch_date = #{lastWatchDate},</if>
  131. <if test="updateTime != null ">update_time = #{updateTime}</if>
  132. </trim>
  133. where user_id = #{userId}
  134. </update>
  135. <delete id="deleteFsUserOnlineStateById" parameterType="Long">
  136. delete from fs_user_online_state where user_id = #{userId}
  137. </delete>
  138. <delete id="deleteFsUserOnlineStateByIds" parameterType="String">
  139. delete from fs_user_online_state where user_id in
  140. <foreach item="userId" collection="array" open="(" separator="," close=")">
  141. #{userId}
  142. </foreach>
  143. </delete>
  144. <select id="selectUserNotOnline" resultType="FsUserOnlineState">
  145. SELECT
  146. a.*,
  147. company_user.nick_name as companyUserName,
  148. company.company_name
  149. FROM
  150. (
  151. SELECT
  152. user_id,
  153. nickname,
  154. avatar,
  155. phone,
  156. create_time,
  157. ma_open_id,
  158. mp_open_id,
  159. union_id,
  160. STATUS,
  161. company_id,
  162. company_user_id,
  163. 2 AS onlineStatus,
  164. 0 AS watchCourseCount,
  165. 0 AS partCourseCount,
  166. NOW() AS updateTime
  167. FROM
  168. fs_user
  169. WHERE
  170. is_del = 0
  171. AND user_id NOT IN ( SELECT DISTINCT user_id FROM fs_course_watch_log WHERE send_type = 1 )
  172. ) a
  173. LEFT JOIN company_user ON company_user.user_id = a.company_user_id
  174. LEFT JOIN company ON company.company_id = a.company_id
  175. </select>
  176. <select id="selectExistWatchLogUser" resultType="FsUser">
  177. SELECT
  178. count( 1 ),
  179. fs_course_watch_log.user_id,
  180. create_time
  181. FROM
  182. fs_course_watch_log
  183. WHERE
  184. send_type = 1
  185. GROUP BY
  186. fs_course_watch_log.user_id
  187. HAVING
  188. count( 1 ) = 1
  189. AND create_time >= DATE_SUB( NOW(), INTERVAL 15 MINUTE )
  190. </select>
  191. </mapper>