<?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.CouponShareMapper">

    <resultMap id="BaseResultMap" type="com.ssm.manage.entity.CouponShare">
        <result property="id" column="id"/>
        <result property="couponId" column="coupon_id"/>
        <result property="couponNum" column="coupon_num"/>
        <result property="couponName" column="coupon_name"/>
        <result property="sharePhone" column="share_phone"/>
        <result property="shareOpenid" column="share_openid"/>
        <result property="getPhone" column="get_phone"/>
        <result property="getOpenid" column="get_openid"/>
        <result property="useNum" column="use_num"/>
        <result property="getDate" column="get_date"/>
        <result property="validity" column="validity"/>
        <result property="shareCommissionRules" column="Share_commission_rules"/>
        <result property="fixedAmoun" column="fixed_amoun"/>
        <result property="orderCommission" column="order_commission"/>
        <result property="couponType" column="coupon_type"/>
        <result property="serviceConditions" column="service_conditions"/>
        <result property="fullReductionMoney" column="full_reduction_money"/>
        <result property="fullDiscountMoney" column="full_discount_money"/>
        <result property="fullKimsMoney" column="full_kims_money"/>
        <result property="suitableStore" column="suitable_store"/>
        <result property="suitableProject" column="suitable_project"/>
        <result property="isUse" column="is_use"/>
        <result property="docDate" column="doc_date"/>
        <result property="storeId" column="store_id"/>
        <result property="storeNum" column="store_num"/>
        <result property="storeName" column="store_name"/>
        <result property="docType" column="doc_type"/>
        <result property="docNum" column="doc_num"/>
        <result property="docMoney" column="doc_money"/>
        <result property="useCommission" column="use_commission"/>
        <result property="docMerchandiserId" column="doc_merchandiser_id"/>
        <result property="docMerchandiserNum" column="doc_merchandiser_num"/>
        <result property="docMerchandiserName" column="doc_merchandiser_name"/>
        <result property="shareExtract" column="share_extract"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        , coupon_id, coupon_num, coupon_name, share_phone, get_phone, use_num, get_date, validity,
Share_commission_rules, fixed_amoun, order_commission, coupon_type, service_conditions, full_reduction_money,
suitable_store, suitable_project, is_use, doc_date, store_id, store_num, store_name, doc_type, doc_num,
doc_money, use_commission, doc_merchandiser_id, doc_merchandiser_num, doc_merchandiser_name,share_extract
    </sql>
    <insert id="save">
        insert into coupon_share(coupon_id, coupon_num, coupon_name, share_phone, get_phone, use_num, get_date,
                                 validity, Share_commission_rules, fixed_amoun, order_commission, coupon_type,
                                 service_conditions, full_reduction_money, suitable_store, suitable_project,
                                 is_use, doc_date, store_id, store_num, store_name, doc_type, doc_num,
                                 doc_money, use_commission, doc_merchandiser_id, doc_merchandiser_num,
                                 doc_merchandiser_name)
        values (#{couponId}, #{couponNum}, #{couponName}, #{sharePhone}, #{getPhone}, #{useNum}, #{getDate},
                #{validity}, #{shareCommissionRules}, #{fixedAmoun}, #{orderCommission}, #{couponType},
                #{serviceConditions}, #{fullReductionMoney}, #{suitableStore}, #{suitableProject}, #{isUse},
                #{docDate}, #{storeId}, #{storeNum}, #{storeName}, #{docType}, #{docNum}, #{docMoney},
                #{useCommission}, #{docMerchandiserId}, #{docMerchandiserNum}, #{docMerchandiserName})
    </insert>
    <update id="updateById">
        update coupon_share
        <set>
            <if test="couponId != null">
                and coupon_id = #{couponId}
            </if>
            <if test="couponNum != null and couponNum != ''">
                and coupon_num = #{couponNum}
            </if>
            <if test="couponName != null and couponName != ''">
                and coupon_name = #{couponName}
            </if>
            <if test="sharePhone != null and sharePhone != ''">
                and share_phone = #{sharePhone}
            </if>
            <if test="getPhone != null and getPhone != ''">
                and get_phone = #{getPhone}
            </if>
            <if test="useNum != null and useNum != ''">
                and use_num = #{useNum}
            </if>
            <if test="getDate != null">
                and get_date = #{getDate}
            </if>
            <if test="validity != null">
                and validity = #{validity}
            </if>
            <if test="shareCommissionRules != null">
                and Share_commission_rules = #{shareCommissionRules}
            </if>
            <if test="fixedAmoun != null">
                and fixed_amoun = #{fixedAmoun}
            </if>
            <if test="orderCommission != null">
                and order_commission = #{orderCommission}
            </if>
            <if test="couponType != null">
                and coupon_type = #{couponType}
            </if>
            <if test="serviceConditions != null">
                and service_conditions = #{serviceConditions}
            </if>
            <if test="fullReductionMoney != null">
                and full_reduction_money = #{fullReductionMoney}
            </if>
            <if test="suitableStore != null">
                and suitable_store = #{suitableStore}
            </if>
            <if test="suitableProject != null">
                and suitable_project = #{suitableProject}
            </if>
            <if test="isUse != null">
                and is_use = #{isUse}
            </if>
            <if test="docDate != null">
                and doc_date = #{docDate}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeNum != null and storeNum != ''">
                and store_num = #{storeNum}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="docType != null">
                and doc_type = #{docType}
            </if>
            <if test="docNum != null and docNum != ''">
                and doc_num = #{docNum}
            </if>
            <if test="docMoney != null">
                and doc_money = #{docMoney}
            </if>
            <if test="useCommission != null">
                and use_commission = #{useCommission}
            </if>
            <if test="docMerchandiserId != null">
                and doc_merchandiser_id = #{docMerchandiserId}
            </if>
            <if test="docMerchandiserNum != null and docMerchandiserNum != ''">
                and doc_merchandiser_num = #{docMerchandiserNum}
            </if>
            <if test="docMerchandiserName != null and docMerchandiserName != ''">
                and doc_merchandiser_name = #{docMerchandiserName}
            </if>
        </set>
        where id = #{id}
    </update>
    <delete id="removeById">
        delete
        from coupon_share
        where id = #{id}
    </delete>

    <select id="queryAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from coupon_share
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="couponId != null">
                and coupon_id = #{couponId}
            </if>
            <if test="couponNum != null and couponNum != ''">
                and coupon_num = #{couponNum}
            </if>
            <if test="couponName != null and couponName != ''">
                and coupon_name = #{couponName}
            </if>
            <if test="sharePhone != null and sharePhone != ''">
                and share_phone = #{sharePhone}
            </if>
            <if test="getPhone != null and getPhone != ''">
                and get_phone = #{getPhone}
            </if>
            <if test="useNum != null and useNum != ''">
                and use_num = #{useNum}
            </if>
            <if test="getDate != null">
                and get_date = #{getDate}
            </if>
            <if test="validity != null">
                and validity = #{validity}
            </if>
            <if test="shareCommissionRules != null">
                and Share_commission_rules = #{shareCommissionRules}
            </if>
            <if test="fixedAmoun != null">
                and fixed_amoun = #{fixedAmoun}
            </if>
            <if test="orderCommission != null">
                and order_commission = #{orderCommission}
            </if>
            <if test="couponType != null">
                and coupon_type = #{couponType}
            </if>
            <if test="serviceConditions != null">
                and service_conditions = #{serviceConditions}
            </if>
            <if test="fullReductionMoney != null">
                and full_reduction_money = #{fullReductionMoney}
            </if>
            <if test="suitableStore != null">
                and suitable_store = #{suitableStore}
            </if>
            <if test="suitableProject != null">
                and suitable_project = #{suitableProject}
            </if>
            <if test="isUse != null">
                and is_use = #{isUse}
            </if>
            <if test="docDate != null">
                and doc_date = #{docDate}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeNum != null and storeNum != ''">
                and store_num = #{storeNum}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="docType != null">
                and doc_type = #{docType}
            </if>
            <if test="docNum != null and docNum != ''">
                and doc_num = #{docNum}
            </if>
            <if test="docMoney != null">
                and doc_money = #{docMoney}
            </if>
            <if test="useCommission != null">
                and use_commission = #{useCommission}
            </if>
            <if test="docMerchandiserId != null">
                and doc_merchandiser_id = #{docMerchandiserId}
            </if>
            <if test="docMerchandiserNum != null and docMerchandiserNum != ''">
                and doc_merchandiser_num = #{docMerchandiserNum}
            </if>
            <if test="docMerchandiserName != null and docMerchandiserName != ''">
                and doc_merchandiser_name = #{docMerchandiserName}
            </if>
        </where>
    </select>
    <select id="getById" resultType="com.ssm.manage.entity.CouponShare">
        select
        <include refid="Base_Column_List"></include>
        from coupon_share where id = #{id}
    </select>

    <select id="selCount" resultType="java.lang.Integer">
        select count(1) from coupon_share <where>
        <if test="couponNum != null and couponNum != ''">
            and coupon_num = #{couponNum}
        </if>
    </where>
    </select>

    <select id="choiceRepeat" resultType="java.lang.Integer">
        select count(1) from coupon_share
         <where>
        <if test="couponNum != null and couponNum != ''">
            and coupon_num = #{couponNum}
        </if>
         <if test="couponId !=null">
            and coupon_id=#{couponId}
         </if>
             <if test="getOpenid !=null and getOpenid != ''">
                 and get_openid=#{getOpenid}
             </if>
             <if test="getPhone !=null and getPhone != ''">
                 and get_phone=#{getPhone}
             </if>
         </where>

    </select>


</mapper>