|
@@ -0,0 +1,78 @@
|
|
|
|
|
+package com.etotem.cfc.mapper;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.ibatis.annotations.Mapper;
|
|
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
|
|
+import org.apache.ibatis.annotations.Select;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 单家庭运营工作台-聚合查询(纯只读 @Select)。
|
|
|
|
|
+ * 序列统一按 DATE(created_at) 分桶,供 FamilyWorkbenchSeriesBuilder 0 填充。
|
|
|
|
|
+ * 聊天无 family_id,经 family_members(user_id) 关联;所有列 alias 到无下划线的驼峰名,规避 map key 转换歧义。
|
|
|
|
|
+ */
|
|
|
|
|
+@Mapper
|
|
|
|
|
+public interface FamilyWorkbenchMapper {
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM health_reports WHERE family_id = #{familyId}")
|
|
|
|
|
+ long countReports(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM health_plans WHERE family_id = #{familyId}")
|
|
|
|
|
+ long countPlans(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM tasks WHERE family_id = #{familyId}")
|
|
|
|
|
+ long countTasks(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM chat_conversations c JOIN family_members fm ON fm.user_id = c.user_id WHERE fm.family_id = #{familyId}")
|
|
|
|
|
+ long countConversations(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM family_coupon WHERE family_id = #{familyId}")
|
|
|
|
|
+ long countCoupons(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COALESCE(SUM(total_earned), 0) FROM cf_balance WHERE family_id = #{familyId}")
|
|
|
|
|
+ Long cfBalance(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT DATE(created_at) AS d, COUNT(*) AS c FROM health_reports WHERE family_id = #{familyId} AND created_at >= #{from} GROUP BY DATE(created_at)")
|
|
|
|
|
+ List<Map<String, Object>> reportDailySeries(@Param("familyId") Long familyId, @Param("from") String from);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT DATE(created_at) AS d, COUNT(*) AS c FROM health_plans WHERE family_id = #{familyId} AND created_at >= #{from} GROUP BY DATE(created_at)")
|
|
|
|
|
+ List<Map<String, Object>> planDailySeries(@Param("familyId") Long familyId, @Param("from") String from);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT DATE(created_at) AS d, COUNT(*) AS c FROM tasks WHERE family_id = #{familyId} AND created_at >= #{from} GROUP BY DATE(created_at)")
|
|
|
|
|
+ List<Map<String, Object>> taskDailySeries(@Param("familyId") Long familyId, @Param("from") String from);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT DATE(c.created_at) AS d, COUNT(*) AS c FROM chat_conversations c JOIN family_members fm ON fm.user_id = c.user_id WHERE fm.family_id = #{familyId} AND c.created_at >= #{from} GROUP BY DATE(c.created_at)")
|
|
|
|
|
+ List<Map<String, Object>> conversationDailySeries(@Param("familyId") Long familyId, @Param("from") String from);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT DATE(received_at) AS d, COUNT(*) AS c FROM family_coupon WHERE family_id = #{familyId} AND received_at >= #{from} GROUP BY DATE(received_at)")
|
|
|
|
|
+ List<Map<String, Object>> couponDailySeries(@Param("familyId") Long familyId, @Param("from") String from);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT DATE(created_at) AS d, SUM(amount) AS c FROM cf_balance_log WHERE family_id = #{familyId} AND created_at >= #{from} GROUP BY DATE(created_at)")
|
|
|
|
|
+ List<Map<String, Object>> cfDailySeries(@Param("familyId") Long familyId, @Param("from") String from);
|
|
|
|
|
+
|
|
|
|
|
+ // ---------------- 家庭聊天(只读,经 family_members 归属) ----------------
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT c.id AS id, c.title AS title, c.assistant_type AS assistantType, "
|
|
|
|
|
+ + "c.last_message_at AS lastMessageAt, c.created_at AS createdAt, fm.user_id AS userId "
|
|
|
|
|
+ + "FROM chat_conversations c JOIN family_members fm ON fm.user_id = c.user_id "
|
|
|
|
|
+ + "WHERE fm.family_id = #{familyId} ORDER BY c.last_message_at DESC, c.id DESC")
|
|
|
|
|
+ List<Map<String, Object>> conversationsByFamily(@Param("familyId") Long familyId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM chat_messages WHERE conversation_id = #{conversationId}")
|
|
|
|
|
+ long conversationMessageCount(@Param("conversationId") Long conversationId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT content FROM chat_messages WHERE conversation_id = #{conversationId} ORDER BY created_at DESC, id DESC LIMIT 1")
|
|
|
|
|
+ String conversationLastMessage(@Param("conversationId") Long conversationId);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT id AS id, role AS role, content AS content, created_at AS createdAt "
|
|
|
|
|
+ + "FROM chat_messages WHERE conversation_id = #{conversationId} "
|
|
|
|
|
+ + "ORDER BY created_at ASC, id ASC LIMIT #{size} OFFSET #{offset}")
|
|
|
|
|
+ List<Map<String, Object>> messagesOfConversation(@Param("conversationId") Long conversationId,
|
|
|
|
|
+ @Param("offset") long offset,
|
|
|
|
|
+ @Param("size") long size);
|
|
|
|
|
+
|
|
|
|
|
+ @Select("SELECT COUNT(*) FROM chat_conversations c JOIN family_members fm ON fm.user_id = c.user_id "
|
|
|
|
|
+ + "WHERE c.id = #{conversationId} AND fm.family_id = #{familyId}")
|
|
|
|
|
+ long conversationInFamily(@Param("conversationId") Long conversationId, @Param("familyId") Long familyId);
|
|
|
|
|
+}
|