Jelajahi Sumber

feat(review-center): 统计合并服务角色待审数并新增知识管理员计数

Xiaogang Liao 5 hari lalu
induk
melakukan
3b2e57c63a

+ 45 - 8
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/ReviewCenterController.java

@@ -8,6 +8,7 @@ import com.etotem.cfc.entity.Article;
 import com.etotem.cfc.entity.ButlerProfile;
 import com.etotem.cfc.entity.Product;
 import com.etotem.cfc.entity.PendingRefund;
+import com.etotem.cfc.entity.ServiceRoleApplication;
 import com.etotem.cfc.entity.SupplyHierarchyChangeRequest;
 import com.etotem.cfc.entity.TaskTemplatePackage;
 import com.etotem.cfc.entity.User;
@@ -17,6 +18,7 @@ import com.etotem.cfc.mapper.ActivityRegistrationMapper;
 import com.etotem.cfc.mapper.ArticleMapper;
 import com.etotem.cfc.mapper.ButlerProfileMapper;
 import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.ServiceRoleApplicationMapper;
 import com.etotem.cfc.mapper.SupplyHierarchyChangeRequestMapper;
 import com.etotem.cfc.mapper.TaskTemplatePackageMapper;
 import com.etotem.cfc.mapper.UserMapper;
@@ -28,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -64,6 +67,29 @@ public class ReviewCenterController {
     @Resource
     private PendingRefundMapper pendingRefundMapper;
 
+    @Resource
+    private ServiceRoleApplicationMapper serviceRoleApplicationMapper;
+
+    /**
+     * 统计待审(status=0)服务角色申请中命中任一目标角色的条数,同一记录只计一次。
+     */
+    public static int countPendingByRoles(List<ServiceRoleApplication> apps, String... roles) {
+        if (apps == null || apps.isEmpty()) {
+            return 0;
+        }
+        int count = 0;
+        for (ServiceRoleApplication app : apps) {
+            if (app == null || app.getStatus() == null || app.getStatus() != 0) {
+                continue;
+            }
+            if (com.etotem.cfc.service.impl.ServiceRoleApplicationServiceImpl.matchesAnyRole(
+                    app.getRoles(), java.util.Arrays.asList(roles))) {
+                count++;
+            }
+        }
+        return count;
+    }
+
     @PostMapping("/summary")
     public Result<Map<String, Integer>> summary() {
         Map<String, Integer> counts = new HashMap<>();
@@ -74,14 +100,22 @@ public class ReviewCenterController {
         counts.put("productPending", productMapper.selectCount(
                 new QueryWrapper<Product>().eq("status", "pending")).intValue());
 
-        counts.put("guidePending", userMapper.selectCount(
-                new QueryWrapper<User>().eq("teacher_status", "pending")).intValue());
+        // 服务角色申请中的待审记录按角色分流合并到各 Tab 计数
+        List<ServiceRoleApplication> pendingApplications = serviceRoleApplicationMapper.selectList(
+                new QueryWrapper<ServiceRoleApplication>().eq("status", 0));
 
-        counts.put("vendorPending", userMapper.selectCount(
-                new QueryWrapper<User>().eq("vendor_status", "pending")).intValue());
+        counts.put("guidePending",
+                userMapper.selectCount(new QueryWrapper<User>().eq("teacher_status", "pending")).intValue()
+                        + countPendingByRoles(pendingApplications, "planner"));
 
-        counts.put("butlerPending", butlerProfileMapper.selectCount(
-                new QueryWrapper<ButlerProfile>().eq("status", "pending")).intValue());
+        counts.put("vendorPending",
+                userMapper.selectCount(new QueryWrapper<User>().eq("vendor_status", "pending")).intValue()
+                        + countPendingByRoles(pendingApplications, "vendor", "activity_provider"));
+
+        counts.put("butlerPending",
+                butlerProfileMapper.selectCount(new QueryWrapper<ButlerProfile>().eq("status", "pending")).intValue()
+                        + userMapper.selectCount(new QueryWrapper<User>().eq("butler_status", "pending")).intValue()
+                        + countPendingByRoles(pendingApplications, "butler"));
 
         counts.put("packagePending", taskTemplatePackageMapper.selectCount(
                 new QueryWrapper<TaskTemplatePackage>().eq("status", "pending")).intValue());
@@ -101,8 +135,11 @@ public class ReviewCenterController {
         counts.put("hierarchyChangePending", supplyHierarchyChangeRequestMapper.selectCount(
                 new QueryWrapper<SupplyHierarchyChangeRequest>().eq("status", "pending")).intValue());
 
-        counts.put("nutritionistPending", userMapper.selectCount(
-                new QueryWrapper<User>().eq("nutritionist_status", "pending")).intValue());
+        counts.put("nutritionistPending",
+                userMapper.selectCount(new QueryWrapper<User>().eq("nutritionist_status", "pending")).intValue()
+                        + countPendingByRoles(pendingApplications, "nutritionist"));
+
+        counts.put("knowledgePending", countPendingByRoles(pendingApplications, "article_admin"));
 
         return Result.success(counts);
     }

+ 46 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/ReviewCenterSummaryTest.java

@@ -0,0 +1,46 @@
+package com.etotem.cfc.unit;
+
+import com.etotem.cfc.controller.admin.ReviewCenterController;
+import com.etotem.cfc.entity.ServiceRoleApplication;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ReviewCenterSummaryTest {
+
+    private ServiceRoleApplication app(String roles, int status) {
+        ServiceRoleApplication a = new ServiceRoleApplication();
+        a.setRoles(roles);
+        a.setStatus(status);
+        return a;
+    }
+
+    @Test
+    void countPendingByRoles_只数status0且角色命中() {
+        List<ServiceRoleApplication> list = Arrays.asList(
+                app("[\"planner\"]", 0),
+                app("[\"planner\"]", 1),
+                app("[\"activity_provider\"]", 0),
+                app("[\"vendor\"]", 0));
+        assertEquals(1, ReviewCenterController.countPendingByRoles(list, "planner"));
+        assertEquals(2, ReviewCenterController.countPendingByRoles(list, "vendor", "activity_provider"));
+        assertEquals(0, ReviewCenterController.countPendingByRoles(Collections.emptyList(), "planner"));
+    }
+
+    @Test
+    void countPendingByRoles_multiRoleRecordOnlyCountsOnce() {
+        List<ServiceRoleApplication> list = Collections.singletonList(
+                app("[\"vendor\",\"activity_provider\"]", 0));
+        assertEquals(1, ReviewCenterController.countPendingByRoles(list, "vendor", "activity_provider"));
+    }
+
+    @Test
+    void countPendingByRoles_非法rolesJSON不计数() {
+        List<ServiceRoleApplication> list = Collections.singletonList(app("not-json", 0));
+        assertEquals(0, ReviewCenterController.countPendingByRoles(list, "planner"));
+    }
+}