<?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.launch.mapper.KuaishouLaunchTargetTemplateMapper">

    <resultMap type="com.ruixuan.launch.entity.KuaishouLaunchTargetTemplate" id="KuaishouLaunchTargetTemplateResult">
        <result property="id" column="id"/>
        <result property="accountId" column="account_id"/>
        <result property="targetName" column="target_name"/>
        <result property="targetType" column="target_type"/>
        <result property="region" column="region"/>
        <result property="regionType" column="region_type"/>
        <result property="age" column="age"/>
        <result property="genderType" column="gender_type"/>
        <result property="population" column="population"/>
        <result property="populationName" column="population_name"/>
        <result property="excludePopulationName" column="exclude_population_name"/>
        <result property="excludePopulation" column="exclude_population"/>
        <result property="paidAudience" column="paid_audience"/>
        <result property="behaviorList" column="behavior_list"/>
        <result property="fansStarList" column="fans_star_list"/>
        <result property="purchaseIntention" column="purchase_intention"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLaunchTargetTemplateVo">
        select id,
               account_id,
               target_name,
               target_type,
               region,
               region_type,
               age,
               gender_type,
               population,
               population_name,
               exclude_population,
               exclude_population_name,
               paid_audience,
               behavior_list,
               fans_star_list,
               purchase_intention
        from kuaishou_launch_target_template
    </sql>

    <select id="selectKuaishouLaunchTargetTemplateList"
            parameterType="com.ruixuan.launch.entity.KuaishouLaunchTargetTemplate"
            resultMap="KuaishouLaunchTargetTemplateResult">
        <include refid="selectKuaishouLaunchTargetTemplateVo"/>
        <where>
            <if test="accountId != null ">and account_id = #{accountId}</if>
            <if test="targetName != null  and targetName != ''">and target_name = #{targetName}</if>
            <if test="targetType != null  and targetType != ''">and target_type = #{targetType}</if>
            <if test="region != null  and region != ''">and region = #{region}</if>
            <if test="regionType != null  and regionType != ''">and region_type = #{regionType}</if>
            <if test="age != null  and age != ''">and age = #{age}</if>
            <if test="genderType != null ">and gender_type = #{genderType}</if>
            <if test="population != null  and population != ''">and population = #{population}</if>
            <if test="populationName != null  and populationName != ''">and population_name = #{populationName}</if>
            <if test="excludePopulationName != null  and excludePopulationName != ''">and exclude_population_name =
                #{excludePopulationName}
            </if>
            <if test="excludePopulation != null  and excludePopulation != ''">and exclude_population =
                #{excludePopulation}
            </if>
            <if test="paidAudience != null  and paidAudience != ''">and paid_audience = #{paidAudience}</if>
            <if test="behaviorList != null  and behaviorList != ''">and behavior_list = #{behaviorList}</if>
            <if test="fansStarList != null  and fansStarList != ''">and fans_star_list = #{fansStarList}</if>
            <if test="purchaseIntention != null  and purchaseIntention != ''">and purchase_intention =
                #{purchaseIntention}
            </if>
        </where>
    </select>

    <select id="selectKuaishouLaunchTargetTemplateById" parameterType="Long"
            resultMap="KuaishouLaunchTargetTemplateResult">
        <include refid="selectKuaishouLaunchTargetTemplateVo"/>
        where id = #{id}
    </select>

    <select id="selectKuaishouLaunchTargetTemplateByIds" resultMap="KuaishouLaunchTargetTemplateResult">
        <include refid="selectKuaishouLaunchTargetTemplateVo"/>
        where id in
        <foreach collection="ids" item="item" separator=","
                 open="(" close=")">
            #{item}
        </foreach>
    </select>

    <insert id="insertKuaishouLaunchTargetTemplate"
            parameterType="com.ruixuan.launch.entity.KuaishouLaunchTargetTemplate" useGeneratedKeys="true"
            keyProperty="id">
        insert into kuaishou_launch_target_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="accountId != null">account_id,</if>
            <if test="targetName != null">target_name,</if>
            <if test="targetType != null">target_type,</if>
            <if test="region != null">region,</if>
            <if test="regionType != null">region_type,</if>
            <if test="age != null">age,</if>
            <if test="genderType != null">gender_type,</if>
            <if test="population != null">population,</if>
            <if test="populationName != null">population_name,</if>
            <if test="excludePopulationName != null">exclude_population_name,</if>
            <if test="excludePopulation != null">exclude_population,</if>
            <if test="paidAudience != null">paid_audience,</if>
            <if test="behaviorList != null">behavior_list,</if>
            <if test="fansStarList != null">fans_star_list,</if>
            <if test="purchaseIntention != null">purchase_intention,</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="targetName != null">#{targetName},</if>
            <if test="targetType != null">#{targetType},</if>
            <if test="region != null">#{region},</if>
            <if test="regionType != null">#{regionType},</if>
            <if test="age != null">#{age},</if>
            <if test="genderType != null">#{genderType},</if>
            <if test="population != null">#{population},</if>
            <if test="populationName != null">#{populationName},</if>
            <if test="excludePopulationName != null">#{excludePopulationName},</if>
            <if test="excludePopulation != null">#{excludePopulation},</if>
            <if test="paidAudience != null">#{paidAudience},</if>
            <if test="behaviorList != null">#{behaviorList},</if>
            <if test="fansStarList != null">#{fansStarList},</if>
            <if test="purchaseIntention != null">#{purchaseIntention},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLaunchTargetTemplate"
            parameterType="com.ruixuan.launch.entity.KuaishouLaunchTargetTemplate">
        update kuaishou_launch_target_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="targetName != null">target_name = #{targetName},</if>
            <if test="targetType != null">target_type = #{targetType},</if>
            <if test="region != null">region = #{region},</if>
            <if test="regionType != null">region_type = #{regionType},</if>
            <if test="age != null">age = #{age},</if>
            <if test="genderType != null">gender_type = #{genderType},</if>
            <if test="population != null">population = #{population},</if>
            <if test="populationName != null">population_name = #{populationName},</if>
            <if test="excludePopulationName != null">exclude_population_name = #{excludePopulationName},</if>
            <if test="excludePopulation != null">exclude_population = #{excludePopulation},</if>
            <if test="paidAudience != null">paid_audience = #{paidAudience},</if>
            <if test="behaviorList != null">behavior_list = #{behaviorList},</if>
            <if test="fansStarList != null">fans_star_list = #{fansStarList},</if>
            <if test="purchaseIntention != null">purchase_intention = #{purchaseIntention},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouLaunchTargetTemplateById" parameterType="Long">
        delete
        from kuaishou_launch_target_template
        where id = #{id}
    </delete>

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