|
|
@@ -29,34 +29,44 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
|
|
|
@Override
|
|
|
public void insertFill(MetaObject metaObject) {
|
|
|
try {
|
|
|
- LoginUser loginUser =null;
|
|
|
+ LoginUser loginUser = null;
|
|
|
try {
|
|
|
- loginUser= SecurityUtil.getLoginUser();
|
|
|
- }catch (Exception __){
|
|
|
+ loginUser = SecurityUtil.getLoginUser();
|
|
|
+ } catch (Exception __) {
|
|
|
|
|
|
}
|
|
|
if (metaObject.hasGetter(MybatisConstant.CREATE_TIME) && metaObject.getValue(MybatisConstant.CREATE_TIME) == null) {
|
|
|
this.strictInsertFill(metaObject, MybatisConstant.CREATE_TIME, Date.class, new Date());
|
|
|
}
|
|
|
if (metaObject.hasGetter(MybatisConstant.IS_DELETE) && metaObject.getValue(MybatisConstant.IS_DELETE) == null) {
|
|
|
- this.strictInsertFill(metaObject, MybatisConstant.IS_DELETE, Integer.class,0);
|
|
|
+ this.strictInsertFill(metaObject, MybatisConstant.IS_DELETE, Integer.class, 0);
|
|
|
}
|
|
|
if (metaObject.hasGetter(MybatisConstant.CREATE_BY) && metaObject.getValue(MybatisConstant.CREATE_BY) == null) {
|
|
|
|
|
|
this.strictInsertFill(metaObject, MybatisConstant.CREATE_BY, String.class, Objects.isNull(loginUser) ? "1" : loginUser.getId().toString());
|
|
|
}
|
|
|
if (metaObject.hasGetter(MybatisConstant.UPDATE_TIME) && metaObject.getValue(MybatisConstant.UPDATE_TIME) == null) {
|
|
|
- this.strictUpdateFill(metaObject, MybatisConstant.UPDATE_TIME, Date.class, new Date());
|
|
|
+ this.strictInsertFill(metaObject, MybatisConstant.UPDATE_TIME, Date.class, new Date());
|
|
|
}
|
|
|
if (metaObject.hasGetter(MybatisConstant.UPDATE_BY) && metaObject.getValue(MybatisConstant.UPDATE_BY) == null) {
|
|
|
- this.strictUpdateFill(metaObject, MybatisConstant.UPDATE_BY, String.class, Objects.isNull(loginUser) ? "1" : loginUser.getId().toString());
|
|
|
+ this.strictInsertFill(metaObject, MybatisConstant.UPDATE_BY, String.class, Objects.isNull(loginUser) ? "1" : loginUser.getId().toString());
|
|
|
}
|
|
|
if (metaObject.hasGetter(MybatisConstant.TENANT_ID) && metaObject.getValue(MybatisConstant.TENANT_ID) == null) {
|
|
|
- ServletRequestAttributes request = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
- String tenantId ="1";
|
|
|
- if(request!=null){
|
|
|
- tenantId = String.valueOf(request.getAttribute("tenantId", SCOPE_REQUEST));
|
|
|
+
|
|
|
+ String tenantId = "1";
|
|
|
+ if (loginUser != null) {
|
|
|
+ //优先从登录用户信息中获取
|
|
|
+ tenantId = loginUser.getTenantId().toString();
|
|
|
+ } else {
|
|
|
+ ServletRequestAttributes request = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
+ if (request != null) {
|
|
|
+ Object requestTenantId = request.getAttribute("tenantId", SCOPE_REQUEST);
|
|
|
+ if (requestTenantId != null) {
|
|
|
+ tenantId = String.valueOf(requestTenantId);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
this.strictInsertFill(metaObject, MybatisConstant.TENANT_ID, String.class, tenantId);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -79,4 +89,4 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+}
|