<?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.api.app.dao.personalData.PersonalDataDao">
    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.app.PersonalDataVo">
        select * from user_resident where id =#{id}
    </select>

    <update id="updateNickName" parameterType="com.api.model.basicArchives.UserResident">
        update user_resident set nick_name = #{nickName} where id = #{id}
    </update>

    <update id="updateTel" parameterType="com.api.model.app.UpdateTel">
        update user_resident set tel = #{newTel} where id = #{id}
    </update>

    <select id="findTelUpdateCodeByTel" parameterType="java.lang.String" resultType="com.api.model.app.UpdateTel">
        select * from user_tel_update_code where new_tel = #{newTel}
    </select>

    <update id="updateTelUpdateCode" parameterType="com.api.model.app.UpdateTel">
        update user_tel_update_code
        set code = #{code},code_send_date = #{codeSendDate}
        where id = #{id}
    </update>

    <insert id="insertTelUpdateCode" parameterType="com.api.model.app.UpdateTel">
        insert into user_tel_update_code(
            new_tel,
            code,
            code_send_date
        )values (
            #{newTel},
            #{code},
            #{codeSendDate}
        )
    </insert>

    <select id="findUserTelUpdateByTel" parameterType="java.lang.String" resultType="com.api.model.app.UpdateTel">
        select * from user_tel_update_code where new_tel = #{newTel}
    </select>

    <delete id="deleteUserTelUpdateByTel" parameterType="java.lang.String">
        delete from user_tel_update_code where new_tel = #{newTel}
    </delete>

    <update id="updateSex" parameterType="com.api.model.app.PersonalData">
        update user_resident set sex = #{sex} where id = #{id}
    </update>

    <update id="updateBirthday" parameterType="com.api.model.app.PersonalData">
        update user_resident set birthday = #{birthday} where id = #{id}
    </update>

    <select id="findEstateNameByResidentId" parameterType="java.lang.Integer" resultType="java.lang.String">
        select concat(cbue.id,"|",cb.no,"幢-",cbu.no,"单元-",cbue.room_number)
        from cpm_resident_estate as cre,cpm_building_unit_estate as cbue,cpm_building_unit as cbu,cpm_building as cb
        where cre.building_unit_estate_id = cbue.id and cbue.building_unit_id = cbu.id and cbu.building_id = cb.id and cre.resident_id = #{id}
    </select>
</mapper>