FunctionMapper.xml 7.07 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.FunctionMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.system.model.Function" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="menu_code" property="menuCode" jdbcType="INTEGER" />
    <result column="function_name" property="functionName" jdbcType="VARCHAR" />
    <result column="function_attr_name" property="functionAttrName" jdbcType="VARCHAR" />
    <result column="function_attr_type" property="functionAttrType" jdbcType="INTEGER" />
    <result column="function_remark" property="functionRemark" jdbcType="VARCHAR" />
    <result column="order_no" property="orderNo" jdbcType="INTEGER" />
    <result column="user_limit_type" property="userLimitType"/>
    <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 type="cn.com.glsx.dj.system.dto.FunctionDTO" id="BaseResultDTOMap" extends="BaseResultMap">
  	<result column="menu_name" property="menuName" jdbcType="VARCHAR"/>
  	<result column="menu_url" property="menuUrl" jdbcType="VARCHAR"/>
  	<collection property="valueList" ofType="cn.com.glsx.dj.system.dto.FunctionValueDTO">
  		<id column="v_id" property="id" jdbcType="INTEGER" />
    	<result column="v_function_id" property="functionId" jdbcType="INTEGER" />
    	<result column="v_val_text" property="valText" jdbcType="VARCHAR" />
    	<result column="v_val_code" property="valCode" jdbcType="VARCHAR" />
  	</collection>
  </resultMap>
  
  <resultMap type="cn.com.glsx.dj.system.dto.FunctionDTO" id="DetailResultMap" extends="BaseResultMap">
  	<result column="menu_name" property="menuName" jdbcType="VARCHAR"/>
  	<collection property="valueList" ofType="cn.com.glsx.dj.system.dto.FunctionValueDTO">
  		<id column="v_id" property="id" jdbcType="INTEGER" />
    	<result column="v_function_id" property="functionId" jdbcType="INTEGER" />
    	<result column="v_val_text" property="valText" jdbcType="VARCHAR" />
    	<result column="v_val_code" property="valCode" jdbcType="VARCHAR" />
  	</collection>
  	<collection property="dataIds" ofType="java.lang.Integer" >
  		<result column="data_id"/>
  	</collection>
  </resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, menu_code, function_name, function_attr_name, function_attr_type, function_remark, 
    order_no,user_limit_type, created_by, created_date, updated_by, updated_date, deleted_flag
  </sql>
  
  <select id="listWithPage" parameterType="cn.com.glsx.dj.system.dto.FunctionDTO" resultMap="BaseResultDTOMap">
  	SELECT a.*,b.name as  menu_name,b.url as menu_url FROM
	dj_system_function a LEFT JOIN dj_system_menu b
	ON a.menu_code = b.`code` and b.deleted_flag='N'
	<where>
		a.deleted_flag = 'N'
		<if test="id != null">
			and a.id = #{id}
		</if>
		<if test="menuName != null and menuName != ''">
			and b.name LIKE CONCAT('%',#{menuName},'%')
		</if>
		<if test="menuCode != null">
			and a.menu_code  LIKE CONCAT('%',#{menuCode},'%')
		</if>
		<if test="functionName != null and functionName != ''">
			and a.function_name LIKE CONCAT('%',#{functionName},'%')
		</if>
		<if test="functionAttrType != null">
		 	and a.function_attr_type = #{functionAttrType}
		</if>
		<if test="userLimitType != null">
			and a.user_limit_type = #{userLimitType}
		</if>
	</where> 
	order by a.order_no desc
  </select>
  
  <select id="list" parameterType="cn.com.glsx.dj.system.dto.FunctionDTO" resultMap="DetailResultMap">
  	select 
  		a.id, a.menu_code, a.function_name, a.function_attr_name, a.function_attr_type, a.function_remark,
  		a.user_limit_type,a.order_no,
  		b.id v_id, b.function_id v_function_id, b.val_text v_val_text, b.val_code v_val_code,
  		e.data_id
    from dj_system_function a
    left join dj_system_function_value b on b.function_id=a.id and b.deleted_flag='N'
	left join dj_system_role_function_value d on d.function_value_id=b.id and d.deleted_flag='N'
	left join dj_system_function_user_limit e on e.function_id=a.id and e.deleted_flag='N'
    <where>
    	a.deleted_flag='N'
    	<if test="menuCode != null">
    		and a.menu_code = #{menuCode}
    	</if>
    	<if test="userLimitTypeArr != null and userLimitTypeArr.length > 0">
			and a.user_limit_type in 
			<foreach collection="userLimitTypeArr" index="index" item="item" open="(" separator="," close=")">
                #{item}       
        	</foreach>
		</if>
    	<if test="roleId != null">
    		and (
    			user_limit_type !=0 or
    			(	user_limit_type = 0
    				and exists (
    					select 1 from dj_system_role_function rf where rf.function_id=a.id and rf.deleted_flag='N'
    					and rf.role_id =#{roleId} limit 1
    				)
    		
					and (
						a.function_attr_type in (1,3,5) 
						or (a.function_attr_type in (2,4) and d.role_id = #{roleId} )
					)
				)
			)
    	</if>
    </where>
    order by a.order_no desc,b.order_no desc
  </select>
  
  <select id="listRoleFunction" parameterType="cn.com.glsx.dj.system.dto.FunctionDTO" resultMap="BaseResultDTOMap">
  	select 
  		a.id, a.menu_code, a.function_name, a.function_attr_name, a.function_attr_type, a.function_remark,
  		a.user_limit_type,a.order_no,
  		b.id v_id, b.function_id v_function_id, b.val_text v_val_text, b.val_code v_val_code
    from dj_system_function a
    left join dj_system_function_value b on b.function_id=a.id and b.deleted_flag='N'
	left join dj_system_function_user_limit e on e.function_id=a.id and e.deleted_flag='N'
    <where>
    	a.deleted_flag='N'
    	and a.menu_code = #{menuCode}
    	and (
    			(a.user_limit_type=1 
    			<if test="userType != null">
    				and e.data_id=#{userType}
    			</if>
    			) or
    			(a.user_limit_type=2 and e.data_id=#{userId}) or
    			(a.user_limit_type=3  
    			<if test="merchantUserType != null">
    				and e.data_id=#{merchantUserType}
    			</if>
    			) or
    			(
    				a.user_limit_type=0 
    					<if test="functionIds != null and functionIds.size > 0">
    						and a.id in 
    						<foreach collection="functionIds" index="index" item="item" open="(" separator="," close=")">
                				#{item}       
        					</foreach>
    					</if>
    					
        			and (a.function_attr_type in (1,3,5) or (
        					a.function_attr_type in (2,4) 
        						<if test="functionValueIds != null and functionValueIds.size > 0 ">
        							and b.id in 
        							<foreach collection="functionValueIds" index="index" item="item" open="(" separator="," close=")">
                						#{item}       
        							</foreach>
        						</if>
        					)
        				)
    			)
			)
    </where>
    order by a.order_no desc,b.order_no desc
  </select>
  
</mapper>