|
|
@@ -3,6 +3,7 @@ package com.etotem.cfc.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.entity.*;
|
|
|
import com.etotem.cfc.mapper.*;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -27,6 +28,12 @@ public class MicroActionService {
|
|
|
@Resource
|
|
|
private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private FiveDimensionSelfCheckMapper fiveDimensionSelfCheckMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private TaskMapper taskMapper;
|
|
|
|
|
|
@@ -58,7 +65,7 @@ public class MicroActionService {
|
|
|
|
|
|
/**
|
|
|
* 获取今日推荐的微行动
|
|
|
- * 如果有未使用的新手体验配额,返回随机行动
|
|
|
+ * 优先按最近一次五维自检的短板维度推荐,无自检记录时按日期取模
|
|
|
* 如果已完成今日配额,返回null
|
|
|
*/
|
|
|
public MicroAction getTodayAction(Long childId) {
|
|
|
@@ -71,6 +78,13 @@ public class MicroActionService {
|
|
|
List<MicroAction> actions = getAllActions();
|
|
|
if (actions.isEmpty()) return null;
|
|
|
|
|
|
+ // 优先按最近自检短板维度推荐(微行动×五维联动)
|
|
|
+ String weakDim = getWeakestDimension(childId);
|
|
|
+ if (weakDim != null) {
|
|
|
+ MicroAction byDim = getActionByDimension(weakDim);
|
|
|
+ if (byDim != null) return byDim;
|
|
|
+ }
|
|
|
+
|
|
|
// Pick one based on the day of month (consistent for the whole day)
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
@@ -78,6 +92,74 @@ public class MicroActionService {
|
|
|
return actions.get(index);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取今日指定维度的微行动(自检结果页"加入今日微行动")
|
|
|
+ * 该维度无对应行动时回退到全量推荐;已完成今日配额返回null
|
|
|
+ */
|
|
|
+ public MicroAction getTodayActionForDimension(Long childId, String dimensionCode) {
|
|
|
+ if (getTodayRecord(childId) != null) {
|
|
|
+ return null; // Already completed today
|
|
|
+ }
|
|
|
+ if (dimensionCode != null && !dimensionCode.isEmpty()) {
|
|
|
+ MicroAction byDim = getActionByDimension(dimensionCode);
|
|
|
+ if (byDim != null) return byDim;
|
|
|
+ }
|
|
|
+ List<MicroAction> actions = getAllActions();
|
|
|
+ if (actions.isEmpty()) return null;
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
+ return actions.get(dayOfMonth % actions.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按维度code获取启用的微行动(当日取模保证整天一致)
|
|
|
+ */
|
|
|
+ public MicroAction getActionByDimension(String dimensionCode) {
|
|
|
+ if (dimensionCode == null || dimensionCode.isEmpty()) return null;
|
|
|
+ List<MicroAction> byDim = microActionMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<MicroAction>()
|
|
|
+ .eq(MicroAction::getStatus, 1)
|
|
|
+ .eq(MicroAction::getDimensionCode, dimensionCode)
|
|
|
+ .orderByAsc(MicroAction::getSortOrder)
|
|
|
+ );
|
|
|
+ if (byDim.isEmpty()) return null;
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ return byDim.get(cal.get(Calendar.DAY_OF_MONTH) % byDim.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析最近一次五维自检,返回最低分(短板)维度code;无记录时返回null
|
|
|
+ */
|
|
|
+ private String getWeakestDimension(Long childId) {
|
|
|
+ if (childId == null) return null;
|
|
|
+ try {
|
|
|
+ FiveDimensionSelfCheck latest = fiveDimensionSelfCheckMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<FiveDimensionSelfCheck>()
|
|
|
+ .eq(FiveDimensionSelfCheck::getFamilyMemberId, childId)
|
|
|
+ .orderByDesc(FiveDimensionSelfCheck::getId)
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+ if (latest == null || latest.getScoresJson() == null) return null;
|
|
|
+ Map<String, Integer> scores = objectMapper.readValue(latest.getScoresJson(),
|
|
|
+ objectMapper.getTypeFactory().constructMapType(Map.class, String.class, Integer.class));
|
|
|
+ // 五行相生顺序:身土→智金→富水→行木→心火
|
|
|
+ String[] order = {"body", "wisdom", "wealth", "action", "mind"};
|
|
|
+ String weakest = null;
|
|
|
+ int minScore = Integer.MAX_VALUE;
|
|
|
+ for (String dim : order) {
|
|
|
+ Integer s = scores.get(dim);
|
|
|
+ if (s != null && s < minScore) {
|
|
|
+ minScore = s;
|
|
|
+ weakest = dim;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return weakest;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析自检短板维度失败: {}", e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查今日是否已完成微行动
|
|
|
*/
|