mirror of
https://github.com/thousmile/molly-multi-tenant.git
synced 2025-12-30 04:32:26 +00:00
1.添加 MyBatis-Plus 自定义ID生成器
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package com.xaaef.molly.monitor.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
@@ -34,7 +31,7 @@ public class LmsLoginLog implements java.io.Serializable {
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "ID")
|
||||
private String id;
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.xaaef.molly.monitor.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -33,7 +30,7 @@ public class LmsOperLog implements java.io.Serializable {
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "ID")
|
||||
private String id;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class PmsUser extends BaseEntity {
|
||||
* 用户ID
|
||||
*/
|
||||
@Schema(description = "用户ID")
|
||||
@TableId(type = IdType.AUTO)
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@NotNull(message = "用户ID,必须填写", groups = {ValidUpdate.class})
|
||||
private Long userId;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PmsUserSocial extends BaseEntity {
|
||||
* id
|
||||
*/
|
||||
@Schema(description = "社交账号ID")
|
||||
@TableId(type = IdType.AUTO)
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@NotNull(message = "社交账号ID,必须填写", groups = {ValidUpdate.class})
|
||||
private Long socialId;
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.xaaef.molly.auth.service.UserLoginService;
|
||||
import com.xaaef.molly.common.enums.AdminFlag;
|
||||
import com.xaaef.molly.common.enums.StatusEnum;
|
||||
import com.xaaef.molly.common.enums.UserType;
|
||||
import com.xaaef.molly.common.util.IdUtils;
|
||||
import com.xaaef.molly.internal.api.ApiCmsProjectService;
|
||||
import com.xaaef.molly.internal.api.ApiSysConfigService;
|
||||
import com.xaaef.molly.internal.api.ApiSysMenuService;
|
||||
@@ -157,7 +156,6 @@ public class PmsUserServiceImpl extends BaseServiceImpl<PmsUserMapper, PmsUser>
|
||||
entity.setStatus(StatusEnum.NORMAL.getCode());
|
||||
}
|
||||
|
||||
entity.setUserId(IdUtils.getStandaloneId());
|
||||
var ok = super.save(entity);
|
||||
|
||||
if (entity.getRoles() != null) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.xaaef.molly.auth.jwt.JwtSecurityUtils;
|
||||
import com.xaaef.molly.common.consts.ConfigDataConst;
|
||||
import com.xaaef.molly.common.consts.JwtConst;
|
||||
import com.xaaef.molly.common.consts.RegexConst;
|
||||
import com.xaaef.molly.common.util.IdUtils;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
import com.xaaef.molly.common.util.TenantUtils;
|
||||
import com.xaaef.molly.common.util.WrapExcelUtils;
|
||||
@@ -257,4 +258,12 @@ public class NoSpringTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test17() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(IdUtils.getStandaloneId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.xaaef.molly.auth.service.impl;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.xaaef.molly.auth.enums.GrantType;
|
||||
import com.xaaef.molly.auth.exception.JwtAuthException;
|
||||
@@ -17,6 +16,7 @@ import com.xaaef.molly.common.domain.CustomRequestInfo;
|
||||
import com.xaaef.molly.common.enums.AdminFlag;
|
||||
import com.xaaef.molly.common.enums.StatusEnum;
|
||||
import com.xaaef.molly.common.enums.UserType;
|
||||
import com.xaaef.molly.common.util.IdUtils;
|
||||
import com.xaaef.molly.common.util.ServletUtils;
|
||||
import com.xaaef.molly.internal.api.*;
|
||||
import com.xaaef.molly.internal.dto.LoginLogDTO;
|
||||
@@ -113,7 +113,7 @@ public class UserLoginServiceImpl implements UserLoginService {
|
||||
target.setLoginTime(LocalDateTime.now());
|
||||
target.setTenantId(currentTenant.getTenantId());
|
||||
// 生成一个随机ID 跟当前用户关联
|
||||
target.setLoginId(IdUtil.getSnowflakeNextIdStr());
|
||||
target.setLoginId(IdUtils.getStandaloneStrId());
|
||||
|
||||
// 判断当前登录的用户类型。系统用户 还是 租户用户
|
||||
String defaultTenantId = tenantService.getByDefaultTenantId();
|
||||
@@ -150,6 +150,9 @@ public class UserLoginServiceImpl implements UserLoginService {
|
||||
|
||||
var props = tokenService.getProps();
|
||||
|
||||
// 将当前用户设置为登录
|
||||
JwtSecurityUtils.setLoginUser(target);
|
||||
|
||||
return JwtTokenValue.builder()
|
||||
.header(props.getTokenHeader())
|
||||
.accessToken(tokenService.createJwtStr(target.getLoginId()))
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.xaaef.molly.tenant;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
||||
import com.xaaef.molly.auth.jwt.JwtSecurityUtils;
|
||||
import com.xaaef.molly.common.util.IdUtils;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
import com.xaaef.molly.common.util.TenantUtils;
|
||||
import com.xaaef.molly.tenant.props.MultiTenantProperties;
|
||||
@@ -88,6 +90,26 @@ public class MybatisPlusConfig {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义 ID 生成器
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.0.1
|
||||
* @date 2024/1/14 14:32
|
||||
*/
|
||||
@Bean
|
||||
public IdentifierGenerator idGenerator() {
|
||||
return entity -> IdUtils.getStandaloneId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 参数 自动 填充
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.0.1
|
||||
* @date 2024/1/14 14:32
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@@ -111,7 +133,6 @@ public class MybatisPlusConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
if (JwtSecurityUtils.isAuthenticated()) {
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.xaaef.molly.web.log;
|
||||
|
||||
import com.xaaef.molly.common.util.JsonResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Hibernate-Validator 错误结果处理切面
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @version 2.0
|
||||
* @date 2019/4/18 11:45
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class BindingResultAspect {
|
||||
|
||||
@Pointcut("execution(public * com.xaaef.molly.*.controller..*.*(..))")
|
||||
public void BindingResult1() {
|
||||
}
|
||||
|
||||
@Pointcut("execution(public * com.xaaef.molly.controller..*.*(..))")
|
||||
public void BindingResult2() {
|
||||
}
|
||||
|
||||
@Around("BindingResult1() || BindingResult2()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
var args = joinPoint.getArgs();
|
||||
for (Object arg : args) {
|
||||
if (arg instanceof BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
var fieldError = result.getFieldError();
|
||||
if (fieldError != null) {
|
||||
return JsonResult.fail(fieldError.getDefaultMessage());
|
||||
} else {
|
||||
return JsonResult.fail("请求参数错误!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.xaaef.molly.web.log;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.xaaef.molly.auth.jwt.JwtSecurityUtils;
|
||||
import com.xaaef.molly.common.util.IdUtils;
|
||||
import com.xaaef.molly.common.util.JsonResult;
|
||||
import com.xaaef.molly.common.util.ServletUtils;
|
||||
import com.xaaef.molly.common.util.TenantUtils;
|
||||
@@ -150,7 +150,7 @@ public class OperateLogAspect {
|
||||
operLog.setTenantId(userInfo.getTenantId());
|
||||
}
|
||||
operLog.setCreateTime(LocalDateTime.now());
|
||||
operLog.setId(IdUtil.getSnowflakeNextIdStr());
|
||||
operLog.setId(IdUtils.getStandaloneStrId());
|
||||
logStorage.asyncOperateSave(operLog);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user