新增:getAdminsByPhone()方法

This commit is contained in:
2025-03-02 15:50:46 +08:00
parent b73b45169b
commit 05ffbb3c75
8 changed files with 307 additions and 241 deletions

View File

@@ -23,6 +23,7 @@ import com.gxwebsoft.common.core.security.JwtSubject;
import com.gxwebsoft.common.core.security.JwtUtil;
import com.gxwebsoft.common.core.utils.CacheClient;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
@@ -54,7 +55,9 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 登录认证控制器
@@ -501,19 +504,27 @@ public class MainController extends BaseController {
String message = "验证码不正确";
return fail(message, null);
}
user = userService.getAdminByPhone(phone);
if(user == null){
// 单用户登录
final List<User> adminsByPhone = userService.getAdminsByPhone(param);
if(adminsByPhone.isEmpty()){
return fail("用户不存在",null);
}
user = adminsByPhone.get(0);
// 签发token
String access_token = JwtUtil.buildToken(new JwtSubject(phone, user.getTenantId()),
tokenExpireTime, configProperties.getTokenKey());
// 同一个手机号码存在多个管理员账号
if(adminsByPhone.size() > 1){
String message = "请选择登录用户";
user.setHasAdminsByPhone(true);
return success(message, new LoginResult(access_token, user));
}
return success("登录成功", new LoginResult(access_token, user));
}
// 普通用户登录
if(tenantId == null){
return fail("TenantId不存在",null);
return fail("用户不存在",null);
}
if (!code.equals(redisUtil.get(key)) && !"789789".equals(code)) {
String message = "验证码不正确";

View File

@@ -14,6 +14,7 @@ import com.gxwebsoft.common.core.security.JwtUtil;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.web.*;
import com.gxwebsoft.common.system.entity.*;
import com.gxwebsoft.common.system.param.LoginParam;
import com.gxwebsoft.common.system.param.UserImportParam;
import com.gxwebsoft.common.system.param.UserParam;
import com.gxwebsoft.common.system.result.LoginResult;
@@ -509,4 +510,10 @@ public class UserController extends BaseController {
return success("统计成功", userService.orgNumInPark(param));
}
@PreAuthorize("hasAuthority('sys:auth:user')")
@ApiOperation("查询全部用户")
@GetMapping("/listAdminsByPhoneAll")
public ApiResult<List<User>> listAdminsByPhoneAll(LoginParam param){
return success(userService.getAdminsByPhone(param));
}
}

View File

@@ -335,6 +335,13 @@ public class User implements UserDetails {
@TableField(exist = false)
private Boolean hasParent;
@ApiModelProperty("同一个手机号码存在多个管理员账号")
@TableField(exist = false)
private Boolean hasAdminsByPhone;
@ApiModelProperty("模板ID")
private Integer templateId;
// @ApiModelProperty("企业信息")
// @TableField(exist = false)
// private Company companyInfo;

View File

@@ -1,6 +1,7 @@
package com.gxwebsoft.common.system.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.common.system.entity.User;
@@ -58,4 +59,9 @@ public interface UserMapper extends BaseMapper<User> {
@InterceptorIgnore(tenantLine = "true")
User selectByUserId(@Param("userId") Integer userId);
@InterceptorIgnore(tenantLine = "true")
List<User> selectListAllRel(@Param("param") UserParam param);
}

View File

@@ -2,246 +2,255 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.gxwebsoft.common.system.mapper.UserMapper">
<!-- 性别字典查询sql -->
<sql id="selectSexDictSql">
SELECT ta.*
FROM sys_dictionary_data ta
LEFT JOIN sys_dictionary tb
ON ta.dict_id = tb.dict_id
AND tb.deleted = 0
WHERE ta.deleted = 0
AND tb.dict_code = 'sex'
</sql>
<!-- 性别字典查询sql -->
<sql id="selectSexDictSql">
SELECT ta.*
FROM sys_dictionary_data ta
LEFT JOIN sys_dictionary tb
ON ta.dict_id = tb.dict_id
AND tb.deleted = 0
WHERE ta.deleted = 0
AND tb.dict_code = 'sex'
</sql>
<!-- 用户角色查询sql -->
<sql id="selectUserRoleSql">
SELECT a.user_id,
GROUP_CONCAT(b.role_name) role_name
FROM sys_user_role a
LEFT JOIN sys_role b ON a.role_id = b.role_id
GROUP BY a.user_id
</sql>
<!-- 用户角色查询sql -->
<sql id="selectUserRoleSql">
SELECT a.user_id,
GROUP_CONCAT(b.role_name) role_name
FROM sys_user_role a
LEFT JOIN sys_role b ON a.role_id = b.role_id
GROUP BY a.user_id
</sql>
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*,
b.organization_name,
c.dict_data_name sex_name,
e.name as groupName,
f.name as gradeName,
g.company_name as companyName,g.company_logo as logo,
t.tenant_name as tenantName
FROM sys_user a
LEFT JOIN sys_organization b ON a.organization_id = b.organization_id
LEFT JOIN (
<include refid="selectSexDictSql"/>
) c ON a.sex = c.dict_data_code
LEFT JOIN(
<include refid="selectUserRoleSql"/>
) d ON a.user_id = d.user_id
LEFT JOIN sys_user_group e ON a.group_id = e.group_id
LEFT JOIN sys_user_grade f ON a.grade_id = f.grade_id
LEFT JOIN sys_tenant t ON a.tenant_id = t.tenant_id
LEFT JOIN sys_company g ON g.tenant_id = t.tenant_id
<where>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.username != null">
AND a.username LIKE CONCAT('%', #{param.username}, '%')
</if>
<if test="param.uid != null">
AND a.uid = #{param.uid}
</if>
<if test="param.userCode != null">
AND a.user_code = #{param.userCode}
</if>
<if test="param.nickname != null">
AND a.nickname LIKE CONCAT('%', #{param.nickname}, '%')
</if>
<if test="param.type != null">
AND a.type = #{param.type}
</if>
<if test="param.sex != null">
AND a.sex = #{param.sex}
</if>
<if test="param.phone != null">
AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
</if>
<if test="param.email != null">
AND a.email LIKE CONCAT('%', #{param.email}, '%')
</if>
<if test="param.emailVerified != null">
AND a.email_verified = #{param.emailVerified}
</if>
<if test="param.realName != null">
AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
</if>
<if test="param.companyName != null">
AND a.company_name LIKE CONCAT('%', #{param.companyName}, '%')
</if>
<if test="param.idCard != null">
AND a.id_card LIKE CONCAT('%', #{param.idCard}, '%')
</if>
<if test="param.birthday != null">
AND a.birthday LIKE CONCAT('%', #{param.birthday}, '%')
</if>
<if test="param.organizationId != null">
AND a.organization_id = #{param.organizationId}
</if>
<if test="param.groupId != null">
AND a.group_id = #{param.groupId}
</if>
<if test="param.isStaff != null">
AND a.organization_id > 0
</if>
<if test="param.merchantId != null">
AND a.merchant_id = #{param.merchantId}
</if>
<if test="param.platform != null">
AND a.platform = #{param.platform}
</if>
<if test="param.status != null">
AND a.`status` = #{param.status}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.recommend != null">
AND a.recommend = #{param.recommend}
</if>
<if test="param.gradeId != null">
AND a.grade_id = #{param.gradeId}
</if>
<if test="param.isAdmin != null">
AND a.is_admin = #{param.isAdmin}
</if>
<if test="param.isOrganizationAdmin != null">
AND a.is_organization_admin = #{param.isOrganizationAdmin}
</if>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
</if>
<if test="param.roleId != null">
AND a.user_id IN (SELECT user_id FROM sys_user_role WHERE role_id=#{param.roleId})
</if>
<if test="param.roleCode != null">
AND a.user_id IN (SELECT user_id FROM sys_user_role WHERE role_code=#{param.roleCode})
</if>
<if test="param.userIds != null">
AND a.user_id IN
<foreach collection="param.userIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.organizationIds != null">
AND a.organization_id IN
<foreach collection="param.organizationIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.phones != null">
AND a.phone IN
<foreach collection="param.phones" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.province != null">
AND a.province LIKE CONCAT('%', #{param.province}, '%')
</if>
<if test="param.city != null">
AND a.city LIKE CONCAT('%', #{param.city}, '%')
</if>
<if test="param.region != null">
AND a.region LIKE CONCAT('%', #{param.region}, '%')
</if>
<if test="param.organizationName != null">
AND b.organization_name LIKE CONCAT('%', #{param.organizationName}, '%')
</if>
<if test="param.sexName != null">
AND c.dict_data_name = #{param.sexName}
</if>
<if test="param.expertType != null">
AND a.expert_type = #{param.expertType}
</if>
<if test="param.keywords != null">
AND (
a.username = #{param.keywords}
OR a.user_id = #{param.keywords}
OR a.id_card = #{param.keywords}
OR a.merchant_id = #{param.keywords}
OR a.nickname LIKE CONCAT('%', #{param.keywords}, '%')
OR a.real_name LIKE CONCAT('%', #{param.keywords}, '%')
OR a.phone LIKE CONCAT('%', #{param.keywords}, '%')
OR a.email = #{param.keywords}
)
</if>
<if test="param.parentId != null">
AND a.organization_id IN (SELECT organization_id FROM sys_organization WHERE parent_id=#{param.parentId})
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.User">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.User">
<include refid="selectSql"></include>
</select>
<!-- 根据账号查询 -->
<select id="selectByUsername" resultType="com.gxwebsoft.common.system.entity.User">
SELECT a.* ,
b.organization_name,
c.dict_data_name sex_name
FROM sys_user a
LEFT JOIN sys_organization b ON a.organization_id = b.organization_id
LEFT JOIN (
<include refid="selectSexDictSql"/>
) c ON a.sex = c.dict_data_code
<where>
AND a.deleted = 0
AND (a.username = #{username} OR a.phone = #{username} OR a.email = #{username})
AND a.tenant_id = #{tenantId}
<!-- <if test="tenantId != null">-->
<!-- AND a.tenant_id = #{tenantId}-->
<!-- </if>-->
<!-- <if test="tenantId == null">-->
<!-- AND a.tenant_id = 1-->
<!-- </if>-->
</where>
LIMIT 1
</select>
<!-- 根据手机号码查询 -->
<select id="selectByPhone" resultType="com.gxwebsoft.common.system.entity.User">
SELECT a.*
FROM sys_user a
<where>
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*,
b.organization_name,
c.dict_data_name sex_name,
e.name as groupName,
f.name as gradeName,
g.company_name as companyName,g.company_logo as logo,
t.tenant_name as tenantName
FROM sys_user a
LEFT JOIN sys_organization b ON a.organization_id = b.organization_id
LEFT JOIN (
<include refid="selectSexDictSql"/>
) c ON a.sex = c.dict_data_code
LEFT JOIN(
<include refid="selectUserRoleSql"/>
) d ON a.user_id = d.user_id
LEFT JOIN sys_user_group e ON a.group_id = e.group_id
LEFT JOIN sys_user_grade f ON a.grade_id = f.grade_id
LEFT JOIN sys_tenant t ON a.tenant_id = t.tenant_id
LEFT JOIN sys_company g ON g.tenant_id = t.tenant_id
<where>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.username != null">
AND a.username LIKE CONCAT('%', #{param.username}, '%')
</if>
<if test="param.uid != null">
AND a.uid = #{param.uid}
</if>
<if test="param.userCode != null">
AND a.user_code = #{param.userCode}
</if>
<if test="param.nickname != null">
AND a.nickname LIKE CONCAT('%', #{param.nickname}, '%')
</if>
<if test="param.type != null">
AND a.type = #{param.type}
</if>
<if test="param.sex != null">
AND a.sex = #{param.sex}
</if>
<if test="param.phone != null">
AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
</if>
<if test="param.email != null">
AND a.email LIKE CONCAT('%', #{param.email}, '%')
</if>
<if test="param.emailVerified != null">
AND a.email_verified = #{param.emailVerified}
</if>
<if test="param.realName != null">
AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
</if>
<if test="param.companyName != null">
AND a.company_name LIKE CONCAT('%', #{param.companyName}, '%')
</if>
<if test="param.idCard != null">
AND a.id_card LIKE CONCAT('%', #{param.idCard}, '%')
</if>
<if test="param.birthday != null">
AND a.birthday LIKE CONCAT('%', #{param.birthday}, '%')
</if>
<if test="param.organizationId != null">
AND a.organization_id = #{param.organizationId}
</if>
<if test="param.groupId != null">
AND a.group_id = #{param.groupId}
</if>
<if test="param.isStaff != null">
AND a.organization_id > 0
</if>
<if test="param.merchantId != null">
AND a.merchant_id = #{param.merchantId}
</if>
<if test="param.platform != null">
AND a.platform = #{param.platform}
</if>
<if test="param.status != null">
AND a.`status` = #{param.status}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.recommend != null">
AND a.recommend = #{param.recommend}
</if>
<if test="param.gradeId != null">
AND a.grade_id = #{param.gradeId}
</if>
<if test="param.isAdmin != null">
AND a.is_admin = #{param.isAdmin}
</if>
<if test="param.templateId != null">
AND a.template_id = #{param.templateId}
</if>
<if test="param.isOrganizationAdmin != null">
AND a.is_organization_admin = #{param.isOrganizationAdmin}
</if>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
AND a.phone = #{phone}
<if test="tenantId != null">
AND a.tenant_id = #{tenantId}
</if>
<if test="tenantId == null">
AND a.tenant_id = 1
</if>
</where>
LIMIT 1
</select>
</if>
<if test="param.roleId != null">
AND a.user_id IN (SELECT user_id FROM sys_user_role WHERE role_id=#{param.roleId})
</if>
<if test="param.roleCode != null">
AND a.user_id IN (SELECT user_id FROM sys_user_role WHERE role_code=#{param.roleCode})
</if>
<if test="param.userIds != null">
AND a.user_id IN
<foreach collection="param.userIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.organizationIds != null">
AND a.organization_id IN
<foreach collection="param.organizationIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.phones != null">
AND a.phone IN
<foreach collection="param.phones" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.province != null">
AND a.province LIKE CONCAT('%', #{param.province}, '%')
</if>
<if test="param.city != null">
AND a.city LIKE CONCAT('%', #{param.city}, '%')
</if>
<if test="param.region != null">
AND a.region LIKE CONCAT('%', #{param.region}, '%')
</if>
<if test="param.organizationName != null">
AND b.organization_name LIKE CONCAT('%', #{param.organizationName}, '%')
</if>
<if test="param.sexName != null">
AND c.dict_data_name = #{param.sexName}
</if>
<if test="param.expertType != null">
AND a.expert_type = #{param.expertType}
</if>
<if test="param.tenantId != null">
AND a.tenant_id = #{param.tenantId}
</if>
<if test="param.keywords != null">
AND (
a.username = #{param.keywords}
OR a.user_id = #{param.keywords}
OR a.id_card = #{param.keywords}
OR a.merchant_id = #{param.keywords}
OR a.nickname LIKE CONCAT('%', #{param.keywords}, '%')
OR a.real_name LIKE CONCAT('%', #{param.keywords}, '%')
OR a.phone LIKE CONCAT('%', #{param.keywords}, '%')
OR a.email = #{param.keywords}
)
</if>
<if test="param.parentId != null">
AND a.organization_id IN (SELECT organization_id FROM sys_organization WHERE parent_id=#{param.parentId})
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.User">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.User">
<include refid="selectSql"></include>
</select>
<!-- 根据账号查询 -->
<select id="selectByUsername" resultType="com.gxwebsoft.common.system.entity.User">
SELECT a.* ,
b.organization_name,
c.dict_data_name sex_name
FROM sys_user a
LEFT JOIN sys_organization b ON a.organization_id = b.organization_id
LEFT JOIN (
<include refid="selectSexDictSql"/>
) c ON a.sex = c.dict_data_code
<where>
AND a.deleted = 0
AND (a.username = #{username} OR a.phone = #{username} OR a.email = #{username})
AND a.tenant_id = #{tenantId}
<!-- <if test="tenantId != null">-->
<!-- AND a.tenant_id = #{tenantId}-->
<!-- </if>-->
<!-- <if test="tenantId == null">-->
<!-- AND a.tenant_id = 1-->
<!-- </if>-->
</where>
LIMIT 1
</select>
<!-- 根据手机号码查询 -->
<select id="selectByPhone" resultType="com.gxwebsoft.common.system.entity.User">
SELECT a.*
FROM sys_user a
<where>
AND a.deleted = 0
AND a.phone = #{phone}
<if test="tenantId != null">
AND a.tenant_id = #{tenantId}
</if>
<if test="tenantId == null">
AND a.tenant_id = 1
</if>
</where>
LIMIT 1
</select>
<!-- 查询单条数据 -->
<select id="getOne" resultType="com.gxwebsoft.common.system.entity.User">
SELECT * FROM sys_user WHERE user_id = #{param.userId} and deleted = 0
SELECT *
FROM sys_user
WHERE user_id = #{param.userId}
and deleted = 0
</select>
<!-- 查询统计数据 -->
@@ -259,11 +268,15 @@
<!-- 更新用户信息 -->
<update id="updateByUserId">
UPDATE sys_user SET grade_id = #{param.gradeId} WHERE user_id = #{param.userId}
UPDATE sys_user
SET grade_id = #{param.gradeId}
WHERE user_id = #{param.userId}
</update>
<select id="selectByUserId" resultType="com.gxwebsoft.common.system.entity.User">
SELECT * FROM sys_user WHERE user_id = #{userId}
SELECT *
FROM sys_user
WHERE user_id = #{userId}
</select>
<!-- 根据手机号码查询 -->
@@ -273,8 +286,13 @@
<where>
AND a.deleted = 0
AND a.phone = #{phone}
AND (a.username = 'superAdmin' OR a.username = 'admin')
AND (a.username = 'superAdmin' OR a.username = 'admin' OR a.is_admin = 1)
</where>
</select>
<select id="selectListAllRel" resultType="com.gxwebsoft.common.system.entity.User">
<include refid="selectSql"></include>
LIMIT 50
</select>
</mapper>

View File

@@ -232,6 +232,9 @@ public class UserParam extends BaseParam {
@TableField(exist = false)
private Date settlementTime;
@ApiModelProperty("模板id")
private Integer templateId;
@ApiModelProperty("报餐时间")
@TableField(exist = false)
private String deliveryTime;

View File

@@ -3,6 +3,7 @@ package com.gxwebsoft.common.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.param.LoginParam;
import com.gxwebsoft.common.system.param.UserParam;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -116,4 +117,6 @@ public interface UserService extends IService<User>, UserDetailsService {
Integer userNumInPark(UserParam param);
Integer orgNumInPark(UserParam param);
List<User> getAdminsByPhone(LoginParam param);
}

View File

@@ -13,6 +13,7 @@ import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.*;
import com.gxwebsoft.common.system.mapper.UserMapper;
import com.gxwebsoft.common.system.param.LoginParam;
import com.gxwebsoft.common.system.param.UserParam;
import com.gxwebsoft.common.system.service.*;
import org.springframework.security.core.userdetails.UserDetails;
@@ -274,7 +275,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
public User getAdminByPhone(String phone) {
return baseMapper.selectAdminByPhone(phone);
return baseMapper.selectAdminByPhone(phone);
}
@Override
public List<User> getAdminsByPhone(LoginParam param){
final UserParam userParam = new UserParam();
userParam.setPhone(param.getPhone());
userParam.setIsAdmin(true);
userParam.setTenantId(param.getTenantId());
userParam.setLimit(50L);
return baseMapper.selectListAllRel(userParam);
}
/**