ChannelMapper.xml 8.48 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.portal.base.dao.ChannelMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Channel" >
    <id column="chId" property="id" jdbcType="INTEGER" />
    <result column="chCode" property="code" jdbcType="VARCHAR" />
    <result column="chName" property="name" jdbcType="VARCHAR" />
    <result column="chDesc" property="desc" jdbcType="VARCHAR" />
    <result column="ptValid" property="valid" jdbcType="SMALLINT" />
    <result column="ptRemark1" property="remark1" jdbcType="VARCHAR" />
    <result column="ptRemark2" property="remark2" jdbcType="VARCHAR" />
    <result column="ptUpTime" property="uptime" jdbcType="TIMESTAMP" />
    <result column="ptUpdater" property="updater" jdbcType="INTEGER" />
    <result column="chLimit" property="limit" jdbcType="BIT"/>
	<result column="brName" property="brName" jdbcType="VARCHAR" />
	
	<result column="brIds" property="brIds" jdbcType="VARCHAR" />
	<collection property="list"  ofType="cn.runsa.portal.base.entity.Brand">
    	<id column="brId" property="id"/>
	</collection>
	</resultMap>
  <sql id="Base_Column_List" >
    chId, chCode, chName, chDesc, ptValid, ptRemark1, ptRemark2, ptUpTime, ptUpdater,chLimit
  </sql>
   <select id="findListByBeId" resultMap="BaseResultMap"> 
  	SELECT
  	  <include refid="Base_Column_List" />
	FROM
		mtChannel t1
	WHERE
		t1.chId NOT IN (
			SELECT
				t3.chId
			FROM
				mtBizChannel t3
			LEFT JOIN mtBizEntity t4 ON t3.beId = t4.beId
			WHERE
				t4.beOrgType = 6
			AND t4.ptValid = 1
		)
	AND t1.ptValid = 1;
  </select>
  <select id="findList" resultMap="BaseResultMap"> 
  	SELECT
	t2.chId, t2.chCode, t2.chName, t2.chDesc, t2.ptValid, t2.ptRemark1, t2.ptRemark2, t2.ptUpTime, t2.ptUpdater, t2.chLimit
	FROM
		mtBizChannel t1
	LEFT JOIN mtchannel t2 ON t2.chId = t1.chId
	WHERE
	t1.beId = #{id,jdbcType=INTEGER} and t1.ptValid=1
  </select>
  <select id="findChannelDetiles" parameterType="java.lang.Integer" resultMap="BaseResultMap" >
		SELECT
			t1.chId,
			t1.chName,
			t1.chDesc,
			t1.ptValid,
			GROUP_CONCAT(DISTINCT t3.brName) brName,
			GROUP_CONCAT(DISTINCT t3.brId) brIds
		FROM
			mtChannel t1
		LEFT JOIN mtChannelBrand t2 ON t2.chId = t1.chId
		LEFT JOIN mtBrand t3 ON (t3.brId=t2.brId AND t3.ptValid=1 AND t1.chLimit=1) OR (1 = 1 AND t1.chLimit=0 AND t3.ptValid=1)
		WHERE
			t1.chId=#{chid,jdbcType=INTEGER}
  </select>
  <select id="findById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from mtChannel
    where chId = #{id,jdbcType=INTEGER}
  </select>
  <select id="existsChannel" parameterType="java.lang.Integer" resultType="java.lang.Integer">
  	 select 
  	 	COUNT(*)
  	 from smUsPermission
  	  where chId=#{chId}
  </select>
 <select id="existsName" resultType="java.lang.Integer">
   select 
 		COUNT(*)
   from mtChannel
   		where chName = #{name,jdbcType=VARCHAR}
   		<if test="chId != null">
     	 AND chId != #{chId,jdbcType=INTEGER}
      	</if>
 </select>
  <delete id="delete" parameterType="java.lang.Integer" >
    delete from mtChannel where chId = #{id}
  </delete>
  <delete id="delChannelBrand" parameterType="java.lang.Integer" >
  	delete from mtChannelBrand where chId = #{id}
  </delete>
  <insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.runsa.portal.base.entity.Channel" >
    insert into mtChannel (chCode, chName, chDesc, 
      ptValid, ptRemark1, ptRemark2, 
      ptUpTime, ptUpdater,chLimit)
    values (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, 
      #{valid,jdbcType=SMALLINT}, #{remark1,jdbcType=VARCHAR}, #{remark2,jdbcType=VARCHAR}, 
      #{uptime,jdbcType=TIMESTAMP}, #{updater,jdbcType=INTEGER},#{limit,jdbcType=BIT})
  </insert>
  <insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="cn.runsa.portal.base.entity.Channel" >
    insert into mtChannel
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="code != null" >
        chCode,
      </if>
      <if test="name != null" >
        chName,
      </if>
      <if test="desc != null" >
        chDesc,
      </if>
      <if test="valid != null" >
        ptValid,
      </if>
      <if test="remark1 != null" >
        ptRemark1,
      </if>
      <if test="remark2 != null" >
        ptRemark2,
      </if>
      <if test="uptime != null" >
        ptUpTime,
      </if>
      <if test="updater != null" >
        ptUpdater,
      </if >
      <if test="limit != null">
     	 chLimit
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="code != null" >
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="desc != null" >
        #{desc,jdbcType=VARCHAR},
      </if>
      <if test="valid != null" >
        #{valid,jdbcType=SMALLINT},
      </if>
      <if test="remark1 != null" >
        #{remark1,jdbcType=VARCHAR},
      </if>
      <if test="remark2 != null" >
        #{remark2,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null" >
        #{uptime,jdbcType=TIMESTAMP},
      </if>
      <if test="updater != null" >
        #{updater,jdbcType=INTEGER},
      </if>
      <if test="limit != null">
      #{limit,jdbcType=BIT}
      </if>
    </trim>
  </insert>
  <insert id="insertBrank" parameterType="cn.runsa.portal.base.entity.Channel">
  	insert into mtChannelBrand
  	(chId,brId)
  	values
  	<foreach collection="list" item="item" index="index" separator=",">
  		(#{id,jdbcType=BIGINT},#{item.id,jdbcType=INTEGER})
  	</foreach>
  </insert>
  <update id="updateSelective" parameterType="cn.runsa.portal.base.entity.Channel">
    update mtChannel
    <set >
      <if test="code != null" >
        chCode = #{code,jdbcType=VARCHAR},
      </if>
      <if test="name != null" >
        chName = #{name,jdbcType=VARCHAR},
      </if>
      <if test="desc != null" >
        chDesc = #{desc,jdbcType=VARCHAR},
      </if>
      <if test="valid != null" >
        ptValid = #{valid,jdbcType=SMALLINT},
      </if>
      <if test="remark1 != null" >
        ptRemark1 = #{remark1,jdbcType=VARCHAR},
      </if>
      <if test="remark2 != null" >
        ptRemark2 = #{remark2,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null" >
        ptUpTime = #{uptime,jdbcType=TIMESTAMP},
      </if>
      <if test="updater != null" >
        ptUpdater = #{updater,jdbcType=INTEGER},
      </if>
      <if test="limit != null">
     	 chLimit = #{limit,jdbcType=BIT}
      </if>
    </set>
    where chId = #{id,jdbcType=INTEGER}
  </update>
  <update id="update" parameterType="cn.runsa.portal.base.entity.Channel" >
    update mtChannel
    set chCode = #{code,jdbcType=VARCHAR},
      chName = #{name,jdbcType=VARCHAR},
      chDesc = #{desc,jdbcType=VARCHAR},
      ptValid = #{valid,jdbcType=SMALLINT},
      ptRemark1 = #{remark1,jdbcType=VARCHAR},
      ptRemark2 = #{remark2,jdbcType=VARCHAR},
      ptUpTime = #{uptime,jdbcType=TIMESTAMP},
      ptUpdater = #{updater,jdbcType=INTEGER},
      chLimit = #{limit,jdbcType=BIT}
    where chId = #{id,jdbcType=INTEGER}
  </update>
  <select id="findChannel" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.Channel" >
    SELECT
		ch.chId,
		ch.chName
	FROM
	smUsers us
	INNER JOIN smPlatform pl ON us.plId= pl.plId and pl.plId = #{plId,jdbcType=INTEGER} 
	INNER JOIN mtBizChannel bc ON pl.beId = bc.beId
	INNER JOIN mtChannel ch ON bc.chId = ch.chId AND ch.ptValid = '1'
	WHERE us.usId = #{usId,jdbcType=INTEGER} 
		AND  NOT EXISTS (
			SELECT
				usp.chId
			FROM
				smUsPermission usp
			WHERE
				usp.chId = ch.chId
				AND usp.usId = #{usId,jdbcType=INTEGER} 
		)
	 GROUP BY 
	ch.chId,
	ch.chName
  </select>
  <select id="findChannelByOrId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  	select t1.chId,t1.chName from mtChannel t1 
  	inner join mtorgchannel t2 
  	on t1.chId = t2.chId and t2.orId = #{orId,jdbcType=INTEGER};
  </select>
  <select id="findChannelByOrIdAndUsId" resultMap="BaseResultMap">
  	select t1.chId,t1.chName from mtChannel t1 
  	inner join mtorgchannel t2 
  	on t1.chId = t2.chId and t2.orId = #{0}
  	where t1.chId in (select t3.chId from smUsPermission t3 where t3.usId = #{1});
  </select>
  <select id="existsMtBizChannel" parameterType="java.lang.Integer" resultType="java.lang.Integer">
  	 select 
  	 	COUNT(*)
  	 from mtBizChannel
  	  where chId=#{chId}
  </select>
</mapper>