SysResSmapper.xml 6.53 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="com.zteits.sys.mapper.smapper.SysResSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.sys.domain.SysRes">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="res_code" property="resCode" jdbcType="VARCHAR"/>
        <result column="res_name" property="resName" jdbcType="VARCHAR"/>
        <result column="res_type" property="resType" jdbcType="INTEGER"/>
        <result column="res_url" property="resUrl" jdbcType="VARCHAR"/>
        <result column="parent_res_id" property="parentResId" jdbcType="BIGINT"/>
        <result column="res_icon" property="resIcon" jdbcType="VARCHAR"/>
        <result column="res_desc" property="resDesc" jdbcType="VARCHAR"/>
        <result column="sort_num" property="sortNum" jdbcType="INTEGER"/>
        <result column="if_display" property="ifDisplay" jdbcType="INTEGER"/>
        <result column="sys_code" property="sysCode" jdbcType="VARCHAR"/>
        <result column="data_state" property="dataState" jdbcType="INTEGER"/>
        <result column="create_empid" property="createEmpid" jdbcType="VARCHAR"/>
        <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
        <result column="modfiy_empid" property="modfiyEmpid" jdbcType="VARCHAR"/>
        <result column="modfiy_date" property="modfiyDate" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
	    id, res_code, res_name, res_type, res_url, parent_res_id, res_icon, res_desc, sort_num, 
	    if_display, sys_code, data_state, create_empid, create_date, modfiy_empid, modfiy_date
	  </sql>

    <!-- 批量更新 -->
    <update id="updateBatchSysRes">
        update sys_res
        <set>
            <if test="sysRes.dataState != null">
                data_state = #{sysRes.dataState,jdbcType=INTEGER},
            </if>

            <if test="sysRes.modfiyEmpid != null">
                modfiy_empid = #{sysRes.modfiyEmpid,jdbcType=VARCHAR},
            </if>
            modfiy_date =
            <choose>
                <when test="sysRes.modfiyDate != null">
                    #{sysRes.modfiyDate,jdbcType=TIMESTAMP},
                </when>
                <otherwise>
                    NOW()
                </otherwise>
            </choose>

        </set>
        <where>
            <choose>
                <when test="ids==null || ids.size==0">
                    1==2
                </when>
                <otherwise>
                    id IN
                    <foreach collection="ids" item="id" open="(" close=")" separator=",">
                        #{id,jdbcType=BIGINT}
                    </foreach>
                </otherwise>
            </choose>
            AND sys_code = #{sysCode,jdbcType=VARCHAR}
        </where>
    </update>

    <!-- 查询菜单列表 -->
    <select id="querySysResBySysCode" resultMap="BaseResultMap">

        select
        <include refid="Base_Column_List"/>
        from sys_res
        <where>
            sys_code = #{sysCode,jdbcType=VARCHAR}
        </where>


    </select>

    <select id="queryPageSysResForList" resultMap="BaseResultMap" parameterType="com.zteits.sys.domain.SysRes">

        select
        <include refid="Base_Column_List"/>
        from sys_res
        <where>
            sys_code = #{sysCode,jdbcType=VARCHAR}
            <if test="sysRes.resName != null">
                and res_name = #{sysRes.resName,jdbcType=VARCHAR}
            </if>
            <if test="sysRes.id != null">
                and id = #{sysRes.id,jdbcType=BIGINT}
            </if>
            <if test="sysRes.resType != null">
                and res_type = #{sysRes.resType,jdbcType=INTEGER}
            </if>
            <if test="sysRes.parentResId != null">
                and parent_res_id = #{sysRes.parentResId,jdbcType=BIGINT}
            </if>
            <if test="sysRes.ifDisplay != null">
                and if_display = #{sysRes.ifDisplay,jdbcType=INTEGER}
            </if>
            <if test="sysRes.dataState != null">
                and data_state = #{sysRes.dataState,jdbcType=INTEGER}
            </if>
        </where>
        order by sort_num asc,id desc

    </select>

    <select id="queryResIdsByOpId" parameterType="java.lang.Long" resultType="java.lang.Long">
        select DISTINCT t3.res_id from sys_op_role t1, sys_role_jobfunc t2, sys_res_jobfunc t3

          where t1.sys_role_id = t2.sys_role_id AND t2.sys_jobfunc_id = t3.jobfunc_id AND t1.sys_op_id = #{opId}

    </select>

    <select id="queryAllRes" resultMap="BaseResultMap" >
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_res
        <where>
            1=1
            <if test="dataStatus != null">
                AND data_state = #{dataStatus}
            </if>
            <if test="sysCode !=null ">
                 and sys_code = #{sysCode,jdbcType=VARCHAR}
            </if>
            <choose>
                <when test="resIds != null and resIds.size > 0">
                    AND id IN
                    <foreach collection="resIds" item="resId" separator="," open="(" close=")" index="index">
                        #{resId}
                    </foreach>
                </when>
            </choose>
        </where>
        order by sort_num asc
    </select>


    <update id="updateSysResSortNumOfSaveOrUpdate">
        update sys_res
        SET sort_num = sort_num
        <if test="sortNum &gt; oldSortNum">
            -1
        </if>
        <if test="sortNum &lt; oldSortNum">
            +1
        </if>
        <where>
            <if test="sortNum &gt; oldSortNum">
                sort_num &lt;= #{sortNum} AND sort_num &gt; #{oldSortNum}
            </if>
            <if test="sortNum &lt; oldSortNum">
                sort_num &gt;= #{sortNum} AND sort_num &lt; #{oldSortNum}
            </if>
            AND id != #{id,jdbcType=BIGINT}
            AND parent_res_id = #{parentResId}
        </where>
    </update>

    <update id="updateSysResSortNumOfDelete">
        UPDATE sys_res
        SET sort_num = sort_num - 1
        WHERE sort_num > (SELECT a.sort_num FROM (SELECT sort_num FROM sys_res WHERE id = #{id}) a)
        AND parent_res_id = (SELECT b.parent_res_id FROM (SELECT parent_res_id FROM sys_res  WHERE id = #{id}) b)
    </update>
    <!--查询公共服务资源ids-->
    <select id="queryPublicService" resultType="java.lang.Long" >
        select a.id from sys_res a where (a.id=#{resId} or a.parent_res_id=#{resId}) and a.data_state=1
    </select>
    

</mapper>