SysOrganizationMapper.xml 12.2 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.glsx.usercenter.mapper.SysOrganizationMapper">
    <resultMap id="BaseResultMap" type="com.glsx.usercenter.pojo.menu.SysOrganization">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="parent_id" jdbcType="INTEGER" property="parentId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="org_status" jdbcType="TINYINT" property="orgStatus"/>
        <result column="org_type" jdbcType="TINYINT" property="orgType"/>
        <result column="sort" jdbcType="INTEGER" property="sort"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="update_by" jdbcType="INTEGER" property="updateBy"/>
        <result column="create_by" jdbcType="INTEGER" property="createBy"/>
        <result column="label" jdbcType="TINYINT" property="label"/>
        <result column="org_group" jdbcType="VARCHAR" property="orgGroup"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        id, parent_id, name, org_status, org_type, sort, create_time, update_time, remark,
        update_by, create_by, label, org_group
    </sql>
    <select id="selectByExample" parameterType="com.glsx.usercenter.pojo.menu.SysOrganizationExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        'false' as QUERYID,
        <include refid="Base_Column_List"/>
        from sys_organization
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_organization
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        DELETE FROM sys_organization
        WHERE id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" parameterType="com.glsx.usercenter.pojo.menu.SysOrganization">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into sys_organization (parent_id, name, org_status,
        org_type, sort, create_time,
        update_time, remark, update_by,
        create_by, label, org_group
        )
        values (#{parentId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{orgStatus,jdbcType=TINYINT},
        #{orgType,jdbcType=TINYINT}, #{sort,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
        #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR}, #{updateBy,jdbcType=INTEGER},
        #{createBy,jdbcType=INTEGER}, #{label,jdbcType=TINYINT}, #{orgGroup,jdbcType=VARCHAR}
        )
    </insert>
    <insert id="insertSelective" parameterType="com.glsx.usercenter.pojo.menu.SysOrganization">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into sys_organization
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">
                parent_id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="orgStatus != null">
                org_status,
            </if>
            <if test="orgType != null">
                org_type,
            </if>
            <if test="sort != null">
                sort,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="updateBy != null">
                update_by,
            </if>
            <if test="createBy != null">
                create_by,
            </if>
            <if test="label != null">
                label,
            </if>
            <if test="orgGroup != null">
                org_group,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">
                #{parentId,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="orgStatus != null">
                #{orgStatus,jdbcType=TINYINT},
            </if>
            <if test="orgType != null">
                #{orgType,jdbcType=TINYINT},
            </if>
            <if test="sort != null">
                #{sort,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=INTEGER},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=INTEGER},
            </if>
            <if test="label != null">
                #{label,jdbcType=TINYINT},
            </if>
            <if test="orgGroup != null">
                #{orgGroup,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.glsx.usercenter.pojo.menu.SysOrganization">
        update sys_organization
        <set>
            <if test="parentId != null">
                parent_id = #{parentId,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="orgStatus != null">
                org_status = #{orgStatus,jdbcType=TINYINT},
            </if>
            <if test="orgType != null">
                org_type = #{orgType,jdbcType=TINYINT},
            </if>
            <if test="sort != null">
                sort = #{sort,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="remark != null">
                remark = #{remark,jdbcType=VARCHAR},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy,jdbcType=INTEGER},
            </if>
            <if test="createBy != null">
                create_by = #{createBy,jdbcType=INTEGER},
            </if>
            <if test="label != null">
                label = #{label,jdbcType=TINYINT},
            </if>
            <if test="orgGroup != null">
                org_group = #{orgGroup,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.glsx.usercenter.pojo.menu.SysOrganization">
        UPDATE sys_organization
        SET parent_id   = #{parentId,jdbcType=INTEGER},
            name        = #{name,jdbcType=VARCHAR},
            org_status  = #{orgStatus,jdbcType=TINYINT},
            org_type    = #{orgType,jdbcType=TINYINT},
            sort        = #{sort,jdbcType=INTEGER},
            create_time = #{createTime,jdbcType=TIMESTAMP},
            update_time = #{updateTime,jdbcType=TIMESTAMP},
            remark      = #{remark,jdbcType=VARCHAR},
            update_by   = #{updateBy,jdbcType=INTEGER},
            create_by   = #{createBy,jdbcType=INTEGER},
            label       = #{label,jdbcType=TINYINT},
            org_group   = #{orgGroup,jdbcType=VARCHAR}
        WHERE id = #{id,jdbcType=INTEGER}
    </update>

    <resultMap id="recursionOrgMap" type="com.glsx.usercenter.pojo.menu.SysOrganization" extends="BaseResultMap">
        <collection property="children" ofType="com.glsx.usercenter.pojo.menu.SysOrganization"
                    column="{id=id,org_status=,org_status}"
                    select="findOrgByParams"/>
    </resultMap>

    <select id="findOrgByParams" resultMap="recursionOrgMap" parameterType="java.util.Map">
        SELECT
        <include refid="Base_Column_List"/>
        from sys_organization WHERE 1=1
        <if test="id != null">
            and parent_id = #{id}
        </if>
        <if test="orgStatus != null">
            and org_status = #{orgStatus}
        </if>
        ORDER BY
        `sort` ASC
    </select>

    <resultMap id="recursionOrgResultMap" type="com.glsx.usercenter.pojo.menu.SysOrganization" extends="BaseResultMap">
        <collection property="children" ofType="com.glsx.usercenter.pojo.menu.SysOrganization"
                    column="{id=id,org_status=org_status}"
                    select="findOrgByParentId"/>
    </resultMap>
    <select id="findOrgByParentId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        from sys_organization WHERE parent_id = #{id}
        and org_status in (1,2)
        ORDER BY
        `sort` ASC
    </select>

    <select id="getAllGroupByParentId" resultType="com.glsx.usercenter.pojo.menu.SysOrganization">
        SELECT
            so.id   id,
            so.name name,
            so.org_type orgType
        FROM
            sys_organization so
        WHERE
            so.parent_id = #{parentId,jdbcType=TINYINT}
            AND so.org_status = 1
    </select>

    <select id="selectDetailById" resultType="com.glsx.usercenter.pojo.menu.SysOrganization">
        SELECT
            sor.*,
            so.name parentName
        FROM
            sys_organization so
            INNER JOIN sys_organization sor ON so.id = sor.parent_id
        WHERE
            sor.id = #{id}

    </select>

	<select id="selectOrgByUserId" resultType="Integer">
		SELECT	so.id
		FROM sys_organization so
		LEFT JOIN sys_user_org suo ON so.id=suo.org_id
		WHERE
		so.org_status in(1,2) 
		and	suo.user_id=  #{userId} 
	</select>

</mapper>