CouponMapper.xml 10.3 KB
<?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.yoho.ufo.dal.CouponMapper">
    <resultMap id="BaseResultMap" type="com.yoho.ufo.model.coupon.Coupon">
        <result column="id" property="id" jdbcType="INTEGER" />
        <result column="coupon_token" property="couponToken" jdbcType="VARCHAR" />
        <result column="coupon_name" property="couponName" jdbcType="VARCHAR" />
        <result column="coupon_amount" property="couponAmount" jdbcType="FLOAT" />
        <result column="coupon_type" property="couponType" jdbcType="INTEGER" />
        <result column="coupon_num" property="couponNum" jdbcType="INTEGER" />
        <result column="use_num" property="useNum" jdbcType="INTEGER" />
        <result column="send_num" property="sendNum" jdbcType="INTEGER" />
        <result column="use_limit_type" property="useLimitType" jdbcType="INTEGER" />
        <result column="use_limit_value" property="useLimitValue" jdbcType="INTEGER" />
        <result column="product_limit_type" property="productLimitType" jdbcType="INTEGER" />
        <result column="product_limit_value" property="productLimitValue" jdbcType="VARCHAR" />
        <result column="start_time" property="startTime" jdbcType="INTEGER" />
        <result column="end_time" property="endTime" jdbcType="INTEGER" />
        <result column="status" property="status" jdbcType="INTEGER" />
        <result column="create_time" property="createTime" jdbcType="INTEGER" />
        <result column="pid" property="pid" jdbcType="INTEGER" />
        <result column="remark" property="remark" jdbcType="VARCHAR" />
        <result column="skup_forbid_type" property="skupForbidType" jdbcType="VARCHAR" />
        <result column="skup_allow_type" property="skupAllowType" jdbcType="VARCHAR" />
        <result column="business_client" property="businessClient" jdbcType="VARCHAR" />
    </resultMap>

    <sql id="Base_Column_List">
        id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
        use_limit_type,use_limit_value,product_limit_type,product_limit_value,start_time,
        end_time,status,create_time,pid,remark,skup_forbid_type,skup_allow_type,business_client
    </sql>
    <insert id="insertOrUpdate" useGeneratedKeys="true" keyProperty="param.id">
        insert into coupon(id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
        use_limit_type,
        <if test="param.useLimitType == 2">
            use_limit_value,
        </if>
        product_limit_type,
        <if test="param.productLimitType != 1">
            product_limit_value,
        </if>
        start_time,end_time,status,create_time,pid,remark)
        values(#{param.id},#{param.couponToken},#{param.couponName},#{param.couponAmount},#{param.couponType}
        ,#{param.couponNum},#{param.useNum},#{param.sendNum},#{param.useLimitType},
        <if test="param.useLimitType == 2">
            #{param.useLimitValue},
        </if>
        #{param.productLimitType},
        <if test="param.productLimitType != 1">
            #{param.productLimitValue},
        </if>
        #{param.startTime},#{param.endTime},#{param.status},#{param.createTime},#{param.pid},#{param.remark})
        on duplicate key update
        coupon_name=#{param.couponName},coupon_amount=#{param.couponAmount},coupon_type=#{param.couponType},coupon_num=#{param.couponNum}
        ,use_num=#{param.useNum},send_num=#{param.sendNum},
        use_limit_type=#{param.useLimitType},
        <if test="param.useLimitType == 2">
            use_limit_value=#{param.useLimitValue},
        </if>
        product_limit_type=#{param.productLimitType},
        <if test="param.productLimitType != 1">
            product_limit_value=#{param.productLimitValue},
        </if>
        start_time=#{param.startTime},end_time=#{param.endTime},status=#{param.status},pid=#{param.pid},remark=#{param.remark}
    </insert>
    <insert id="insertByCouponSaveUpdateReq" useGeneratedKeys="true" keyProperty="param.id">
        insert into coupon(coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
        use_limit_type,
        <if test="param.useLimitType == 2">
            use_limit_value,
        </if>
        product_limit_type,
        start_time,end_time,status,create_time,pid,remark,skup_forbid_type,skup_allow_type, business_client)
        values(#{param.couponToken},#{param.couponName},#{param.couponAmount},#{param.couponType}
        ,#{param.couponNum},#{param.useNum},#{param.sendNum},#{param.useLimitType},
        <if test="param.useLimitType == 2">
            #{param.useLimitValue},
        </if>
        #{param.productLimitType},
        #{param.startTime},#{param.endTime},#{param.status},#{param.createTime},#{param.pid},#{param.remark},#{param.skupForbidType},#{param.skupAllowType},#{param.businessClient})
    </insert>
    <update id="updateByCouponSaveUpdateReq">
        update coupon
        <set>
            <if test="param.couponToken != null">
                coupon_token=#{param.couponToken},
            </if>
            <if test="param.couponName != null">
                coupon_name=#{param.couponName},
            </if>
            <if test="param.couponAmount != null">
                coupon_amount=#{param.couponAmount},
            </if>
            <if test="param.couponType != null">
                coupon_type=#{param.couponType},
            </if>
            <if test="param.couponNum != null">
                coupon_num=#{param.couponNum},
            </if>
            <if test="param.useNum != null">
                use_num=#{param.useNum},
            </if>
            <if test="param.sendNum != null">
                send_num=#{param.sendNum},
            </if>
            <if test="param.useLimitType != null">
                use_limit_type=#{param.useLimitType},
            </if>
            <if test="param.useLimitValue != null">
                use_limit_value=#{param.useLimitValue},
            </if>
            <if test="param.productLimitType != null">
                product_limit_type=#{param.productLimitType},
            </if>
            <if test="param.startTime != null">
                start_time=#{param.startTime},
            </if>
            <if test="param.endTime != null">
                end_time=#{param.endTime},
            </if>
            <if test="param.status != null">
                status=#{param.status},
            </if>
            <if test="param.createTime != null">
                create_time=#{param.createTime},
            </if>
            <if test="param.pid != null">
                pid=#{param.pid},
            </if>
            <if test="param.remark != null">
                remark=#{param.remark},
            </if>
            <if test="param.skupAllowType != null">
                skup_allow_type=#{param.skupAllowType},
            </if>
        </set>
        where id = #{param.id}
    </update>
    <select id="selectTotalByCondition" resultType="java.lang.Integer">
        select count(1) from coupon where 1=1
        <if test="param.id != null">
            and id=#{param.id}
        </if>
        <if test="param.name != null">
            and coupon_name=#{param.name}
        </if>

        <if test="param.startTime != null">
            and start_time>=#{param.startTime}
        </if>
        <if test="param.endTime != null">
            and end_time <![CDATA[<= ]]> #{param.endTime}
        </if>
        <if test="param.status != null">
            <if test="param.status == 3">
                <!--已作废-->
                and status=#{param.status}
            </if>
            <if test="param.status == 2">
                <!--已过期-->
                and end_time <![CDATA[< ]]> #{param.curTime}
                and status != 3
            </if>
            <if test="param.status == 1">
                <!--生效中-->
                and start_time <![CDATA[<= ]]> #{param.curTime}
                and end_time >= #{param.curTime}
                and status != 3
            </if>
            <if test="param.status == 0">
                <!--未生效-->
                and start_time > #{param.curTime}
                and status != 3
            </if>
        </if>
    </select>
    <select id="selectByCondition" resultType="com.yoho.ufo.model.coupon.Coupon">
        select <include refid="Base_Column_List" /> from coupon where 1=1
        <if test="param.id != null">
            and id=#{param.id}
        </if>
        <if test="param.name != null">
            and coupon_name=#{param.name}
        </if>
        <if test="param.startTime != null">
            and start_time>=#{param.startTime}
        </if>
        <if test="param.endTime != null">
            and end_time <![CDATA[<= ]]> #{param.endTime}
        </if>
        <if test="param.status != null">
            <if test="param.status == 3">
                <!--已作废-->
                and status=#{param.status}
            </if>
            <if test="param.status == 2">
                <!--已过期-->
                and end_time <![CDATA[< ]]> #{param.curTime}
                and status != 3
            </if>
            <if test="param.status == 1">
                <!--生效中-->
                and start_time <![CDATA[<= ]]> #{param.curTime}
                and end_time >= #{param.curTime}
                and status != 3
            </if>
            <if test="param.status == 0">
                <!--未生效-->
                and start_time > #{param.curTime}
                and status != 3
            </if>
        </if>
        order by id desc
        <if test="param.size > 0">
            limit #{param.start},#{param.size}
        </if>
    </select>
    <select id="selectById" resultType="com.yoho.ufo.model.coupon.Coupon">
        select <include refid="Base_Column_List" /> from coupon where id=#{id} limit 1;
    </select>
    <select id="selectValidByToken" resultType="com.yoho.ufo.model.coupon.Coupon">
        select <include refid="Base_Column_List" /> from coupon
        where coupon_token =#{token} and status = 1 limit 1;
    </select>
    
    <select id="selectByIds" resultType="com.yoho.ufo.model.coupon.Coupon">
        select <include refid="Base_Column_List" /> from coupon where id in
        <foreach collection="ids" close=")" open="(" separator="," item="item">
            #{item}
        </foreach>
    </select>
</mapper>