RoleMapper.xml 7.27 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.com.glsx.dj.system.mapper.RoleMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.system.model.Role" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="created_user_id" property="createdUserId"/>
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="description" property="description" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="TINYINT" />
    <result column="is_super" property="isSuper" jdbcType="BIT"/>
    <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
    <result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
    <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
    <result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
    <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
  </resultMap>
  <resultMap id="DTOResultMap" type="cn.com.glsx.dj.system.dto.RoleDTO" extends="BaseResultMap">
  	<result column="merchant_id" property="merchantId"/>
  	<result column="merchant_name" property="merchantName"/>
  </resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, created_user_id,name, description, status,is_super, created_by, created_date, updated_by, updated_date, 
    deleted_flag
  </sql>
  <select id="listBase" parameterType="cn.com.glsx.dj.system.model.Role" resultMap="BaseResultMap">
  	select <include refid="Base_Column_List"/> from dj_system_role
  	<where>
  		deleted_flag = 'N'
  		<if test="createdUserId != null">
  			and created_user_id = #{createdUserId}
  		</if>
  		<if test="id != null">
  			and id = #{id}
  		</if>
  	</where>
  	order by updated_date desc,id desc
  </select>
  
  <select id="list" parameterType="cn.com.glsx.dj.system.dto.RoleDTO" resultMap="DTOResultMap">
  	select 
  		a.id, a.created_user_id,a.name, a.description, a.status,a.is_super, a.created_date, a.updated_date, 
    	c.merchant_id,c.merchant_name
  	 from dj_system_role a
  	left join dj_system_user b on b.id=a.created_user_id and b.deleted_flag='N'
  	left join dj_system_merchant c on c.merchant_id=b.merchant_id and c.deleted_flag='N'
  	<where>
  		a.deleted_flag = 'N'
  		<if test="id != null">
  			and a.id = #{id}
  		</if>
  		<if test="createdUserId != null">
  			and a.created_user_id = #{createdUserId}
  		</if>
  		<if test="status != null">
  			and a.status = #{status}
  		</if>
  		<if test="name != null and name !=''">
  			and a.name like CONCAT('%',#{name},'%')
  		</if>
  		<if test="merchantName != null and merchantName !=''">
  			and c.merchant_name like CONCAT('%',#{merchantName},'%')
  		</if>
  		<if test="merchantId != null">
  			and c.merchant_id = #{merchantId}
  		</if>
  		<if test="startTime != null">
  			 <![CDATA[
        	and a.created_date >= #{startTime}
        	]]>
  		</if>
  		<if test="endTime != null">
  			 <![CDATA[
        	and a.created_date <= #{endTime}
        	]]>
  		</if>
  		<if test="isSuper != null">
  			and a.is_super = #{isSuper}
  		</if>
  		<if test="ids != null">
  			and a.id in 
  			<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
                #{item}       
        	</foreach>  
  		</if>
  		<if test="userId != null">
  			and a.id in (
  				select ur.role_id from dj_system_user_role ur where ur.deleted_flag='N' and ur.user_id=#{userId}
  			)
  		</if>
  	</where>
  	order by a.updated_date desc,a.id desc
  </select>
  
  <update id="updateAllChildRoleMenu" parameterType="cn.com.glsx.dj.system.dto.RoleDTO">
  	update dj_system_role_menu a set a.deleted_flag='D',updated_by=#{updatedBy},updated_date=#{updatedDate} 
  	<where>
  		and a.deleted_flag ='N'
  		and menu_code in 
  		<foreach collection="deleteMenuCodes" index="index" item="item" open="(" separator="," close=")">
        	#{item}       
        </foreach>  
        and role_id in (
					select b.id 
				from dj_system_role b 
				join dj_system_user c on c.id=b.created_user_id and c.deleted_flag='N'
				where b.deleted_flag='N'
				and ( 1=2 
				<!-- 商户及商户员工 -->
				<if test="merchantIds != null and merchantIds.size() > 0">
					or c.merchant_id in 
  					<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
        				#{item}       
        			</foreach>  
				</if>
				<!--  用户 -->
				<if test="userIds != null and userIds.size() > 0 ">
					or b.created_user_id in 
  					<foreach collection="userIds" index="index" item="item" open="(" separator="," close=")">
        				#{item}       
        			</foreach>  
				</if>
				
        		)
		)
  	</where>
  </update>
  <!-- 删除角色下功能点 -->
  <update id="updateAllChildRoleFunction" parameterType="cn.com.glsx.dj.system.dto.RoleDTO">
  	update dj_system_role_function a set a.deleted_flag='D',updated_by=#{updatedBy},updated_date=#{updatedDate} 
  	<where>
  		and a.deleted_flag ='N'
  		and function_id in 
  		<foreach collection="deleteFunctionIds" index="index" item="item" open="(" separator="," close=")">
        	#{item}       
        </foreach>  
        and role_id in (
					select b.id 
				from dj_system_role b 
				join dj_system_user c on c.id=b.created_user_id and c.deleted_flag='N'
				where b.deleted_flag='N'
				and ( 1=2 
				<!-- 商户及商户员工 -->
				<if test="merchantIds != null and merchantIds.size() > 0">
					or c.merchant_id in 
  					<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
        				#{item}       
        			</foreach>  
				</if>
				<!--  用户 -->
				<if test="userIds != null and userIds.size() > 0 ">
					or b.created_user_id in 
  					<foreach collection="userIds" index="index" item="item" open="(" separator="," close=")">
        				#{item}       
        			</foreach>  
				</if>
				
        		)
		)
  	</where>
  </update>
  <!-- 删除角色下功能值 -->
  <update id="updateAllChildRoleFunctionValue" parameterType="cn.com.glsx.dj.system.dto.RoleDTO">
  	update dj_system_role_function_value a set a.deleted_flag='D',updated_by=#{updatedBy},updated_date=#{updatedDate} 
  	<where>
  		and a.deleted_flag ='N'
  		and function_value_id in 
  		<foreach collection="deleteFunctionValueIds" index="index" item="item" open="(" separator="," close=")">
        	#{item}       
        </foreach>  
        and role_id in (
					select b.id 
				from dj_system_role b 
				join dj_system_user c on c.id=b.created_user_id and c.deleted_flag='N'
				where b.deleted_flag='N'
				and ( 1=2 
				<!-- 商户及商户员工 -->
				<if test="merchantIds != null and merchantIds.size() > 0">
					or c.merchant_id in 
  					<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
        				#{item}       
        			</foreach>  
				</if>
				<!--  用户 -->
				<if test="userIds != null and userIds.size() > 0 ">
					or b.created_user_id in 
  					<foreach collection="userIds" index="index" item="item" open="(" separator="," close=")">
        				#{item}       
        			</foreach>  
				</if>
				
        		)
		)
  	</where>
  </update>
</mapper>