RoleMapper.xml 5.74 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.RoleMapper" >
<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Role" >
    <id column="roId" property="id" />
    <result column="roName" property="name" />
    <result column="roCode" property="code" />
    <result column="roDesc" property="desc" />
    <result column="ptValid" property="valid" />
    <result column="roType" property="type" />
    <result column="ptUpTime" property="uptime" />
    <result column="ptUpdater" property="updater" />
    <association property="platform" javaType="cn.runsa.portal.base.entity.Platform">
    	<id column="plId" property="id" />
    	<result column="plName" property="name"/>
    </association>
    <association property="platType" javaType="cn.runsa.portal.base.entity.PlatformType">
    	<id column="pltId" property="id" />
    	<result column="pltName" property="name"/>
    </association>
  </resultMap>
 <select id="selectPageList" parameterType="cn.runsa.portal.base.entity.Role" resultType="cn.runsa.portal.base.entity.Role">
		select t1.* from smRole t1 where 1=1 
		<if test="id!=null">
			and t1.id=#{id}
		</if>
		<if test="pltId!=null">
			and t1.pltId=#{pltId}
		</if>
		<if test="plId!=null">
			and t1.plId=#{plId}
		</if>
		<if test="code!=null and code!='' ">
			and t1.roCode=#{code}
		</if>
		<if test="name!=null and name!=''">
			and t1.roName=#{name}
		</if>
		<if test="desc!=null and desc!=''">
			and t1.roDesc=#{desc}
		</if>
		<if test="valid!=null ">
			and t1.roValid=#{valid}
		</if>
		<if test="type!=null ">
			and t1.roType=#{type}
		</if>
		<if test="startDate!=null and startDate!=''">
		    and ptUptime &gt;= #{startDate}
		 </if>
		 <if test="endDate!=null and endDate!=''">
			and ptUptime &lt;= #{endDate}
		 </if>
		<if test="updater!=null and updater!=''">
			and t1.ptUpdater=#{updater}
		</if>
		limit #{offset},#{pageSize}
 </select>
 <select id="selectCount" parameterType="cn.runsa.portal.base.entity.Role" resultType="java.lang.Integer">
		select count(*) from smRole t1 where 1=1 
		<if test="id!=null">
			and t1.id=#{id}
		</if>
		<if test="pltId!=null">
			and t1.pltId=#{pltId}
		</if>
		<if test="plId!=null">
			and t1.plId=#{plId}
		</if>
		<if test="code!=null and code!='' ">
			and t1.roCode=#{code}
		</if>
		<if test="name!=null and name!=''">
			and t1.roName=#{name}
		</if>
		<if test="desc!=null and desc!=''">
			and t1.roDesc=#{desc}
		</if>
		<if test="valid!=null ">
			and t1.roValid=#{valid}
		</if>
		<if test="type!=null ">
			and t1.roType=#{type}
		</if>
		<if test="startDate!=null and startDate!=''">
		    and ptUptime &gt;= #{startDate}
		 </if>
		 <if test="endDate!=null and endDate!=''">
			and ptUptime &lt;= #{endDate}
		 </if>
		<if test="updater!=null and updater!=''">
			and t1.ptUpdater=#{updater}
		</if>
 </select>
 <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select t1.roId,t1.plId,t2.plName,t1.pltId,t3.pltName,t1.roName,t1.roCode,t1.roDesc,t1.ptValid,t1.roType,t1.ptUpdater,t1.ptUptime 
    from smRole t1
    left join smPlatform t2 on t1.plId=t2.plId
    left join smPlatformType t3 on t1.pltId=t3.pltId
    where t1.roId=#{id} 
 </select>
 <select id="existsCode" resultType="Boolean">
 	select count(*)
 	from smRole
 	where roCode=#{code}
 	<if test="id != null">
 		and roId<![CDATA[<>]]>#{id}
 	</if>
 </select>
 <select id="existsName" resultType="Boolean">
 	select count(*)
 	from smRole
 	where roName=#{name}
 	<if test="id != null">
 		and roId<![CDATA[<>]]>#{id}
 	</if>
 </select>
 <insert id="insert" parameterType="cn.runsa.portal.base.entity.Role">
 	<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into smRole(
    roId,ptUpTime,ptUpdater
	<if test="platType !=null and platType.id !=null ">
		,pltId
	</if>
	<if test="platform !=null and platform.id !=null ">
		,plId
	</if>
	<if test="code!=null and code!='' ">
	    ,roCode
	</if>
	<if test="name!=null and name!=''">
		,roName
	</if>
	<if test="desc!=null and desc!=''">
		,roDesc
	</if>
	<if test="valid!=null ">
		,ptValid
	</if>
	<if test="type!=null ">
		,roType
	</if>
	)
	values(
	#{id},now(),#{updater}
	<if test="platType !=null and platType.id !=null ">
		,#{platType.id}
	</if>
	<if test="platform !=null and platform.id !=null ">
		,#{platform.id}
	</if>
	<if test="code!=null and code!='' ">
	    ,#{code}
	</if>
	<if test="name!=null and name!=''">
		,#{name}
	</if>
	<if test="desc!=null and desc!=''">
		,#{desc}
	</if>
	<if test="valid!=null ">
		,#{valid}
	</if>
	<if test="type!=null ">
		,#{type}
	</if>
	)
 </insert>
 <update id="update"  parameterType="cn.runsa.portal.base.entity.Role" >
   update smRole set ptUpTime=now(),ptUpdater=#{updater}
   <if test="platType !=null and platType.id !=null ">
		,pltId=#{platType.id}
	</if>
	<if test="platform !=null and platform.id !=null ">
		,plId=#{platform.id}
	</if>
	<if test="code!=null and code!='' ">
	    ,roCode=#{code}
	</if>
	<if test="name!=null and name!=''">
		,roName=#{name}
	</if>
	<if test="desc!=null and desc!=''">
		,roDesc=#{desc}
	</if>
	<if test="valid!=null ">
		,ptValid=#{valid}
	</if>
	<if test="type!=null ">
		,roType=#{type}
	</if>
   where roId=#{id}
 </update>
 <delete id="delete"  parameterType="Integer" >
   delete from smRole where roId=#{id}
 </delete>
 <insert id="insertMenuAction" parameterType="cn.runsa.portal.base.entity.Role">
 	insert into smRoleMenuAction(roId,meaId) values
    <foreach collection="actions" item="item" separator=",">
     (#{id},#{item.id})
    </foreach>
 </insert>
 <delete id="deleteMenuAction" parameterType="Integer">
 	delete from smRoleMenuAction where roId=#{id}
 </delete>
</mapper>