<?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.mmc.iuav.user.dao.UserServiceDao">
    <resultMap id="userAccountResultMap" type="com.mmc.iuav.user.entity.UserAccountDO">
        <id property="id" column="id"/>
        <result property="accountType" column="account_type"/>
        <result property="uid" column="uid"/>
        <result property="phoneNum" column="phone_num"/>
        <result property="userName" column="user_name"/>
        <result property="nickName" column="nick_name"/>
        <result property="userImg" column="user_img"/>
        <result property="openId" column="open_id"/>
        <result property="unionId" column="union_id"/>
        <result property="userSex" column="user_sex"/>
        <result property="email" column="email"/>
        <result property="source" column="source"/>
        <result property="accountStatus" column="account_status"/>
        <result property="remark" column="remark"/>
        <result property="portType" column="port_type"/>
        <result property="deleted" column="is_deleted"/>
        <result property="createTime" column="createTime"/>
        <result property="updateTime" column="update_time"/>

    </resultMap>

    <insert id="insertUserAccount" parameterType="com.mmc.iuav.user.entity.UserAccountDO"
            useGeneratedKeys="true" keyProperty="id">
        insert into user_account(account_type, uid,	phone_num, user_name, nick_name, user_img, open_id,	union_id, user_sex,	email, source, remark,	port_type, create_time)
        	values(#{accountType}, #{uid}, #{phoneNum}, #{userName}, #{nickName}, #{userImg}, #{userImg}, #{openId}, #{unionId}, #{userSex}, #{email}, #{source}, #{accountStatus},
        	#{remark}, #{portType}, NOW())
    </insert>

    <update id="update" parameterType="com.mmc.iuav.user.entity.UserAccountDO">
        update user_account
        <set>
            <if test="phoneNum != null">
                phone_num = #{phoneNum},
            </if>
            <if test="userName != null">
                user_name = #{userName},
            </if>
            <if test="nickName != null">
                nick_name = #{nickName},
            </if>
            <if test="userImg != null">
                user_img = #{userImg},
            </if>
            <if test="userSex != null">
                user_sex = #{userSex},
            </if>
            <if test="email != null">
                email = #{email},
            </if>
            <if test="accountStatus != null">
                account_status = #{accountStatus},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
            <if test="portType != null">
                port_type = #{portType}
            </if>
        </set>
         <where>
             id = #{id}
         </where>
    </update>

    <select id="getUserAccountInfoByUnionId" resultType="com.mmc.iuav.user.entity.UserAccountDO">
        select id, account_type, uid, phone_num, user_name, nick_name, user_img, open_id, union_id, user_sex, email, source, account_status, remark,
        	port_type, is_deleted, create_time, update_time
        from user_account
        where union_id = #{unionId} and is_deleted = 0
    </select>

    <select id="getUserAccountById" resultType="com.mmc.iuav.user.entity.UserAccountDO">
        select id, account_type, uid, phone_num, user_name, nick_name, user_img, open_id, union_id, user_sex, email, source, account_status, remark,
        	port_type, is_deleted, create_time, update_time
        from user_account
        where id = #{id}
    </select>
</mapper>