From 6baefd1a8aa4f1f0154a71e9241e6c5800a7e59b Mon Sep 17 00:00:00 2001
From: lanyuanxiaoyao
Date: Thu, 21 Aug 2025 10:36:21 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96Global=E8=BF=94?=
=?UTF-8?q?=E5=9B=9E=E5=80=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../template/controller/DetailController.java | 20 +-
.../template/controller/GlobalResponse.java | 77 ++
.../template/controller/ListController.java | 34 +-
.../service/template/controller/Query.java | 264 ++--
.../template/controller/RemoveController.java | 20 +-
.../template/controller/SaveController.java | 20 +-
.../controller/SimpleControllerSupport.java | 251 ++--
.../response/GlobalCrudResponse.java | 24 -
.../response/GlobalDetailResponse.java | 7 -
.../response/GlobalMapResponse.java | 15 -
.../controller/response/GlobalResponse.java | 105 --
.../service/template/entity/IdOnlyEntity.java | 20 +-
.../service/template/entity/SimpleEntity.java | 38 +-
.../service/template/helper/ObjectHelper.java | 176 +--
.../template/repository/SimpleRepository.java | 2 +-
.../template/service/SimpleService.java | 20 +-
.../service/SimpleServiceSupport.java | 1080 ++++++++---------
.../service/template/TestApplication.java | 278 ++---
.../controller/CompanyController.java | 126 +-
.../controller/EmployeeController.java | 148 +--
.../service/template/entity/Company.java | 18 +-
.../service/template/entity/Employee.java | 38 +-
.../repository/EmployeeRepository.java | 6 +-
.../template/service/CompanyService.java | 6 +-
.../template/service/EmployeeService.java | 6 +-
25 files changed, 1359 insertions(+), 1440 deletions(-)
create mode 100644 src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java
delete mode 100644 src/main/java/com/lanyuanxiaoyao/service/template/controller/response/GlobalCrudResponse.java
delete mode 100644 src/main/java/com/lanyuanxiaoyao/service/template/controller/response/GlobalDetailResponse.java
delete mode 100644 src/main/java/com/lanyuanxiaoyao/service/template/controller/response/GlobalMapResponse.java
delete mode 100644 src/main/java/com/lanyuanxiaoyao/service/template/controller/response/GlobalResponse.java
diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java b/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java
index b51060c..3adfd16 100644
--- a/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java
+++ b/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java
@@ -1,7 +1,5 @@
package com.lanyuanxiaoyao.service.template.controller;
-import com.lanyuanxiaoyao.service.template.controller.response.GlobalResponse;
-
/**
* 详情控制器接口,用于定义统一的获取实体详情的接口规范
*
@@ -16,14 +14,14 @@ import com.lanyuanxiaoyao.service.template.controller.response.GlobalResponse;
* @author lanyuanxiaoyao
*/
public interface DetailController {
- String DETAIL = "/detail/{id}";
+ String DETAIL = "/detail/{id}";
- /**
- * 根据ID获取实体详情
- *
- * @param id 实体ID
- * @return GlobalResponse 返回实体详情
- * @throws Exception 查询过程中可能抛出的异常
- */
- GlobalResponse detail(Long id) throws Exception;
+ /**
+ * 根据ID获取实体详情
+ *
+ * @param id 实体ID
+ * @return GlobalResponse 返回实体详情
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ GlobalResponse detail(Long id) throws Exception;
}
\ No newline at end of file
diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java b/src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java
new file mode 100644
index 0000000..e1575fe
--- /dev/null
+++ b/src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java
@@ -0,0 +1,77 @@
+package com.lanyuanxiaoyao.service.template.controller;
+
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+@Setter
+@Getter
+@ToString
+public class GlobalResponse {
+ private static final int SUCCESS_STATUS = 0;
+ private static final int ERROR_STATUS = 500;
+ private static final String SUCCESS_MESSAGE = "OK";
+ private static final String ERROR_MESSAGE = "ERROR";
+ private Integer status;
+ private String message;
+ private T data;
+
+ private GlobalResponse() {
+ this(SUCCESS_STATUS, SUCCESS_MESSAGE, null);
+ }
+
+ private GlobalResponse(Integer status, String message) {
+ this(status, message, null);
+ }
+
+ private GlobalResponse(Integer status, String message, T data) {
+ this.status = status;
+ this.message = message;
+ this.data = data;
+ }
+
+ public static GlobalResponse
*
- * @param 实体类型,必须继承SimpleEntity
- * @param 保存项类型
- * @param 列表项类型
+ * @param 实体类型,必须继承SimpleEntity
+ * @param 保存项类型
+ * @param 列表项类型
* @param 详情项类型
* @author lanyuanxiaoyao
*/
@Slf4j
public abstract class SimpleControllerSupport implements SimpleController {
- protected final SimpleServiceSupport service;
+ protected final SimpleServiceSupport service;
- /**
- * 构造函数
- *
- * @param service 简单服务支持类实例
- */
- public SimpleControllerSupport(SimpleServiceSupport service) {
- this.service = service;
+ /**
+ * 构造函数
+ *
+ * @param service 简单服务支持类实例
+ */
+ public SimpleControllerSupport(SimpleServiceSupport service) {
+ this.service = service;
+ }
+
+ /**
+ * 保存实体对象
+ *
+ * @param item 需要保存的项
+ * @return GlobalResponse 返回保存后的实体ID
+ * @throws Exception 保存过程中可能抛出的异常
+ */
+ @PostMapping(SAVE)
+ @Override
+ public GlobalResponse save(@RequestBody SAVE_ITEM item) throws Exception {
+ var mapper = saveItemMapper();
+ return GlobalResponse.responseSuccess(service.save(mapper.apply(item)));
+ }
+
+ /**
+ * 获取所有实体列表
+ *
+ * @return GlobalCrudResponse 返回实体列表
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ @GetMapping(LIST)
+ @Override
+ public GlobalResponse