<?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.ruixuan.jinniu.mapper.KuaishouAgentAccountListMapper">

    <resultMap type="com.ruixuan.jinniu.entity.KuaishouAgentAccountList" id="KuaishouAgentAccountListResult">
        <result property="accountId"    column="account_id"    />
        <result property="userId"    column="user_id"    />
        <result property="accountName"    column="account_name"    />
        <result property="userName"    column="user_name"    />
        <result property="accountCreateTime"    column="account_create_time"    />
        <result property="productName"    column="product_name"    />
        <result property="industry"    column="industry"    />
        <result property="secondIndustry"    column="second_industry"    />
        <result property="corporationName"    column="corporation_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectKuaishouAgentAccountListVo">
        select account_id, user_id, account_name, user_name, account_create_time, product_name, industry, second_industry, corporation_name, create_time, update_time from kuaishou_agent_account_list
    </sql>

    <select id="selectKuaishouAgentAccountListList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList" resultMap="KuaishouAgentAccountListResult">
        <include refid="selectKuaishouAgentAccountListVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="accountName != null  and accountName != ''"> and account_name like concat('%', #{accountName}, '%')</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="accountCreateTime != null "> and account_create_time = #{accountCreateTime}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="industry != null  and industry != ''"> and industry = #{industry}</if>
            <if test="secondIndustry != null  and secondIndustry != ''"> and second_industry = #{secondIndustry}</if>
            <if test="corporationName != null  and corporationName != ''"> and corporation_name like concat('%', #{corporationName}, '%')</if>
        </where>
    </select>

    <select id="selectKuaishouAgentAccountListByAccountId" parameterType="Long" resultMap="KuaishouAgentAccountListResult">
        <include refid="selectKuaishouAgentAccountListVo"/>
        where account_id = #{accountId}
    </select>
    <select id="getCookie" resultType="java.lang.String">
        select  cookie  from kuaishou_agent_cookie
    </select>

    <insert id="insertKuaishouAgentAccountList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList">
        insert into kuaishou_agent_account_list
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="accountId != null">account_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="accountName != null">account_name,</if>
            <if test="userName != null">user_name,</if>
            <if test="accountCreateTime != null">account_create_time,</if>
            <if test="productName != null">product_name,</if>
            <if test="industry != null">industry,</if>
            <if test="secondIndustry != null">second_industry,</if>
            <if test="corporationName != null">corporation_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="accountId != null">#{accountId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="accountName != null">#{accountName},</if>
            <if test="userName != null">#{userName},</if>
            <if test="accountCreateTime != null">#{accountCreateTime},</if>
            <if test="productName != null">#{productName},</if>
            <if test="industry != null">#{industry},</if>
            <if test="secondIndustry != null">#{secondIndustry},</if>
            <if test="corporationName != null">#{corporationName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <insert id="addBatch">
        replace into kuaishou_agent_account_list(
        account_id,
        user_id,
        account_name,
        user_name,
        account_create_time,
        product_name,
        industry,
        second_industry,
        corporation_name
        )
        values
        <foreach collection="adds" item="add" separator=",">
            (
            #{add.accountId},
            #{add.userId},
            #{add.accountName},
            #{add.userName},
            #{add.accountCreateTime},
            #{add.productName},
            #{add.industry},
            #{add.secondIndustry},
            #{add.corporationName}
            )
        </foreach>

    </insert>

    <update id="updateKuaishouAgentAccountList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList">
        update kuaishou_agent_account_list
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="accountName != null">account_name = #{accountName},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="accountCreateTime != null">account_create_time = #{accountCreateTime},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="industry != null">industry = #{industry},</if>
            <if test="secondIndustry != null">second_industry = #{secondIndustry},</if>
            <if test="corporationName != null">corporation_name = #{corporationName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where account_id = #{accountId}
    </update>

    <delete id="deleteKuaishouAgentAccountListByAccountId" parameterType="Long">
        delete from kuaishou_agent_account_list where account_id = #{accountId}
    </delete>

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