<?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.UserPartnerDao">
    <update id="update">
        update user_partner
        <set>
            <if test="userAddress != null and userAddress != ''">
                user_address = #{userAddress},
            </if>
            <if test="userName != null and userName != ''">
                user_name = #{userName},
            </if>
            <if test="phoneNumber != null and phoneNumber != ''">
                phone_number = #{phoneNumber},
            </if>
            <if test="updateTime != null">
                update_time = NOW(),
            </if>
            <if test="status != null">
                status = #{status},
            </if>
        </set>
        where id = #{id}
    </update>


    <!--查询单个-->


    <!--查询指定行数据-->


    <!--统计总行数-->
    <select id="count" resultType="java.lang.Integer">
        select count(*)
        from user_partner
        <where>
            <if test="userAddress != null and userAddress != ''">
                and user_address = #{userAddress}
            </if>
            <if test="userName != null and userName != ''">
                and user_name = #{userName}
            </if>
            <if test="phoneNumber != null and phoneNumber != ''">
                and phone_number = #{phoneNumber}
            </if>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
        </where>
    </select>
    <select id="queryAllByLimit" resultType="com.mmc.iuav.user.model.vo.UserPartnerVO">
        select
        id,user_address, user_name, phone_number, create_time, update_time, status,user_account_id
        from user_partner
        <where>
            <if test="userAddress != null and userAddress != ''">
                and user_address = #{userAddress}
            </if>
            <if test="userName != null and userName != ''">
                and user_name = #{userName}
            </if>
            <if test="phoneNumber != null and phoneNumber != ''">
                and phone_number = #{phoneNumber}
            </if>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
        </where>
        order by create_time desc
        limit #{pageNo},#{pageSize}
    </select>
    <select id="queryById" resultType="com.mmc.iuav.user.model.vo.UserPartnerVO">
        select user_address,
               user_name,
               phone_number,
               id,
               create_time,
               update_time,
               status,
               intention
        from user_partner
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insertPartner" keyProperty="id" useGeneratedKeys="true">
        insert into user_partner(user_address, user_name, phone_number, create_time, update_time, status,user_account_id,intention)
        values (#{userAddress}, #{userName}, #{phoneNumber},NOW(), #{updateTime}, #{status},#{userAccountId},#{intention})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into user_partner(user_address, user_name, phone_number, create_time, update_time, status)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.userAddress}, #{entity.userName}, #{entity.phoneNumber}, #{entity.createTime},
            #{entity.updateTime}, #{entity.status})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into user_partner(user_address, user_name, phone_number, create_time, update_time, status)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.userAddress}, #{entity.userName}, #{entity.phoneNumber}, #{entity.createTime},
            #{entity.updateTime}, #{entity.status})
        </foreach>
        on duplicate key update
        user_address = values(user_address),
        user_name = values(user_name),
        phone_number = values(phone_number),
        create_time = values(create_time),
        update_time = values(update_time),
        status = values(status)
    </insert>

    <!--通过主键修改数据-->

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from user_partner
        where id = #{id}
    </delete>

</mapper>

