<?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.dgtly.system.mapper.PeopInfoMapper">
    
    <resultMap type="PeopInfo" id="PeopInfoResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="belongCommunityId"    column="belong_community_id"    />
        <result property="isWuhan"    column="is_wuhan"    />
        <result property="address"    column="address"    />
        <result property="qrCode"    column="qr_code"    />
        <result property="residentNum"    column="resident_num"    />
        <result property="householdRelation"    column="household_relation"    />
        <result property="ownership"    column="ownership"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectPeopInfoVo">
        select id, user_id, belong_community_id, is_wuhan, address, qr_code, resident_num, household_relation, ownership, create_by, create_time, update_by, update_time, remark from peop_info
    </sql>

    <select id="selectPeopInfoList" parameterType="PeopInfo" resultMap="PeopInfoResult">
        <include refid="selectPeopInfoVo"/>
        <where>  
            <if test="belongCommunityId != null "> and belong_community_id = #{belongCommunityId}</if>
            <if test="isWuhan != null  and isWuhan != ''"> and is_wuhan = #{isWuhan}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
            <if test="residentNum != null "> and resident_num = #{residentNum}</if>
            <if test="householdRelation != null  and householdRelation != ''"> and household_relation = #{householdRelation}</if>
            <if test="ownership != null  and ownership != ''"> and ownership = #{ownership}</if>
        </where>
    </select>
    
    <select id="selectPeopInfoById" parameterType="Long" resultMap="PeopInfoResult">
        <include refid="selectPeopInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPeopInfo" parameterType="PeopInfo">
        insert into peop_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="userId != null ">user_id,</if>
            <if test="belongCommunityId != null ">belong_community_id,</if>
            <if test="isWuhan != null  and isWuhan != ''">is_wuhan,</if>
            <if test="address != null  and address != ''">address,</if>
            <if test="qrCode != null  and qrCode != ''">qr_code,</if>
            <if test="residentNum != null ">resident_num,</if>
            <if test="householdRelation != null  and householdRelation != ''">household_relation,</if>
            <if test="ownership != null  and ownership != ''">ownership,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="belongCommunityId != null ">#{belongCommunityId},</if>
            <if test="isWuhan != null  and isWuhan != ''">#{isWuhan},</if>
            <if test="address != null  and address != ''">#{address},</if>
            <if test="qrCode != null  and qrCode != ''">#{qrCode},</if>
            <if test="residentNum != null ">#{residentNum},</if>
            <if test="householdRelation != null  and householdRelation != ''">#{householdRelation},</if>
            <if test="ownership != null  and ownership != ''">#{ownership},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updatePeopInfo" parameterType="PeopInfo">
        update peop_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="belongCommunityId != null ">belong_community_id = #{belongCommunityId},</if>
            <if test="isWuhan != null  and isWuhan != ''">is_wuhan = #{isWuhan},</if>
            <if test="address != null  and address != ''">address = #{address},</if>
            <if test="qrCode != null  and qrCode != ''">qr_code = #{qrCode},</if>
            <if test="residentNum != null ">resident_num = #{residentNum},</if>
            <if test="householdRelation != null  and householdRelation != ''">household_relation = #{householdRelation},</if>
            <if test="ownership != null  and ownership != ''">ownership = #{ownership},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePeopInfoById" parameterType="Long">
        delete from peop_info where id = #{id}
    </delete>

    <delete id="deletePeopInfoByIds" parameterType="String">
        delete from peop_info where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>