CouponsMapper.xml 10.8 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="cn.runsa.crmapp.coupon.mapper.CouponsMapper">
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.coupon.entity.Coupons">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="CPN_ID" jdbcType="VARCHAR" property="cpnId" />
    <result column="CPL_ID" jdbcType="VARCHAR" property="cplId" />
    <result column="CPN_STAT" jdbcType="TINYINT" property="cpnStat" />
    <result column="S_TIME" jdbcType="TIMESTAMP" property="sTime" />
    <result column="E_TIME" jdbcType="TIMESTAMP" property="eTime" />
    <result column="CRT_TIME" jdbcType="TIMESTAMP" property="crtTime" />
    <result column="LOK_TIME" jdbcType="TIMESTAMP" property="lokTime" />
    <result column="USE_TIME" jdbcType="TIMESTAMP" property="useTime" />
    <result column="CPN_FROM" jdbcType="VARCHAR" property="cpnFrom" />
    <result column="CPN_FROM_INST" jdbcType="VARCHAR" property="cpnFromInst" />
    <result column="CPN_USE" jdbcType="VARCHAR" property="cpnUse" />
    <result column="CPN_USE_INST" jdbcType="VARCHAR" property="cpnUseInst" />
    <result column="REC_TIME" jdbcType="TIMESTAMP" property="recTime" />
  </resultMap>
  <resultMap id="InfoResultMap" type="cn.runsa.crmapp.coupon.vo.CouponVo">
    <id column="CPN_ID" jdbcType="VARCHAR" property="cpnId" />
    <result column="CPL_ID" jdbcType="VARCHAR" property="cplId" />
    <result column="CPN_STAT" jdbcType="TINYINT" property="cpnStat" />
    <result column="S_TIME" jdbcType="TIMESTAMP" property="sTime" />
    <result column="E_TIME" jdbcType="TIMESTAMP" property="eTime" />
    <result column="CPL_NAME" jdbcType="VARCHAR" property="cplName" />
    <result column="CPL_DESC" jdbcType="VARCHAR" property="cplDesc" />
    <result column="CPN_TYPE" jdbcType="TINYINT" property="cpnType" />
    <result column="PRICE" jdbcType="DECIMAL" property="price" />
    <result column="MONEY" jdbcType="DECIMAL" property="money" />
    <result column="ICON" jdbcType="VARCHAR" property="icon" />
    <result column="URL" jdbcType="VARCHAR" property="url" />
    <result column="DISCOUNT" jdbcType="DOUBLE" property="discount" />
    <result column="MONEY_LMT" jdbcType="DECIMAL" property="moneyLmt" />
    <result column="DISCOUNT_LMT" jdbcType="DOUBLE" property="discountLmt" />
    <result column="AMOUNT_LIMIT" jdbcType="INTEGER" property="amountLimit" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    `CPN_ID`, `CPL_ID`, `CPN_STAT`, `S_TIME`, `E_TIME`, `CRT_TIME`, `LOK_TIME`, `USE_TIME`, 
    `CPN_FROM`, `CPN_FROM_INST`, `CPN_USE`, `CPN_USE_INST`, `REC_TIME`
  </sql>
  <sql id="Info_Column_List">
  	a.`CPN_ID`, a.`CPL_ID`, a.`CPN_STAT`, a.`S_TIME`, a.`E_TIME`, b.`CPL_NAME`, b.`CPL_DESC`, b.`CPN_TYPE`, 
    b.`PRICE`, b.`MONEY`, b.`VERIFY`, b.`ICON`, b.`URL`,b.`DISCOUNT`, b.`MONEY_LMT`, b.`DISCOUNT_LMT`, b.`AMOUNT_LIMIT`
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from crm_coupons
    where `CPN_ID` = #{cpnId,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from crm_coupons
    where `CPN_ID` = #{cpnId,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="cn.runsa.crmapp.coupon.entity.Coupons">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_coupons (`CPN_ID`, `CPL_ID`, `CPN_STAT`, 
      `S_TIME`, `E_TIME`, `CRT_TIME`, 
      `LOK_TIME`, `USE_TIME`, `CPN_FROM`, 
      `CPN_FROM_INST`, `CPN_USE`, `CPN_USE_INST`, 
      `REC_TIME`)
    values (#{cpnId,jdbcType=VARCHAR}, #{cplId,jdbcType=VARCHAR}, #{cpnStat,jdbcType=TINYINT}, 
      #{sTime,jdbcType=TIMESTAMP}, #{eTime,jdbcType=TIMESTAMP}, #{crtTime,jdbcType=TIMESTAMP}, 
      #{lokTime,jdbcType=TIMESTAMP}, #{useTime,jdbcType=TIMESTAMP}, #{cpnFrom,jdbcType=VARCHAR}, 
      #{cpnFromInst,jdbcType=VARCHAR}, #{cpnUse,jdbcType=VARCHAR}, #{cpnUseInst,jdbcType=VARCHAR}, 
      #{recTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.crmapp.coupon.entity.Coupons">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_coupons
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="cpnId != null">
        `CPN_ID`,
      </if>
      <if test="cplId != null">
        `CPL_ID`,
      </if>
      <if test="cpnStat != null">
        `CPN_STAT`,
      </if>
      <if test="sTime != null">
        `S_TIME`,
      </if>
      <if test="eTime != null">
        `E_TIME`,
      </if>
      <if test="crtTime != null">
        `CRT_TIME`,
      </if>
      <if test="lokTime != null">
        `LOK_TIME`,
      </if>
      <if test="useTime != null">
        `USE_TIME`,
      </if>
      <if test="cpnFrom != null">
        `CPN_FROM`,
      </if>
      <if test="cpnFromInst != null">
        `CPN_FROM_INST`,
      </if>
      <if test="cpnUse != null">
        `CPN_USE`,
      </if>
      <if test="cpnUseInst != null">
        `CPN_USE_INST`,
      </if>
      <if test="recTime != null">
        `REC_TIME`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="cpnId != null">
        #{cpnId,jdbcType=VARCHAR},
      </if>
      <if test="cplId != null">
        #{cplId,jdbcType=VARCHAR},
      </if>
      <if test="cpnStat != null">
        #{cpnStat,jdbcType=TINYINT},
      </if>
      <if test="sTime != null">
        #{sTime,jdbcType=TIMESTAMP},
      </if>
      <if test="eTime != null">
        #{eTime,jdbcType=TIMESTAMP},
      </if>
      <if test="crtTime != null">
        #{crtTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lokTime != null">
        #{lokTime,jdbcType=TIMESTAMP},
      </if>
      <if test="useTime != null">
        #{useTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cpnFrom != null">
        #{cpnFrom,jdbcType=VARCHAR},
      </if>
      <if test="cpnFromInst != null">
        #{cpnFromInst,jdbcType=VARCHAR},
      </if>
      <if test="cpnUse != null">
        #{cpnUse,jdbcType=VARCHAR},
      </if>
      <if test="cpnUseInst != null">
        #{cpnUseInst,jdbcType=VARCHAR},
      </if>
      <if test="recTime != null">
        #{recTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.runsa.crmapp.coupon.entity.Coupons">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_coupons
    <set>
      <if test="cplId != null">
        `CPL_ID` = #{cplId,jdbcType=VARCHAR},
      </if>
      <if test="cpnStat != null">
        `CPN_STAT` = #{cpnStat,jdbcType=TINYINT},
      </if>
      <if test="sTime != null">
        `S_TIME` = #{sTime,jdbcType=TIMESTAMP},
      </if>
      <if test="eTime != null">
        `E_TIME` = #{eTime,jdbcType=TIMESTAMP},
      </if>
      <if test="crtTime != null">
        `CRT_TIME` = #{crtTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lokTime != null">
        `LOK_TIME` = #{lokTime,jdbcType=TIMESTAMP},
      </if>
      <if test="useTime != null">
        `USE_TIME` = #{useTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cpnFrom != null">
        `CPN_FROM` = #{cpnFrom,jdbcType=VARCHAR},
      </if>
      <if test="cpnFromInst != null">
        `CPN_FROM_INST` = #{cpnFromInst,jdbcType=VARCHAR},
      </if>
      <if test="cpnUse != null">
        `CPN_USE` = #{cpnUse,jdbcType=VARCHAR},
      </if>
      <if test="cpnUseInst != null">
        `CPN_USE_INST` = #{cpnUseInst,jdbcType=VARCHAR},
      </if>
      <if test="recTime != null">
        `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where `CPN_ID` = #{cpnId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.runsa.crmapp.coupon.entity.Coupons">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_coupons
    <set>
      <if test="cpnStat != null">
        `CPN_STAT` = #{cpnStat,jdbcType=TINYINT},
      </if>
      <if test="lokTime != null">
        `LOK_TIME` = #{lokTime,jdbcType=TIMESTAMP},
      </if>
      <if test="useTime != null">
        `USE_TIME` = #{useTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cpnUse != null">
        `CPN_USE` = #{cpnUse,jdbcType=VARCHAR},
      </if>
      <if test="cpnUseInst != null">
        `CPN_USE_INST` = #{cpnUseInst,jdbcType=VARCHAR},
      </if>
    </set>
    where `CPN_ID` = #{cpnId,jdbcType=VARCHAR}
  </update>
  <insert id="insertMore">
  	insert into crm_coupons (`CPN_ID`, `CPL_ID`, `CPN_STAT`, `S_TIME`, `E_TIME`, `CRT_TIME`,`CPN_FROM`, `CPN_FROM_INST`)
	values
	<foreach collection="list" item="it" separator=",">
		(#{it.cpnId,jdbcType=VARCHAR}, #{it.cplId,jdbcType=VARCHAR},
		#{it.cpnStat,jdbcType=TINYINT},#{it.sTime,jdbcType=TIMESTAMP}, #{it.eTime,jdbcType=TIMESTAMP},
		#{it.crtTime,jdbcType=TIMESTAMP}, #{it.cpnFrom,jdbcType=VARCHAR}, #{it.cpnFromInst,jdbcType=VARCHAR})
	</foreach>
  </insert>
  <select id="selectCustomerConpons" parameterType="cn.runsa.crmapp.coupon.vo.CouponQueryVo" resultMap="InfoResultMap">
    <choose>
    	<when test="sitId != null">
    		SELECT <include refid="Info_Column_List" />
    		FROM crm_coupons_customer c 
    		INNER JOIN crm_coupons a 
    		ON a.CPN_ID = c.CPN_ID 
    		LEFT JOIN 
    		( SELECT r.* FROM crm_coupon_site_receive s LEFT JOIN crm_coupon_rule r ON r.CPL_ID = s.CPL_ID WHERE s.SIT_ID = 2 AND r.SITE_LMT = 1 OR r.SITE_LMT = 0 ) b 
    		ON a.CPL_ID = b.CPL_ID 
    		WHERE c.CST_ID = #{cstId} 
    		AND c.`ENABLE` = 1 AND a.`CPN_STAT` IN (
    		<foreach collection="states" item="it" separator=",">
    		#{it}
    		</foreach>
    		) ORDER BY a.`CRT_TIME` DESC LIMIT #{start},#{size}
    	</when>
    	<otherwise>
    		SELECT <include refid="Info_Column_List" />
    		FROM crm_coupons a 
    		INNER JOIN crm_coupons_customer c 
    		ON a.`CPN_ID` = c.`CPN_ID` 
    		LEFT JOIN crm_coupon_rule b 
    		ON a.`CPL_ID` = b.`CPL_ID` 
    		WHERE c.`CST_ID` = #{cstId} 
			AND c.`ENABLE` = 1 AND a.`CPN_STAT` IN (
			<foreach collection="states" item="it" separator=",">
    		#{it}
    		</foreach>
    		) ORDER BY a.`CRT_TIME` DESC LIMIT #{start},#{size}
    	</otherwise>
    </choose>
  </select>
</mapper>