CustomerAccountMapper.xml 11.4 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.CustomerAccountMapper">
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.customer.entity.CustomerAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="CST_ID" jdbcType="BIGINT" property="cstId" />
    <id column="ACT_ID" jdbcType="BIGINT" property="actId" />
    <id column="ACT_NAME" jdbcType="VARCHAR" property="actName" />
    <result column="CST_CHL" jdbcType="VARCHAR" property="cstChl" />
    <result column="CST_SRC" jdbcType="VARCHAR" property="cstSrc" />
    <result column="SRC_VAL" jdbcType="VARCHAR" property="srcVal" />
    <result column="REFERRER" jdbcType="BIGINT" property="referrer" />
    <result column="CST_RANK" jdbcType="VARCHAR" property="cstRank" />
    <result column="RAK_NAME" jdbcType="VARCHAR" property="rakName" />
    <result column="RANK_TIME" jdbcType="TIMESTAMP" property="rankTime" />
    <result column="NEXT_RANK_TIME" jdbcType="TIMESTAMP" property="nextRankTime" />
    <result column="FAV_SITE" jdbcType="BIGINT" property="favSite" />
    <result column="FAV_SERVICE" jdbcType="BIGINT" property="favService" />
    <result column="LAST_LOGIN" jdbcType="TIMESTAMP" property="lastLogin" />
    <result column="TOTAL_PROFIT" jdbcType="DECIMAL" property="totalProfit" />
    <result column="TOTAL_AMOUNT" jdbcType="DECIMAL" property="totalAmount" />
    <result column="TOTAL_TIMES" jdbcType="INTEGER" property="totalTimes" />
  </resultMap>
  <resultMap type="cn.runsa.crmapp.customer.vo.CustomerAccountWithUpgradeId" id="BaseResultMapWithUpgradeId" extends="BaseResultMap">
  <id column="ID" jdbcType="BIGINT" property="upId" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    `CST_ID`, `ACT_ID`, `CST_CHL`,`CST_SRC`, `SRC_VAL`, `REFERRER`, `CST_RANK`, `RANK_TIME`, `NEXT_RANK_TIME`,`FAV_SITE`, 
    `FAV_SERVICE`, `LAST_LOGIN`, `TOTAL_PROFIT`, `TOTAL_AMOUNT`, `TOTAL_TIMES`
  </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_account
    where `CST_ID` = #{cstId,jdbcType=BIGINT}
      and `ACT_ID` = #{actId,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="map">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from crm_customer_account
    where `CST_ID` = #{cstId,jdbcType=BIGINT}
      and `ACT_ID` = #{actId,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="cn.runsa.crmapp.customer.entity.CustomerAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_customer_account (`CST_ID`, `ACT_ID`, `CST_CHL`,`CST_SRC`, 
      `SRC_VAL`, `REFERRER`, `CST_RANK`,`RANK_TIME`,`NEXT_RANK_TIME`,  `FAV_SITE`, `FAV_SERVICE`, 
      `LAST_LOGIN`, `TOTAL_PROFIT`, `TOTAL_AMOUNT`, 
      `TOTAL_TIMES`)
    values (#{cstId,jdbcType=BIGINT}, #{actId,jdbcType=BIGINT}, #{cstChl,jdbcType=VARCHAR},#{cstSrc,jdbcType=VARCHAR}, 
      #{srcVal,jdbcType=VARCHAR}, #{referrer,jdbcType=BIGINT}, #{cstRank,jdbcType=VARCHAR}, 
      #{rankTime,jdbcType=TIMESTAMP}, #{nextRankTime,jdbcType=TIMESTAMP}, #{favSite,jdbcType=BIGINT}, #{favService,jdbcType=BIGINT}, 
      #{lastLogin,jdbcType=TIMESTAMP}, #{totalProfit,jdbcType=DECIMAL}, #{totalAmount,jdbcType=DECIMAL}, 
      #{totalTimes,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.crmapp.customer.entity.CustomerAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_customer_account
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="cstId != null">
        `CST_ID`,
      </if>
      <if test="actId != null">
        `ACT_ID`,
      </if>
      <if test="cstChl != null">
        `CST_CHL`,
      </if>
      <if test="cstSrc != null">
        `CST_SRC`,
      </if>
      <if test="srcVal != null">
        `SRC_VAL`,
      </if>
      <if test="referrer != null">
        `REFERRER`,
      </if>
      <if test="cstRank != null">
        `CST_RANK`,
      </if>
      <if test="rankTime != null">
        `RANK_TIME`,
      </if>
      <if test="nextRankTime != null">
        `NEXT_RANK_TIME`,
      </if>
      <if test="favSite != null">
        `FAV_SITE`,
      </if>
      <if test="favService != null">
        `FAV_SERVICE`,
      </if>
      <if test="lastLogin != null">
        `LAST_LOGIN`,
      </if>
      <if test="totalProfit != null">
        `TOTAL_PROFIT`,
      </if>
      <if test="totalAmount != null">
        `TOTAL_AMOUNT`,
      </if>
      <if test="totalTimes != null">
        `TOTAL_TIMES`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="cstId != null">
        #{cstId,jdbcType=BIGINT},
      </if>
      <if test="actId != null">
        #{actId,jdbcType=BIGINT},
      </if>
      <if test="cstChl != null">
        #{cstChl,jdbcType=VARCHAR},
      </if>
      <if test="cstSrc != null">
        #{cstSrc,jdbcType=VARCHAR},
      </if>
      <if test="srcVal != null">
        #{srcVal,jdbcType=VARCHAR},
      </if>
      <if test="referrer != null">
        #{referrer,jdbcType=BIGINT},
      </if>
      <if test="cstRank != null">
        #{cstRank,jdbcType=VARCHAR},
      </if>
      <if test="rankTime != null">
        #{rankTime,jdbcType=TIMESTAMP},
      </if>
      <if test="nextRankTime != null">
        #{nextRankTime,jdbcType=TIMESTAMP},
      </if>
      <if test="favSite != null">
        #{favSite,jdbcType=BIGINT},
      </if>
      <if test="favService != null">
        #{favService,jdbcType=BIGINT},
      </if>
      <if test="lastLogin != null">
        #{lastLogin,jdbcType=TIMESTAMP},
      </if>
      <if test="totalProfit != null">
        #{totalProfit,jdbcType=DECIMAL},
      </if>
      <if test="totalAmount != null">
        #{totalAmount,jdbcType=DECIMAL},
      </if>
      <if test="totalTimes != null">
        #{totalTimes,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.runsa.crmapp.customer.entity.CustomerAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_customer_account
    <set>
      <if test="cstSrc != null">
        `CST_SRC` = #{cstSrc,jdbcType=VARCHAR},
      </if>
      <if test="srcVal != null">
        `SRC_VAL` = #{srcVal,jdbcType=VARCHAR},
      </if>
      <if test="referrer != null">
        `REFERRER` = #{referrer,jdbcType=BIGINT},
      </if>
      <if test="cstRank != null">
        `CST_RANK` = #{cstRank,jdbcType=VARCHAR},
      </if>
      <if test="rankTime != null">
        `RANK_TIME` = #{rankTime,jdbcType=TIMESTAMP},
      </if>
      <if test="nextRankTime != null">
        `NEXT_RANK_TIME` = #{nextRankTime,jdbcType=TIMESTAMP},
      </if>
      <if test="favSite != null">
        `FAV_SITE` = #{favSite,jdbcType=BIGINT},
      </if>
      <if test="favService != null">
        `FAV_SERVICE` = #{favService,jdbcType=BIGINT},
      </if>
      <if test="lastLogin != null">
        `LAST_LOGIN` = #{lastLogin,jdbcType=TIMESTAMP},
      </if>
      <if test="totalProfit != null">
        `TOTAL_PROFIT` = #{totalProfit,jdbcType=DECIMAL},
      </if>
      <if test="totalAmount != null">
        `TOTAL_AMOUNT` = #{totalAmount,jdbcType=DECIMAL},
      </if>
      <if test="totalTimes != null">
        `TOTAL_TIMES` = #{totalTimes,jdbcType=INTEGER},
      </if>
    </set>
    where `CST_ID` = #{cstId,jdbcType=BIGINT}
      and `ACT_ID` = #{actId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.runsa.crmapp.customer.entity.CustomerAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_customer_account
    set `CST_SRC` = #{cstSrc,jdbcType=VARCHAR},
      `SRC_VAL` = #{srcVal,jdbcType=VARCHAR},
      `REFERRER` = #{referrer,jdbcType=BIGINT},
      `CST_RANK` = #{cstRank,jdbcType=VARCHAR},
      `RANK_TIME` = #{rankTime,jdbcType=TIMESTAMP},
      `NEXT_RANK_TIME` = #{rankTime,jdbcType=TIMESTAMP},
      `FAV_SITE` = #{favSite,jdbcType=BIGINT},
      `FAV_SERVICE` = #{favService,jdbcType=BIGINT},
      `LAST_LOGIN` = #{lastLogin,jdbcType=TIMESTAMP},
      `TOTAL_PROFIT` = #{totalProfit,jdbcType=DECIMAL},
      `TOTAL_AMOUNT` = #{totalAmount,jdbcType=DECIMAL},
      `TOTAL_TIMES` = #{totalTimes,jdbcType=INTEGER}
    where `CST_ID` = #{cstId,jdbcType=BIGINT}
      and `ACT_ID` = #{actId,jdbcType=BIGINT}
  </update>
  <select id="selectCustomerAccounts" parameterType="map" resultMap="BaseResultMap">
  	SELECT ca.*,a.`ACT_NAME`,r.`RAK_NAME` 
	FROM crm_customer_account ca 
	INNER JOIN crm_account_set a 
	ON ca.`ACT_ID` = a.`ACT_ID` 
	LEFT JOIN crm_customer_rank r 
	ON (ca.`ACT_ID`  = r.`ACT_ID` AND ca.`CST_RANK` = r.`RAK_ID`) 
  	WHERE ca.`CST_ID` = #{cstId} 
	<if test="sets !=null">
	AND ca.`ACT_ID` IN
	<foreach collection="sets" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
  </select>
  
  <select id="selectCustomerAccountWithRankName" parameterType="map" resultMap="BaseResultMap">
  	SELECT a.*,b.rak_name FROM `crm_customer_account` a 
		left join crm_customer_rank b on 
		a.cst_rank=b.rak_id and a.act_id=b.act_id 
	where a.`CST_ID` = #{cstId,jdbcType=BIGINT}
      and a.`ACT_ID` = #{actId,jdbcType=BIGINT}
  </select>
  <select id="selectAccountsNeedDegrade" parameterType="map" resultMap="BaseResultMap">
  	SELECT a.* 
  	FROM crm_customer_account a 
  	INNER JOIN crm_customer c 
  	ON a.`CST_ID` = c.`CST_ID` 
  	WHERE a.`ACT_ID` = #{actId,jdbcType=BIGINT} 
  	AND c.`CST_TYPE` = #{cstType,jdbcType=TINYINT}
  	AND a.`CST_RANK`= #{rank,jdbcType=VARCHAR} 
  	AND a.`RANK_TIME` &lt; #{date,jdbcType=TIMESTAMP}
  	LIMIT #{start,jdbcType=INTEGER},#{length,jdbcType=INTEGER}
  </select>
  <select id="selectAccountsNeedUpgrade" parameterType="map" resultMap="BaseResultMapWithUpgradeId">
  	SELECT n.`ID`,a.* 
  	FROM crm_customer_need_upgrade n 
  	INNER JOIN crm_customer c 
  	ON n.`CST_ID` = c.`CST_ID` 
  	INNER JOIN crm_customer_account a 
  	ON (n.`ACT_ID` = a.`ACT_ID` AND n.`CST_ID` = a.`CST_ID`) 
  	WHERE 
  	a.`ACT_ID` = #{actId,jdbcType=BIGINT} 
  	AND c.`CST_TYPE` = #{cstType,jdbcType=TINYINT} 
  	AND a.`CST_RANK`= #{rank,jdbcType=VARCHAR} 
  	AND n.`UP_DATE` = #{date,jdbcType=DATE} 
  	LIMIT #{start,jdbcType=INTEGER},#{length,jdbcType=INTEGER}
  </select>
  <insert id="updateAccountsRank">
  	INSERT INTO crm_customer_account (`CST_ID`, `ACT_ID`, `CST_RANK`,`RANK_TIME`,`NEXT_RANK_TIME`)
  	VALUES
  	<foreach collection="list" item="it" separator=",">
  	(#{it.cstId,jdbcType=BIGINT}, #{it.actId,jdbcType=BIGINT},#{it.cstRank,jdbcType=VARCHAR}, 
      #{it.rankTime,jdbcType=TIMESTAMP}, #{it.nextRankTime,jdbcType=TIMESTAMP})
  	</foreach> 
  	ON DUPLICATE KEY UPDATE 
  	`CST_RANK` = values(`CST_RANK`),
  	`RANK_TIME`= values(`RANK_TIME`),
  	`NEXT_RANK_TIME` = values(`NEXT_RANK_TIME`)
  </insert>
</mapper>