inleft
2024-05-18 2ddbd99aa5b2e396f96c6daba60fe1ac2573d9fb
snowy-base/snowy-system/src/main/java/vip/xiaonuo/sys/core/mybatis/fieldfill/CustomMetaObjectHandler.java
@@ -63,29 +63,43 @@
        try {
            Object updateDate = metaObject.getValue(UPDATE_DATE);
            if(ObjectUtil.isNull(updateDate)) {
            if (ObjectUtil.isNull(updateDate)) {
                setFieldValByName(UPDATE_DATE, new Date(), metaObject);
            }
            Object createDate = metaObject.getValue(CREATE_DATE);
            if(ObjectUtil.isNull(createDate)) {
            if (ObjectUtil.isNull(createDate)) {
                setFieldValByName(CREATE_DATE, new Date(), metaObject);
            }
            //为空则设置createUser(BaseEntity)
            Object createUser = metaObject.getValue(CREATE_USER);
            if(ObjectUtil.isNull(createUser)) {
            if (ObjectUtil.isNull(createUser)) {
                setFieldValByName(CREATE_USER, this.getUserUniqueId(), metaObject);
            }
            //为空则设置createTime(BaseEntity)
            Object createTime = metaObject.getValue(CREATE_TIME);
            if(ObjectUtil.isNull(createTime)) {
            if (ObjectUtil.isNull(createTime)) {
                setFieldValByName(CREATE_TIME, new Date(), metaObject);
            }
        } catch (ReflectionException e) {
            log.warn(">>> CustomMetaObjectHandler处理过程中无相关字段,不做处理");
            //二次设置
            try {
                //为空则设置createTime(BaseEntity)
                Object createTime = metaObject.getValue(CREATE_TIME);
                if (ObjectUtil.isNull(createTime)) {
                    setFieldValByName(CREATE_TIME, new Date(), metaObject);
                }
                //为空则设置createUser(BaseEntity)
                Object createUser = metaObject.getValue(CREATE_USER);
                if (ObjectUtil.isNull(createUser)) {
                    setFieldValByName(CREATE_USER, this.getUserUniqueId(), metaObject);
                }
            } catch (ReflectionException ex) {
                log.warn(">>> CustomMetaObjectHandler处理过程中无相关字段,不做处理");
            }
        }
    }
@@ -110,7 +124,7 @@
    private Long getUserUniqueId() {
        try {
            SysLoginUser sysLoginUser = LoginContextHolder.me().getSysLoginUserWithoutException();
            if(ObjectUtil.isNotNull(sysLoginUser)) {
            if (ObjectUtil.isNotNull(sysLoginUser)) {
                return sysLoginUser.getId();
            } else {
                return -1L;