UsPermissionMapper.xml 6.32 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.UsPermissionMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.UsPermission" >
    <id column="uspId" property="id" jdbcType="INTEGER" />
    <result column="usId" property="usid" jdbcType="INTEGER" />
    <result column="uspLimit" property="limit" jdbcType="BIT" />
    <result column="moId" property="moId" jdbcType="INTEGER" />
    <result column="moName" property="moName" jdbcType="VARCHAR" />
    <association property="channel" javaType="cn.runsa.portal.base.entity.Channel">
    	<id column="chId" property="id" />
    	<result column="chName" property="name"/>
    </association>
    <association property="organization" javaType="cn.runsa.portal.base.entity.Organization">
    	<id column="orId" property="id" />
    	<result column="orName" property="name"/>
    </association>
    <collection property="brandList" ofType="cn.runsa.portal.base.entity.Brand">
    	<id column="brId" property="id" />
    	<result column="brName" property="name"/>
    </collection>
    <collection property="roleList" ofType="cn.runsa.portal.base.entity.Role">
    	<id column="roId" property="id" />
    	<result column="roName" property="name"/>
    </collection>
  </resultMap>
  <sql id="Base_Column_List" >
    uspId, usId, chId, uspLimit, moId
  </sql>
  <select id="findById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    SELECT
		p.usId,
		p.uspId,
		p.uspLimit
		p.chId,
		ch.chName,
		p.moId,
		r.roName,
		b.brName
	FROM
		`smUsPermission` p
	LEFT JOIN mtChannel ch ON p.chId = ch.chId
	LEFT JOIN smUsPermRole pr ON p.uspId = pr.uspId
	LEFT JOIN smRole r ON pr.roId = r.roId
	LEFT JOIN smUsPermBrand pb ON p.uspId = pb.uspId
	LEFT JOIN mtBrand b ON pb.brId = b.brId
	WHERE
		p.uspId = #{id,jdbcType=INTEGER}
  </select>
  <select id="findList" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
	  SELECT
		p.usId,
		p.uspId,
		ch.chId,
		ch.chName,
		oz.orId,
		oz.orName,
		r.roId,
		r.roName,
		b.brId,
		b.brName
	FROM
		`smUsPermission` p
	INNER JOIN mtChannel ch ON p.chId = ch.chId
	INNER JOIN smUsPermRole pr ON p.uspId = pr.uspId
	INNER JOIN smRole r ON pr.roId = r.roId
	INNER JOIN smUsPermBrand pb ON p.uspId = pb.uspId
	INNER JOIN mtBrand b ON pb.brId = b.brId
	LEFT JOIN mtOrganization oz ON p.moId = oz.orId
	WHERE
		p.usId =  #{id,jdbcType=INTEGER}
  </select>
  <delete id="delete" parameterType="java.lang.Integer" >
    delete from smUsPermission
    where uspId = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="cn.runsa.portal.base.entity.UsPermission" >
    <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into smUsPermission (usId, chId, uspLimit, 
      moId)
    values (#{usid,jdbcType=INTEGER}, #{chid,jdbcType=INTEGER}, #{limit,jdbcType=BIT}, 
      #{moid,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.portal.base.entity.UsPermission" >
    <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into smUsPermission
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="usid != null" >
        usId,
      </if>
      <if test="channel.id != null" >
        chId,
      </if>
      <if test="limit != null" >
        uspLimit,
      </if>
      <if test="moId != null" >
        moId,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="usid != null" >
        #{usid,jdbcType=INTEGER},
      </if>
      <if test="channel.id != null" >
        #{channel.id,jdbcType=INTEGER},
      </if>
      <if test="limit != null" >
        #{limit,jdbcType=BIT},
      </if>
      <if test="moId != null" >
        #{moId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateSelective" parameterType="cn.runsa.portal.base.entity.UsPermission" >
    update smUsPermission
    <set >
      <if test="usid != null" >
        usId = #{usid,jdbcType=INTEGER},
      </if>
      <if test="chid != null" >
        chId = #{chid,jdbcType=INTEGER},
      </if>
      <if test="limit != null" >
        uspLimit = #{limit,jdbcType=BIT},
      </if>
      <if test="moid != null" >
        moId = #{moid,jdbcType=INTEGER},
      </if>
    </set>
    where uspId = #{id,jdbcType=INTEGER}
  </update>
  <update id="update" parameterType="cn.runsa.portal.base.entity.UsPermission" >
    update smUsPermission
    set usId = #{usid,jdbcType=INTEGER},
      chId = #{chid,jdbcType=INTEGER},
      uspLimit = #{limit,jdbcType=BIT},
      moId = #{moid,jdbcType=INTEGER}
    where uspId = #{id,jdbcType=INTEGER}
  </update>
  <insert  id="insertPermBrand" parameterType="cn.runsa.portal.base.entity.UsPermission" >
      insert into smUsPermBrand (uspId,brId) values
      <foreach collection="brandList" item="item" index="index" separator="," >  
	     (
	      #{id,jdbcType=INTEGER},
	      #{item.id,jdbcType=INTEGER}
	      )  
	  </foreach> 
  </insert>
   <insert  id="insertUsPermRole" parameterType="cn.runsa.portal.base.entity.UsPermission" >
      insert into smUsPermRole (uspId,roId) values
      <foreach collection="roleList" item="item" index="index" separator="," >  
	     (
	      #{id,jdbcType=INTEGER},
	      #{item.id,jdbcType=INTEGER}
	      )  
	  </foreach> 
  </insert>
   <delete id="deletePermBrand" parameterType="java.lang.Integer" >
    delete from smUsPermBrand
    where uspId = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteUsPermRole" parameterType="java.lang.Integer" >
    delete from smUsPermRole
    where uspId = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByUsid" parameterType="java.lang.Integer" >
    delete from smUsPermission
    where usId = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deletePermRoleByUsid" parameterType="java.lang.Integer" >
    DELETE
	FROM
		smUsPermRole 
	WHERE
	uspId IN (
		SELECT
			uspid
		FROM
			smUsPermission
		where
			usId = #{id,jdbcType=INTEGER}
	)
  </delete>
  <delete id="deletePermBrandByUsid" parameterType="java.lang.Integer" >
    DELETE
	FROM
		smUsPermBrand 
	WHERE
	uspId IN (
		SELECT
			uspid
		FROM
			smUsPermission
		where
			usId = #{id,jdbcType=INTEGER}
	)
  </delete>
</mapper>