AccountSetMapper.xml 14.2 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.common.mapper.AccountSetMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.common.entity.AccountSet" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ACT_ID" property="actId" jdbcType="BIGINT" />
    <result column="ACT_CODE" property="actCode" jdbcType="VARCHAR" />
    <result column="ACT_NAME" property="actName" jdbcType="VARCHAR" />
    <result column="PTF_ID" property="ptfId" jdbcType="BIGINT" />
    <result column="ENABLE" property="enable" jdbcType="BIT" />
    <result column="ACT_DESC" property="actDesc" jdbcType="VARCHAR" />
    <result column="REC_TIME" property="recTime" jdbcType="TIMESTAMP" />
    <result column="REC_USER" property="recUser" jdbcType="BIGINT" />
    <result column="ACT_TYPE" property="actType" jdbcType="VARCHAR" />
    <result column="brId" property="brId" jdbcType="VARCHAR" />
    <result column="brName" property="brName" jdbcType="VARCHAR" />
    <result column="ptfName" property="ptfName" jdbcType="VARCHAR" />
  </resultMap>
  
    <resultMap id="BaseResultMap2" type="cn.runsa.crmapp.common.entity.AccountSet" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ACT_ID" property="actId" jdbcType="BIGINT" />
    <result column="ACT_CODE" property="actCode" jdbcType="VARCHAR" />
    <result column="ACT_NAME" property="actName" jdbcType="VARCHAR" />
    <result column="PTF_ID" property="ptfId" jdbcType="BIGINT" />
    <result column="CHL_ID" property="msgChannel" jdbcType="BIGINT" />
    <result column="ENABLE" property="enable" jdbcType="BIT" />
    <result column="ACT_DESC" property="actDesc" jdbcType="VARCHAR" />
    <result column="REC_TIME" property="recTime" jdbcType="TIMESTAMP" />
    <result column="REC_USER" property="recUser" jdbcType="BIGINT" />
    <result column="ACT_TYPE" property="actType" jdbcType="VARCHAR" />
    <result column="brId" property="brId" jdbcType="VARCHAR" />
    <result column="brName" property="brName" jdbcType="VARCHAR" />
    <result column="ptfName" property="ptfName" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    `ACT_ID`, `ACT_CODE`, `ACT_NAME`,`PTF_ID`, `ENABLE`, `ACT_DESC`, `REC_TIME`, `REC_USER` , `ACT_TYPE`
  </sql>
  <select id="countSetBrand" parameterType="java.lang.Long" resultType="java.lang.Integer">
		SELECT COUNT(*) FROM crm_customer_account  c WHERE c.ACT_ID IN (
			SELECT a.ACT_ID FROM crm_account_set a where a.ACT_ID = #{actId,jdbcType=BIGINT}); 
  </select>
  <select id="findByActName" parameterType="java.lang.String" resultType="java.lang.Integer">
  		select
			COUNT(*)
		from
			crm_account_set
		where ACT_NAME = #{actName,jdbcType=VARCHAR}
  </select>
  <select id="findAccountSetAll" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from
		crm_account_set
		where 1=1  and ACT_TYPE=1
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from crm_account_set
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </select>
  <select id="selectAccSet" resultMap="BaseResultMap2" parameterType="java.lang.Long" >
    SELECT
		accset.`ACT_ID`,
		accset.`ACT_CODE`,
		accset.`ACT_NAME`,
		accset.`PTF_ID`,
		accset.`ENABLE`,
		accset.`ACT_DESC`,
		accset.`REC_TIME`,
		accset.`REC_USER`,
		accset.`ACT_TYPE`,
		pf.plName ptfName,
		GROUP_CONCAT(br.brId) brId,
		GROUP_CONCAT(br.brName) brName,
		channel.CHL_ID CHL_ID
	FROM
		`crm_account_set` accset
	LEFT JOIN smplatform pf ON accset.PTF_ID = pf.plId
	LEFT JOIN crm_account_set_brand asb ON asb.ACT_ID = accset.ACT_ID 
	LEFT JOIN mtbrand br ON br.brId = asb.BND_ID
	LEFT JOIN crm_account_set_channel channel ON accset.ACT_ID = channel.ACT_ID and channel.SCENE=1
	WHERE accset.`ACT_ID` = #{actId,jdbcType=BIGINT}
	GROUP BY accset.ACT_ID
  </select>
  <select id="selectByActCode" resultMap="BaseResultMap" >
    select 
    <include refid="Base_Column_List" />
    from crm_account_set
    ORDER BY ACT_CODE DESC 
	LIMIT 1
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from crm_account_set
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </delete>
  <insert id="insert" useGeneratedKeys="true" keyProperty="actId" parameterType="cn.runsa.crmapp.common.entity.AccountSet" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_account_set (`ACT_ID`, `ACT_CODE`, `ACT_NAME`, `PTF_ID`, 
      `ENABLE`, `ACT_DESC`, `REC_TIME`, 
      `REC_USER`, `ACT_TYPE`)
    values (#{actId,jdbcType=BIGINT}, #{actCode,jdbcType=VARCHAR}, #{actName,jdbcType=VARCHAR}, #{ptfId,jdbcType=BIGINT}, 
    		#{enable,jdbcType=BIT}, #{actDesc,jdbcType=VARCHAR}, #{recTime,jdbcType=TIMESTAMP}, #{recUser,jdbcType=BIGINT}, #{actType,jdbcType=VARCHAR})
  </insert>
  <insert id="insertBrand" parameterType="java.util.Map">
  	insert into crm_account_set_brand (`ACT_ID`, `BND_ID`) values (#{actId,jdbcType=BIGINT}, #{brId,jdbcType=BIGINT})
  </insert>
  <insert id="insertChannel" parameterType="java.util.Map">
  	insert into crm_account_set_channel (`ACT_ID`, `SCENE`, `CHL_ID`) values (#{actId,jdbcType=BIGINT}, #{scene,jdbcType=VARCHAR}, #{msgChannel,jdbcType=BIGINT})
  </insert>
  <insert id="insertRights" parameterType="java.util.Map">
  	insert into crm_account_set_rights (`ACT_ID`, `RIGHTS`) values (#{actId,jdbcType=BIGINT}, #{rights,jdbcType=VARCHAR})
  </insert>
  <!-- 绑定默认顾客等级 -->
    <insert id="createCustRank" parameterType="java.util.Map">
  	insert into crm_customer_rank 
	  	(`ACT_ID`, `RAK_ID`, `RAK_NAME`, `RAK_DESC`, `RAK_INDEX`, `IS_FANS`, `IS_MEMBER`,`REC_TIME`, `REC_USER`) 
    values 
    	(#{actId,jdbcType=BIGINT},1,'初级会员','不可删除,可修改,全局统一',1,0,1,SYSDATE(),#{recUser,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" useGeneratedKeys="true" keyProperty="actId" parameterType="cn.runsa.crmapp.common.entity.AccountSet" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into crm_account_set
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="actId != null" >
        `ACT_ID`,
      </if>
      <if test="actCode != null" >
        `ACT_CODE`,
      </if>
      <if test="actName != null" >
        `ACT_NAME`,
      </if>
      <if test="ptfId != null" >
        `PTF_ID`,
      </if>
      <if test="enable != null" >
        `ENABLE`,
      </if>
      <if test="actDesc != null" >
        `ACT_DESC`,
      </if>
      <if test="recTime != null" >
        `REC_TIME`,
      </if>
      <if test="recUser != null" >
        `REC_USER`,
      </if>
      <if test="actType != null" >
        `ACT_TYPE`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="actId != null" >
        #{actId,jdbcType=BIGINT},
      </if>
      <if test="actCode != null" >
        #{actCode,jdbcType=VARCHAR},
      </if>
      <if test="actName != null" >
        #{actName,jdbcType=VARCHAR},
      </if>
      <if test="ptfId != null" >
        #{ptfId,jdbcType=BIGINT},
      </if>
      <if test="enable != null" >
        #{enable,jdbcType=BIT},
      </if>
      <if test="actDesc != null" >
        #{actDesc,jdbcType=VARCHAR},
      </if>
      <if test="recTime != null" >
        #{recTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recUser != null" >
        #{recUser,jdbcType=BIGINT},
      </if>
      <if test="actType != null" >
        #{actType,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" useGeneratedKeys="true" keyProperty="actId" parameterType="cn.runsa.crmapp.common.entity.AccountSet" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_account_set
    <set >
      <if test="actCode != null" >
        `ACT_CODE` = #{actCode,jdbcType=VARCHAR},
      </if>
      <if test="actName != null" >
        `ACT_NAME` = #{actName,jdbcType=VARCHAR},
      </if>
      <if test="ptfId != 9999" >
        `PTF_ID` = #{ptfId,jdbcType=BIGINT},
      </if>
      <if test="enable != null" >
        `ENABLE` = #{enable,jdbcType=BIT},
      </if>
      <if test="actDesc != null" >
        `ACT_DESC` = #{actDesc,jdbcType=VARCHAR},
      </if>
      <if test="recTime != null" >
        `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recUser != null" >
        `REC_USER` = #{recUser,jdbcType=BIGINT},
      </if>
      <if test="actType != null" >
        `ACT_TYPE` = #{actType,jdbcType=VARCHAR},
      </if>
    </set>
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" useGeneratedKeys="true" keyProperty="actId" parameterType="cn.runsa.crmapp.common.entity.AccountSet" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_account_set
    set `ACT_CODE` = #{actCode,jdbcType=VARCHAR},
      `ACT_NAME` = #{actName,jdbcType=VARCHAR},
      `PTF_ID` = #{ptfId,jdbcType=BIGINT},
      `ENABLE` = #{enable,jdbcType=BIT},
      `ACT_DESC` = #{actDesc,jdbcType=VARCHAR},
      `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
      `REC_USER` = #{recUser,jdbcType=BIGINT},
      `ACT_TYPE` = #{actType,jdbcType=VARCHAR},
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </update>
  <delete id="deleteBrand" parameterType="java.lang.Long" >
    delete from crm_account_set_brand
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </delete>
  <update id="updateAccChannel" parameterType="java.util.Map">
    update crm_account_set_channel
    <set >
      
      <if test="msgChannel != null" >
        `CHL_ID` = #{msgChannel,jdbcType=BIGINT}
      </if>
    </set>
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
    and `SCENE` = #{scene,jdbcType=VARCHAR}
  </update>
  <delete id="daleteAccSite" parameterType="java.lang.Long" >
    delete from crm_account_set_site
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </delete>
  <select id="findBySiteId" resultType="java.lang.String" parameterType="java.lang.Integer">
  		SELECT
			GROUP_CONCAT(t1.brId) brId
		FROM
			mtSiteBrand t1
		WHERE
			t1.sirId = #{sirId,jdbcType=INTEGER}
		GROUP BY
			t1.sirId
  </select>
  <insert id="insertAccSetSite"  useGeneratedKeys="true" keyProperty="actId" parameterType="java.util.Map" >
    insert into crm_account_set_site
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="actId != null" >
        `ACT_ID`,
      </if>
      <if test="grpId != null" >
        `GRP_ID`,
      </if>
      <if test="sitId != null" >
        `SIT_ID`,
      </if>
      <if test="bndId != null" >
        `BND_ID`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="actId != null" >
        #{actId,jdbcType=BIGINT},
      </if>
      <if test="grpId != null" >
        #{grpId,jdbcType=BIGINT},
      </if>
      <if test="sitId != null" >
        #{sitId,jdbcType=BIGINT},
      </if>
      <if test="bndId != null" >
        #{bndId,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  
    <insert id="insertAccountSiteBrands"  useGeneratedKeys="true" keyProperty="actId" parameterType="java.util.Map" >
    insert ignore into crm_account_set_site (ACT_ID, GRP_ID, SIT_ID, BND_ID) 
   	select #{actId} actId,#{grpId} GRP_ID,siId,brId 
   	from mtsiterange a
       	left join mtsitebrand b on a.sirId=b.sirId 
       	left join crm_account_set_site t10 ON a.SIID =t10.SIT_ID AND b.BRID=t10.BND_ID
	where  (t10.SIT_ID IS NULL AND t10.BND_ID IS NULL)
		and a.siId in (${sitesId})   
		<if test="bndsId != null and bndsId != ''" >
			and b.brId IN (${bndsId})  
  		</if> 
  </insert>
  
  <delete id="deleteAccountSiteBrands"  >
  	delete from crm_account_set_site where ACT_ID=#{actId}
  	
  	<if test="grpId != null ">
  		and GRP_ID=#{grpId} 
  	</if>
  	<if test="sitesId != null and sitesId != ''">
  		and SIT_ID in (${sitesId})
  	</if>
  	<if test="brId != null and brId != ''">
  		and BND_ID in (${brId})
  	</if>
  </delete>
  
  <delete id="deleteAccountSiteBrandsByBrands"  >
  	delete from crm_account_set_site where ACT_ID=#{actId}
  	<if test="brId != null and brId != ''">
  		and BND_ID not in (${brId})
  	</if>
  </delete>
  
   <delete id="insertAccountSiteBrandsOnGroup"  parameterType="java.util.Map" >
  	    insert ignore into crm_account_set_site (ACT_ID, GRP_ID, SIT_ID, BND_ID) 
   	select #{actId} actId,#{grpId} GRP_ID,siId,brId 
   	from mtsiterange a
       	left join mtsitebrand b on a.sirId=b.sirId 
       	left join crm_account_set_site t10 ON a.SIID =t10.SIT_ID AND b.BRID=t10.BND_ID
	where  (t10.SIT_ID IS NULL AND t10.BND_ID IS NULL)
		and a.siId in (${sitesId})   
		<if test="bndsId != null and bndsId != ''" >
			and b.brId IN (${bndsId})  
  		</if> 
  </delete>
  
  <select id="findAccountSetByFilterCondition" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from crm_account_set t1 LEFT JOIN smPlatform t2 ON t2.plId=t1.PTF_ID 
		WHERE (CASE WHEN ${ptfId}= 1 THEN 1 = 1 WHEN ${ptfId}!= 1 THEN t1.PTF_ID=${ptfId} END)
		AND t1.act_type=1
  </select>
  
  <insert id="changeAccountSiteBrands">
  	  insert ignore  into crm_account_set_site (ACT_ID, GRP_ID, SIT_ID, BND_ID) 
		select act_id, grp_id, sit_id, bb.brid from   
			(select distinct act_id, grp_id, sit_id from crm_account_set_site where act_id = #{actId}) aa left join 
        (select a.SIID,b.brid from  mtsiterange a
       	left join mtsitebrand b on a.sirId=b.sirId ) bb on aa.sit_id = bb.siid
       	where bb.brid in (${brId})
  </insert>
</mapper>