新增:AND a.username = 'admin'
This commit is contained in:
@@ -75,7 +75,8 @@ public class MybatisPlusConfig {
|
||||
"sys_website_field",
|
||||
"sys_modules",
|
||||
"sys_environment",
|
||||
"sys_components"
|
||||
"sys_components",
|
||||
"sys_company"
|
||||
).contains(tableName);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 常用工具方法
|
||||
@@ -232,4 +233,21 @@ public class CommonUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证给定的字符串是否为有效的中国大陆手机号码。
|
||||
*
|
||||
* @param phoneNumber 要验证的电话号码字符串
|
||||
* @return 如果字符串是有效的手机号码,则返回true;否则返回false
|
||||
*/
|
||||
public static boolean isValidPhoneNumber(String phoneNumber) {
|
||||
// 定义手机号码的正则表达式
|
||||
String regex = "^1[3-9]\\d{9}$";
|
||||
|
||||
// 创建Pattern对象
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
// 使用matcher方法创建Matcher对象并进行匹配
|
||||
return pattern.matcher(phoneNumber).matches();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.gxwebsoft.common.system.controller;
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.CommonRequest;
|
||||
@@ -86,6 +87,8 @@ public class MainController extends BaseController {
|
||||
@ApiOperation("用户登录")
|
||||
@PostMapping("/login")
|
||||
public ApiResult<LoginResult> login(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
String username = param.getUsername();
|
||||
Integer tenantId;
|
||||
if(param.getTenantId() != null){
|
||||
@@ -113,11 +116,6 @@ public class MainController extends BaseController {
|
||||
// 登录账号|手机号码|邮箱登录
|
||||
User user = userService.getByUsername(username, tenantId);
|
||||
|
||||
// 租户管理员模式
|
||||
if (param.getIsAdmin() != null) {
|
||||
user = userService.getAdminByPhone(param.getPhone());
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
String message = "账号不存在";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
@@ -145,8 +143,7 @@ public class MainController extends BaseController {
|
||||
|
||||
// 登录成功
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_LOGIN, null, tenantId, request);
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
|
||||
final JSONObject register = cacheClient.getSettingInfo("register", tenantId);
|
||||
if (register != null) {
|
||||
System.out.println("register = " + register);
|
||||
@@ -343,6 +340,11 @@ public class MainController extends BaseController {
|
||||
String userTemplateId = "SMS_257840118";
|
||||
String sign = "南宁网宿科技";
|
||||
|
||||
if (!CommonUtil.isValidPhoneNumber(param.getPhone())) {
|
||||
return fail("请输入有效的手机号码");
|
||||
}
|
||||
|
||||
|
||||
// 读取租户的短信配置
|
||||
if (getTenantId() != null) {
|
||||
String string = redisUtil.get("setting:sms:" + getTenantId());
|
||||
@@ -456,6 +458,8 @@ public class MainController extends BaseController {
|
||||
@ApiOperation("短信验证码登录")
|
||||
@PostMapping("/loginBySms")
|
||||
public ApiResult<LoginResult> loginBySms(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
final String phone = param.getPhone();
|
||||
final Integer tenantId = getTenantId();
|
||||
final String code = param.getCode();
|
||||
@@ -464,11 +468,6 @@ public class MainController extends BaseController {
|
||||
}
|
||||
User user = userService.getByUsername(phone, tenantId);
|
||||
|
||||
// 租户管理员模式
|
||||
if(param.getIsAdmin() != null){
|
||||
user = userService.getAdminByPhone(param.getPhone());
|
||||
}
|
||||
|
||||
// 验证码校验
|
||||
String key = "code:" + param.getPhone();
|
||||
if (!code.equals(redisUtil.get(key)) && !"789789".equals(code)) {
|
||||
@@ -491,8 +490,6 @@ public class MainController extends BaseController {
|
||||
}
|
||||
loginRecordService.saveAsync(phone, LoginRecord.TYPE_LOGIN, null, tenantId, request);
|
||||
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
final JSONObject register = cacheClient.getSettingInfo("register", tenantId);
|
||||
if (register != null) {
|
||||
final String ExpireTime = register.getString("tokenExpireTime");
|
||||
@@ -523,13 +520,33 @@ public class MainController extends BaseController {
|
||||
throw new BusinessException("验证码不正确");
|
||||
}
|
||||
|
||||
// 注册会员
|
||||
// 注册网站平台会员
|
||||
final User byPhone = userService.getByPhone(phone);
|
||||
if(ObjectUtil.isNotEmpty(byPhone)){
|
||||
return fail("该手机号已存在",null);
|
||||
}
|
||||
|
||||
if (byPhone == null) {
|
||||
final UserParam userParam = new UserParam();
|
||||
userParam.setPhone(phone);
|
||||
userParam.setTenantId(5);
|
||||
final User addUser = userService.addUser(userParam);
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(phone, addUser.getTenantId()),
|
||||
tokenExpireTime, configProperties.getTokenKey());
|
||||
return success("注册成功", new LoginResult(access_token, addUser));
|
||||
}
|
||||
|
||||
// 注册管理员
|
||||
if (userService.getAdminByPhone(phone) != null) {
|
||||
throw new BusinessException("该手机号码已注册");
|
||||
}
|
||||
// 添加租户
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTenantName(tenantName);
|
||||
tenant.setPhone(phone);
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
tenantService.save(tenant);
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ public class TenantController extends BaseController {
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("分页查询租户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -20,6 +21,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -36,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:41
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "用户")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user")
|
||||
@@ -83,6 +86,11 @@ public class UserController extends BaseController {
|
||||
public ApiResult<?> add(@RequestBody User user) {
|
||||
user.setStatus(0);
|
||||
user.setPassword(userService.encodePassword(user.getPassword()));
|
||||
// 排重
|
||||
final User byPhone = userService.getByPhone(user.getPhone());
|
||||
if(ObjectUtil.isNotEmpty(byPhone)){
|
||||
return fail("该手机号码已存在");
|
||||
}
|
||||
if (userService.saveUser(user)) {
|
||||
return success("添加成功",user.getUserId());
|
||||
}
|
||||
@@ -99,6 +107,15 @@ public class UserController extends BaseController {
|
||||
d.setPassword(userService.encodePassword(d.getPassword()));
|
||||
}
|
||||
});
|
||||
|
||||
final Set<String> collect = userList.stream().map(User::getPhone).collect(Collectors.toSet());
|
||||
final List<User> list = userService.list(new LambdaQueryWrapper<User>().in(User::getPhone, collect).select(User::getPhone));
|
||||
System.out.println("list = " + list);
|
||||
final Map<String, List<User>> phoneCollect = list.stream().collect(Collectors.groupingBy(User::getPhone));
|
||||
System.out.println("phoneCollect = " + phoneCollect);
|
||||
userList.removeIf(d -> phoneCollect.containsKey(d.getPhone()));
|
||||
System.out.println("phoneCollect = " + phoneCollect);
|
||||
|
||||
if (userService.saveBatch(userList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -79,4 +80,11 @@ public class Tenant implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Object date;
|
||||
|
||||
@ApiModelProperty(value = "手机号码")
|
||||
@TableField(exist = false)
|
||||
private String phone;
|
||||
|
||||
public String getPhone(){
|
||||
return DesensitizedUtil.mobilePhone(this.phone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +177,14 @@ public class User implements UserDetails {
|
||||
@ApiModelProperty(value = "是否管理员")
|
||||
private Boolean isAdmin;
|
||||
|
||||
@ApiModelProperty(value = "租户管理员ID")
|
||||
@TableField(exist = false)
|
||||
private Integer adminId;
|
||||
|
||||
@ApiModelProperty(value = "用于一键登录控制台")
|
||||
@TableField(exist = false)
|
||||
private String adminToken;
|
||||
|
||||
@ApiModelProperty("评论数")
|
||||
private Integer commentNumbers;
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@
|
||||
<where>
|
||||
AND a.deleted = 0
|
||||
AND a.phone = #{phone}
|
||||
AND a.nickname = '超级管理员'
|
||||
AND a.username = 'admin'
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
@@ -50,24 +50,6 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
||||
PageParam<Tenant, TenantParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||
List<Tenant> list = baseMapper.selectPageRel(page, param);
|
||||
// if (param.getSceneType() != null && param.getSceneType().equals("plug")) {
|
||||
// final Set<Integer> collectIds = list.stream().map(Tenant::getTenantId).collect(Collectors.toSet());
|
||||
// System.out.println("collectIds = " + collectIds);
|
||||
// final List<Company> companyList = companyService.list(new LambdaUpdateWrapper<Company>().in(Company::getTenantId, collectIds));
|
||||
// System.out.println("companyList = " + companyList);
|
||||
// final Map<Integer, List<Company>> collect = companyList.stream().collect(Collectors.groupingBy(Company::getTenantId));
|
||||
// list.forEach(d -> {
|
||||
// final List<Company> companies = collect.get(d.getTenantId());
|
||||
// if (!CollectionUtils.isEmpty(companies)) {
|
||||
// final Company c1 = companies.get(0);
|
||||
// final Company c2 = new Company();
|
||||
// c2.setCompanyName(c1.getCompanyName());
|
||||
// c2.setShortName(c1.getShortName());
|
||||
// c2.setPhone(DesensitizedUtil.mobilePhone(c1.getPhone()));
|
||||
// d.setCompany(c2);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user