CouponMapper.xml 5.14 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" />
    </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
    </sql>
    <insert id="insertOrUpdate" useGeneratedKeys="true" keyProperty="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>
    <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.couponName != null">
            and coupon_name=#{param.couponName}
        </if>
        <if test="param.status != null">
            and status=#{param.status}
        </if>
        <if test="param.startTime != null">
            and start_time>=#{param.startTime}
        </if>
        <if test="param.endTime != null">
            and end_time <![CDATA[<= ]]> #{param.endTime}
        </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.couponName != null">
            and coupon_name=#{param.couponName}
        </if>
        <if test="param.status != null">
            and status=#{param.status}
        </if>
        <if test="param.startTime != null">
            and start_time>=#{param.startTime}
        </if>
        <if test="param.endTime != null">
            and end_time <![CDATA[<= ]]> #{param.endTime}
        </if>
        order by id desc
        limit #{param.start},#{param.size}
    </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>
</mapper>