<?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.cloud.user.dao.SysOrganizationDao">
|
<resultMap id="BaseResultMap" type="com.cloud.model.sys.SysOrganization">
|
<id column="id" jdbcType="INTEGER" property="id" />
|
<result column="orgId" jdbcType="INTEGER" property="orgId" />
|
<result column="parentId" jdbcType="INTEGER" property="parentId" />
|
<result column="headquartersId" jdbcType="INTEGER" property="headquartersId" />
|
<result column="areaId" jdbcType="INTEGER" property="areaId" />
|
<result column="parentIds" jdbcType="VARCHAR" property="parentIds" />
|
<result column="parentJson" jdbcType="VARCHAR" property="parentJson" />
|
<result column="name" jdbcType="VARCHAR" property="name" />
|
<result column="sort" jdbcType="INTEGER" property="sort" />
|
<result column="type" jdbcType="VARCHAR" property="type" />
|
<result column="address" jdbcType="VARCHAR" property="address" />
|
<result column="master" jdbcType="VARCHAR" property="master" />
|
<result column="phone" jdbcType="VARCHAR" property="phone" />
|
<result column="webUrl" jdbcType="VARCHAR" property="webUrl" />
|
<result column="partack" jdbcType="VARCHAR" property="partack" />
|
<result column="enabled" jdbcType="VARCHAR" property="enabled" />
|
<result column="delFlag" jdbcType="VARCHAR" property="delFlag" />
|
<result column="createTime" jdbcType="TIMESTAMP" property="createTime" />
|
<result column="updateTime" jdbcType="TIMESTAMP" property="updateTime" />
|
<result column="revJson" jdbcType="CHAR" property="revJson" />
|
</resultMap>
|
|
<resultMap id="BaseMessageMap" type="com.cloud.model.sys.SysOrganization">
|
<id column="id" jdbcType="INTEGER" property="id" />
|
<result column="orgId" jdbcType="INTEGER" property="orgId" />
|
<result column="parentId" jdbcType="INTEGER" property="parentId" />
|
<result column="headquartersId" jdbcType="INTEGER" property="headquartersId" />
|
<result column="areaId" jdbcType="INTEGER" property="areaId" />
|
<result column="parentIds" jdbcType="VARCHAR" property="parentIds" />
|
<result column="name" jdbcType="VARCHAR" property="name" />
|
<result column="sort" jdbcType="INTEGER" property="sort" />
|
<result column="type" jdbcType="VARCHAR" property="type" />
|
<result column="address" jdbcType="VARCHAR" property="address" />
|
<result column="master" jdbcType="VARCHAR" property="master" />
|
<result column="phone" jdbcType="VARCHAR" property="phone" />
|
<result column="webUrl" jdbcType="VARCHAR" property="webUrl" />
|
<result column="partack" jdbcType="VARCHAR" property="partack" />
|
<result column="revJson" jdbcType="CHAR" property="revJson" />
|
</resultMap>
|
|
<resultMap id="BaseIdMap" type="com.cloud.model.sys.SysOrganization">
|
<id column="id" jdbcType="INTEGER" property="id" />
|
<result column="orgId" jdbcType="INTEGER" property="orgId" />
|
<result column="parentId" jdbcType="INTEGER" property="parentId" />
|
<result column="headquartersId" jdbcType="INTEGER" property="headquartersId" />
|
<result column="areaId" jdbcType="INTEGER" property="areaId" />
|
<result column="parentIds" jdbcType="VARCHAR" property="parentIds" />
|
<result column="revJson" jdbcType="CHAR" property="revJson" />
|
</resultMap>
|
|
|
<select id="findAll" resultType="com.cloud.model.sys.SysOrganization">
|
select * from sys_organization t where delFlag = '0'
|
<if test="type != null and type != ''">
|
and type < #{type}
|
</if>
|
order by t.sort
|
</select>
|
|
<!---默认查全部-->
|
<sql id="Base_Column_List">
|
id, orgId, parentId, headquartersId, areaId, parentIds, parentJson, name, sort,
|
type, address, master, phone, webUrl, partack, enabled, delFlag, createTime, updateTime,revJson
|
</sql>
|
|
<!---查基本信息-->
|
<sql id="Base_Message_List">
|
id, orgId, parentId, headquartersId, areaId, parentIds, name, sort,
|
type, address, master, phone, webUrl, partack,revJson
|
</sql>
|
|
<!---查基本ID信息-->
|
<sql id="Base_ID_List">
|
id, orgId, parentId, headquartersId, areaId, parentIds,revJson
|
</sql>
|
|
<select id="findById" parameterType="java.util.Map" resultType="com.cloud.model.sys.SysOrganization">
|
select
|
<include refid="Base_Column_List" />
|
from sys_organization
|
where id = #{id,jdbcType=INTEGER}
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
</select>
|
|
<!--机构逻辑删除-->
|
<update id="deleteOrg">
|
UPDATE sys_organization SET delFlag = '1' WHERE parentIds like concat('%,', #{id}, ',%')
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
</update>
|
|
<insert id="save" parameterType="com.cloud.model.sys.SysOrganization" keyProperty="id" useGeneratedKeys="true">
|
insert into sys_organization (orgId, parentId, headquartersId,
|
areaId, parentIds, parentJson,
|
name, sort, type, address,
|
master, phone, webUrl,
|
partack, enabled, delFlag,
|
createTime, updateTime,revJson)
|
values (#{orgId,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{headquartersId,jdbcType=INTEGER},
|
#{areaId,jdbcType=INTEGER}, #{parentIds,jdbcType=VARCHAR}, #{parentJson,jdbcType=VARCHAR},
|
#{name,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
|
#{master,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{webUrl,jdbcType=VARCHAR},
|
#{partack,jdbcType=VARCHAR}, #{enabled,jdbcType=VARCHAR}, #{delFlag,jdbcType=VARCHAR},
|
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},#{revJson,jdbcType=VARCHAR})
|
</insert>
|
<insert id="saveSelective" parameterType="com.cloud.model.sys.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="orgId != null">
|
orgId,
|
</if>
|
<if test="parentId != null">
|
parentId,
|
</if>
|
<if test="headquartersId != null">
|
headquartersId,
|
</if>
|
<if test="areaId != null">
|
areaId,
|
</if>
|
<if test="parentIds != null">
|
parentIds,
|
</if>
|
<if test="parentJson != null">
|
parentJson,
|
</if>
|
<if test="name != null">
|
name,
|
</if>
|
<if test="sort != null">
|
sort,
|
</if>
|
<if test="type != null">
|
type,
|
</if>
|
<if test="address != null">
|
address,
|
</if>
|
<if test="master != null">
|
master,
|
</if>
|
<if test="phone != null">
|
phone,
|
</if>
|
<if test="webUrl != null">
|
webUrl,
|
</if>
|
<if test="partack != null">
|
partack,
|
</if>
|
<if test="enabled != null">
|
enabled,
|
</if>
|
<if test="delFlag != null">
|
delFlag,
|
</if>
|
<if test="createTime != null">
|
createTime,
|
</if>
|
<if test="updateTime != null">
|
updateTime,
|
</if>
|
<if test="revJson != null">
|
revJson,
|
</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<if test="orgId != null">
|
#{orgId,jdbcType=INTEGER},
|
</if>
|
<if test="parentId != null">
|
#{parentId,jdbcType=INTEGER},
|
</if>
|
<if test="headquartersId != null">
|
#{headquartersId,jdbcType=INTEGER},
|
</if>
|
<if test="areaId != null">
|
#{areaId,jdbcType=INTEGER},
|
</if>
|
<if test="parentIds != null">
|
#{parentIds,jdbcType=VARCHAR},
|
</if>
|
<if test="parentJson != null">
|
#{parentJson,jdbcType=VARCHAR},
|
</if>
|
<if test="name != null">
|
#{name,jdbcType=VARCHAR},
|
</if>
|
<if test="sort != null">
|
#{sort,jdbcType=INTEGER},
|
</if>
|
<if test="type != null">
|
#{type,jdbcType=VARCHAR},
|
</if>
|
<if test="address != null">
|
#{address,jdbcType=VARCHAR},
|
</if>
|
<if test="master != null">
|
#{master,jdbcType=VARCHAR},
|
</if>
|
<if test="phone != null">
|
#{phone,jdbcType=VARCHAR},
|
</if>
|
<if test="webUrl != null">
|
#{webUrl,jdbcType=VARCHAR},
|
</if>
|
<if test="partack != null">
|
#{partack,jdbcType=VARCHAR},
|
</if>
|
<if test="enabled != null">
|
#{enabled,jdbcType=VARCHAR},
|
</if>
|
<if test="delFlag != null">
|
#{delFlag,jdbcType=VARCHAR},
|
</if>
|
<if test="createTime != null">
|
#{createTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="updateTime != null">
|
#{updateTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="revJson != null">
|
#{revJson,jdbcType=VARCHAR},
|
</if>
|
</trim>
|
</insert>
|
<update id="update" parameterType="com.cloud.model.sys.SysOrganization">
|
update sys_organization
|
<set>
|
<if test="orgId != null">
|
orgId = #{orgId,jdbcType=INTEGER},
|
</if>
|
<if test="parentId != null">
|
parentId = #{parentId,jdbcType=INTEGER},
|
</if>
|
<if test="headquartersId != null">
|
headquartersId = #{headquartersId,jdbcType=INTEGER},
|
</if>
|
<if test="areaId != null">
|
areaId = #{areaId,jdbcType=INTEGER},
|
</if>
|
<if test="parentIds != null">
|
parentIds = #{parentIds,jdbcType=VARCHAR},
|
</if>
|
<if test="parentJson != null">
|
parentJson = #{parentJson,jdbcType=VARCHAR},
|
</if>
|
<if test="name != null">
|
name = #{name,jdbcType=VARCHAR},
|
</if>
|
<if test="sort != null">
|
sort = #{sort,jdbcType=INTEGER},
|
</if>
|
<if test="type != null">
|
type = #{type,jdbcType=VARCHAR},
|
</if>
|
<if test="address != null">
|
address = #{address,jdbcType=VARCHAR},
|
</if>
|
<if test="master != null">
|
master = #{master,jdbcType=VARCHAR},
|
</if>
|
<if test="phone != null">
|
phone = #{phone,jdbcType=VARCHAR},
|
</if>
|
<if test="webUrl != null">
|
webUrl = #{webUrl,jdbcType=VARCHAR},
|
</if>
|
<if test="partack != null">
|
partack = #{partack,jdbcType=VARCHAR},
|
</if>
|
<if test="enabled != null">
|
enabled = #{enabled,jdbcType=VARCHAR},
|
</if>
|
<if test="delFlag != null">
|
delFlag = #{delFlag,jdbcType=VARCHAR},
|
</if>
|
<if test="createTime != null">
|
createTime = #{createTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="updateTime != null">
|
updateTime = #{updateTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="revJson != null">
|
revJson = #{revJson,jdbcType=VARCHAR},
|
</if>
|
</set>
|
where id = #{id,jdbcType=INTEGER}
|
<if test="orgId != null">
|
and orgId=#{orgId}
|
</if>
|
</update>
|
|
<sql id="where">
|
<where>
|
<if test="orgId != null and orgId != ''">
|
orgId = #{orgId,jdbcType=INTEGER},
|
</if>
|
<if test="parentId != null and parentId != ''">
|
parentId = #{parentId,jdbcType=INTEGER},
|
</if>
|
<if test="headquartersId != null and headquartersId != ''">
|
headquartersId = #{headquartersId,jdbcType=INTEGER},
|
</if>
|
<if test="areaId != null and areaId != ''">
|
areaId = #{areaId,jdbcType=INTEGER},
|
</if>
|
<if test="name != null and name != ''">
|
name like concat('%', #{name}, '%'),
|
</if>
|
<if test="type != null and type != ''">
|
type = #{type,jdbcType=VARCHAR},
|
</if>
|
<if test="partack != null and partack != ''">
|
partack = #{partack,jdbcType=VARCHAR},
|
</if>
|
<if test="enabled != null and enabled != ''" >
|
enabled = #{enabled,jdbcType=VARCHAR},
|
</if>
|
<if test="delFlag != null">
|
delFlag = #{delFlag,jdbcType=VARCHAR},
|
</if>
|
</where>
|
</sql>
|
<select id="findPageByParams" resultType="com.cloud.model.sys.SysOrganization">
|
select * from sys_organization t
|
<include refid="where" />
|
order by t.id desc
|
<if test="start != null and start >= 0 and length != null and length > 0">
|
limit #{start}, #{length}
|
</if>
|
</select>
|
<select id="count" resultType="int">
|
select count(*) from sys_organization t
|
<include refid="where" />
|
</select>
|
|
|
<!--findCurentParentIds查找组织机构的父集集合-->
|
<select id="findCurentParentIds" resultType="String">
|
select parentIds from sys_organization where id = #{currentId} and delFlag = '0' /*wp 2018-12-08添加 删除不查*/
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
</select>
|
|
<!--查找上级第一个机构(机构类型)-->
|
<select id="findUpById" resultMap="BaseMessageMap">
|
SELECT
|
<include refid="Base_Message_List" />
|
FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%') AND t.partack = #{partack}
|
ORDER BY parentIds DESC limit 1
|
</select>
|
|
<!--查找上级第一个指定的机构类型-->
|
<select id="findUpByType" resultMap="BaseMessageMap">
|
SELECT
|
<include refid="Base_Message_List" />
|
FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%') AND t.type = #{type}
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
</select>
|
|
<!--查找下级的指定类型的所有机构-->
|
<select id="findDownByType" resultMap="BaseMessageMap">
|
SELECT
|
<include refid="Base_Message_List" />
|
FROM sys_organization WHERE parentIds LIKE '%${parentIds}%' and delFlag = '0' /*wp 2018-12-08添加 删除不查*/
|
<if test="type != '' and type != null">
|
AND type = #{type}
|
</if>
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
order by name asc
|
</select> <!-- 王鹏 和金尔松 修改 排序 -->
|
|
<!--查找下级的指定类型的所有机构id集合-->
|
<select id="findDownByOffIds" resultType="int">
|
SELECT
|
id
|
FROM sys_organization WHERE parentIds LIKE '%${parentIds}%'
|
<if test="type != '' and type != null">
|
AND type = #{type}
|
</if>
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
</select>
|
|
<select id="findCheckSchool" resultType="map">
|
SELECT id,name,address,revJson
|
FROM sys_organization WHERE delFlag = 0 and parentIds LIKE '%${parentIds}%' AND
|
type in <foreach collection="type" item="typeId" open="(" separator="," close=")">
|
#{typeId}
|
</foreach>
|
<if test="searchName != null and searchName != ''">
|
and name like '%${searchName}%'
|
</if>
|
ORDER BY name DESC
|
</select>
|
|
<!---->
|
<select id="finCurentOrgs" resultType="String">
|
SELECT
|
name
|
FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%')
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
ORDER by TYPE
|
</select>
|
|
<!--根据orgId 得到所有父节点的name,按照指定分隔符分隔-->
|
<select id="getParentNames" resultType="String">
|
SELECT
|
GROUP_CONCAT(name SEPARATOR #{separator})
|
FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%')
|
<if test="orgId != null and orgId != ''">
|
and orgId = #{orgId}
|
</if>
|
and delFlag = 0 and enabled = 0
|
</select>
|
|
|
|
<select id="findHeadquarters" resultType="com.cloud.model.sys.SysOrganization">
|
select
|
<include refid="Base_Column_List" />
|
from sys_organization t
|
<if test="type != null and type != ''">
|
where type = #{type}
|
</if>
|
<if test="currentId != null and currentId != ''">
|
and parentIds like concat('%,',#{currentId},',%')
|
</if>
|
</select>
|
|
<select id="findSubOrg" resultType="com.cloud.model.sys.SysOrganization">
|
select
|
<include refid="Base_Column_List" />
|
from sys_organization where headquartersId = #{headId}
|
<if test="isSelf == false and type != null and type != ''" >
|
and type != #{type}
|
</if>
|
</select>
|
|
<!--验证此部门是否是班级-->
|
<select id="isImportStudentClass" resultType="boolean" parameterType="map">
|
select type = #{type} from sys_organization where id = #{officeId}
|
</select>
|
|
<!--验证此部门是否是学校或者部门-->
|
<select id="isisImportTeacherOffice" resultType="map" parameterType="map">
|
select type = #{schoolValue} as isSchool,type = #{compactValue} as isCompact from sys_organization where id = #{officeId}
|
</select>
|
|
<!--查找部门名称-->
|
<select id="findCompactName" resultType="String">
|
select name from sys_organization where id = #{officeId}
|
</select>
|
|
<select id="findOrgIds" resultType="java.lang.Integer" parameterType="map">
|
select id from sys_organization where #{parentIds} LIKE CONCAT('',parentIds,'%')
|
AND type in <foreach collection="types" open="(" separator="," close=")" item="value">
|
#{value}
|
</foreach>
|
</select>
|
|
<select id="findOrgName" parameterType="Integer" resultType="String">
|
SELECT name from sys_organization WHERE delFlag = '0' and id = #{id}
|
</select>
|
<!--新建组织机构时查询当前机构下是否有重名机构-->
|
<select id="isRepeatOrgName" resultType="Integer">
|
SELECT count(*) from sys_organization WHERE parentId = #{parentId} and name = #{name} and delFlag = '0'
|
</select>
|
|
</mapper>
|