SysOrgSmapper.xml 5.97 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.SysOrgSmapper">
    <resultMap id="BaseResultMap" type="com.zteits.sys.domain.SysOrg">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="org_code" property="orgCode" jdbcType="VARCHAR"/>
        <result column="org_name" property="orgName" jdbcType="VARCHAR"/>
        <result column="short_name" property="shortName" jdbcType="VARCHAR"/>
        <result column="sort_num" property="sortNum" jdbcType="INTEGER"/>
        <result column="org_level" property="orgLevel" jdbcType="INTEGER"/>
        <result column="parent_org_id" property="parentOrgId" jdbcType="BIGINT"/>
        <result column="org_desc" property="orgDesc" jdbcType="VARCHAR"/>
        <result column="org_leader_id" property="orgLeaderId" jdbcType="BIGINT"/>
        <result column="org_icon" property="orgIcon" jdbcType="VARCHAR"/>
        <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, org_code, org_name, short_name, sort_num, org_level, parent_org_id, org_desc, 
    org_leader_id, org_icon, sys_code, data_state, create_empid, create_date, modfiy_empid, 
    modfiy_date
  </sql>

    <!--通过组织等级查询组织信息-->
    <select id="queryOrgByOrgLevel" resultMap="BaseResultMap"
            parameterType="com.zteits.clouds.api.dto.sys.param.OrgByOrgLevelRequest">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        sys_org a
        WHERE a.data_state=1
        and a.sys_code = #{sysCode,jdbcType=VARCHAR}
        <if test="orgLevel != null">
            and (org_level=#{orgLevel,jdbcType=INTEGER} or a.org_level=1)
        </if>
    </select>

    <!-- 通过操作员id查询组织ID -->
    <select id="querySysOrgBySysOpId" resultType="java.lang.Long">
        select b.id
        from sys_op_org a,sys_org b
        where a.sys_org_id = b.id
        and a.sys_op_id =#{sysOpId,jdbcType=BIGINT}
        <if test="sysCode != null">
            and b.sys_code = #{sysCode,jdbcType=VARCHAR}
        </if>
        and b.data_state =1
    </select>


    <!-- 查询组织   langlw 2017-08-14 -->
    <select id="queryPageSysOrgForList" resultMap="BaseResultMap" parameterType="com.zteits.sys.domain.SysOrg">
        select
        <include refid="Base_Column_List"/>
        from sys_org
        <where>
            <if test="id != null">
                and id= #{id,jdbcType=BIGINT}
            </if>
            <if test="parentOrgId != null">
                and parent_org_id= #{parentOrgId,jdbcType=BIGINT}
            </if>
            <if test="sysCode != null">
                and sys_code = #{sysCode,jdbcType=VARCHAR}
            </if>
            <choose>
                <when test="dataState != null">
                    and data_state = #{dataState,jdbcType=INTEGER}
                </when>
                <otherwise>
                    and data_state = 1
                </otherwise>
            </choose>
        </where>
        order by sort_num asc
    </select>

    <!-- 批量查询组织 -->
    <select id="queryBatchSysOrgById" resultType="com.zteits.sys.domain.SysOrg">
        SELECT
        <include refid="Base_Column_List"/>
        from sys_org
        <where>
            <if test="sysCode != null">
                and sys_code = #{sysCode,jdbcType=VARCHAR}
            </if>
            AND id IN
            <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>

            <choose>
                <when test="dataState != null">
                    and data_state = #{dataState,jdbcType=INTEGER}
                </when>
                <otherwise>
                    and data_state = 1
                </otherwise>
            </choose>
        </where>

    </select>

    <!-- 通过主键批量删除组织  逻辑删除 langlw 2017-08-14 -->
    <update id="deleteBatchForLogicByPrimaryKey">
        update sys_org set data_state = 0
        where id IN
        <foreach collection="ids" item="id" separator="," open="(" close=")" index="index">
            #{id,jdbcType=BIGINT}
        </foreach>
    </update>


    <!-- 更新排序 langlw 2017-08-17 -->
    <update id="updateSysOrgSortNumOfSaveOrUpdate">
        update sys_org
        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_org_id = #{parentOrgId}
        </where>
    </update>

    <!-- 更新排序 langlw 2017-08-17 -->
    <update id="updateSysOrgSortNumOfDelete">
        UPDATE sys_org
        SET sort_num = sort_num - 1
        WHERE sort_num > (SELECT a.sort_num FROM (SELECT sort_num FROM sys_org WHERE id = #{id}) a)
        AND parent_org_id = (SELECT b.parent_org_id FROM (SELECT parent_org_id FROM sys_org  WHERE id = #{id}) b)
    </update>

    <select id="querySysOrgByParentId" parameterType="java.lang.Long" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_org WHERE data_state = 1 AND parent_org_id = #{parentId}

    </select>


</mapper>