forked from dyf/fys-Multi-tenant
客户管理 接口
This commit is contained in:
@ -65,6 +65,12 @@
|
||||
<artifactId>fys-common-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 客户管理模块 -->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-customer</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 设备管理模块 -->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.fuyuanshen.fyscustomer.controller;
|
||||
|
||||
import com.fuyuanshen.common.core.domain.ResponseVO;
|
||||
import com.fuyuanshen.fyscustomer.domain.Customer;
|
||||
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
|
||||
import com.fuyuanshen.fyscustomer.service.CustomerService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-07-0114:20
|
||||
*/
|
||||
@Slf4j
|
||||
@Tag(name = "WEB:客户管理", description = "WEB:客户管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/customers")
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerController {
|
||||
|
||||
private final CustomerService customerService;
|
||||
|
||||
|
||||
|
||||
@GetMapping(value = "/allCustomer")
|
||||
@Operation(summary = "查询所有客户")
|
||||
public ResponseVO<List<Customer>> queryAllCustomer(UserQueryCriteria criteria) {
|
||||
List<Customer> customers = customerService.queryAllCustomers(criteria);
|
||||
return ResponseVO.success(customers);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package com.fuyuanshen.fyscustomer.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.core.constant.SystemConstants;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户对象 sys_user
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_user")
|
||||
public class Customer extends TenantEntity {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableId(value = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 父id
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户类型(sys_user系统用户)
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 用户性别
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private Long avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@TableField(
|
||||
insertStrategy = FieldStrategy.NOT_EMPTY,
|
||||
updateStrategy = FieldStrategy.NOT_EMPTY,
|
||||
whereStrategy = FieldStrategy.NOT_EMPTY
|
||||
)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 1代表删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 最后登录IP
|
||||
*/
|
||||
private String loginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
|
||||
public Customer(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isSuperAdmin() {
|
||||
return SystemConstants.SUPER_ADMIN_ID.equals(this.userId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2019-2025 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.fuyuanshen.fyscustomer.domain.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Data
|
||||
public class UserQueryCriteria implements Serializable {
|
||||
|
||||
@Schema(name = "ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(name = "ids")
|
||||
private Set<Long> ids;
|
||||
|
||||
@Schema(name = "多个ID")
|
||||
private Set<Long> deptIds = new HashSet<>();
|
||||
|
||||
@Schema(name = "模糊查询")
|
||||
private String blurry;
|
||||
|
||||
@Schema(name = "是否启用")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(name = "部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@Schema(name = "创建时间")
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer page = 1;
|
||||
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer size = 10;
|
||||
|
||||
@Schema(name = "偏移量", hidden = true)
|
||||
private long offset;
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
* 0 app
|
||||
* 1 小程序
|
||||
*/
|
||||
@Schema(name = "用户类型 0 app 1 小程序")
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
@Schema(name = "APP/小程序账号")
|
||||
private String username;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.fuyuanshen.fyscustomer.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fuyuanshen.fyscustomer.domain.Customer;
|
||||
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-07-0114:37
|
||||
*/
|
||||
@Mapper
|
||||
public interface CustomerMapper extends BaseMapper<Customer> {
|
||||
|
||||
/**
|
||||
* 查询所有客户
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<Customer> queryAllCustomers(@Param("criteria") UserQueryCriteria criteria);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.fuyuanshen.fyscustomer.service;
|
||||
|
||||
import com.fuyuanshen.fyscustomer.domain.Customer;
|
||||
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-07-0114:31
|
||||
*/
|
||||
public interface CustomerService {
|
||||
|
||||
/**
|
||||
* 查询所有客户
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<Customer> queryAllCustomers(UserQueryCriteria criteria);
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.fuyuanshen.fyscustomer.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.fyscustomer.domain.Customer;
|
||||
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
|
||||
import com.fuyuanshen.fyscustomer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.fyscustomer.service.CustomerService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-07-0114:31
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
|
||||
|
||||
private final CustomerMapper customerMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有客户
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Customer> queryAllCustomers(UserQueryCriteria criteria) {
|
||||
List<Customer> users = customerMapper.queryAllCustomers(criteria);
|
||||
return users;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,438 @@
|
||||
<?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.fuyuanshen.fyscustomer.mapper.CustomerMapper">
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
<id column="user_user_id" property="userId"/>
|
||||
<result column="user_dept_id" property="deptId"/>
|
||||
<result column="user_username" property="userName"/>
|
||||
<result column="user_nick_name" property="nickName"/>
|
||||
<result column="user_email" property="email"/>
|
||||
<result column="user_pid" property="pid"/>
|
||||
<result column="user_create_by" property="createBy"/>
|
||||
<result column="user_update_by" property="updateBy"/>
|
||||
<result column="user_create_time" property="createTime"/>
|
||||
<result column="user_update_time" property="updateTime"/>
|
||||
<result column="tenant_id" property="tenantId"/>
|
||||
|
||||
</resultMap>
|
||||
|
||||
<!-- 公共查询字段 -->
|
||||
<sql id="selectUserColumns">
|
||||
u
|
||||
.
|
||||
user_user_id
|
||||
AS user_user_id,
|
||||
u.username,
|
||||
u.nick_name AS nickName,
|
||||
u.email,
|
||||
u.phone,
|
||||
u.gender,
|
||||
u.avatar_name AS avatarName,
|
||||
u.avatar_path AS avatarPath,
|
||||
u.enabled,
|
||||
IF(u.is_admin = 1, true, false) AS isAdmin,
|
||||
u.pwd_reset_time AS pwdResetTime,
|
||||
u.dept_id AS deptId,
|
||||
u.tenant_id AS tenantId
|
||||
</sql>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
u1.user_id
|
||||
as user_user_id, u1.dept_id as user_dept_id, u1.username as user_username,
|
||||
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,
|
||||
u1.enabled as user_enabled, u1.pwd_reset_time as user_pwd_reset_time, u1.create_by as user_create_by,
|
||||
u1.update_by as user_update_by, u1.create_time as user_create_time, u1.update_time as user_update_time,
|
||||
u1.user_level, u1.pid as user_pid,u1.is_admin AS admin,
|
||||
d.dept_id as dept_id, d.name as dept_name
|
||||
</sql>
|
||||
|
||||
<sql id="Job_Column_List">
|
||||
j . job_id
|
||||
as job_id, j.name as job_name
|
||||
</sql>
|
||||
|
||||
<sql id="Role_Column_List">
|
||||
r . role_id
|
||||
as role_id, r.name as role_name, r.level as role_level, r.data_scope as role_data_scope
|
||||
</sql>
|
||||
|
||||
<sql id="Whrer_Sql">
|
||||
<where>
|
||||
<if test="criteria.id != null">
|
||||
and u1.user_id = #{criteria.id}
|
||||
</if>
|
||||
<if test="criteria.enabled != null">
|
||||
and u1.enabled = #{criteria.enabled}
|
||||
</if>
|
||||
<if test="criteria.deptIds != null and criteria.deptIds.size() != 0">
|
||||
and u1.dept_id in
|
||||
<foreach collection="criteria.deptIds" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="criteria.blurry != null and criteria.blurry != ''">
|
||||
and (
|
||||
u1.username like concat('%', #{criteria.blurry}, '%')
|
||||
or u1.nick_name like concat('%', #{criteria.blurry}, '%')
|
||||
or u1.email like concat('%', #{criteria.blurry}, '%')
|
||||
)
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and u1.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
</if>
|
||||
</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.username != null">
|
||||
AND u.username = #{userQuery.username}
|
||||
</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.username, 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,
|
||||
u.nick_name,
|
||||
u.username,
|
||||
u.enabled,
|
||||
u.create_time
|
||||
from sys_user u
|
||||
<where>
|
||||
<!-- 增加非空判断 -->
|
||||
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
|
||||
u.pid IN
|
||||
<foreach item="item" collection="criteria.ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="findByUsername" 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.username = #{username}
|
||||
</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, username
|
||||
from sys_user
|
||||
where email = #{email}
|
||||
</select>
|
||||
|
||||
<select id="findByPhone" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
select user_id as id, username
|
||||
from sys_user
|
||||
where phone = #{phone}
|
||||
</select>
|
||||
|
||||
<select id="findByRoleId" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
|
||||
SELECT u.user_id as id, u.username
|
||||
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.username
|
||||
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.username,
|
||||
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, username, pid
|
||||
FROM sys_user
|
||||
WHERE user_id = #{currentUserId} -- 替换为你要查询的用户ID
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归部分:查找所有子节点
|
||||
SELECT u.user_id AS id, u.username, 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, username, pid
|
||||
FROM sys_user
|
||||
WHERE pid = #{currentUserId} -- 当前用户的子节点
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归部分:查找所有后代节点
|
||||
SELECT u.user_id AS id, u.username, 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.username, u.enabled, u.create_time,
|
||||
u.pid -- 确保包含 pid 字段
|
||||
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="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>
|
||||
|
||||
|
||||
</mapper>
|
6
fys-modules/fys-customer/web2/WEB-INF/web.xml
Normal file
6
fys-modules/fys-customer/web2/WEB-INF/web.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
@ -16,6 +16,7 @@
|
||||
<module>fys-system</module>
|
||||
<module>fys-workflow</module>
|
||||
<module>fys-equipment</module>
|
||||
<module>fys-customer</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>fys-modules</artifactId>
|
||||
|
7
pom.xml
7
pom.xml
@ -351,6 +351,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 客户管理模块 -->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-customer</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-job</artifactId>
|
||||
|
Reference in New Issue
Block a user