255 lines
7.7 KiB
XML
255 lines
7.7 KiB
XML
|
|
<?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.bonus.system.basic.dao.SysUserMapper">
|
||
|
|
<insert id="insertUser" keyColumn="user_id" useGeneratedKeys="true" keyProperty="userId">
|
||
|
|
insert into sys_user(
|
||
|
|
<if test="userName != null and userName != ''">user_name,</if>
|
||
|
|
<if test="phone != null and phone != ''">phone,</if>
|
||
|
|
<if test="idNumber != null and idNumber != ''">id_number,</if>
|
||
|
|
<if test="password != null and password != ''">password,</if>
|
||
|
|
<if test="createBy != null and createBy != ''">create_user_id,</if>
|
||
|
|
<if test="isCadre != null and isCadre != ''">is_cadre,</if>
|
||
|
|
create_time
|
||
|
|
)values(
|
||
|
|
<if test="userName != null and userName != ''">#{userName},</if>
|
||
|
|
<if test="phone != null and phone != ''">#{phone},</if>
|
||
|
|
<if test="idNumber != null and idNumber != ''">#{idNumber},</if>
|
||
|
|
<if test="password != null and password != ''">#{password},</if>
|
||
|
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||
|
|
<if test="isCadre != null and isCadre != ''">#{isCadre},</if>
|
||
|
|
sysdate()
|
||
|
|
)
|
||
|
|
</insert>
|
||
|
|
|
||
|
|
<insert id="insertUserPost">
|
||
|
|
insert into sys_user_post(user_id, post_id) values
|
||
|
|
<foreach collection="list" item="item" separator=",">
|
||
|
|
(#{item.userId},#{item.postId})
|
||
|
|
</foreach>
|
||
|
|
</insert>
|
||
|
|
<insert id="insertUserRole">
|
||
|
|
insert into sys_user_role(user_id, role_id) values
|
||
|
|
<foreach collection="list" item="item" separator=",">
|
||
|
|
(#{item.userId},#{item.roleId})
|
||
|
|
</foreach>
|
||
|
|
</insert>
|
||
|
|
<insert id="insertUserOrg">
|
||
|
|
insert into sys_user_org(user_id, org_id) values
|
||
|
|
<foreach collection="list" item="item" separator=",">
|
||
|
|
(#{item.userId},#{item.orgId})
|
||
|
|
</foreach>
|
||
|
|
</insert>
|
||
|
|
<delete id="deleteUserOrgByUserId">
|
||
|
|
delete from sys_user_org where user_id = #{userId}
|
||
|
|
</delete>
|
||
|
|
<delete id="deleteUserPostByUserId">
|
||
|
|
delete from sys_user_post where user_id = #{userId}
|
||
|
|
</delete>
|
||
|
|
<delete id="deleteUserRoleByUserId">
|
||
|
|
delete from sys_user_role where user_id = #{userId}
|
||
|
|
</delete>
|
||
|
|
<update id="deleteUserById">
|
||
|
|
update sys_user
|
||
|
|
set is_active = 0
|
||
|
|
where user_id = #{userId}
|
||
|
|
</update>
|
||
|
|
<update id="updateUser">
|
||
|
|
update sys_user
|
||
|
|
<set>
|
||
|
|
<if test="userName != null and userName != ''">user_name = #{userName},</if>
|
||
|
|
<if test="phone != null and phone != ''">phone = #{phone},</if>
|
||
|
|
<if test="idNumber != null and idNumber != ''">id_number = #{idNumber},</if>
|
||
|
|
<if test="password != null and password != ''">password = #{password},</if>
|
||
|
|
<if test="updateBy != null and updateBy != ''">update_user_id = #{updateBy},</if>
|
||
|
|
<if test="isCadre != null and isCadre != ''">is_cadre = #{isCadre},</if>
|
||
|
|
update_time = sysdate()
|
||
|
|
</set>
|
||
|
|
where user_id = #{userId}
|
||
|
|
</update>
|
||
|
|
|
||
|
|
<select id="selectUserByUserName" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
select * from sys_user su
|
||
|
|
where su.is_active = 1 and su.phone = #{userName}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="selectUserById" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
select * from sys_user su
|
||
|
|
where su.user_id = #{userId}
|
||
|
|
</select>
|
||
|
|
<select id="getOrgByUserId" resultType="com.bonus.system.api.domain.MapVo">
|
||
|
|
SELECT
|
||
|
|
id,
|
||
|
|
`org_name` AS `name`
|
||
|
|
FROM
|
||
|
|
sys_organization
|
||
|
|
WHERE
|
||
|
|
id IN (
|
||
|
|
SELECT
|
||
|
|
org_id
|
||
|
|
FROM
|
||
|
|
sys_user_org
|
||
|
|
WHERE
|
||
|
|
user_id = #{userId})
|
||
|
|
</select>
|
||
|
|
<select id="selectUserList" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
SELECT
|
||
|
|
su.user_id AS userId,
|
||
|
|
su.user_name as userName,
|
||
|
|
su.id_number as idNumber,
|
||
|
|
GROUP_CONCAT(DISTINCT so.org_name ORDER BY so.id SEPARATOR ', ') as orgName,
|
||
|
|
GROUP_CONCAT(DISTINCT sdd.dict_label ORDER BY sdd.dict_code SEPARATOR ', ') as postName,
|
||
|
|
GROUP_CONCAT(DISTINCT sr.role_name ORDER BY sr.role_id SEPARATOR ', ') as roleName,
|
||
|
|
su.phone,su.is_cadre as isCadre
|
||
|
|
FROM
|
||
|
|
sys_user su
|
||
|
|
LEFT JOIN sys_user_post sup on sup.user_id=su.user_id and sup.is_active=1
|
||
|
|
LEFT JOIN sys_dict_data sdd on sdd.dict_code=sup.post_id and sdd.`status`=0
|
||
|
|
LEFT JOIN sys_user_role sur on sur.user_id=su.user_id and sur.is_active=1
|
||
|
|
LEFT JOIN sys_role sr on sr.role_id=sur.role_id and sr.del_flag=0
|
||
|
|
LEFT JOIN sys_user_org suo on suo.user_id=su.user_id and suo.is_active=1
|
||
|
|
LEFT JOIN sys_organization so on so.id=suo.org_id and so.is_active=1
|
||
|
|
WHERE
|
||
|
|
su.is_active =1
|
||
|
|
<if test="userName != null and userName != ''">
|
||
|
|
AND su.user_name like concat('%', #{userName}, '%')
|
||
|
|
</if>
|
||
|
|
<if test="orgId != null and orgId != ''">
|
||
|
|
AND suo.org_id = #{orgId}
|
||
|
|
</if>
|
||
|
|
<if test="phone != null and phone != ''">
|
||
|
|
AND su.phone = #{phone}
|
||
|
|
</if>
|
||
|
|
<if test="userId != null">
|
||
|
|
AND su.user_id = #{userId}
|
||
|
|
</if>
|
||
|
|
GROUP BY su.user_id
|
||
|
|
order by su.update_time desc
|
||
|
|
</select>
|
||
|
|
<select id="getSelectRole" resultType="com.bonus.system.api.domain.SysRole">
|
||
|
|
SELECT role_id,
|
||
|
|
role_name
|
||
|
|
FROM sys_role
|
||
|
|
WHERE del_flag = '0'
|
||
|
|
and status = '0'
|
||
|
|
</select>
|
||
|
|
<select id="getSelectPost" resultType="com.bonus.system.api.domain.SysDictData">
|
||
|
|
SELECT dict_code,
|
||
|
|
dict_label
|
||
|
|
FROM sys_dict_data
|
||
|
|
WHERE dict_type = 'post_list'
|
||
|
|
and status = '0'
|
||
|
|
</select>
|
||
|
|
<select id="getRoleIdsByUserId">
|
||
|
|
SELECT
|
||
|
|
role_id as roleId
|
||
|
|
FROM
|
||
|
|
sys_user_role
|
||
|
|
WHERE
|
||
|
|
user_id = #{userId}
|
||
|
|
and is_active=1
|
||
|
|
</select>
|
||
|
|
<select id="getOrgIdsByUserId">
|
||
|
|
SELECT
|
||
|
|
org_id as orgId
|
||
|
|
FROM
|
||
|
|
sys_user_org
|
||
|
|
WHERE
|
||
|
|
user_id = #{userId}
|
||
|
|
and is_active=1
|
||
|
|
</select>
|
||
|
|
<select id="getPostIdsByUserId">
|
||
|
|
SELECT
|
||
|
|
sdd.dict_value as postId
|
||
|
|
FROM
|
||
|
|
sys_dict_data sdd
|
||
|
|
LEFT JOIN sys_user_post sup on sup.post_id=sdd.dict_code and sup.is_active=1
|
||
|
|
WHERE
|
||
|
|
sup.user_id=#{userId}
|
||
|
|
and sdd.`status`=0
|
||
|
|
</select>
|
||
|
|
<select id="checkPhoneUnique" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
select user_id as userId, phone
|
||
|
|
from sys_user
|
||
|
|
where phone = #{phone}
|
||
|
|
and is_active = '1' limit 1
|
||
|
|
</select>
|
||
|
|
<select id="selectPostIdById" resultType="java.lang.String">
|
||
|
|
select dict_code as postId from sys_dict_data where dict_value = #{postId} and dict_type = 'post_list' and status = '0' limit 1
|
||
|
|
</select>
|
||
|
|
<select id="getOrgList" resultType="com.bonus.system.holiday.entity.HolidayKeyBean">
|
||
|
|
SELECT
|
||
|
|
id,
|
||
|
|
org_name as `name`
|
||
|
|
FROM
|
||
|
|
`sys_organization`
|
||
|
|
WHERE
|
||
|
|
is_active=1
|
||
|
|
and org_name is not null
|
||
|
|
GROUP BY org_name
|
||
|
|
</select>
|
||
|
|
<select id="getRoleList" resultType="com.bonus.system.holiday.entity.HolidayKeyBean">
|
||
|
|
SELECT
|
||
|
|
role_id as id,
|
||
|
|
role_name as `name`
|
||
|
|
FROM
|
||
|
|
sys_role
|
||
|
|
WHERE
|
||
|
|
del_flag = '0'
|
||
|
|
and status = '0'
|
||
|
|
and role_name is not null
|
||
|
|
GROUP BY role_name
|
||
|
|
</select>
|
||
|
|
<select id="getPostList" resultType="com.bonus.system.holiday.entity.HolidayKeyBean">
|
||
|
|
SELECT
|
||
|
|
dict_code as id,
|
||
|
|
dict_label as `name`
|
||
|
|
FROM
|
||
|
|
sys_dict_data
|
||
|
|
WHERE
|
||
|
|
dict_type = 'post_list'
|
||
|
|
and status = '0'
|
||
|
|
and dict_label is not null
|
||
|
|
GROUP BY dict_label
|
||
|
|
</select>
|
||
|
|
<select id="getSelectUser" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
SELECT
|
||
|
|
user_id AS userIds,
|
||
|
|
user_name AS userName,
|
||
|
|
id_number AS idNumber,
|
||
|
|
phone
|
||
|
|
FROM
|
||
|
|
sys_user
|
||
|
|
WHERE
|
||
|
|
is_active = 1
|
||
|
|
AND user_name IS NOT NULL
|
||
|
|
</select>
|
||
|
|
<select id="checkIdNumberUnique" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
select user_id as userId, id_number as idNumber
|
||
|
|
from sys_user
|
||
|
|
where id_number = #{idNumber}
|
||
|
|
and is_active = '1' limit 1
|
||
|
|
</select>
|
||
|
|
<select id="selectUserByUserNames" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
SELECT suo.org_id AS orgId
|
||
|
|
FROM sys_user su
|
||
|
|
LEFT JOIN sys_user_org suo ON suo.user_id = su.user_id
|
||
|
|
AND suo.is_active = 1
|
||
|
|
WHERE su.is_active = 1
|
||
|
|
AND su.user_name = #{userName}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="getSelectUserCurrent" resultType="com.bonus.system.api.domain.SysUser">
|
||
|
|
SELECT
|
||
|
|
user_id AS userIds,
|
||
|
|
user_name AS userName,
|
||
|
|
id_number AS idNumber,
|
||
|
|
phone
|
||
|
|
FROM
|
||
|
|
sys_user
|
||
|
|
WHERE
|
||
|
|
is_active = 1
|
||
|
|
AND user_name IS NOT NULL and user_id!=#{userId}
|
||
|
|
</select>
|
||
|
|
</mapper>
|