|
@@ -1,47 +1,22 @@
|
|
|
package com.etotem.cfc.service;
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
-import com.etotem.cfc.entity.FamilyMember;
|
|
|
|
|
-import com.etotem.cfc.entity.OnboardingTask;
|
|
|
|
|
-import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
|
|
-import com.etotem.cfc.mapper.OnboardingTaskMapper;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 新人引导服务(统一任务系统:已迁移至 TaskService,本类保留为兼容委托层)
|
|
|
|
|
+ */
|
|
|
@Service
|
|
@Service
|
|
|
public class OnboardingService {
|
|
public class OnboardingService {
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private OnboardingTaskMapper onboardingTaskMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private PointsService pointsService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private EnergyService energyService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
@Lazy
|
|
@Lazy
|
|
|
private TaskService taskService;
|
|
private TaskService taskService;
|
|
|
|
|
|
|
|
- private static final Map<String, int[]> REWARDS = new LinkedHashMap<>();
|
|
|
|
|
- static {
|
|
|
|
|
- REWARDS.put("REGISTER", new int[]{100, 10});
|
|
|
|
|
- REWARDS.put("COMPLETE_PROFILE", new int[]{50, 5});
|
|
|
|
|
- REWARDS.put("ADD_CHILD", new int[]{100, 10});
|
|
|
|
|
- REWARDS.put("FIRST_CHECKIN", new int[]{30, 5});
|
|
|
|
|
- REWARDS.put("FIRST_TASK", new int[]{50, 5});
|
|
|
|
|
- REWARDS.put("BIND_REFERRAL", new int[]{50, 10});
|
|
|
|
|
- REWARDS.put("COMPLETE_SELF_CHECK", new int[]{60, 10});
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Initialize 6 PENDING onboarding tasks for a new user
|
|
* Initialize 6 PENDING onboarding tasks for a new user
|
|
|
* 统一任务系统:委托 TaskService(生成 tasks 表 onboarding 任务)
|
|
* 统一任务系统:委托 TaskService(生成 tasks 表 onboarding 任务)
|
|
@@ -62,55 +37,19 @@ public class OnboardingService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Claim reward for a COMPLETED task: set CLAIMED, award points + energy
|
|
* Claim reward for a COMPLETED task: set CLAIMED, award points + energy
|
|
|
|
|
+ * 统一任务系统:奖励已自动发放,无 claimed 概念
|
|
|
*/
|
|
*/
|
|
|
- @Transactional
|
|
|
|
|
|
|
+ @Deprecated
|
|
|
public String claimReward(Long userId, String taskType) {
|
|
public String claimReward(Long userId, String taskType) {
|
|
|
- OnboardingTask task = onboardingTaskMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<OnboardingTask>()
|
|
|
|
|
- .eq(OnboardingTask::getUserId, userId)
|
|
|
|
|
- .eq(OnboardingTask::getTaskType, taskType)
|
|
|
|
|
- .eq(OnboardingTask::getStatus, "COMPLETED")
|
|
|
|
|
- .last("LIMIT 1")
|
|
|
|
|
- );
|
|
|
|
|
- if (task == null) {
|
|
|
|
|
- return "任务未完成或已领取";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- task.setStatus("CLAIMED");
|
|
|
|
|
- onboardingTaskMapper.updateById(task);
|
|
|
|
|
-
|
|
|
|
|
- // Find child by userId to award points and energy
|
|
|
|
|
- FamilyMember child = familyMemberMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<FamilyMember>()
|
|
|
|
|
- .eq(FamilyMember::getUserId, userId)
|
|
|
|
|
- .last("LIMIT 1")
|
|
|
|
|
- );
|
|
|
|
|
- if (child != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- pointsService.awardCfPoints(child.getId(), task.getRewardPoints(),
|
|
|
|
|
- "新手引导奖励: " + taskType);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // Points award failure should not block claim
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- energyService.awardEnergy(child.getId(), "onboarding", 0L,
|
|
|
|
|
- task.getRewardEnergy(), "新手引导奖励: " + taskType, 30);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // Energy award failure should not block claim
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return "奖励已发放";
|
|
|
|
|
|
|
+ return "奖励已自动发放";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Get all onboarding tasks for a user
|
|
* Get all onboarding tasks for a user
|
|
|
|
|
+ * 统一任务系统:委托 TaskService(读 tasks 表 source_type=onboarding)
|
|
|
*/
|
|
*/
|
|
|
- public List<OnboardingTask> getProgress(Long userId) {
|
|
|
|
|
- return onboardingTaskMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<OnboardingTask>()
|
|
|
|
|
- .eq(OnboardingTask::getUserId, userId)
|
|
|
|
|
- .orderByAsc(OnboardingTask::getTaskType)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ @Deprecated
|
|
|
|
|
+ public List<Map<String, Object>> getProgress(Long userId) {
|
|
|
|
|
+ return taskService.getOnboardingTasks(userId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|