| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zhentao.mapper.MyResourceMapper">
- <resultMap id="BaseResultMap" type="com.zhentao.entity.MyResource">
- <id property="resourceId" column="resource_id" jdbcType="INTEGER"/>
- <result property="matchmakerId" column="matchmaker_id" jdbcType="INTEGER"/>
- <result property="name" column="name" jdbcType="VARCHAR"/>
- <result property="age" column="age" jdbcType="INTEGER"/>
- <result property="gender" column="gender" jdbcType="INTEGER"/>
- <result property="constellation" column="constellation" jdbcType="VARCHAR"/>
- <result property="height" column="height" jdbcType="INTEGER"/>
- <result property="weight" column="weight" jdbcType="INTEGER"/>
- <result property="marrStatus" column="marr_status" jdbcType="INTEGER"/>
- <result property="diploma" column="diploma" jdbcType="VARCHAR"/>
- <result property="income" column="income" jdbcType="VARCHAR"/>
- <result property="address" column="address" jdbcType="VARCHAR"/>
- <result property="domicile" column="domicile" jdbcType="VARCHAR"/>
- <result property="occupation" column="occupation" jdbcType="VARCHAR"/>
- <result property="house" column="house" jdbcType="INTEGER"/>
- <result property="phone" column="phone" jdbcType="VARCHAR"/>
- <result property="backupPhone" column="backup_phone" jdbcType="VARCHAR"/>
- <result property="car" column="car" jdbcType="INTEGER"/>
- <result property="mateSelectionCriteria" column="mate_selection_criteria" jdbcType="VARCHAR"/>
- <result property="isUser" column="is_user" jdbcType="INTEGER"/>
- <result property="userId" column="user_id" jdbcType="INTEGER"/>
- <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
- <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
- </resultMap>
- <sql id="Base_Column_List">
- resource_id,matchmaker_id,name,
- age,gender,constellation,
- height,weight,marr_status,
- diploma,income,address,
- domicile,occupation,house,
- phone,backup_phone,car,
- mate_selection_criteria,
- is_user,user_id,
- create_time,update_time
- </sql>
- <!-- 自定义插入方法,确保所有字段(包括null值)都被插入 -->
- <insert id="insertWithNulls" parameterType="com.zhentao.entity.MyResource" useGeneratedKeys="true" keyProperty="resourceId">
- INSERT INTO my_resource (
- matchmaker_id, name, age, gender, constellation,
- height, weight, marr_status, diploma, income,
- address, domicile, occupation, house, phone,
- backup_phone, car, mate_selection_criteria,
- is_user, user_id, create_time, update_time
- ) VALUES (
- #{matchmakerId}, #{name}, #{age}, #{gender}, #{constellation},
- #{height}, #{weight}, #{marrStatus}, #{diploma}, #{income},
- #{address}, #{domicile}, #{occupation}, #{house}, #{phone},
- #{backupPhone}, #{car}, #{mateSelectionCriteria},
- #{isUser}, #{userId}, #{createTime}, #{updateTime}
- )
- </insert>
- <!-- MyResourceVO结果映射 -->
- <resultMap id="MyResourceVOMap" type="com.zhentao.vo.MyResourceVO">
- <id property="resourceId" column="resource_id" jdbcType="INTEGER"/>
- <result property="matchmakerId" column="matchmaker_id" jdbcType="INTEGER"/>
- <result property="name" column="name" jdbcType="VARCHAR"/>
- <result property="age" column="age" jdbcType="INTEGER"/>
- <result property="gender" column="gender" jdbcType="INTEGER"/>
- <result property="constellation" column="constellation" jdbcType="VARCHAR"/>
- <result property="height" column="height" jdbcType="INTEGER"/>
- <result property="weight" column="weight" jdbcType="INTEGER"/>
- <result property="marrStatus" column="marr_status" jdbcType="INTEGER"/>
- <result property="diploma" column="diploma" jdbcType="VARCHAR"/>
- <result property="income" column="income" jdbcType="VARCHAR"/>
- <result property="address" column="address" jdbcType="VARCHAR"/>
- <result property="domicile" column="domicile" jdbcType="VARCHAR"/>
- <result property="occupation" column="occupation" jdbcType="VARCHAR"/>
- <result property="house" column="house" jdbcType="INTEGER"/>
- <result property="phone" column="phone" jdbcType="VARCHAR"/>
- <result property="backupPhone" column="backup_phone" jdbcType="VARCHAR"/>
- <result property="car" column="car" jdbcType="INTEGER"/>
- <result property="mateSelectionCriteria" column="mate_selection_criteria" jdbcType="VARCHAR"/>
- <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
- <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
- <result property="avatarUrl" column="avatar_url" jdbcType="VARCHAR"/>
- <result property="isUser" column="is_user" jdbcType="INTEGER"/>
- <result property="isMatch" column="is_match" jdbcType="INTEGER"/>
- <result property="isInvitation" column="is_invitation" jdbcType="INTEGER"/>
- <result property="invitationTime" column="invitation_time" jdbcType="TIMESTAMP"/>
- </resultMap>
- <!-- 分页查询资源列表(关联users表获取头像) -->
- <select id="selectResourceListWithAvatar" resultMap="MyResourceVOMap">
- SELECT
- r.resource_id,
- r.matchmaker_id,
- r.name,
- r.age,
- r.gender,
- r.constellation,
- r.height,
- r.weight,
- r.marr_status,
- r.diploma,
- r.income,
- r.address,
- r.domicile,
- r.occupation,
- r.house,
- r.phone,
- r.backup_phone,
- r.car,
- r.mate_selection_criteria,
- r.is_user,
- r.create_time,
- r.update_time,
- u.avatar_url,
- COALESCE(f.is_match, 0) as is_match,
- COALESCE(f.is_invitation, 0) as is_invitation,
- f.invitation_time
- FROM my_resource r
- LEFT JOIN users u ON r.user_id = u.user_id
- LEFT JOIN (
- SELECT f1.resource_id, f1.matchmaker_id, f1.is_match, f1.is_invitation, f1.invitation_time
- FROM user_follow_up f1
- INNER JOIN (
- SELECT resource_id, matchmaker_id, MAX(update_time) as max_update_time
- FROM user_follow_up
- GROUP BY resource_id, matchmaker_id
- ) f2 ON f1.resource_id = f2.resource_id
- AND f1.matchmaker_id = f2.matchmaker_id
- AND f1.update_time = f2.max_update_time
- ) f ON r.resource_id = f.resource_id AND r.matchmaker_id = f.matchmaker_id
- WHERE 1=1
- <if test="matchmakerId != null">
- AND r.matchmaker_id = #{matchmakerId}
- </if>
- <if test="keyword != null and keyword != ''">
- AND (r.name LIKE CONCAT('%', #{keyword}, '%')
- OR r.phone LIKE CONCAT('%', #{keyword}, '%'))
- </if>
- ORDER BY r.create_time DESC
- </select>
- </mapper>
|