diff --git a/hxhq-common/hxhq-common-core/pom.xml b/hxhq-common/hxhq-common-core/pom.xml index de321a9..69d0b65 100644 --- a/hxhq-common/hxhq-common-core/pom.xml +++ b/hxhq-common/hxhq-common-core/pom.xml @@ -112,12 +112,6 @@ mybatis-plus-boot-starter - - - com.hxhq - hxhq-common-security - - diff --git a/hxhq-common/hxhq-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/hxhq-common/hxhq-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index e0a51ca..e341c46 100644 --- a/hxhq-common/hxhq-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/hxhq-common/hxhq-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1 @@ -com.hxhq.common.core.utils.SpringUtils -com.hxhq.common.core.config.MyBatisPlusConfig \ No newline at end of file +com.hxhq.common.core.utils.SpringUtils \ No newline at end of file diff --git a/hxhq-common/hxhq-common-security/pom.xml b/hxhq-common/hxhq-common-security/pom.xml index 2ed3959..a5dd55c 100644 --- a/hxhq-common/hxhq-common-security/pom.xml +++ b/hxhq-common/hxhq-common-security/pom.xml @@ -34,6 +34,11 @@ hxhq-common-redis + + com.baomidou + mybatis-plus-boot-starter + + diff --git a/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/config/BaseMetaObjectHandler.java b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/config/BaseMetaObjectHandler.java new file mode 100644 index 0000000..51e7414 --- /dev/null +++ b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/config/BaseMetaObjectHandler.java @@ -0,0 +1,73 @@ +package com.hxhq.common.security.config; + + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.hxhq.common.security.utils.SecurityUtils; +import org.apache.ibatis.reflection.MetaObject; + +import java.util.Date; + +/** + * + * @author memory + */ +public class BaseMetaObjectHandler implements MetaObjectHandler { + /** + * 删除标记 + */ + public static final String DEL_FLAG = "delFlag"; + /** + * 创建时间 + */ + public static final String CREATE_BY = "createBy"; + /** + * 创建时间 + */ + public static final String CREATE_DATE = "createTime"; + /** + * 创建时间 + */ + public static final String UPDATE_BY = "updateBy"; + /** + * 更新时间 + */ + public static final String UPDATE_DATE = "updateTime"; + + /** + * 新增 + */ + @Override + public void insertFill(MetaObject metaObject) { + // 创建用户 + Object createBy = getFieldValByName(CREATE_BY, metaObject); + if (createBy == null || createBy.equals("")) { + setFieldValByName(CREATE_BY, SecurityUtils.getLoginUserOfEmpty().getUserid()==null?"": SecurityUtils.getLoginUserOfEmpty().getUserid().toString(), metaObject); + } + + // 创建时间 + Object createDate = getFieldValByName(CREATE_DATE, metaObject); + if (createDate == null) { + setFieldValByName(CREATE_DATE, new Date(), metaObject); + } + + // 删除标记 + Object delFlag = getFieldValByName(DEL_FLAG, metaObject); + if (delFlag == null) { + setFieldValByName(DEL_FLAG, "0", metaObject); + } + } + + @Override + public void updateFill(MetaObject metaObject) { +// Object updateBy = getFieldValByName(UPDATE_BY, metaObject); +// if (updateBy == null || updateBy.equals("")) { + setFieldValByName(UPDATE_BY, SecurityUtils.getLoginUserOfEmpty().getUserid()==null?"": SecurityUtils.getLoginUserOfEmpty().getUserid().toString(), metaObject); +// } + + // 更新用户 +// Object updateDate = getFieldValByName(UPDATE_DATE, metaObject); +// if (updateDate == null) { + setFieldValByName(UPDATE_DATE, new Date(), metaObject); +// } + } +} \ No newline at end of file diff --git a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/config/MyBatisPlusConfig.java similarity index 98% rename from hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java rename to hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/config/MyBatisPlusConfig.java index 4c050e7..26357b1 100644 --- a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java +++ b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/config/MyBatisPlusConfig.java @@ -1,4 +1,4 @@ -package com.hxhq.common.core.config; +package com.hxhq.common.security.config; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; diff --git a/hxhq-common/hxhq-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/hxhq-common/hxhq-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index b091e33..b57002a 100644 --- a/hxhq-common/hxhq-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/hxhq-common/hxhq-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -3,3 +3,4 @@ com.hxhq.common.security.service.TokenService com.hxhq.common.security.aspect.PreAuthorizeAspect com.hxhq.common.security.aspect.InnerAuthAspect com.hxhq.common.security.handler.GlobalExceptionHandler +com.hxhq.common.security.config.MyBatisPlusConfig \ No newline at end of file