ImUserFriendMapper.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.ImUserFriendDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.ImUserFriend" id="ImUserFriend">
  9. <result column="id_" property="id" />
  10. <result column="user_id_" property="userId" />
  11. <result column="friend_id_" property="friendId" />
  12. <result column="friend_nickname_" property="friendNickname" />
  13. <result column="memo_" property="memo" />
  14. <result column="tags_" property="tags" />
  15. <result column="member_rank_setting_id_" property="memberRankSettingId" />
  16. <result column="subject_name_" property="subjectName" />
  17. <result column="subject_id_" property="subjectId" />
  18. <result column="create_time_" property="createTime" />
  19. <result column="update_time_" property="updateTime" />
  20. <result column="tenant_id_" property="tenantId"/>
  21. </resultMap>
  22. <resultMap type="com.ym.mec.biz.dal.dto.ImUserFriendDto" id="ImUserFriendDto" extends="ImUserFriend">
  23. <result column="real_name_" property="friend.realName" />
  24. <result column="avatar_" property="friend.avatar" />
  25. <result column="user_type_" property="friend.userType" />
  26. <result column="phone_" property="friend.phone" />
  27. </resultMap>
  28. <!-- 根据主键查询一条记录 -->
  29. <select id="get" resultMap="ImUserFriend" >
  30. SELECT * FROM im_user_friend WHERE id_ = #{id}
  31. </select>
  32. <!-- 全查询 -->
  33. <select id="findAll" resultMap="ImUserFriend">
  34. SELECT * FROM im_user_friend where tenant_id_ = #{tenantId} ORDER BY id_
  35. </select>
  36. <!-- 向数据库增加一条记录 -->
  37. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ImUserFriend" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  38. INSERT INTO im_user_friend (id_,user_id_,friend_id_,friend_nickname_,memo_,tags_,create_time_,update_time_,tenant_id_)
  39. VALUES(#{id},#{userId},#{friendId},#{friendNickname},#{memo},#{tags},NOW(),NOW(),#{tenantId})
  40. </insert>
  41. <insert id="insertByBasicUser">
  42. INSERT INTO im_user_friend (user_id_,friend_id_,friend_nickname_,tags_,memo_,create_time_,update_time_,tenant_id_)
  43. VALUES (#{teacherId},#{basicUserDto.userId},#{basicUserDto.name},#{basicUserDto.subjectName},#{basicUserDto.musicGroupName},NOW(),NOW(),#{basicUserDto.tenantId})
  44. </insert>
  45. <!-- 根据主键查询一条记录 -->
  46. <update id="update" parameterType="com.ym.mec.biz.dal.entity.ImUserFriend">
  47. UPDATE im_user_friend <set>
  48. <if test="userId != null">
  49. user_id_ = #{userId},
  50. </if>
  51. <if test="friendId != null">
  52. friend_id_ = #{friendId},
  53. </if>
  54. <if test="friendNickname != null">
  55. friend_nickname_ = #{friendNickname},
  56. </if>
  57. <if test="memo != null">
  58. memo_ = #{memo},
  59. </if>
  60. <if test="tags != null">
  61. tags_ = #{tags},
  62. </if>
  63. update_time_ = NOW()
  64. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  65. </update>
  66. <update id="updateNullNickName">
  67. UPDATE im_user_friend iuf
  68. LEFT JOIN sys_user su ON su.id_ = iuf.friend_id_
  69. SET iuf.friend_nickname_ = CASE WHEN su.real_name_ IS NULL OR su.real_name_ = '' THEN su.username_ ELSE su.real_name_ END
  70. WHERE iuf.friend_nickname_ IS NULL
  71. </update>
  72. <!-- 根据主键删除一条记录 -->
  73. <delete id="delete" >
  74. DELETE FROM im_user_friend WHERE id_ = #{id}
  75. </delete>
  76. <delete id="deleteByUserId">
  77. DELETE FROM im_user_friend WHERE user_id_ = #{teacherId}
  78. </delete>
  79. <!-- 分页查询 -->
  80. <select id="queryPage" resultMap="ImUserFriend" parameterType="map">
  81. SELECT * FROM im_user_friend where tenant_id_ = #{tenantId} ORDER BY id_ <include refid="global.limit"/>
  82. </select>
  83. <!-- 查询当前表的总记录数 -->
  84. <select id="queryCount" resultType="int">
  85. SELECT COUNT(*) FROM im_user_friend where tenant_id_ = #{tenantId}
  86. </select>
  87. <select id="query" resultMap="ImUserFriend" parameterType="map">
  88. SELECT * FROM im_user_friend where user_id_ = #{userId} and friend_id_ = #{friendId} LIMIT 1
  89. </select>
  90. <select id="queryFriendListByUserId" resultMap="ImUserFriendDto" parameterType="map">
  91. SELECT iuf.*,u.real_name_,u.avatar_,u.phone_,u.user_type_,st.member_rank_setting_id_,s.name_ subject_name_,st.subject_id_list_ subject_id_
  92. FROM im_user_friend iuf
  93. LEFT JOIN sys_user u ON iuf.friend_id_ = u.id_
  94. LEFT JOIN student st ON st.user_id_ = u.id_
  95. LEFT JOIN `subject` s ON s.id_ = st.subject_id_list_
  96. WHERE iuf.user_id_ = #{userId}
  97. <if test="search != null">
  98. and (u.real_name_ like concat('%',#{search},'%') or iuf.friend_nickname_ like concat('%',#{search},'%'))
  99. </if>
  100. </select>
  101. <select id="queryFriendDetail" resultMap="ImUserFriendDto" parameterType="map">
  102. SELECT iuf.*,u.real_name_,u.avatar_,u.phone_,u.user_type_,s.subject_id_list_ subject_id_,s.member_rank_setting_id_,sb.name_ subject_name_
  103. FROM im_user_friend iuf
  104. LEFT JOIN sys_user u ON iuf.friend_id_ = u.id_
  105. LEFT JOIN student s ON s.user_id_ = u.id_
  106. LEFT JOIN subject sb ON s.subject_id_list_ = sb.id_
  107. WHERE iuf.user_id_ = #{userId} AND iuf.friend_id_ = #{friendUserId}
  108. </select>
  109. <resultMap id="NameDto" type="com.ym.mec.biz.dal.dto.NameDto">
  110. <result property="id" column="id_" />
  111. <result property="name" column="name_" />
  112. <result property="type" column="type_"/>
  113. <result property="avatar" column="avatar_"/>
  114. </resultMap>
  115. <select id="queryNameByIds" resultMap="NameDto">
  116. select iuf.friend_id_ id_,iuf.friend_nickname_ name_,1 type_,su.avatar_
  117. from im_user_friend iuf
  118. left join sys_user su on iuf.friend_id_ = su.id_
  119. where iuf.user_id_ = #{userId} and find_in_set(friend_id_,#{ids})
  120. </select>
  121. </mapper>