SiteGroupMapper.xml 5.62 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.SiteGroupMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.common.entity.SiteGroup" >
    <id column="GRP_ID" property="grpId" jdbcType="BIGINT" />
    <result column="ACT_ID" property="actId" jdbcType="BIGINT" />
    <result column="GRP_NAME" property="grpName" jdbcType="VARCHAR" />
    <result column="GRP_DESC" property="grpDesc" jdbcType="VARCHAR" />
    <result column="GRP_INDEX" property="grpIndex" jdbcType="INTEGER" />
    <result column="REC_TIME" property="recTime" jdbcType="TIMESTAMP" />
    <result column="REC_USER" property="recUser" jdbcType="BIGINT" />
    <result column="GZH_ID" property="gzhId" jdbcType="VARCHAR" />
    <result column="GZH_TYPE" property="gzhType" jdbcType="INTEGER" />
    <result column="NICK_NAME" property="nickName" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    `GRP_ID`, `ACT_ID`, `GRP_NAME`, `GRP_DESC`, `GRP_INDEX`, `REC_TIME`, `REC_USER`
  </sql>
  <select id="findList" resultMap="BaseResultMap" parameterType="java.lang.Long" >
   SELECT
		t1.`GRP_ID`,
		t1.`ACT_ID`,
		t1.`GRP_NAME`,
		t1.`GRP_DESC`,
		t1.`GRP_INDEX`,
		t1.`REC_TIME`,
		t1.`REC_USER`,
		t3.GZH_ID,
		t3.GZH_TYPE,
		t3.NICK_NAME
	FROM
		crm_site_group t1
	LEFT JOIN crm_site_group_wxgzh t2 ON t2.GRP_ID = t1.GRP_ID
	LEFT JOIN crm_wxgzh t3 ON t3.GZH_ID = t2.GZH_ID
	WHERE
		ACT_ID = #{actId,jdbcType=INTEGER}
	ORDER BY
		GRP_INDEX
  </select>
  <insert id="insert" useGeneratedKeys="true" keyProperty="grpId" parameterType="cn.runsa.crmapp.common.entity.SiteGroup" >
    insert into crm_site_group
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="actId != null" >
        `ACT_ID`,
      </if>
      <if test="grpName != null" >
        `GRP_NAME`,
      </if>
      <if test="grpDesc != null" >
        `GRP_DESC`,
      </if>
      <if test="grpIndex != null" >
        `GRP_INDEX`,
      </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="grpName != null" >
        #{grpName,jdbcType=VARCHAR},
      </if>
      <if test="grpDesc != null" >
        #{grpDesc,jdbcType=VARCHAR},
      </if>
      <if test="grpIndex != null" >
        #{grpIndex,jdbcType=INTEGER},
      </if>
      <if test="recTime != null" >
        #{recTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recUser != null" >
        #{recUser,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="update" useGeneratedKeys="true" keyProperty="grpId" parameterType="cn.runsa.crmapp.common.entity.SiteGroup">
    update crm_site_group
    <set >
      <if test="actId != null" >
        `ACT_ID` = #{actId,jdbcType=BIGINT},
      </if>
      <if test="grpName != null" >
        `GRP_NAME` = #{grpName,jdbcType=VARCHAR},
      </if>
      <if test="grpDesc != null" >
        `GRP_DESC` = #{grpDesc,jdbcType=VARCHAR},
      </if>
      <if test="grpIndex != null" >
        `GRP_INDEX` = #{grpIndex,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}
  </update>
  <insert id="insertSiteGroupWxgzh" useGeneratedKeys="true" keyProperty="grpId" parameterType="cn.runsa.crmapp.common.entity.SiteGroup" >
    insert ignore into crm_site_group_wxgzh
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="grpId != null" >
        `GRP_ID`,
      </if>
      <if test="gzhId != null" >
        `GZH_ID`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="grpId != null" >
        #{grpId,jdbcType=BIGINT},
      </if>
      <if test="gzhId != null" >
        #{gzhId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <insert id="insertSiteGroupSite" useGeneratedKeys="true" keyProperty="grpId" parameterType="cn.runsa.crmapp.common.entity.SiteGroup" >
    insert into crm_site_group_site
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="grpId != null" >
        `GRP_ID`,
      </if>
      <if test="sitIt != null" >
        `SIT_ID`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="grpId != null" >
        #{grpId,jdbcType=BIGINT},
      </if>
      <if test="sitIt != null" >
        #{sitIt,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <delete id="delete" parameterType="java.lang.Long" >
    delete from crm_site_group
    where `ACT_ID` = #{actId,jdbcType=BIGINT}
  </delete>
  
  <delete id="deleteByGroupId" parameterType="java.lang.Long" >
    delete from crm_site_group
    where `GRP_ID` = #{grpId,jdbcType=BIGINT}
  </delete>
   <delete id="deleteWxgzhByGroupId" parameterType="java.lang.Long" >
    delete from crm_site_group_wxgzh
    where `GRP_ID` = #{grpId,jdbcType=BIGINT}
  </delete>
  
  <delete id="deleteSiteGroupWxgzh" parameterType="java.lang.Long" >
    delete from crm_site_group_wxgzh
    where `GRP_ID` IN (select GRP_ID from crm_site_group where ACT_ID = #{actId,jdbcType=BIGINT} )
  </delete>
  <delete id="deleteSiteGroupSite" parameterType="java.lang.Long" >
    delete from crm_site_group_site
    where `GRP_ID` IN (select GRP_ID from crm_site_group where ACT_ID = #{actId,jdbcType=BIGINT} )
  </delete>
</mapper>