<?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.gic.haoban.manage.service.dao.mapper.TabHaobanRenewalUserMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.TabHaobanRenewalUser" id="TabHaobanRenewalUserMap">
        <result property="renewalId" column="renewal_id" jdbcType="INTEGER"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="wxUserId" column="wx_user_id" jdbcType="VARCHAR"/>
        <result property="orderId" column="order_id" jdbcType="INTEGER"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="postion" column="postion" jdbcType="VARCHAR"/>
        <result property="invalidFlag" column="invalid_flag" jdbcType="INTEGER"/>
        <result property="invalidCode" column="invalid_code" jdbcType="VARCHAR"/>
        <result property="invalidMsg" column="invalid_msg" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanRenewalUserMap">
        select
          renewal_id, wx_enterprise_id, wx_user_id, order_id, phone, name, postion, invalid_flag, invalid_code, invalid_msg, update_time, create_time, delete_flag
        from tab_haoban_renewal_user
        where renewal_id = #{renewalId}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TabHaobanRenewalUserMap">
        select
          renewal_id, wx_enterprise_id, wx_user_id, order_id, phone, name, postion, invalid_flag, invalid_code, invalid_msg, update_time, create_time, delete_flag
        from tab_haoban_renewal_user
        <where>
            <if test="renewalId != null">
                and renewal_id = #{renewalId}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="wxUserId != null and wxUserId != ''">
                and wx_user_id = #{wxUserId}
            </if>
            <if test="orderId != null">
                and order_id = #{orderId}
            </if>
            <if test="phone != null and phone != ''">
                and phone = #{phone}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="postion != null and postion != ''">
                and postion = #{postion}
            </if>
            <if test="invalidFlag != null">
                and invalid_flag = #{invalidFlag}
            </if>
            <if test="invalidCode != null and invalidCode != ''">
                and invalid_code = #{invalidCode}
            </if>
            <if test="invalidMsg != null and invalidMsg != ''">
                and invalid_msg = #{invalidMsg}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_renewal_user
        <where>
            <if test="renewalId != null">
                and renewal_id = #{renewalId}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="wxUserId != null and wxUserId != ''">
                and wx_user_id = #{wxUserId}
            </if>
            <if test="orderId != null">
                and order_id = #{orderId}
            </if>
            <if test="phone != null and phone != ''">
                and phone = #{phone}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="postion != null and postion != ''">
                and postion = #{postion}
            </if>
            <if test="invalidFlag != null">
                and invalid_flag = #{invalidFlag}
            </if>
            <if test="invalidCode != null and invalidCode != ''">
                and invalid_code = #{invalidCode}
            </if>
            <if test="invalidMsg != null and invalidMsg != ''">
                and invalid_msg = #{invalidMsg}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="renewalId" useGeneratedKeys="true">
        insert into tab_haoban_renewal_user(wx_enterprise_id, wx_user_id, order_id, phone, name, postion, invalid_flag, invalid_code, invalid_msg, update_time, create_time, delete_flag)
        values (#{wxEnterpriseId}, #{wxUserId}, #{orderId}, #{phone}, #{name}, #{postion}, #{invalidFlag}, #{invalidCode}, #{invalidMsg}, #{updateTime}, #{createTime}, #{deleteFlag})
    </insert>

    <insert id="insertBatch" >
        insert into tab_haoban_renewal_user(renewal_id,wx_enterprise_id, wx_user_id, order_id, phone, name, postion, invalid_flag, invalid_code, invalid_msg, update_time, create_time, delete_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.renewalId},#{entity.wxEnterpriseId}, #{entity.wxUserId}, #{entity.orderId}, #{entity.phone}, #{entity.name}, #{entity.postion}, #{entity.invalidFlag}, #{entity.invalidCode}, #{entity.invalidMsg}, #{entity.updateTime}, #{entity.createTime}, #{entity.deleteFlag})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="renewalId" useGeneratedKeys="true">
        insert into tab_haoban_renewal_user(wx_enterprise_id, wx_user_id, order_id, phone, name, postion, invalid_flag, invalid_code, invalid_msg, update_time, create_time, delete_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.wxEnterpriseId}, #{entity.wxUserId}, #{entity.orderId}, #{entity.phone}, #{entity.name}, #{entity.postion}, #{entity.invalidFlag}, #{entity.invalidCode}, #{entity.invalidMsg}, #{entity.updateTime}, #{entity.createTime}, #{entity.deleteFlag})
        </foreach>
        on duplicate key update
        wx_enterprise_id = values(wx_enterprise_id),
        wx_user_id = values(wx_user_id),
        order_id = values(order_id),
        phone = values(phone),
        name = values(name),
        postion = values(postion),
        invalid_flag = values(invalid_flag),
        invalid_code = values(invalid_code),
        invalid_msg = values(invalid_msg),
        update_time = values(update_time),
        create_time = values(create_time),
        delete_flag = values(delete_flag)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_renewal_user
        <set>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
            <if test="wxUserId != null and wxUserId != ''">
                wx_user_id = #{wxUserId},
            </if>
            <if test="orderId != null">
                order_id = #{orderId},
            </if>
            <if test="phone != null and phone != ''">
                phone = #{phone},
            </if>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="postion != null and postion != ''">
                postion = #{postion},
            </if>
            <if test="invalidFlag != null">
                invalid_flag = #{invalidFlag},
            </if>
            <if test="invalidCode != null and invalidCode != ''">
                invalid_code = #{invalidCode},
            </if>
            <if test="invalidMsg != null and invalidMsg != ''">
                invalid_msg = #{invalidMsg},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
        </set>
        where renewal_id = #{renewalId}
    </update>

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

    <select id="getRenewalUserPage" resultMap="TabHaobanRenewalUserMap">
        select
        renewal_id, wx_enterprise_id, wx_user_id, order_id, phone, name, postion, invalid_flag, invalid_code, invalid_msg, update_time, create_time, delete_flag
        from tab_haoban_renewal_user
        where wx_enterprise_id = #{wxEnterpriseId} and order_id = #{orderId} and delete_flag = 0 and invalid_flag = 1
            <if test="searchParam != null">
                and (phone like CONCAT('%',#{searchParam},'%') or name like CONCAT('%',#{searchParam},'%'))
            </if>
    </select>

</mapper>

