<?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.ruoyi.system.mapper.SalesPromotionMapper">

    <resultMap type="SalesPromotion" id="SalesPromotionResult">
        <result property="id"    column="id"    />
        <result property="salesName"    column="sales_name"    />
        <result property="salesType"    column="sales_type"    />
        <result property="salesReduction"    column="sales_reduction"    />
        <result property="shId"    column="sh_id"    />
        <result property="spId"    column="sp_id"    />
        <result property="salesCondition"    column="sales_condition"    />
        <result property="salesFund"    column="sales_fund"    />
        <result property="endTime"    column="end_time"    />
        <result property="salesState"    column="sales_state"    />
        <result property="illustrate"    column="illustrate"    />
        <result property="poster"    column="poster"    />
        <result property="language"    column="language"    />
        <result property="deleted"    column="deleted"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectSalesPromotionVo">
        select id, sales_name, sales_type, sales_reduction, sh_id, sp_id, sales_condition, sales_fund,
               end_time, sales_state, illustrate, poster, language, deleted,type
        from sales_promotion
    </sql>

    <select id="selectSalesPromotionList" parameterType="SalesPromotion" resultMap="SalesPromotionResult">
        <include refid="selectSalesPromotionVo"/>
        <where>
            deleted !='1' and  type='0'
            <if test="salesName != null  and salesName != ''"> and BINARY sales_name like concat('%', #{salesName}, '%')</if>
            <if test="salesType != null  and salesType != ''"> and sales_type = #{salesType}</if>
            <if test="salesReduction != null "> and sales_reduction = #{salesReduction}</if>
            <if test="shId != null "> and sh_id = #{shId}</if>
            <if test="spId != null "> and sp_id = #{spId}</if>
            <if test="salesCondition != null "> and sales_condition = #{salesCondition}</if>
            <if test="salesFund != null "> and sales_fund = #{salesFund}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="salesState != null  and salesState != ''"> and sales_state = #{salesState}</if>
            <if test="illustrate != null  and illustrate != ''"> and illustrate = #{illustrate}</if>
            <if test="poster != null  and poster != ''"> and poster = #{poster}</if>
            <if test="language != null  and language != ''"> and language = #{language}</if>
            <if test="deleted != null  and deleted != ''"> and deleted = #{deleted}</if>
            <!-- 默认查询未删除的数据 -->
            <if test="deleted == null or deleted == ''"> and (deleted = '0' or deleted is null)</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>

    <select id="selectSalesPromotionById" parameterType="Long" resultMap="SalesPromotionResult">
        <include refid="selectSalesPromotionVo"/>
        where id = #{id}
    </select>

    <insert id="insertSalesPromotion" parameterType="SalesPromotion" useGeneratedKeys="true" keyProperty="id">
        insert into sales_promotion
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="salesName != null">sales_name,</if>
            <if test="salesType != null">sales_type,</if>
            <if test="salesReduction != null">sales_reduction,</if>
            <if test="shId != null">sh_id,</if>
            <if test="spId != null">sp_id,</if>
            <if test="salesCondition != null">sales_condition,</if>
            <if test="salesFund != null">sales_fund,</if>
            <if test="endTime != null">end_time,</if>
            <if test="salesState != null">sales_state,</if>
            <if test="illustrate != null">illustrate,</if>
            <if test="poster != null">poster,</if>
            <if test="language != null">language,</if>
            <if test="deleted != null">deleted,</if>
            <if test="type != null">type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="salesName != null">#{salesName},</if>
            <if test="salesType != null">#{salesType},</if>
            <if test="salesReduction != null">#{salesReduction},</if>
            <if test="shId != null">#{shId},</if>
            <if test="spId != null">#{spId},</if>
            <if test="salesCondition != null">#{salesCondition},</if>
            <if test="salesFund != null">#{salesFund},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="salesState != null">#{salesState},</if>
            <if test="illustrate != null">#{illustrate},</if>
            <if test="poster != null">#{poster},</if>
            <if test="language != null">#{language},</if>
            <if test="deleted != null">#{deleted},</if>
            <if test="type != null">#{type},</if>
        </trim>
    </insert>

    <update id="updateSalesPromotion" parameterType="SalesPromotion">
        update sales_promotion
        <trim prefix="SET" suffixOverrides=",">
            <if test="salesName != null">sales_name = #{salesName},</if>
            <if test="salesType != null">sales_type = #{salesType},</if>
            <if test="salesReduction != null">sales_reduction = #{salesReduction},</if>
            <if test="shId != null">sh_id = #{shId},</if>
            <if test="spId != null">sp_id = #{spId},</if>
            <if test="salesCondition != null">sales_condition = #{salesCondition},</if>
            <if test="salesFund != null">sales_fund = #{salesFund},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="salesState != null">sales_state = #{salesState},</if>
            <if test="illustrate != null">illustrate = #{illustrate},</if>
            <if test="poster != null">poster = #{poster},</if>
            <if test="language != null">language = #{language},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <!-- 修改为逻辑删除，将deleted设置为"1" -->
    <update id="deleteSalesPromotionById" parameterType="Long">
        update sales_promotion set deleted = '1' where id = #{id}
    </update>

    <!-- 修改为逻辑删除，将deleted设置为"1" -->
    <update id="deleteSalesPromotionByIds" parameterType="String">
        update sales_promotion set deleted = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
