|
|
@@ -67,6 +67,15 @@ public class EnergyService {
|
|
|
@Resource
|
|
|
private HealthDimensionScoreService healthDimensionScoreService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private FamilyPlatformBalanceMapper familyPlatformBalanceMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ReferralTreeMapper referralTreeMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private GuideMapper guideMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 计算整个家庭的能量沙盘数据
|
|
|
*
|
|
|
@@ -316,50 +325,58 @@ public class EnergyService {
|
|
|
Arrays.asList("习惯", "好习惯", "自律", "家务", "自理", "作息"), 365);
|
|
|
}
|
|
|
|
|
|
- /** 家长 富 — 三子维度加权 */
|
|
|
+ /** 家长 富 — 利他创富四子维度加权:个人能力25% + 利他贡献30% + 财务积累(CF值)35% + 财务素养10% */
|
|
|
private int calcParentWealth(User parent, MemberEnergyDTO dto) {
|
|
|
+ int skill = calcParentWealthSkill(parent);
|
|
|
+ int altruism = calcParentWealthAltruism(parent);
|
|
|
int income = calcParentWealthIncome(parent);
|
|
|
- int achievement = calcParentWealthAchievement(parent);
|
|
|
- int network = calcParentWealthNetwork(parent);
|
|
|
+ int fx = calcParentWealthFx(parent);
|
|
|
+ dto.setWealthSkill(skill);
|
|
|
+ dto.setWealthAltruism(altruism);
|
|
|
dto.setWealthIncome(income);
|
|
|
- dto.setWealthAchievement(achievement);
|
|
|
- dto.setWealthNetwork(network);
|
|
|
- return (int) Math.round(income * 0.5 + achievement * 0.3 + network * 0.2);
|
|
|
+ dto.setWealthFx(fx);
|
|
|
+ // 旧字段兼容(新前端改为读 wealthSkill/wealthAltruism/wealthIncome/wealthFx)
|
|
|
+ dto.setWealthAchievement(skill);
|
|
|
+ dto.setWealthNetwork(altruism);
|
|
|
+ return (int) Math.round(skill * 0.25 + altruism * 0.3 + income * 0.35 + fx * 0.1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 家长富-个人能力:服务商/规划师资质(active) 满分100,否则按成长类任务完成率 */
|
|
|
+ private int calcParentWealthSkill(User parent) {
|
|
|
+ Long guideCount = guideMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<Guide>()
|
|
|
+ .eq(Guide::getUserId, parent.getId())
|
|
|
+ .eq(Guide::getStatus, "active"));
|
|
|
+ if (guideCount != null && guideCount > 0) {
|
|
|
+ return 100;
|
|
|
+ }
|
|
|
+ return calcTaskCompletionRate(parent.getId(), "parent",
|
|
|
+ Arrays.asList("学习", "培训", "技能", "阅读", "知识"), 365);
|
|
|
}
|
|
|
|
|
|
- /** 家长富-金钱收入:积分总量/500 */
|
|
|
- private int calcParentWealthIncome(User parent) {
|
|
|
- Integer totalPoints = parent.getTotalPoints();
|
|
|
- if (totalPoints == null) totalPoints = 0;
|
|
|
- int refMax = 500;
|
|
|
- int score = Math.min(totalPoints * 100 / Math.max(refMax, 1), 100);
|
|
|
- return Math.max(score, 0);
|
|
|
+ /** 家长富-利他贡献:ReferralTree 直接邀请人数折算(1人=20分,每多1人+15分,最高100) */
|
|
|
+ private int calcParentWealthAltruism(User parent) {
|
|
|
+ Long count = referralTreeMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<ReferralTree>().eq(ReferralTree::getParentId, parent.getId()));
|
|
|
+ if (count == null || count == 0) return 0;
|
|
|
+ return clamp(20 + (int) ((count - 1) * 15), 0, 100);
|
|
|
}
|
|
|
|
|
|
- /** 家长富-社会成就:家庭任务完成率(近30天completed/total,0=无数据) */
|
|
|
- private int calcParentWealthAchievement(User parent) {
|
|
|
+ /** 家长富-财务积累:家庭CF值累计获得(totalEarned)折算,5000CF=100分 */
|
|
|
+ private int calcParentWealthIncome(User parent) {
|
|
|
if (parent.getFamilyId() == null) return 0;
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
- cal.add(Calendar.DAY_OF_YEAR, -30);
|
|
|
- LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<Task>()
|
|
|
- .eq(Task::getFamilyId, parent.getFamilyId())
|
|
|
- .eq(Task::getExecutorType, "parent")
|
|
|
- .gt(Task::getCreatedAt, cal.getTime())
|
|
|
- .ne(Task::getIsTemplate, 1);
|
|
|
- SortUtil.applySort(wrapper);
|
|
|
- List<Task> tasks = taskMapper.selectList(wrapper);
|
|
|
- if (tasks.isEmpty()) return 0;
|
|
|
- long completed = tasks.stream().filter(t -> "completed".equals(t.getStatus())).count();
|
|
|
- return clamp((int) Math.round(completed * 100.0 / tasks.size()), 0, 100);
|
|
|
+ FamilyPlatformBalance balance = familyPlatformBalanceMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<FamilyPlatformBalance>()
|
|
|
+ .eq(FamilyPlatformBalance::getFamilyId, parent.getFamilyId())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (balance == null || balance.getTotalEarned() == null) return 0;
|
|
|
+ return clamp(balance.getTotalEarned() / 50, 0, 100);
|
|
|
}
|
|
|
|
|
|
- /** 家长富-资源网络:家庭成员数折算(1人=20分,每多1人+15分,最高100) */
|
|
|
- private int calcParentWealthNetwork(User parent) {
|
|
|
- if (parent.getFamilyId() == null) return 0;
|
|
|
- Long count = familyMemberMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<FamilyMember>().eq(FamilyMember::getFamilyId, parent.getFamilyId()));
|
|
|
- if (count == null || count == 0) return 0;
|
|
|
- return clamp(20 + (int) ((count - 1) * 15), 0, 100);
|
|
|
+ /** 家长富-财务素养:记账/理财/储蓄类任务完成率 */
|
|
|
+ private int calcParentWealthFx(User parent) {
|
|
|
+ return calcTaskCompletionRate(parent.getId(), "parent",
|
|
|
+ Arrays.asList("记账", "理财", "财务", "储蓄", "投资"), 365);
|
|
|
}
|
|
|
|
|
|
// ==================== 孩子能量计算 ====================
|
|
|
@@ -698,18 +715,24 @@ public class EnergyService {
|
|
|
return Math.min((int) Math.round(streakScore * 0.4 + habitScore * 0.6), 100);
|
|
|
}
|
|
|
|
|
|
- /** 孩子 富 — 三子维度加权 */
|
|
|
+ /** 孩子 富 — 利他创富四子维度加权:学业能力25% + 利他贡献30% + 积分积累35% + 财务素养10% */
|
|
|
private int calcChildWealth(FamilyMember child, MemberEnergyDTO dto) {
|
|
|
int edu = calcChildWealthEducation(child);
|
|
|
- int social = calcChildWealthSocial(child);
|
|
|
+ int altruism = calcChildWealthAltruism(child);
|
|
|
int points = calcChildWealthPoints(child);
|
|
|
+ int fx = calcChildWealthFx(child);
|
|
|
+ dto.setWealthSkill(edu);
|
|
|
+ dto.setWealthAltruism(altruism);
|
|
|
+ dto.setWealthIncome(points);
|
|
|
+ dto.setWealthFx(fx);
|
|
|
+ // 旧字段兼容(新前端改为读 wealthSkill/wealthAltruism/wealthIncome/wealthFx)
|
|
|
dto.setWealthEducation(edu);
|
|
|
- dto.setWealthSocial(social);
|
|
|
+ dto.setWealthSocial(altruism);
|
|
|
dto.setWealthPoints(points);
|
|
|
- return (int) Math.round(edu * 0.3 + social * 0.2 + points * 0.5);
|
|
|
+ return (int) Math.round(edu * 0.25 + altruism * 0.3 + points * 0.35 + fx * 0.1);
|
|
|
}
|
|
|
|
|
|
- /** 孩子富-学业成绩:DAN测评最近3次综合分+进步趋势 */
|
|
|
+ /** 孩子富-学业能力:DAN测评最近3次综合分+进步趋势 */
|
|
|
private int calcChildWealthEducation(FamilyMember child) {
|
|
|
Long memberId = child.getId();
|
|
|
LambdaQueryWrapper<DanAssessmentResult> qw = new LambdaQueryWrapper<DanAssessmentResult>()
|
|
|
@@ -741,9 +764,16 @@ public class EnergyService {
|
|
|
return clamp((int) Math.round(avg), 0, 100);
|
|
|
}
|
|
|
|
|
|
- /** 孩子富-社交筹码:活动参与次数(第一阶段返回0) */
|
|
|
- private int calcChildWealthSocial(FamilyMember child) {
|
|
|
- return 0;
|
|
|
+ /** 孩子富-利他贡献:帮助他人/分享/公益/家务类任务完成率 */
|
|
|
+ private int calcChildWealthAltruism(FamilyMember child) {
|
|
|
+ return calcTaskCompletionRate(child.getId(), "child",
|
|
|
+ Arrays.asList("帮助", "分享", "公益", "家务", "合作"), 365);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 孩子富-财务素养:财商/记账/理财/储蓄类任务完成率 */
|
|
|
+ private int calcChildWealthFx(FamilyMember child) {
|
|
|
+ return calcTaskCompletionRate(child.getId(), "child",
|
|
|
+ Arrays.asList("财商", "记账", "理财", "储蓄", "投资"), 365);
|
|
|
}
|
|
|
|
|
|
/** 孩子富-规则博弈:积分获取效率 */
|