|
@@ -1,8 +1,15 @@
|
|
|
package com.etotem.cfc.controller.stats;
|
|
package com.etotem.cfc.controller.stats;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.entity.Child;
|
|
|
|
|
+import com.etotem.cfc.entity.Family;
|
|
|
|
|
+import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.ChildMapper;
|
|
import com.etotem.cfc.mapper.ChildMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.GuidePackageMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
import com.etotem.cfc.service.TaskStatsService;
|
|
import com.etotem.cfc.service.TaskStatsService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
@@ -13,7 +20,11 @@ import javax.annotation.Resource;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
|
|
@Tag(name = "任务统计", description = "任务完成率分析")
|
|
@Tag(name = "任务统计", description = "任务完成率分析")
|
|
|
@RestController
|
|
@RestController
|
|
@@ -29,6 +40,56 @@ public class StatsController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private ChildMapper childMapper;
|
|
private ChildMapper childMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FamilyMapper familyMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TaskMapper taskMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private GuidePackageMapper guidePackageMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ThreadPoolExecutor taskExecutor;
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "管理后台仪表盘汇总")
|
|
|
|
|
+ @PostMapping("/dashboard")
|
|
|
|
|
+ public Result<Map<String, Object>> getDashboardSummary() {
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ CompletableFuture<Long> familyFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ familyMapper.selectCount(null), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> parentFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ userMapper.selectCount(new QueryWrapper<User>().eq("role", "parent")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> childFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ childMapper.selectCount(null), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> teacherFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ userMapper.selectCount(new QueryWrapper<User>().eq("role", "teacher")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> pendingGuideFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ userMapper.selectCount(new QueryWrapper<User>().eq("role", "teacher").eq("status", "pending")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> pendingPackageFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ guidePackageMapper.selectCount(new QueryWrapper<com.etotem.cfc.entity.GuidePackage>()
|
|
|
|
|
+ .eq("status", "pending")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<List<Task>> recentTasksFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
+ QueryWrapper<Task> q = new QueryWrapper<Task>().orderByDesc("created_at").last("LIMIT 5");
|
|
|
|
|
+ return taskMapper.selectList(q);
|
|
|
|
|
+ }, taskExecutor);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ data.put("totalFamilies", familyFuture.get());
|
|
|
|
|
+ data.put("totalParents", parentFuture.get());
|
|
|
|
|
+ data.put("totalChildren", childFuture.get());
|
|
|
|
|
+ data.put("totalTeachers", teacherFuture.get());
|
|
|
|
|
+ data.put("pendingGuideCount", pendingGuideFuture.get());
|
|
|
|
|
+ data.put("pendingPackageCount", pendingPackageFuture.get());
|
|
|
|
|
+ data.put("recentTasks", recentTasksFuture.get());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return Result.error("获取仪表盘数据失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Operation(summary = "孩子任务完成率")
|
|
@Operation(summary = "孩子任务完成率")
|
|
|
@PostMapping("/child-completion")
|
|
@PostMapping("/child-completion")
|
|
|
public Result<Map<String, Object>> childCompletion(
|
|
public Result<Map<String, Object>> childCompletion(
|