ImUserFriendMapper.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.ImUserFriendDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ImUserFriend">
  5. <id column="id_" jdbcType="INTEGER" property="id"/>
  6. <result column="user_id_" jdbcType="INTEGER" property="userId"/>
  7. <result column="friend_id_" jdbcType="INTEGER" property="friendId"/>
  8. <result column="friend_nickname_" jdbcType="VARCHAR" property="friendNickname"/>
  9. <result column="friend_avatar_" jdbcType="VARCHAR" property="friendAvatar"/>
  10. <result column="memo_" jdbcType="VARCHAR" property="memo"/>
  11. <result column="source_form_" jdbcType="VARCHAR" property="sourceForm"/>
  12. <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
  13. <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
  14. </resultMap>
  15. <sql id="Base_Column_List">
  16. id_, user_id_, friend_id_, friend_nickname_,friend_avatar_, memo_, create_time_, update_time_
  17. </sql>
  18. <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
  19. parameterType="com.yonge.cooleshow.biz.dal.entity.ImUserFriend">
  20. INSERT INTO im_user_friend(user_id_, client_type_, friend_id_, friend_type_, friend_nickname_,friend_avatar_, memo_, source_form_, create_time_, update_time_) VALUES
  21. <foreach collection="entities" item="entity" separator=",">
  22. (#{entity.userId}, #{entity.clientType}, #{entity.friendId}, #{entity.friendType}, #{entity.friendNickname}, #{entity.friendAvatar}, #{entity.memo},
  23. #{entity.sourceForm},#{entity.createTime}, #{entity.updateTime})
  24. </foreach>
  25. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_), client_type_ = VALUES(client_type_), friend_id_ = VALUES(friend_id_), friend_type_ = VALUES(friend_type_)
  26. </insert>
  27. <select id="findByUserIdAndFriendId" resultMap="BaseResultMap">
  28. SELECT <include refid="Base_Column_List"/> FROM im_user_friend WHERE user_id_ = #{userId} AND friend_id_ = #{friendId} LIMIT 1
  29. </select>
  30. <delete id="delTeacherFriendByTenantId">
  31. DELETE t1
  32. FROM im_user_friend t1
  33. LEFT JOIN teacher t2 ON t1.friend_id_ = t2.user_id_
  34. LEFT JOIN teacher t3 ON t1.user_id_ = t3.user_id_
  35. WHERE (t1.user_id_ = #{userId} and t1.client_type_ = #{clientType} and t2.tenant_id_ = #{tenantId})
  36. OR (t1.friend_id_ = #{userId} and t1.friend_type_ = #{clientType} and t3.tenant_id_ = #{tenantId})
  37. </delete>
  38. <delete id="delStudentFriendByTenantId">
  39. DELETE t1
  40. FROM im_user_friend t1
  41. LEFT JOIN student t2 ON t1.friend_id_ = t2.user_id_
  42. LEFT JOIN student t3 ON t1.user_id_ = t3.user_id_
  43. WHERE (t1.user_id_ = #{userId} and t1.client_type_ = #{clientType} and t2.tenant_id_ = #{tenantId})
  44. OR (t1.friend_id_ = #{userId} and t1.friend_type_ = #{clientType} and t3.tenant_id_ = #{tenantId})
  45. </delete>
  46. <select id="queryExistCustomerServiceFriend" resultMap="BaseResultMap">
  47. select distinct t.*
  48. from im_user_friend t
  49. left join teacher te on t.friend_id_ = te.user_id_ and te.customer_service_ = 1 and te.lock_flag_ = 0
  50. left join sys_user su on te.user_id_ = su.id_
  51. where t.friend_type_ = 'TEACHER'
  52. and find_in_set(t.user_id_, #{userIds})
  53. and t.client_type_ = #{clientType}
  54. and su.del_flag_ = 0
  55. and su.lock_flag_ = 0
  56. and te.user_id_ is not null
  57. </select>
  58. </mapper>