CustomerRankMapper.xml 11.1 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.customer.mapper.CustomerRankMapper">
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.customer.entity.CustomerRank">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ACT_ID" jdbcType="BIGINT" property="actId" />
    <id column="RAK_ID" jdbcType="VARCHAR" property="rakId" />
    <result column="RAK_NAME" jdbcType="VARCHAR" property="rakName" />
    <result column="RAK_DESC" jdbcType="VARCHAR" property="rakDesc" />
    <result column="RAK_INDEX" jdbcType="INTEGER" property="rakIndex" />
    <result column="IS_FANS" jdbcType="BIT" property="isFans" />
    <result column="IS_MEMBER" jdbcType="BIT" property="isMember" />
    <result column="IS_SYSTEM" jdbcType="BIT" property="isSystem" />
    <result column="RAK_DELAY" jdbcType="INTEGER" property="rakDelay" />
    <result column="RAK_EXPIRY" jdbcType="INTEGER" property="rakExpiry" />
    <result column="REC_TIME" jdbcType="TIMESTAMP" property="recTime" />
    <result column="REC_USER" jdbcType="BIGINT" property="recUser" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    `ACT_ID`, `RAK_ID`, `RAK_NAME`, `RAK_DESC`, `RAK_INDEX`, `IS_FANS`, `IS_MEMBER`, 
    `IS_SYSTEM`, `RAK_DELAY`, `RAK_EXPIRY`,`REC_TIME`, `REC_USER`
  </sql>
  <select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from crm_customer_rank
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
      and `RAK_ID` = #{rakId,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="map">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from crm_customer_rank
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
      and `RAK_ID` = #{rakId,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_customer_rank (`ACT_ID`, `RAK_ID`, `RAK_NAME`, 
      `RAK_DESC`, `RAK_INDEX`, `IS_FANS`, 
      `IS_MEMBER`, `IS_SYSTEM`, `REC_TIME`, 
      `REC_USER`)
    values (#{actId,jdbcType=BIGINT}, #{rakId,jdbcType=VARCHAR}, #{rakName,jdbcType=VARCHAR}, 
      #{rakDesc,jdbcType=VARCHAR}, #{rakIndex,jdbcType=INTEGER}, #{isFans,jdbcType=BIT}, 
      #{isMember,jdbcType=BIT}, #{isSystem,jdbcType=BIT}, #{recTime,jdbcType=TIMESTAMP}, 
      #{recUser,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_customer_rank
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="actId != null">
        `ACT_ID`,
      </if>
      <if test="rakId != null">
        `RAK_ID`,
      </if>
      <if test="rakName != null">
        `RAK_NAME`,
      </if>
      <if test="rakDesc != null">
        `RAK_DESC`,
      </if>
      <if test="rakIndex != null">
        `RAK_INDEX`,
      </if>
      <if test="rakExpiry != null">
        `RAK_EXPIRY`,
      </if>
      <if test="isFans != null">
        `IS_FANS`,
      </if>
      <if test="isMember != null">
        `IS_MEMBER`,
      </if>
      <if test="isSystem != null">
        `IS_SYSTEM`,
      </if>
      <if test="recTime != null">
        `REC_TIME`,
      </if>
      <if test="recUser != null">
        `REC_USER`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="actId != null">
        #{actId,jdbcType=BIGINT},
      </if>
      <if test="rakId != null">
        #{rakId,jdbcType=VARCHAR},
      </if>
      <if test="rakName != null">
        #{rakName,jdbcType=VARCHAR},
      </if>
      <if test="rakDesc != null">
        #{rakDesc,jdbcType=VARCHAR},
      </if>
      <if test="rakIndex != null">
        #{rakIndex,jdbcType=INTEGER},
      </if>
      <if test="rakExpiry != null">
        #{rakExpiry,jdbcType=INTEGER},
      </if>
      <if test="isFans != null">
        #{isFans,jdbcType=BIT},
      </if>
      <if test="isMember != null">
        #{isMember,jdbcType=BIT},
      </if>
      <if test="isSystem != null">
        #{isSystem,jdbcType=BIT},
      </if>
      <if test="recTime != null">
        #{recTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recUser != null">
        #{recUser,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_customer_rank
    <set>
      <if test="rakName != null">
        `RAK_NAME` = #{rakName,jdbcType=VARCHAR},
      </if>
      <if test="rakDesc != null">
        `RAK_DESC` = #{rakDesc,jdbcType=VARCHAR},
      </if>
      <if test="rakIndex != null">
        `RAK_INDEX` = #{rakIndex,jdbcType=INTEGER},
      </if>
      <if test="isFans != null">
        `IS_FANS` = #{isFans,jdbcType=BIT},
      </if>
      <if test="isMember != null">
        `IS_MEMBER` = #{isMember,jdbcType=BIT},
      </if>
      <if test="isSystem != null">
        `IS_SYSTEM` = #{isSystem,jdbcType=BIT},
      </if>
      <if test="rakDelay != null">
        `RAK_DELAY` = #{rakDelay,jdbcType=INTEGER},
      </if>
      <if test="rakExpiry != null">
        `RAK_EXPIRY` = #{rakExpiry,jdbcType=INTEGER},
      </if>
      <if test="recTime != null">
        `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recUser != null">
        `REC_USER` = #{recUser,jdbcType=BIGINT},
      </if>
    </set>
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
      and `RAK_ID` = #{rakId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_customer_rank
    set `RAK_NAME` = #{rakName,jdbcType=VARCHAR},
      `RAK_DESC` = #{rakDesc,jdbcType=VARCHAR},
      `RAK_INDEX` = #{rakIndex,jdbcType=INTEGER},
      `IS_FANS` = #{isFans,jdbcType=BIT},
      `IS_MEMBER` = #{isMember,jdbcType=BIT},
      `IS_SYSTEM` = #{isSystem,jdbcType=BIT},
      `RAK_DELAY` = #{rakDelay,jdbcType=INTEGER},
      `RAK_EXPIRY` = #{rakExpiry,jdbcType=INTEGER},
      `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
      `REC_USER` = #{recUser,jdbcType=BIGINT}
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
      and `RAK_ID` = #{rakId,jdbcType=VARCHAR}
  </update>
  
	<select id="findAccountSetRanks" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultMap="BaseResultMap">
	   	select 
	    <include refid="Base_Column_List" />
	    from crm_customer_rank
	    where `ACT_ID` = #{actId,jdbcType=BIGINT} ORDER BY `RAK_INDEX` ASC
 	</select> 
 	
 	<select id="findMaxRakIndex" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultType="java.lang.String">
 		select 
	    	MAX(`RAK_INDEX`)
	    from crm_customer_rank
	    where `ACT_ID` = #{actId,jdbcType=BIGINT}
 	</select>
 	<select id="findByRakName" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultType="java.lang.Integer">
 		select 
	    	COUNT(*)
	    from crm_customer_rank
	    where `ACT_ID` = #{actId,jdbcType=BIGINT} and `RAK_NAME` = #{rakName,jdbcType=VARCHAR}
 	</select>
 	<select id="findByRakId" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultType="java.lang.Integer">
 		select 
	    	COUNT(*)
	    from crm_customer_rank
	    where `ACT_ID` = #{actId,jdbcType=BIGINT} and `RAK_ID` = #{rakId,jdbcType=VARCHAR}
 	</select>
 	<select id="findByActId" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultType="java.lang.Integer">
 		select 
 			COUNT(*)
 			from crm_customer_account
 			where `ACT_ID` = #{actId,jdbcType=BIGINT} and `CST_RANK` =#{rakId,jdbcType=VARCHAR}
 	</select>
 	
 	<delete id="removeCustomerRank" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
 		delete from crm_customer_rank
 		where ACT_ID= #{actId,jdbcType=BIGINT} and RAK_ID= #{rakId,jdbcType=VARCHAR}
 	</delete>
 	<update id="updateCustomerRank" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
 		update crm_customer_rank
 			<set>
			      <if test="rakIndex != null">
			        `RAK_INDEX` = #{rakIndex,jdbcType=INTEGER},
			      </if>
			      <if test="rakName != null">
			        `RAK_NAME` = #{rakName,jdbcType=VARCHAR},
			      </if>
			      <if test="rakName != null">
			        `RAK_EXPIRY` = #{rakExpiry,jdbcType=INTEGER},
			      </if>
			      <if test="rakDesc != null">
			        `RAK_DESC` = #{rakDesc,jdbcType=VARCHAR},
			      </if>
			       <if test="isFans != null">
			        `IS_FANS` = #{isFans,jdbcType=BIT},
			      </if>
			        <if test="isMember != null">
			        `IS_MEMBER` = #{isMember,jdbcType=BIT},
			      </if>
			       <if test="recTime != null">
			        `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
			      </if>
			       <if test="recUser != null">
			         `REC_USER` = #{recUser,jdbcType=BIGINT}
			      </if>
  		 	 </set>
  		  where ACT_ID= #{actId,jdbcType=BIGINT} and RAK_ID= #{rakId,jdbcType=VARCHAR}
 	</update>
 	<select id="selectLowestRank" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultMap="BaseResultMap">
 		SELECT 
 		<include refid="Base_Column_List" />
 		FROM crm_customer_rank 
 		WHERE ACT_ID = #{actId} 
 		AND RAK_INDEX = (
 		SELECT MIN(`RAK_INDEX`) 
 		FROM crm_customer_rank 
 		WHERE ACT_ID = #{actId}
 		<if test="isFans != null">
 		AND `IS_FANS` = #{isFans}
 		</if>
 		<if test="isMember != null">
 		AND `IS_MEMBER` = #{isMember}
 		</if> 
 		) 
 	</select>
 	<select id="selectActAndName" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank" resultMap="BaseResultMap">
	   	select 
	    `RAK_ID`
	    from crm_customer_rank
	    where `ACT_ID` = #{actId,jdbcType=BIGINT} and `RAK_NAME` = #{rakName,jdbcType=VARCHAR}
 	</select> 
 	<select id="findRelegationRanks" parameterType="boolean" resultMap="BaseResultMap">
 		SELECT r.*  
 		FROM crm_rank_policy_change c 
 		INNER JOIN crm_customer_rank r 
 		ON (c.`ACT_ID` = r.`ACT_ID` AND c.`RANK_FROM` = r.`RAK_ID`)
		WHERE c.`RANK_TYPE` = #{upgrade}
 	</select>
 	<update id="updateMemberAndFans" parameterType="cn.runsa.crmapp.customer.entity.CustomerRank">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_customer_rank
    set `IS_FANS` = #{isFans,jdbcType=BIT},
      `IS_MEMBER` = #{isMember,jdbcType=BIT}
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </update>
</mapper>