新增客户
This commit is contained in:
@ -37,7 +37,9 @@
|
||||
</sql>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
u1.user_id
|
||||
u1
|
||||
.
|
||||
user_id
|
||||
as user_user_id, u1.dept_id as user_dept_id, u1.user_name as user_user_name,
|
||||
u1.nick_name as user_nick_name, u1.email as user_email, u1.phone as user_phone,
|
||||
u1.gender as user_gender, u1.avatar_name as user_avatar_name, u1.avatar_path as user_avatar_path,
|
||||
@ -48,12 +50,16 @@
|
||||
</sql>
|
||||
|
||||
<sql id="Job_Column_List">
|
||||
j . job_id
|
||||
j
|
||||
.
|
||||
job_id
|
||||
as job_id, j.name as job_name
|
||||
</sql>
|
||||
|
||||
<sql id="Role_Column_List">
|
||||
r . role_id
|
||||
r
|
||||
.
|
||||
role_id
|
||||
as role_id, r.name as role_name, r.level as role_level, r.data_scope as role_data_scope
|
||||
</sql>
|
||||
|
||||
@ -84,137 +90,10 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- user_user_id 是您在SELECT子句中创建的别名,但ORDER BY不能直接使用这个别名引用原始表 -->
|
||||
<select id="findAll" resultMap="BaseResultMap">
|
||||
select
|
||||
u.*,
|
||||
<include refid="Job_Column_List"/>,
|
||||
<include refid="Role_Column_List"/>
|
||||
from (
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from sys_user u1
|
||||
left join sys_dept d on u1.dept_id = d.dept_id
|
||||
<include refid="Whrer_Sql"/>
|
||||
order by u1.user_id desc
|
||||
<if test="criteria.offset != null">
|
||||
limit #{criteria.offset}, #{criteria.size}
|
||||
</if>
|
||||
) u
|
||||
left join sys_users_jobs suj on u.user_user_id = suj.user_id
|
||||
left join sys_job j on suj.job_id = j.job_id
|
||||
left join sys_users_roles sur on u.user_user_id = sur.user_id
|
||||
left join sys_role r on sur.role_id = r.role_id
|
||||
order by u.user_user_id desc
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 根据条件查询 用户 -->
|
||||
<select id="selectByQuery" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
SELECT u.*
|
||||
FROM sys_user u
|
||||
<where>
|
||||
<if test="userQuery.pid != null">
|
||||
AND u.pid = #{userQuery.pid}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY u.user_id DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询一个用户 -->
|
||||
<select id="selectByQueryOne" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select
|
||||
u.*
|
||||
from sys_user u
|
||||
<where>
|
||||
<if test="userQuery.pid != null">
|
||||
AND u.pid = #{userQuery.pid}
|
||||
</if>
|
||||
<if test="userQuery.nickName != null">
|
||||
AND u.nick_name = #{userQuery.nickName}
|
||||
</if>
|
||||
<if test="userQuery.user_name != null">
|
||||
AND u.user_name = #{userQuery.user_name}
|
||||
</if>
|
||||
<if test="userQuery.password != null">
|
||||
AND u.password = #{userQuery.password}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 根据租户ID查询用户 -->
|
||||
<select id="findByTenantId" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select
|
||||
u.*
|
||||
from sys_user u
|
||||
<where>
|
||||
<if test="tenantId != null">
|
||||
and u.tenant_id = #{tenantId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="countAll" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from sys_user u1
|
||||
<include refid="Whrer_Sql"/>
|
||||
</select>
|
||||
|
||||
<!-- 分页查询客户 -->
|
||||
<select id="findCustomers" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select
|
||||
u.user_id as id, u.nick_name , u.user_name, u.enabled, u.create_time
|
||||
from sys_user u
|
||||
<where>
|
||||
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
|
||||
and u.pid IN
|
||||
<foreach item="item" collection="criteria.ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
|
||||
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
|
||||
</if>
|
||||
<if test="criteria.enabled != null">
|
||||
and u.enabled = #{criteria.enabled}
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and u.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
order by u.user_id desc
|
||||
<if test="criteria.offset != null">
|
||||
limit #{criteria.offset}, #{criteria.size}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 获取分页总数 -->
|
||||
<select id="countCustomers" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from sys_user u
|
||||
<where>
|
||||
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
|
||||
and u.pid IN
|
||||
<foreach item="item" collection="criteria.ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
|
||||
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
|
||||
</if>
|
||||
<if test="criteria.enabled != null">
|
||||
and u.enabled = #{criteria.enabled}
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and u.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 查询所有客户 -->
|
||||
<select id="queryAllCustomers" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select u.user_id as id,
|
||||
select u.user_id as customerId,
|
||||
u.nick_name,
|
||||
u.user_name,
|
||||
u.enabled,
|
||||
@ -231,207 +110,21 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="findByuser_name" resultMap="BaseResultMap">
|
||||
select
|
||||
u1.password user_password, u1.is_admin user_is_admin, u1.tenant_id,
|
||||
<include refid="Base_Column_List"/>
|
||||
from sys_user u1
|
||||
left join sys_dept d on u1.dept_id = d.dept_id
|
||||
where u1.user_name = #{user_name}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findByNickName" resultMap="BaseResultMap">
|
||||
select
|
||||
u1.password user_password, u1.is_admin user_is_admin, u1.tenant_id,
|
||||
<include refid="Base_Column_List"/>
|
||||
from sys_user u1
|
||||
left join sys_dept d on u1.dept_id = d.dept_id
|
||||
where u1.nick_name = #{nickName}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findByEmail" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select user_id as id, user_name
|
||||
from sys_user
|
||||
where email = #{email}
|
||||
</select>
|
||||
|
||||
<select id="findByPhone" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select user_id as id, user_name
|
||||
from sys_user
|
||||
where phone = #{phone}
|
||||
</select>
|
||||
|
||||
<select id="findByRoleId" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
SELECT u.user_id as id, u.user_name
|
||||
FROM sys_user u,
|
||||
sys_users_roles r
|
||||
WHERE u.user_id = r.user_id
|
||||
AND r.role_id = #{roleId}
|
||||
group by u.user_id
|
||||
</select>
|
||||
|
||||
<select id="findByRoleDeptId" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
SELECT u.*
|
||||
FROM sys_user u,
|
||||
sys_users_roles r,
|
||||
sys_roles_depts d
|
||||
WHERE u.user_id = r.user_id
|
||||
AND r.role_id = d.role_id
|
||||
AND d.dept_id = #{deptId}
|
||||
group by u.user_id
|
||||
</select>
|
||||
|
||||
<select id="findByMenuId" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
SELECT u.user_id as id, u.user_name
|
||||
FROM sys_user u,
|
||||
sys_users_roles ur,
|
||||
sys_roles_menus rm
|
||||
WHERE u.user_id = ur.user_id
|
||||
AND ur.role_id = rm.role_id
|
||||
AND rm.menu_id = #{menuId}
|
||||
group by u.user_id
|
||||
</select>
|
||||
|
||||
<select id="countByJobs" resultType="int">
|
||||
SELECT count(*) FROM sys_user u, sys_users_jobs j
|
||||
WHERE u.user_id = j.user_id AND j.job_id IN
|
||||
<foreach collection="jobIds" item="jobId" open="(" separator="," close=")">
|
||||
#{jobId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="countByDepts" resultType="int">
|
||||
SELECT count(*) FROM sys_user u
|
||||
WHERE u.dept_id IN
|
||||
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="countByRoles" resultType="int">
|
||||
SELECT count(*) FROM sys_user u, sys_users_roles r
|
||||
WHERE u.user_id = r.user_id AND r.role_id in
|
||||
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
<update id="resetPwd">
|
||||
update sys_user set password = #{pwd}
|
||||
where user_id in
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 获取当前用户以及子用户 -->
|
||||
<select id="getSubUsers" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
SELECT u.user_id AS id,
|
||||
u.nick_name,
|
||||
u.user_name,
|
||||
u.enabled,
|
||||
u.create_time
|
||||
FROM sys_user u
|
||||
WHERE u.pid = #{currentUserId}
|
||||
OR u.user_id = #{currentUserId}
|
||||
</select>
|
||||
|
||||
<!-- 获取当前用户以及子用户(递归) -->
|
||||
<select id="findUserTree1" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
WITH RECURSIVE UserTree AS (
|
||||
-- 初始查询:查找指定用户自己
|
||||
SELECT user_id AS id, user_name, pid
|
||||
FROM sys_user
|
||||
WHERE user_id = #{currentUserId} -- 替换为你要查询的用户ID
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归部分:查找所有子节点
|
||||
SELECT u.user_id AS id, u.user_name, u.pid
|
||||
FROM sys_user u
|
||||
INNER JOIN UserTree ut ON u.pid = ut.id)
|
||||
SELECT *
|
||||
FROM UserTree;
|
||||
</select>
|
||||
|
||||
<!-- 获取当前用户以及子用户(递归)不包含本身 -->
|
||||
<select id="findUserTree" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
WITH RECURSIVE UserTree AS (
|
||||
-- 初始查询:查找当前用户的直接子节点
|
||||
SELECT user_id AS id, user_name, pid
|
||||
FROM sys_user
|
||||
WHERE pid = #{currentUserId} -- 当前用户的子节点
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归部分:查找所有后代节点
|
||||
SELECT u.user_id AS id, u.user_name, u.pid
|
||||
FROM sys_user u
|
||||
INNER JOIN UserTree ut ON u.pid = ut.id)
|
||||
SELECT *
|
||||
FROM UserTree;
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findCustomers1" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select
|
||||
u.user_id as id, u.nick_name , u.user_name, u.enabled, u.create_time,
|
||||
u.pid -- 确保包含 pid 字段
|
||||
<!-- 根据条件查询客户 -->
|
||||
<select id="queryCustomers" resultType="com.fuyuanshen.fyscustomer.domain.Customer"
|
||||
parameterType="com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria">
|
||||
select u.user_id as customerId,
|
||||
u.nick_name,
|
||||
u.user_name,
|
||||
u.enabled,
|
||||
u.create_time
|
||||
from sys_user u
|
||||
<where>
|
||||
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
|
||||
and u.pid IN
|
||||
<foreach item="item" collection="criteria.ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
|
||||
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
|
||||
</if>
|
||||
<if test="criteria.enabled != null">
|
||||
and u.enabled = #{criteria.enabled}
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and u.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
<if test="criteria.customerName != null and criteria.customerName.trim() != ''">
|
||||
and u.user_name = concat('%', TRIM(#{criteria.customerName}), '%')
|
||||
</if>
|
||||
</where>
|
||||
order by u.user_id desc
|
||||
<if test="criteria.offset != null">
|
||||
limit #{criteria.offset}, #{criteria.size}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="findUsersWithAncestorsByIds" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
WITH RECURSIVE user_tree AS (
|
||||
SELECT * FROM sys_user WHERE user_id IN
|
||||
<foreach item="item" collection="ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
UNION ALL
|
||||
SELECT u.* FROM sys_user u
|
||||
INNER JOIN user_tree ut ON u.user_id = ut.pid
|
||||
)
|
||||
SELECT DISTINCT * FROM user_tree;
|
||||
</select>
|
||||
|
||||
<!-- 获取当前用户的祖先用户 -->
|
||||
<select id="findAncestorsById" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
WITH RECURSIVE user_ancestors AS (SELECT user_id, pid, tenant_id
|
||||
FROM sys_user
|
||||
WHERE user_id = #{currentUserId}
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT u.user_id, u.pid, u.tenant_id
|
||||
FROM sys_user u
|
||||
INNER JOIN user_ancestors a ON u.user_id = a.pid)
|
||||
SELECT *
|
||||
FROM user_ancestors
|
||||
WHERE user_id != #{currentUserId}
|
||||
AND user_id IS NOT NULL;
|
||||
</select>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user