|
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import com.huashe.common.annotation.TenantField;
|
|
import com.huashe.common.exception.ServiceException;
|
|
import com.huashe.common.exception.ServiceException;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
@@ -55,46 +56,44 @@ public class MybatisInterceptor implements Interceptor {
|
|
if ("createBy".equals(field.getName())) {
|
|
if ("createBy".equals(field.getName())) {
|
|
field.setAccessible(true);
|
|
field.setAccessible(true);
|
|
Object local_createBy = field.get(parameter);
|
|
Object local_createBy = field.get(parameter);
|
|
- field.setAccessible(false);
|
|
|
|
if (local_createBy == null || local_createBy.equals("")) {
|
|
if (local_createBy == null || local_createBy.equals("")) {
|
|
if (sysUser != null) {
|
|
if (sysUser != null) {
|
|
// 登录人账号
|
|
// 登录人账号
|
|
- field.setAccessible(true);
|
|
|
|
field.set(parameter, sysUser.getUser().getNickName());
|
|
field.set(parameter, sysUser.getUser().getNickName());
|
|
- field.setAccessible(false);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ field.setAccessible(false);
|
|
}
|
|
}
|
|
if ("createName".equals(field.getName())) {
|
|
if ("createName".equals(field.getName())) {
|
|
field.setAccessible(true);
|
|
field.setAccessible(true);
|
|
Object local_createBy = field.get(parameter);
|
|
Object local_createBy = field.get(parameter);
|
|
- field.setAccessible(false);
|
|
|
|
|
|
+
|
|
if (local_createBy == null || local_createBy.equals("")) {
|
|
if (local_createBy == null || local_createBy.equals("")) {
|
|
if (sysUser != null) {
|
|
if (sysUser != null) {
|
|
// 登录人账号
|
|
// 登录人账号
|
|
- field.setAccessible(true);
|
|
|
|
field.set(parameter, sysUser.getUser().getNickName());
|
|
field.set(parameter, sysUser.getUser().getNickName());
|
|
- field.setAccessible(false);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ field.setAccessible(false);
|
|
}
|
|
}
|
|
// 注入创建时间
|
|
// 注入创建时间
|
|
if ("createTime".equals(field.getName())) {
|
|
if ("createTime".equals(field.getName())) {
|
|
field.setAccessible(true);
|
|
field.setAccessible(true);
|
|
Object local_createDate = field.get(parameter);
|
|
Object local_createDate = field.get(parameter);
|
|
- field.setAccessible(false);
|
|
|
|
|
|
+
|
|
if (local_createDate == null || local_createDate.equals("")) {
|
|
if (local_createDate == null || local_createDate.equals("")) {
|
|
- field.setAccessible(true);
|
|
|
|
field.set(parameter, new Date());
|
|
field.set(parameter, new Date());
|
|
- field.setAccessible(false);
|
|
|
|
}
|
|
}
|
|
|
|
+ field.setAccessible(false);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
catch (Exception e) {
|
|
log.error("------MybatisInterceptor field.name------{},error:", field.getName(), e);
|
|
log.error("------MybatisInterceptor field.name------{},error:", field.getName(), e);
|
|
}
|
|
}
|
|
|
|
+ setTenantField(parameter, field);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
if (SqlCommandType.UPDATE == sqlCommandType) {
|
|
if (SqlCommandType.UPDATE == sqlCommandType) {
|
|
LoginUser sysUser = this.getLoginUser();
|
|
LoginUser sysUser = this.getLoginUser();
|
|
@@ -133,17 +132,17 @@ public class MybatisInterceptor implements Interceptor {
|
|
if (sysUser != null) {
|
|
if (sysUser != null) {
|
|
// 登录账号
|
|
// 登录账号
|
|
field.set(parameter, sysUser.getUser().getNickName());
|
|
field.set(parameter, sysUser.getUser().getNickName());
|
|
- field.setAccessible(false);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ("updateTime".equals(field.getName())) {
|
|
if ("updateTime".equals(field.getName())) {
|
|
field.set(parameter, new Date());
|
|
field.set(parameter, new Date());
|
|
- field.setAccessible(false);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
catch (Exception e) {
|
|
log.error("------ MybatisInterceptor field.name------{},error:", field.getName(), e);
|
|
log.error("------ MybatisInterceptor field.name------{},error:", field.getName(), e);
|
|
}
|
|
}
|
|
|
|
+ field.setAccessible(false);
|
|
|
|
+ setTenantField(parameter, field);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return invocation.proceed();
|
|
return invocation.proceed();
|
|
@@ -154,6 +153,20 @@ public class MybatisInterceptor implements Interceptor {
|
|
return Plugin.wrap(target, this);
|
|
return Plugin.wrap(target, this);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void setTenantField(Object parameter, Field field) {
|
|
|
|
+ TenantField annotation = field.getAnnotation(TenantField.class);
|
|
|
|
+ if (annotation != null) {
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
+ try {
|
|
|
|
+ field.set(parameter, getLoginUser().getUser().getTenantId());
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e) {
|
|
|
|
+ log.error("------MybatisInterceptor field.name------{},error:", field.getName(), e);
|
|
|
|
+ }
|
|
|
|
+ field.setAccessible(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private LoginUser getLoginUser() {
|
|
private LoginUser getLoginUser() {
|
|
LoginUser userNow = new LoginUser();
|
|
LoginUser userNow = new LoginUser();
|
|
userNow.setUser(new SysUser() {
|
|
userNow.setUser(new SysUser() {
|