<?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.ssm.manage.mapper.PromotionUnitMapper">
    <resultMap type="com.ssm.manage.entity.PromotionUnit" id="PromotionUnitMap">
        <result property="promotionId" column="Promotion_id" jdbcType="INTEGER"/>
        <result property="storeId" column="store_id" jdbcType="INTEGER"/>
        <result property="storeName" column="store_name" jdbcType="VARCHAR"/>
        <result property="promotionNum" column="promotion_num" jdbcType="VARCHAR"/>
        <result property="promotionName" column="promotion_name" jdbcType="VARCHAR"/>
        <result property="saleMoney" column="sale_money" jdbcType="NUMERIC"/>
        <result property="totalMoney" column="total_money" jdbcType="NUMERIC"/>
        <result property="beginDate" column="begin_date" jdbcType="TIMESTAMP"/>
        <result property="endDate" column="end_date" jdbcType="TIMESTAMP"/>
        <result property="suitableObject" column="suitable_object" jdbcType="INTEGER"/>
        <result property="limitBuy" column="limit_buy" jdbcType="INTEGER"/>
        <result property="limitCount" column="limit_count" jdbcType="INTEGER"/>
        <result property="createdDate" column="created_date" jdbcType="TIMESTAMP"/>
        <result property="createdId" column="created_id" jdbcType="INTEGER"/>
        <result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
        <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
        <result property="updatedId" column="updated_id" jdbcType="INTEGER"/>
        <result property="updatedBy" column="updated_by" jdbcType="VARCHAR"/>
        <result property="auditDate" column="audit_date" jdbcType="TIMESTAMP"/>
        <result property="auditId" column="audit_id" jdbcType="INTEGER"/>
        <result property="auditBy" column="audit_by" jdbcType="VARCHAR"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
        <result property="salesCommission" column="sales_commission" jdbcType="NUMERIC"/>
        <result property="cardSalesCommission" column="card_sales_commission" jdbcType="NUMERIC"/>
        <result property="pushState" column="push_state" jdbcType="INTEGER"/>
        <result property="pushCount" column="push_count" jdbcType="INTEGER"/>
        <result property="cardBuy" column="card_buy" jdbcType="INTEGER"/>
        <result property="cardLimit" column="card_limit" jdbcType="INTEGER"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="id" column="id" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="PromotionUnitMap">
        select Promotion_id,
               store_id,
               store_name,
               promotion_num,
               promotion_name,
               sale_money,
               total_money,
               begin_date,
               end_date,
               suitable_object,
               limit_buy,
               limit_count,
               created_date,
               created_id,
               created_by,
               update_date,
               updated_id,
               updated_by,
               audit_date,
               audit_id,
               audit_by,
               state,
               sales_commission,
               card_sales_commission,
               push_state,
               push_count,
               card_buy,
               card_limit,
               type,
               id
        from dcmy.promotion_unit
        where Promotion_id = #{promotionId}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="PromotionUnitMap">
        select Promotion_id,
               store_id,
               store_name,
               promotion_num,
               promotion_name,
               sale_money,
               total_money,
               begin_date,
               end_date,
               suitable_object,
               limit_buy,
               limit_count,
               created_date,
               created_id,
               created_by,
               update_date,
               updated_id,
               updated_by,
               audit_date,
               audit_id,
               audit_by,
               state,
               sales_commission,
               card_sales_commission,
               push_state,
               push_count,
               card_buy,
               card_limit,
               type,
               id
        from dcmy.promotion_unit limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="PromotionUnitMap">
        select
        Promotion_id, store_id, store_name, promotion_num, promotion_name, sale_money, total_money, begin_date,
        end_date, suitable_object, limit_buy, limit_count, created_date, created_id, created_by, update_date,
        updated_id, updated_by, audit_date, audit_id, audit_by, state, sales_commission, card_sales_commission,
        push_state, push_count, card_buy, card_limit, type, id
        from dcmy.promotion_unit
        <where>
            <if test="promotionId != null">
                and Promotion_id = #{promotionId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="promotionNum != null and promotionNum != ''">
                and promotion_num = #{promotionNum}
            </if>
            <if test="promotionName != null and promotionName != ''">
                and promotion_name = #{promotionName}
            </if>
            <if test="saleMoney != null">
                and sale_money = #{saleMoney}
            </if>
            <if test="totalMoney != null">
                and total_money = #{totalMoney}
            </if>
            <if test="beginDate != null">
                and begin_date = #{beginDate}
            </if>
            <if test="endDate != null">
                and end_date = #{endDate}
            </if>
            <if test="suitableObject != null">
                and suitable_object = #{suitableObject}
            </if>
            <if test="limitBuy != null">
                and limit_buy = #{limitBuy}
            </if>
            <if test="limitCount != null">
                and limit_count = #{limitCount}
            </if>
            <if test="createdDate != null">
                and created_date = #{createdDate}
            </if>
            <if test="createdId != null">
                and created_id = #{createdId}
            </if>
            <if test="createdBy != null and createdBy != ''">
                and created_by = #{createdBy}
            </if>
            <if test="updateDate != null">
                and update_date = #{updateDate}
            </if>
            <if test="updatedId != null">
                and updated_id = #{updatedId}
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                and updated_by = #{updatedBy}
            </if>
            <if test="auditDate != null">
                and audit_date = #{auditDate}
            </if>
            <if test="auditId != null">
                and audit_id = #{auditId}
            </if>
            <if test="auditBy != null and auditBy != ''">
                and audit_by = #{auditBy}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="salesCommission != null">
                and sales_commission = #{salesCommission}
            </if>
            <if test="cardSalesCommission != null">
                and card_sales_commission = #{cardSalesCommission}
            </if>
            <if test="pushState != null">
                and push_state = #{pushState}
            </if>
            <if test="pushCount != null">
                and push_count = #{pushCount}
            </if>
            <if test="cardBuy != null">
                and card_buy = #{cardBuy}
            </if>
            <if test="cardLimit != null">
                and card_limit = #{cardLimit}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="id != null">
                and id = #{id}
            </if>
        </where>
    </select>

    <select id="selectallId" resultMap="PromotionUnitMap">
        select
        id
        from dcmy.promotion_unit
        <where>
            <if test="promotionId != null">
                and Promotion_id = #{promotionId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="promotionNum != null and promotionNum != ''">
                and promotion_num = #{promotionNum}
            </if>
            <if test="promotionName != null and promotionName != ''">
                and promotion_name = #{promotionName}
            </if>
            <if test="saleMoney != null">
                and sale_money = #{saleMoney}
            </if>
            <if test="totalMoney != null">
                and total_money = #{totalMoney}
            </if>
            <if test="beginDate != null">
                and begin_date = #{beginDate}
            </if>
            <if test="endDate != null">
                and end_date = #{endDate}
            </if>
            <if test="suitableObject != null">
                and suitable_object = #{suitableObject}
            </if>
            <if test="limitBuy != null">
                and limit_buy = #{limitBuy}
            </if>
            <if test="limitCount != null">
                and limit_count = #{limitCount}
            </if>
            <if test="createdDate != null">
                and created_date = #{createdDate}
            </if>
            <if test="createdId != null">
                and created_id = #{createdId}
            </if>
            <if test="createdBy != null and createdBy != ''">
                and created_by = #{createdBy}
            </if>
            <if test="updateDate != null">
                and update_date = #{updateDate}
            </if>
            <if test="updatedId != null">
                and updated_id = #{updatedId}
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                and updated_by = #{updatedBy}
            </if>
            <if test="auditDate != null">
                and audit_date = #{auditDate}
            </if>
            <if test="auditId != null">
                and audit_id = #{auditId}
            </if>
            <if test="auditBy != null and auditBy != ''">
                and audit_by = #{auditBy}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="salesCommission != null">
                and sales_commission = #{salesCommission}
            </if>
            <if test="cardSalesCommission != null">
                and card_sales_commission = #{cardSalesCommission}
            </if>
            <if test="pushState != null">
                and push_state = #{pushState}
            </if>
            <if test="pushCount != null">
                and push_count = #{pushCount}
            </if>
            <if test="cardBuy != null">
                and card_buy = #{cardBuy}
            </if>
            <if test="cardLimit != null">
                and card_limit = #{cardLimit}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="id != null">
                and id = #{id}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="promotionId" useGeneratedKeys="true">
        insert into dcmy.promotion_unit(store_id, store_name, promotion_num, promotion_name, sale_money, total_money,
                                        begin_date, end_date, suitable_object, limit_buy, limit_count, created_date,
                                        created_id, created_by, update_date, updated_id, updated_by, audit_date,
                                        audit_id, audit_by, state, sales_commission, card_sales_commission, push_state,
                                        push_count, card_buy, card_limit, type, id)
        values (#{storeId}, #{storeName}, #{promotionNum}, #{promotionName}, #{saleMoney}, #{totalMoney}, #{beginDate},
                #{endDate}, #{suitableObject}, #{limitBuy}, #{limitCount}, #{createdDate}, #{createdId}, #{createdBy},
                #{updateDate}, #{updatedId}, #{updatedBy}, #{auditDate}, #{auditId}, #{auditBy}, #{state},
                #{salesCommission}, #{cardSalesCommission}, #{pushState}, #{pushCount}, #{cardBuy}, #{cardLimit},
                #{type}, #{id})
    </insert>

    <insert id="insertBatch" keyProperty="promotionId" useGeneratedKeys="true">
        insert into dcmy.promotion_unit(store_id, store_name, promotion_num, promotion_name, sale_money, total_money,
        begin_date, end_date, suitable_object, limit_buy, limit_count, created_date, created_id, created_by,
        update_date, updated_id, updated_by, audit_date, audit_id, audit_by, state, sales_commission,
        card_sales_commission, push_state, push_count, card_buy, card_limit, type, id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.storeId}, #{entity.storeName}, #{entity.promotionNum}, #{entity.promotionName},
            #{entity.saleMoney}, #{entity.totalMoney}, #{entity.beginDate}, #{entity.endDate}, #{entity.suitableObject},
            #{entity.limitBuy}, #{entity.limitCount}, #{entity.createdDate}, #{entity.createdId}, #{entity.createdBy},
            #{entity.updateDate}, #{entity.updatedId}, #{entity.updatedBy}, #{entity.auditDate}, #{entity.auditId},
            #{entity.auditBy}, #{entity.state}, #{entity.salesCommission}, #{entity.cardSalesCommission},
            #{entity.pushState}, #{entity.pushCount}, #{entity.cardBuy}, #{entity.cardLimit}, #{entity.type},
            #{entity.id})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="promotionId" useGeneratedKeys="true">
        insert into dcmy.promotion_unit(store_id, store_name, promotion_num, promotion_name, sale_money, total_money,
        begin_date, end_date, suitable_object, limit_buy, limit_count, created_date, created_id, created_by,
        update_date, updated_id, updated_by, audit_date, audit_id, audit_by, state, sales_commission,
        card_sales_commission, push_state, push_count, card_buy, card_limit, type, id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.storeId}, #{entity.storeName}, #{entity.promotionNum}, #{entity.promotionName},
            #{entity.saleMoney}, #{entity.totalMoney}, #{entity.beginDate}, #{entity.endDate}, #{entity.suitableObject},
            #{entity.limitBuy}, #{entity.limitCount}, #{entity.createdDate}, #{entity.createdId}, #{entity.createdBy},
            #{entity.updateDate}, #{entity.updatedId}, #{entity.updatedBy}, #{entity.auditDate}, #{entity.auditId},
            #{entity.auditBy}, #{entity.state}, #{entity.salesCommission}, #{entity.cardSalesCommission},
            #{entity.pushState}, #{entity.pushCount}, #{entity.cardBuy}, #{entity.cardLimit}, #{entity.type},
            #{entity.id})
        </foreach>
        on duplicate key update
        store_id = values(store_id) , store_name = values(store_name) , promotion_num = values(promotion_num) ,
        promotion_name = values(promotion_name) , sale_money = values(sale_money) , total_money = values(total_money) ,
        begin_date = values(begin_date) , end_date = values(end_date) , suitable_object = values(suitable_object) ,
        limit_buy = values(limit_buy) , limit_count = values(limit_count) , created_date = values(created_date) ,
        created_id = values(created_id) , created_by = values(created_by) , update_date = values(update_date) ,
        updated_id = values(updated_id) , updated_by = values(updated_by) , audit_date = values(audit_date) , audit_id =
        values(audit_id) , audit_by = values(audit_by) , state = values(state) , sales_commission =
        values(sales_commission) , card_sales_commission = values(card_sales_commission) , push_state =
        values(push_state) , push_count = values(push_count) , card_buy = values(card_buy) , card_limit =
        values(card_limit) , type = values(type) , id = values(id)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update dcmy.promotion_unit
        <set>
            <if test="storeId != null">
                store_id = #{storeId},
            </if>
            <if test="storeName != null and storeName != ''">
                store_name = #{storeName},
            </if>
            <if test="promotionNum != null and promotionNum != ''">
                promotion_num = #{promotionNum},
            </if>
            <if test="promotionName != null and promotionName != ''">
                promotion_name = #{promotionName},
            </if>
            <if test="saleMoney != null">
                sale_money = #{saleMoney},
            </if>
            <if test="totalMoney != null">
                total_money = #{totalMoney},
            </if>
            <if test="beginDate != null">
                begin_date = #{beginDate},
            </if>
            <if test="endDate != null">
                end_date = #{endDate},
            </if>
            <if test="suitableObject != null">
                suitable_object = #{suitableObject},
            </if>
            <if test="limitBuy != null">
                limit_buy = #{limitBuy},
            </if>
            <if test="limitCount != null">
                limit_count = #{limitCount},
            </if>
            <if test="createdDate != null">
                created_date = #{createdDate},
            </if>
            <if test="createdId != null">
                created_id = #{createdId},
            </if>
            <if test="createdBy != null and createdBy != ''">
                created_by = #{createdBy},
            </if>
            <if test="updateDate != null">
                update_date = #{updateDate},
            </if>
            <if test="updatedId != null">
                updated_id = #{updatedId},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updated_by = #{updatedBy},
            </if>
            <if test="auditDate != null">
                audit_date = #{auditDate},
            </if>
            <if test="auditId != null">
                audit_id = #{auditId},
            </if>
            <if test="auditBy != null and auditBy != ''">
                audit_by = #{auditBy},
            </if>
            <if test="state != null">
                state = #{state},
            </if>
            <if test="salesCommission != null">
                sales_commission = #{salesCommission},
            </if>
            <if test="cardSalesCommission != null">
                card_sales_commission = #{cardSalesCommission},
            </if>
            <if test="pushState != null">
                push_state = #{pushState},
            </if>
            <if test="pushCount != null">
                push_count = #{pushCount},
            </if>
            <if test="cardBuy != null">
                card_buy = #{cardBuy},
            </if>
            <if test="cardLimit != null">
                card_limit = #{cardLimit},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="id != null">
                id = #{id},
            </if>
        </set>
        where Promotion_id = #{promotionId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from dcmy.promotion_unit
        where Promotion_id = #{promotionId}
    </delete>

    <delete id="empty">
        delete
        from dcmy.promotion_unit
        where promotion_num = #{promotionNum}
    </delete>

</mapper>
