CouponMapper.xml 10.6 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="user_type" property="userType" 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" />
        <result column="receive_start_time" property="receiveStartTime" jdbcType="INTEGER" />
        <result column="receive_end_time" property="receiveEndTime" jdbcType="INTEGER" />
        <result column="receive_channels" property="receiveChannels" jdbcType="VARCHAR" />
        <result column="check_required" property="checkRequired" jdbcType="INTEGER" />
    </resultMap>

    <sql id="Base_Column_List">
        id,user_type,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,
        receive_start_time,receive_end_time,receive_channels,check_required
    </sql>

    <insert id="insertByCouponSaveUpdateReq" useGeneratedKeys="true" keyProperty="param.id">
        insert into coupon(
        user_type,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,
        use_limit_type,
        <if test="param.useLimitType == 2">
            use_limit_value,
        </if>
        product_limit_type,
        product_limit_value,
        start_time,end_time,
        status,
        create_time,
        pid,remark,
        skup_forbid_type,
        skup_allow_type,
        business_client,
        receive_start_time,
        receive_end_time,
        receive_channels,
        check_required
        )
        values(
        #{param.userType},
        #{param.couponToken},#{param.couponName},#{param.couponAmount},#{param.couponType}
        ,#{param.couponNum},#{param.useNum},#{param.useLimitType},
        <if test="param.useLimitType == 2">
            #{param.useLimitValue},
        </if>
        #{param.productLimitType},
        #{param.productLimitValue},
        #{param.startTime},
        #{param.endTime},
        #{param.status},
        #{param.createTime},
        #{param.pid},
        #{param.remark},
        #{param.skupForbidType},
        #{param.skupAllowType},
        #{param.businessClient},
        #{param.receiveStartTime},
        #{param.receiveEndTime},
        #{param.receiveChannels},
        #{param.checkRequired}
        )
    </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.productLimitValue != null">
                product_limit_value=#{param.productLimitValue},
            </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>
            <if test="param.businessClient != null">
                business_client=#{param.businessClient},
            </if>
            <if test="param.receiveStartTime != null">
                receive_start_time = #{param.receiveStartTime},
            </if>
            <if test="param.receiveEndTime != null">
                receive_end_time = #{param.receiveEndTime},
            </if>
            <if test="param.receiveChannels != null">
                receive_channels = #{param.receiveChannels},
            </if>
            <if test="param.checkRequired != null">
                check_required = #{param.checkRequired},
            </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.userType != null">
            and user_type=#{param.userType}
        </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.userType != null">
            and user_type=#{param.userType}
        </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>