|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
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.Article;
|
|
import com.etotem.cfc.entity.Article;
|
|
|
|
|
+import com.etotem.cfc.entity.Activity;
|
|
|
import com.etotem.cfc.entity.AfterSalesRequest;
|
|
import com.etotem.cfc.entity.AfterSalesRequest;
|
|
|
import com.etotem.cfc.entity.ArticleReadingRecord;
|
|
import com.etotem.cfc.entity.ArticleReadingRecord;
|
|
|
import com.etotem.cfc.entity.CommissionRecord;
|
|
import com.etotem.cfc.entity.CommissionRecord;
|
|
@@ -20,6 +21,7 @@ import com.etotem.cfc.entity.ShareRead;
|
|
|
import com.etotem.cfc.entity.Task;
|
|
import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.entity.TrialMembership;
|
|
import com.etotem.cfc.entity.TrialMembership;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
|
|
+import com.etotem.cfc.mapper.ActivityMapper;
|
|
|
import com.etotem.cfc.mapper.AfterSalesRequestMapper;
|
|
import com.etotem.cfc.mapper.AfterSalesRequestMapper;
|
|
|
import com.etotem.cfc.mapper.ArticleMapper;
|
|
import com.etotem.cfc.mapper.ArticleMapper;
|
|
|
import com.etotem.cfc.mapper.ArticleReadingRecordMapper;
|
|
import com.etotem.cfc.mapper.ArticleReadingRecordMapper;
|
|
@@ -82,6 +84,7 @@ public class StatsController {
|
|
|
@Resource private ProductMapper productMapper;
|
|
@Resource private ProductMapper productMapper;
|
|
|
@Resource private ProductViewRecordMapper productViewRecordMapper;
|
|
@Resource private ProductViewRecordMapper productViewRecordMapper;
|
|
|
@Resource private ShareReadMapper shareReadMapper;
|
|
@Resource private ShareReadMapper shareReadMapper;
|
|
|
|
|
+ @Resource private ActivityMapper activityMapper;
|
|
|
|
|
|
|
|
/** 单条停留时长上限(秒):超过 30 分钟按 30 分钟计,避免后台挂起/埋点异常把时长放大成天文数字 */
|
|
/** 单条停留时长上限(秒):超过 30 分钟按 30 分钟计,避免后台挂起/埋点异常把时长放大成天文数字 */
|
|
|
private static final int MAX_DWELL_SECONDS = 1800;
|
|
private static final int MAX_DWELL_SECONDS = 1800;
|
|
@@ -111,6 +114,42 @@ public class StatsController {
|
|
|
}, taskExecutor);
|
|
}, taskExecutor);
|
|
|
CompletableFuture<Long> pendingRefundFuture = CompletableFuture.supplyAsync(() ->
|
|
CompletableFuture<Long> pendingRefundFuture = CompletableFuture.supplyAsync(() ->
|
|
|
afterSalesRequestMapper.selectCount(new QueryWrapper<AfterSalesRequest>().eq("status", "pending")), taskExecutor);
|
|
afterSalesRequestMapper.selectCount(new QueryWrapper<AfterSalesRequest>().eq("status", "pending")), taskExecutor);
|
|
|
|
|
+
|
|
|
|
|
+ // ── 「新/总」口径:总=有效状态全量,新=近7天新增(created_at >= 7天前)且同样套用有效过滤 ──
|
|
|
|
|
+ Date weekAgo = new Date(System.currentTimeMillis() - 7L * 24 * 60 * 60 * 1000);
|
|
|
|
|
+ // 家庭:新=近7天创建的家庭数
|
|
|
|
|
+ CompletableFuture<Long> weekNewFamiliesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ familyMapper.selectCount(new QueryWrapper<Family>().ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+ // 用户(家长账号):新=近7天新增家长
|
|
|
|
|
+ CompletableFuture<Long> weekNewParentsFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ userMapper.selectCount(new QueryWrapper<User>().eq("role", "parent").ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+ // 非用户:家庭成员中 userId 为空(无账号)
|
|
|
|
|
+ CompletableFuture<Long> totalNonUsersFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ familyMemberMapper.selectCount(new QueryWrapper<FamilyMember>().isNull("user_id")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> weekNewNonUsersFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ familyMemberMapper.selectCount(new QueryWrapper<FamilyMember>().isNull("user_id").ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+ // 商品:有效=已上架 on_shelf
|
|
|
|
|
+ CompletableFuture<Long> totalProductsFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ productMapper.selectCount(new QueryWrapper<Product>().eq("status", "on_shelf")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> weekNewProductsFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ productMapper.selectCount(new QueryWrapper<Product>().eq("status", "on_shelf").ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+ // 商品订单:有效=排除已取消/已关闭/已退款
|
|
|
|
|
+ CompletableFuture<Long> totalOrdersFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().notIn("status", "cancelled", "closed", "refunded")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> weekNewOrdersFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ productOrderMapper.selectCount(new QueryWrapper<ProductOrder>()
|
|
|
|
|
+ .notIn("status", "cancelled", "closed", "refunded").ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+ // 文章:有效=已发布 published
|
|
|
|
|
+ CompletableFuture<Long> totalArticlesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ articleMapper.selectCount(new QueryWrapper<Article>().eq("status", "published")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> weekNewArticlesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ articleMapper.selectCount(new QueryWrapper<Article>().eq("status", "published").ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+ // 活动:有效=发布中 published
|
|
|
|
|
+ CompletableFuture<Long> totalActivitiesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ activityMapper.selectCount(new QueryWrapper<Activity>().eq("status", "published")), taskExecutor);
|
|
|
|
|
+ CompletableFuture<Long> weekNewActivitiesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
|
|
+ activityMapper.selectCount(new QueryWrapper<Activity>().eq("status", "published").ge("created_at", weekAgo)), taskExecutor);
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
data.put("totalFamilies", familyFuture.get());
|
|
data.put("totalFamilies", familyFuture.get());
|
|
|
data.put("totalParents", parentFuture.get());
|
|
data.put("totalParents", parentFuture.get());
|
|
@@ -119,6 +158,18 @@ public class StatsController {
|
|
|
data.put("pendingGuideCount", pendingGuideFuture.get());
|
|
data.put("pendingGuideCount", pendingGuideFuture.get());
|
|
|
data.put("pendingPackageCount", pendingPackageFuture.get());
|
|
data.put("pendingPackageCount", pendingPackageFuture.get());
|
|
|
data.put("pendingRefundCount", pendingRefundFuture.get());
|
|
data.put("pendingRefundCount", pendingRefundFuture.get());
|
|
|
|
|
+ data.put("weekNewFamilies", weekNewFamiliesFuture.get());
|
|
|
|
|
+ data.put("weekNewParents", weekNewParentsFuture.get());
|
|
|
|
|
+ data.put("totalNonUsers", totalNonUsersFuture.get());
|
|
|
|
|
+ data.put("weekNewNonUsers", weekNewNonUsersFuture.get());
|
|
|
|
|
+ data.put("totalProducts", totalProductsFuture.get());
|
|
|
|
|
+ data.put("weekNewProducts", weekNewProductsFuture.get());
|
|
|
|
|
+ data.put("totalOrders", totalOrdersFuture.get());
|
|
|
|
|
+ data.put("weekNewOrders", weekNewOrdersFuture.get());
|
|
|
|
|
+ data.put("totalArticles", totalArticlesFuture.get());
|
|
|
|
|
+ data.put("weekNewArticles", weekNewArticlesFuture.get());
|
|
|
|
|
+ data.put("totalActivities", totalActivitiesFuture.get());
|
|
|
|
|
+ data.put("weekNewActivities", weekNewActivitiesFuture.get());
|
|
|
data.put("recentTasks", recentTasksFuture.get());
|
|
data.put("recentTasks", recentTasksFuture.get());
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("获取仪表盘数据失败", e);
|
|
log.error("获取仪表盘数据失败", e);
|