فهرست منبع

fix(backend): SupplyHierarchy change-requests systemId 改为可选 + ((Number)→Long.valueOf) 解析修复

- supply-hierarchy/change-requests 入口: 移除 'systemId 不能为空' 强校验, systemId 改为可选过滤
- Service.getChangeRequests: 仅在 systemId != null 时加入 where 条件
- 全 Controller 20 处 ((Number) ...).longValue() → Long.valueOf(... .toString()) 防 String/Integer 类型解析异常
Xiaogang Liao 2 ماه پیش
والد
کامیت
d9760e6d7a

+ 20 - 23
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/SupplyHierarchyController.java

@@ -41,9 +41,9 @@ public class SupplyHierarchyController {
     @PostMapping("/set")
     public Result<Void> setHierarchy(@RequestBody Map<String, Object> params) {
         try {
-            Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-            Long parentId = params.get("parentId") != null ? ((Number) params.get("parentId")).longValue() : null;
-            Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null;
+            Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+            Long parentId = params.get("parentId") != null ? Long.valueOf(params.get("parentId").toString()) : null;
+            Long childId = params.get("childId") != null ? Long.valueOf(params.get("childId").toString()) : null;
             if (systemId == null || parentId == null || childId == null) {
                 return Result.error("参数不完整");
             }
@@ -59,8 +59,8 @@ public class SupplyHierarchyController {
     @PostMapping("/remove")
     public Result<Void> removeRelation(@RequestBody Map<String, Object> params) {
         try {
-            Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-            Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null;
+            Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+            Long childId = params.get("childId") != null ? Long.valueOf(params.get("childId").toString()) : null;
             if (systemId == null || childId == null) {
                 return Result.error("参数不完整");
             }
@@ -73,8 +73,8 @@ public class SupplyHierarchyController {
 
     @PostMapping("/direct-children")
     public Result<List<User>> getDirectChildren(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-        Long parentId = params.get("parentId") != null ? ((Number) params.get("parentId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+        Long parentId = params.get("parentId") != null ? Long.valueOf(params.get("parentId").toString()) : null;
         if (systemId == null || parentId == null) {
             return Result.error("参数不完整");
         }
@@ -84,8 +84,8 @@ public class SupplyHierarchyController {
 
     @PostMapping("/all-children")
     public Result<List<User>> getAllChildren(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-        Long parentId = params.get("parentId") != null ? ((Number) params.get("parentId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+        Long parentId = params.get("parentId") != null ? Long.valueOf(params.get("parentId").toString()) : null;
         if (systemId == null || parentId == null) {
             return Result.error("参数不完整");
         }
@@ -95,8 +95,8 @@ public class SupplyHierarchyController {
 
     @PostMapping("/parent")
     public Result<User> getParent(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-        Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+        Long userId = params.get("userId") != null ? Long.valueOf(params.get("userId").toString()) : null;
         if (systemId == null || userId == null) {
             return Result.error("参数不完整");
         }
@@ -106,8 +106,8 @@ public class SupplyHierarchyController {
 
     @PostMapping("/parent-chain")
     public Result<List<User>> getParentChain(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-        Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+        Long userId = params.get("userId") != null ? Long.valueOf(params.get("userId").toString()) : null;
         if (systemId == null || userId == null) {
             return Result.error("参数不完整");
         }
@@ -117,7 +117,7 @@ public class SupplyHierarchyController {
 
     @PostMapping("/tree")
     public Result<List<Map<String, Object>>> getTree(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
         if (systemId == null) {
             return Result.error("systemId 不能为空");
         }
@@ -181,8 +181,8 @@ public class SupplyHierarchyController {
 
     @PostMapping("/my")
     public Result<Map<String, Object>> getMyRelation(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-        Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+        Long userId = params.get("userId") != null ? Long.valueOf(params.get("userId").toString()) : null;
         if (systemId == null || userId == null) {
             return Result.error("参数不完整");
         }
@@ -197,11 +197,8 @@ public class SupplyHierarchyController {
 
     @PostMapping("/change-requests")
     public Result<List<SupplyHierarchyChangeRequest>> getChangeRequests(@RequestBody Map<String, Object> params) {
-        Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
+        Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
         String status = (String) params.get("status");
-        if (systemId == null) {
-            return Result.error("systemId 不能为空");
-        }
         List<SupplyHierarchyChangeRequest> requests = supplyHierarchyService.getChangeRequests(systemId, status);
         return Result.success(requests);
     }
@@ -209,8 +206,8 @@ public class SupplyHierarchyController {
     @PostMapping("/change/apply")
     public Result<Void> applyChange(@RequestBody Map<String, Object> params) {
         try {
-            Long systemId = params.get("systemId") != null ? ((Number) params.get("systemId")).longValue() : null;
-            Long targetParentId = params.get("targetParentId") != null ? ((Number) params.get("targetParentId")).longValue() : null;
+            Long systemId = params.get("systemId") != null ? Long.valueOf(params.get("systemId").toString()) : null;
+            Long targetParentId = params.get("targetParentId") != null ? Long.valueOf(params.get("targetParentId").toString()) : null;
             String reason = (String) params.get("reason");
             if (systemId == null || targetParentId == null) {
                 return Result.error("参数不完整");
@@ -227,7 +224,7 @@ public class SupplyHierarchyController {
     @PostMapping("/change/review")
     public Result<Void> reviewChange(@RequestBody Map<String, Object> params) {
         try {
-            Long requestId = params.get("requestId") != null ? ((Number) params.get("requestId")).longValue() : null;
+            Long requestId = params.get("requestId") != null ? Long.valueOf(params.get("requestId").toString()) : null;
             String status = (String) params.get("status");
             String rejectReason = (String) params.get("rejectReason");
             if (requestId == null || status == null) {

+ 3 - 1
cfc-backend/src/main/java/com/etotem/cfc/service/SupplyHierarchyService.java

@@ -189,7 +189,9 @@ public class SupplyHierarchyService extends ServiceImpl<SupplyHierarchyMapper, S
 
     public List<SupplyHierarchyChangeRequest> getChangeRequests(Long systemId, String status) {
         LambdaQueryWrapper<SupplyHierarchyChangeRequest> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(SupplyHierarchyChangeRequest::getSystemId, systemId);
+        if (systemId != null) {
+            wrapper.eq(SupplyHierarchyChangeRequest::getSystemId, systemId);
+        }
         if (status != null && !status.isEmpty()) {
             wrapper.eq(SupplyHierarchyChangeRequest::getStatus, status);
         }