|
|
<?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.inspect.system.mapper.ExtOrgSyncMapper">
|
|
|
|
|
|
<resultMap type="com.inspect.system.base.domain.SysDept" id="DeptResult">
|
|
|
<id property="deptId" column="dept_id"/>
|
|
|
<result property="extId" column="ext_id"/>
|
|
|
<result property="parentId" column="parent_id"/>
|
|
|
<result property="ancestors" column="ancestors"/>
|
|
|
<result property="deptName" column="dept_name"/>
|
|
|
<result property="orderNum" column="order_num"/>
|
|
|
<result property="status" column="status"/>
|
|
|
<result property="delFlag" column="del_flag"/>
|
|
|
<result property="createBy" column="create_by"/>
|
|
|
<result property="createTime" column="create_time"/>
|
|
|
<result property="updateBy" column="update_by"/>
|
|
|
<result property="updateTime" column="update_time"/>
|
|
|
</resultMap>
|
|
|
|
|
|
<resultMap type="com.inspect.system.base.domain.SysUser" id="UserResult">
|
|
|
<id property="userId" column="user_id"/>
|
|
|
<result property="extId" column="ext_id"/>
|
|
|
<result property="deptId" column="dept_id"/>
|
|
|
<result property="userName" column="user_name"/>
|
|
|
<result property="nickName" column="nick_name"/>
|
|
|
<result property="userType" column="user_type"/>
|
|
|
<result property="email" column="email"/>
|
|
|
<result property="phonenumber" column="phonenumber"/>
|
|
|
<result property="sex" column="sex"/>
|
|
|
<result property="avatar" column="avatar"/>
|
|
|
<result property="password" column="password"/>
|
|
|
<result property="status" column="status"/>
|
|
|
<result property="delFlag" column="del_flag"/>
|
|
|
<result property="remark" column="remark"/>
|
|
|
</resultMap>
|
|
|
|
|
|
<resultMap type="com.inspect.system.domain.ext.ExtDeptRef" id="DeptRefResult">
|
|
|
<result property="deptId" column="dept_id"/>
|
|
|
<result property="extId" column="ext_id"/>
|
|
|
<result property="parentId" column="parent_id"/>
|
|
|
<result property="ancestors" column="ancestors"/>
|
|
|
<result property="status" column="status"/>
|
|
|
</resultMap>
|
|
|
|
|
|
<resultMap type="com.inspect.system.domain.ext.ExtUserRef" id="UserRefResult">
|
|
|
<result property="userId" column="user_id"/>
|
|
|
<result property="extId" column="ext_id"/>
|
|
|
<result property="deptId" column="dept_id"/>
|
|
|
<result property="status" column="status"/>
|
|
|
</resultMap>
|
|
|
|
|
|
<!-- ============================ 部门 ============================ -->
|
|
|
<select id="selectDeptIdByExtId" resultType="java.lang.Long">
|
|
|
select dept_id from sys_dept where ext_id = #{extId} limit 1
|
|
|
</select>
|
|
|
|
|
|
<select id="selectDeptIdByParentAndName" resultType="java.lang.Long">
|
|
|
select dept_id
|
|
|
from sys_dept
|
|
|
where parent_id = #{parentId}
|
|
|
and dept_name = #{deptName}
|
|
|
and ext_id is null
|
|
|
and del_flag = '0'
|
|
|
limit 1
|
|
|
</select>
|
|
|
|
|
|
<insert id="insertDept" parameterType="com.inspect.system.base.domain.SysDept"
|
|
|
useGeneratedKeys="true" keyProperty="deptId">
|
|
|
insert into sys_dept (ext_id, parent_id, ancestors, dept_name, order_num, status, del_flag, create_by, create_time)
|
|
|
values (#{extId}, #{parentId}, #{ancestors}, #{deptName}, #{orderNum}, '0', '0', #{createBy}, now())
|
|
|
</insert>
|
|
|
|
|
|
<update id="updateDept" parameterType="com.inspect.system.base.domain.SysDept">
|
|
|
update sys_dept
|
|
|
set parent_id = #{parentId},
|
|
|
ancestors = #{ancestors},
|
|
|
dept_name = #{deptName},
|
|
|
order_num = #{orderNum},
|
|
|
status = '0',
|
|
|
update_by = #{updateBy},
|
|
|
update_time = now()
|
|
|
where dept_id = #{deptId}
|
|
|
</update>
|
|
|
|
|
|
<update id="bindDeptExtId">
|
|
|
update sys_dept
|
|
|
set ext_id = #{extId}, update_by = 'ext_sync', update_time = now()
|
|
|
where dept_id = #{deptId}
|
|
|
</update>
|
|
|
|
|
|
<select id="selectSyncedDepts" resultMap="DeptRefResult">
|
|
|
select dept_id, ext_id, parent_id, ancestors, status
|
|
|
from sys_dept
|
|
|
where ext_id is not null
|
|
|
</select>
|
|
|
|
|
|
<update id="deactivateDept">
|
|
|
update sys_dept
|
|
|
set status = '1', update_by = 'ext_sync', update_time = now()
|
|
|
where dept_id = #{deptId} and status = '0'
|
|
|
</update>
|
|
|
|
|
|
<!-- ============================ 用户 ============================ -->
|
|
|
<select id="selectRoleIdByRoleKey" resultType="java.lang.Long">
|
|
|
select role_id from sys_role where role_key = #{roleKey} and del_flag = '0' limit 1
|
|
|
</select>
|
|
|
|
|
|
<select id="selectUserIdByExtId" resultType="java.lang.Long">
|
|
|
select user_id from sys_user where ext_id = #{extId} limit 1
|
|
|
</select>
|
|
|
|
|
|
<select id="selectUserById" resultMap="UserResult">
|
|
|
select user_id, ext_id, dept_id, user_name, nick_name, status, del_flag
|
|
|
from sys_user
|
|
|
where user_id = #{userId}
|
|
|
</select>
|
|
|
|
|
|
<select id="selectUserByUserName" resultMap="UserResult">
|
|
|
select user_id, ext_id, dept_id, user_name, nick_name, status, del_flag
|
|
|
from sys_user
|
|
|
where user_name = #{userName}
|
|
|
order by del_flag asc
|
|
|
limit 1
|
|
|
</select>
|
|
|
|
|
|
<insert id="insertUser" parameterType="com.inspect.system.base.domain.SysUser"
|
|
|
useGeneratedKeys="true" keyProperty="userId">
|
|
|
insert into sys_user (ext_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex,
|
|
|
avatar, password, status, del_flag, create_by, create_time, remark, aollow_ip)
|
|
|
values (#{extId}, #{deptId}, #{userName}, #{nickName}, #{userType}, #{email}, #{phonenumber}, '0',
|
|
|
'', #{password}, #{status}, '0', #{createBy}, now(), #{remark}, #{aollowIp})
|
|
|
</insert>
|
|
|
|
|
|
<update id="updateUser" parameterType="com.inspect.system.base.domain.SysUser">
|
|
|
update sys_user
|
|
|
set nick_name = #{nickName},
|
|
|
user_type = #{userType},
|
|
|
<if test="deptId != null">dept_id = #{deptId},</if>
|
|
|
status = #{status},
|
|
|
<if test="email != null and email != ''">email = #{email},</if>
|
|
|
<if test="phonenumber != null and phonenumber != ''">phonenumber = #{phonenumber},</if>
|
|
|
update_by = #{updateBy},
|
|
|
update_time = now()
|
|
|
where user_id = #{userId}
|
|
|
</update>
|
|
|
|
|
|
<update id="bindUserExtId">
|
|
|
update sys_user
|
|
|
set ext_id = #{extId}, update_by = 'ext_sync', update_time = now()
|
|
|
where user_id = #{userId}
|
|
|
</update>
|
|
|
|
|
|
<insert id="insertUserRole">
|
|
|
insert ignore into sys_user_role (user_id, role_id) values (#{userId}, #{roleId})
|
|
|
</insert>
|
|
|
|
|
|
<select id="selectSyncedUsers" resultMap="UserRefResult">
|
|
|
select user_id, ext_id, dept_id, status
|
|
|
from sys_user
|
|
|
where ext_id is not null
|
|
|
</select>
|
|
|
|
|
|
<update id="deactivateUser">
|
|
|
update sys_user
|
|
|
set status = '1', update_by = 'ext_sync', update_time = now()
|
|
|
where user_id = #{userId} and status = '0'
|
|
|
</update>
|
|
|
|
|
|
</mapper>
|