MyResourceMapper.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.zhentao.mapper.MyResourceMapper">
  6. <resultMap id="BaseResultMap" type="com.zhentao.entity.MyResource">
  7. <id property="resourceId" column="resource_id" jdbcType="INTEGER"/>
  8. <result property="matchmakerId" column="matchmaker_id" jdbcType="INTEGER"/>
  9. <result property="name" column="name" jdbcType="VARCHAR"/>
  10. <result property="age" column="age" jdbcType="INTEGER"/>
  11. <result property="gender" column="gender" jdbcType="INTEGER"/>
  12. <result property="constellation" column="constellation" jdbcType="VARCHAR"/>
  13. <result property="height" column="height" jdbcType="INTEGER"/>
  14. <result property="weight" column="weight" jdbcType="INTEGER"/>
  15. <result property="marrStatus" column="marr_status" jdbcType="INTEGER"/>
  16. <result property="diploma" column="diploma" jdbcType="VARCHAR"/>
  17. <result property="income" column="income" jdbcType="VARCHAR"/>
  18. <result property="address" column="address" jdbcType="VARCHAR"/>
  19. <result property="domicile" column="domicile" jdbcType="VARCHAR"/>
  20. <result property="occupation" column="occupation" jdbcType="VARCHAR"/>
  21. <result property="house" column="house" jdbcType="INTEGER"/>
  22. <result property="phone" column="phone" jdbcType="VARCHAR"/>
  23. <result property="backupPhone" column="backup_phone" jdbcType="VARCHAR"/>
  24. <result property="car" column="car" jdbcType="INTEGER"/>
  25. <result property="mateSelectionCriteria" column="mate_selection_criteria" jdbcType="VARCHAR"/>
  26. <result property="isUser" column="is_user" jdbcType="INTEGER"/>
  27. <result property="userId" column="user_id" jdbcType="INTEGER"/>
  28. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  29. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  30. </resultMap>
  31. <sql id="Base_Column_List">
  32. resource_id,matchmaker_id,name,
  33. age,gender,constellation,
  34. height,weight,marr_status,
  35. diploma,income,address,
  36. domicile,occupation,house,
  37. phone,backup_phone,car,
  38. mate_selection_criteria,
  39. is_user,user_id,
  40. create_time,update_time
  41. </sql>
  42. <!-- 自定义插入方法,确保所有字段(包括null值)都被插入 -->
  43. <insert id="insertWithNulls" parameterType="com.zhentao.entity.MyResource" useGeneratedKeys="true" keyProperty="resourceId">
  44. INSERT INTO my_resource (
  45. matchmaker_id, name, age, gender, constellation,
  46. height, weight, marr_status, diploma, income,
  47. address, domicile, occupation, house, phone,
  48. backup_phone, car, mate_selection_criteria,
  49. is_user, user_id, create_time, update_time
  50. ) VALUES (
  51. #{matchmakerId}, #{name}, #{age}, #{gender}, #{constellation},
  52. #{height}, #{weight}, #{marrStatus}, #{diploma}, #{income},
  53. #{address}, #{domicile}, #{occupation}, #{house}, #{phone},
  54. #{backupPhone}, #{car}, #{mateSelectionCriteria},
  55. #{isUser}, #{userId}, #{createTime}, #{updateTime}
  56. )
  57. </insert>
  58. <!-- MyResourceVO结果映射 -->
  59. <resultMap id="MyResourceVOMap" type="com.zhentao.vo.MyResourceVO">
  60. <id property="resourceId" column="resource_id" jdbcType="INTEGER"/>
  61. <result property="matchmakerId" column="matchmaker_id" jdbcType="INTEGER"/>
  62. <result property="name" column="name" jdbcType="VARCHAR"/>
  63. <result property="age" column="age" jdbcType="INTEGER"/>
  64. <result property="gender" column="gender" jdbcType="INTEGER"/>
  65. <result property="constellation" column="constellation" jdbcType="VARCHAR"/>
  66. <result property="height" column="height" jdbcType="INTEGER"/>
  67. <result property="weight" column="weight" jdbcType="INTEGER"/>
  68. <result property="marrStatus" column="marr_status" jdbcType="INTEGER"/>
  69. <result property="diploma" column="diploma" jdbcType="VARCHAR"/>
  70. <result property="income" column="income" jdbcType="VARCHAR"/>
  71. <result property="address" column="address" jdbcType="VARCHAR"/>
  72. <result property="domicile" column="domicile" jdbcType="VARCHAR"/>
  73. <result property="occupation" column="occupation" jdbcType="VARCHAR"/>
  74. <result property="house" column="house" jdbcType="INTEGER"/>
  75. <result property="phone" column="phone" jdbcType="VARCHAR"/>
  76. <result property="backupPhone" column="backup_phone" jdbcType="VARCHAR"/>
  77. <result property="car" column="car" jdbcType="INTEGER"/>
  78. <result property="mateSelectionCriteria" column="mate_selection_criteria" jdbcType="VARCHAR"/>
  79. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  80. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  81. <result property="avatarUrl" column="avatar_url" jdbcType="VARCHAR"/>
  82. <result property="isUser" column="is_user" jdbcType="INTEGER"/>
  83. <result property="isMatch" column="is_match" jdbcType="INTEGER"/>
  84. <result property="isInvitation" column="is_invitation" jdbcType="INTEGER"/>
  85. <result property="invitationTime" column="invitation_time" jdbcType="TIMESTAMP"/>
  86. </resultMap>
  87. <!-- 分页查询资源列表(关联users表获取头像) -->
  88. <select id="selectResourceListWithAvatar" resultMap="MyResourceVOMap">
  89. SELECT
  90. r.resource_id,
  91. r.matchmaker_id,
  92. r.name,
  93. r.age,
  94. r.gender,
  95. r.constellation,
  96. r.height,
  97. r.weight,
  98. r.marr_status,
  99. r.diploma,
  100. r.income,
  101. r.address,
  102. r.domicile,
  103. r.occupation,
  104. r.house,
  105. r.phone,
  106. r.backup_phone,
  107. r.car,
  108. r.mate_selection_criteria,
  109. r.is_user,
  110. r.create_time,
  111. r.update_time,
  112. u.avatar_url,
  113. COALESCE(f.is_match, 0) as is_match,
  114. COALESCE(f.is_invitation, 0) as is_invitation,
  115. f.invitation_time
  116. FROM my_resource r
  117. LEFT JOIN users u ON r.user_id = u.user_id
  118. LEFT JOIN (
  119. SELECT f1.resource_id, f1.matchmaker_id, f1.is_match, f1.is_invitation, f1.invitation_time
  120. FROM user_follow_up f1
  121. INNER JOIN (
  122. SELECT resource_id, matchmaker_id, MAX(update_time) as max_update_time
  123. FROM user_follow_up
  124. GROUP BY resource_id, matchmaker_id
  125. ) f2 ON f1.resource_id = f2.resource_id
  126. AND f1.matchmaker_id = f2.matchmaker_id
  127. AND f1.update_time = f2.max_update_time
  128. ) f ON r.resource_id = f.resource_id AND r.matchmaker_id = f.matchmaker_id
  129. WHERE 1=1
  130. <if test="matchmakerId != null">
  131. AND r.matchmaker_id = #{matchmakerId}
  132. </if>
  133. <if test="keyword != null and keyword != ''">
  134. AND (r.name LIKE CONCAT('%', #{keyword}, '%')
  135. OR r.phone LIKE CONCAT('%', #{keyword}, '%'))
  136. </if>
  137. ORDER BY r.create_time DESC
  138. </select>
  139. </mapper>