diff --git a/continew-starter-captcha/continew-starter-captcha-graphic/pom.xml b/continew-starter-captcha/continew-starter-captcha-graphic/pom.xml
index fdc876a0..af8369fc 100644
--- a/continew-starter-captcha/continew-starter-captcha-graphic/pom.xml
+++ b/continew-starter-captcha/continew-starter-captcha-graphic/pom.xml
@@ -22,7 +22,7 @@
easy-captcha
-
+
org.openjdk.nashorn
nashorn-core
diff --git a/continew-starter-dependencies/pom.xml b/continew-starter-dependencies/pom.xml
index 392ab323..be1e41ca 100644
--- a/continew-starter-dependencies/pom.xml
+++ b/continew-starter-dependencies/pom.xml
@@ -55,9 +55,8 @@
1.2.0-SNAPSHOT
- 2.3.1
- 1.16.6
1.37.0
+ 1.16.6
3.5.5
4.2.0
3.9.1
@@ -69,6 +68,7 @@
15.4
2.0.0
1.12.626
+ 2.3.1
4.4.0
2.14.4
3.1.6
@@ -77,11 +77,24 @@
-
+
- cn.crane4j
- crane4j-spring-boot-starter
- ${crane4j.version}
+ cn.dev33
+ sa-token-spring-boot3-starter
+ ${sa-token.version}
+
+
+
+
+ cn.dev33
+ sa-token-jwt
+ ${sa-token.version}
+
+
+ cn.hutool
+ hutool-all
+
+
@@ -106,26 +119,6 @@
-
-
- cn.dev33
- sa-token-spring-boot3-starter
- ${sa-token.version}
-
-
-
-
- cn.dev33
- sa-token-jwt
- ${sa-token.version}
-
-
- cn.hutool
- hutool-all
-
-
-
-
com.baomidou
@@ -175,7 +168,7 @@
${easy-captcha.version}
-
+
org.openjdk.nashorn
nashorn-core
@@ -203,6 +196,13 @@
${aws-s3.version}
+
+
+ cn.crane4j
+ crane4j-spring-boot-starter
+ ${crane4j.version}
+
+
com.github.xiaoymin
diff --git a/continew-starter-extension/continew-starter-extension-crud/pom.xml b/continew-starter-extension/continew-starter-extension-crud/pom.xml
index 1d0b99a0..bc645adb 100644
--- a/continew-starter-extension/continew-starter-extension-crud/pom.xml
+++ b/continew-starter-extension/continew-starter-extension-crud/pom.xml
@@ -44,5 +44,11 @@
top.charles7c.continew
continew-starter-api-doc
+
+
+
+ cn.crane4j
+ crane4j-spring-boot-starter
+
\ No newline at end of file
diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/CrudAutoConfiguration.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/CrudAutoConfiguration.java
index bf3fa42f..95f7919b 100644
--- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/CrudAutoConfiguration.java
+++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/CrudAutoConfiguration.java
@@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.accept.ContentNegotiationManager;
@@ -37,6 +38,7 @@ import top.charles7c.continew.starter.extension.crud.handler.CrudRequestMappingH
*/
@Slf4j
@AutoConfiguration
+@Import({UserNicknameContainer.class})
public class CrudAutoConfiguration extends DelegatingWebMvcConfiguration {
/**
diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/UserNicknameContainer.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/UserNicknameContainer.java
new file mode 100644
index 00000000..378717dd
--- /dev/null
+++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/autoconfigure/UserNicknameContainer.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.charles7c.continew.starter.extension.crud.autoconfigure;
+
+import cn.crane4j.core.container.Container;
+import cn.hutool.core.collection.CollUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+import top.charles7c.continew.starter.extension.crud.base.CommonUserService;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * 用户昵称容器
+ *
+ * @author Charles7c
+ * @since 1.2.0
+ */
+@Component
+@RequiredArgsConstructor
+public class UserNicknameContainer implements Container {
+
+ private final CommonUserService userService;
+
+ @Override
+ public String getNamespace() {
+ return "userNickname";
+ }
+
+ @Override
+ public Map get(Collection ids) {
+ Long id = CollUtil.getFirst(ids);
+ String name = userService.getNicknameById(id);
+ return Collections.singletonMap(id, name);
+ }
+}
\ No newline at end of file
diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseDetailResp.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseDetailResp.java
index 300d57a5..cdfe1c02 100644
--- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseDetailResp.java
+++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseDetailResp.java
@@ -16,6 +16,8 @@
package top.charles7c.continew.starter.extension.crud.base;
+import cn.crane4j.annotation.Assemble;
+import cn.crane4j.annotation.Mapping;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -42,6 +44,7 @@ public class BaseDetailResp extends BaseResp {
* 修改人
*/
@JsonIgnore
+ @Assemble(container = "userNickname", props = @Mapping(ref = "updateUserString"))
private Long updateUser;
/**
diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseResp.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseResp.java
index ed6304d1..81ba8af4 100644
--- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseResp.java
+++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseResp.java
@@ -16,6 +16,8 @@
package top.charles7c.continew.starter.extension.crud.base;
+import cn.crane4j.annotation.Assemble;
+import cn.crane4j.annotation.Mapping;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -47,6 +49,7 @@ public class BaseResp implements Serializable {
* 创建人
*/
@JsonIgnore
+ @Assemble(container = "userNickname", props = @Mapping(ref = "createUserString"))
private Long createUser;
/**
diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java
index 669a8965..dca7db9a 100644
--- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java
+++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java
@@ -16,6 +16,7 @@
package top.charles7c.continew.starter.extension.crud.base;
+import cn.crane4j.core.support.OperateTemplate;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollUtil;
@@ -34,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import top.charles7c.continew.starter.core.util.ClassUtils;
-import top.charles7c.continew.starter.core.util.ExceptionUtils;
import top.charles7c.continew.starter.core.util.ReflectUtils;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
@@ -137,26 +137,11 @@ public abstract class BaseServiceImpl, T extends BaseDO,
return BeanUtil.copyToList(entityList, targetClass);
}
- /**
- * 设置排序
- *
- * @param queryWrapper 查询 Wrapper
- * @param sortQuery 排序查询条件
- */
- protected void sort(QueryWrapper queryWrapper, SortQuery sortQuery) {
- Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort();
- for (Sort.Order order : sort) {
- if (null != order) {
- queryWrapper.orderBy(true, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
- }
- }
- }
-
@Override
public D get(Long id) {
T entity = this.getById(id);
D detail = BeanUtil.copyProperties(entity, detailClass);
- this.fillDetail(detail);
+ this.fill(detail);
return detail;
}
@@ -186,10 +171,20 @@ public abstract class BaseServiceImpl, T extends BaseDO,
@Override
public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
List list = this.list(query, sortQuery, detailClass);
- list.forEach(this::fillDetail);
+ list.forEach(this::fill);
ExcelUtils.export(list, "导出数据", detailClass, response);
}
+ /**
+ * 填充数据
+ *
+ * @param obj 待填充信息
+ */
+ protected void fill(Object obj) {
+ OperateTemplate operateTemplate = SpringUtil.getBean(OperateTemplate.class);
+ operateTemplate.execute(obj);
+ }
+
/**
* 根据 ID 查询
*
@@ -203,35 +198,17 @@ public abstract class BaseServiceImpl, T extends BaseDO,
}
/**
- * 填充数据
+ * 设置排序
*
- * @param baseObj 待填充列表信息
+ * @param queryWrapper 查询 Wrapper
+ * @param sortQuery 排序查询条件
*/
- protected void fill(Object baseObj) {
- if (baseObj instanceof BaseResp baseResp) {
- Long createUser = baseResp.getCreateUser();
- if (null == createUser) {
- return;
+ protected void sort(QueryWrapper queryWrapper, SortQuery sortQuery) {
+ Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort();
+ for (Sort.Order order : sort) {
+ if (null != order) {
+ queryWrapper.orderBy(true, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
}
- CommonUserService userService = SpringUtil.getBean(CommonUserService.class);
- baseResp.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getNicknameById(createUser)));
- }
- }
-
- /**
- * 填充详情数据
- *
- * @param detailObj 待填充详情信息
- */
- public void fillDetail(Object detailObj) {
- if (detailObj instanceof BaseDetailResp detailResp) {
- this.fill(detailResp);
- Long updateUser = detailResp.getUpdateUser();
- if (null == updateUser) {
- return;
- }
- CommonUserService userService = SpringUtil.getBean(CommonUserService.class);
- detailResp.setUpdateUserString(ExceptionUtils.exToNull(() -> userService.getNicknameById(updateUser)));
}
}