|
@@ -48,6 +48,9 @@ public class TaskService implements TaskServiceInterface {
|
|
|
@Resource
|
|
@Resource
|
|
|
private OnboardingService onboardingService;
|
|
private OnboardingService onboardingService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FamilyRelationshipScoreMapper familyRelationshipScoreMapper;
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private GrowthTaskService growthTaskService;
|
|
private GrowthTaskService growthTaskService;
|
|
|
|
|
|
|
@@ -59,10 +62,9 @@ public class TaskService implements TaskServiceInterface {
|
|
|
public Long createTask(Long userId, CreateTaskDTO dto) {
|
|
public Long createTask(Long userId, CreateTaskDTO dto) {
|
|
|
User currentUser = userService.getUserInfo(userId);
|
|
User currentUser = userService.getUserInfo(userId);
|
|
|
|
|
|
|
|
- // 处理执行者类型 - 支持孩子任务和家长任务
|
|
|
|
|
|
|
+ // 处理执行者类型 - 支持孩子任务、家长任务、家庭成员任务
|
|
|
String executorType = dto.getExecutorType();
|
|
String executorType = dto.getExecutorType();
|
|
|
if (executorType == null || executorType.isEmpty()) {
|
|
if (executorType == null || executorType.isEmpty()) {
|
|
|
- // 兼容旧版:默认给孩子创建任务
|
|
|
|
|
executorType = "child";
|
|
executorType = "child";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -109,11 +111,14 @@ public class TaskService implements TaskServiceInterface {
|
|
|
task.setExecutorType(executorType);
|
|
task.setExecutorType(executorType);
|
|
|
|
|
|
|
|
if ("child".equals(executorType)) {
|
|
if ("child".equals(executorType)) {
|
|
|
- // 给孩子安排的任务
|
|
|
|
|
task.setExecutorId(memberId);
|
|
task.setExecutorId(memberId);
|
|
|
task.setChildId(memberId);
|
|
task.setChildId(memberId);
|
|
|
|
|
+ } else if ("member".equals(executorType)) {
|
|
|
|
|
+ task.setExecutorId(memberId);
|
|
|
|
|
+ task.setChildId(null);
|
|
|
|
|
+ task.setStatus("assigned");
|
|
|
|
|
+ task.setAcceptDeadline(dto.getDeadline());
|
|
|
} else {
|
|
} else {
|
|
|
- // 给家长安排的任务
|
|
|
|
|
task.setExecutorId(dto.getExecutorId() != null ? dto.getExecutorId() : userId);
|
|
task.setExecutorId(dto.getExecutorId() != null ? dto.getExecutorId() : userId);
|
|
|
task.setChildId(null);
|
|
task.setChildId(null);
|
|
|
}
|
|
}
|
|
@@ -893,4 +898,107 @@ return 0; // 达到每日扣分上限
|
|
|
wrapper.orderByDesc(Task::getCreatedAt);
|
|
wrapper.orderByDesc(Task::getCreatedAt);
|
|
|
return taskMapper.selectPage(new Page<>(page, size), wrapper);
|
|
return taskMapper.selectPage(new Page<>(page, size), wrapper);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当前用户收到的待接受任务列表(executor_type='member' AND status='assigned')
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Task> getMyPendingTasks(Long memberId) {
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
+ Date startOfDay = calendar.getTime();
|
|
|
|
|
+
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
+ Date endOfDay = calendar.getTime();
|
|
|
|
|
+
|
|
|
|
|
+ return taskMapper.selectList(new LambdaQueryWrapper<Task>()
|
|
|
|
|
+ .eq(Task::getExecutorType, "member")
|
|
|
|
|
+ .eq(Task::getExecutorId, memberId)
|
|
|
|
|
+ .eq(Task::getStatus, "assigned")
|
|
|
|
|
+ .ge(Task::getDeadline, startOfDay)
|
|
|
|
|
+ .lt(Task::getDeadline, endOfDay)
|
|
|
|
|
+ .or()
|
|
|
|
|
+ .and(w -> w.eq(Task::getExecutorType, "member")
|
|
|
|
|
+ .eq(Task::getExecutorId, memberId)
|
|
|
|
|
+ .eq(Task::getStatus, "assigned")
|
|
|
|
|
+ .isNull(Task::getDeadline))
|
|
|
|
|
+ .orderByAsc(Task::getDeadline));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 接受任务:status 从 assigned 改为 in_progress
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public boolean acceptTask(Long taskId, Long memberId) {
|
|
|
|
|
+ Task task = taskMapper.selectById(taskId);
|
|
|
|
|
+ if (task == null || !task.getExecutorId().equals(memberId) || !"assigned".equals(task.getStatus())) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ task.setStatus("in_progress");
|
|
|
|
|
+ task.setAcceptDeadline(null);
|
|
|
|
|
+ task.setUpdatedAt(new Date());
|
|
|
|
|
+ taskMapper.updateById(task);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 拒绝任务:status 改为 rejected,调整 creator→assignee 和 assignee→creator 的关系分数
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public boolean rejectTask(Long taskId, Long memberId) {
|
|
|
|
|
+ Task task = taskMapper.selectById(taskId);
|
|
|
|
|
+ if (task == null || !task.getExecutorId().equals(memberId) || !"assigned".equals(task.getStatus())) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ task.setStatus("rejected");
|
|
|
|
|
+ task.setUpdatedAt(new Date());
|
|
|
|
|
+ taskMapper.updateById(task);
|
|
|
|
|
+
|
|
|
|
|
+ Long creatorId = task.getCreatorId();
|
|
|
|
|
+ Long assigneeId = memberId;
|
|
|
|
|
+ Long familyId = task.getFamilyId();
|
|
|
|
|
+ if (creatorId == null || assigneeId == null || familyId == null) return true;
|
|
|
|
|
+
|
|
|
|
|
+ int trustDelta = -1;
|
|
|
|
|
+ int intimacyDelta = -1;
|
|
|
|
|
+ int commDelta = -1;
|
|
|
|
|
+
|
|
|
|
|
+ adjustRelationshipScore(familyId, creatorId, assigneeId, trustDelta, intimacyDelta, commDelta);
|
|
|
|
|
+ adjustRelationshipScore(familyId, assigneeId, creatorId, 0, 0, 1);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void adjustRelationshipScore(Long familyId, Long fromId, Long toId, int trustDelta, int intimacyDelta, int commDelta) {
|
|
|
|
|
+ FamilyRelationshipScore score = familyRelationshipScoreMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<FamilyRelationshipScore>()
|
|
|
|
|
+ .eq(FamilyRelationshipScore::getFamilyId, familyId)
|
|
|
|
|
+ .eq(FamilyRelationshipScore::getFromMemberId, fromId)
|
|
|
|
|
+ .eq(FamilyRelationshipScore::getToMemberId, toId));
|
|
|
|
|
+ if (score == null) {
|
|
|
|
|
+ FamilyMember from = familyMemberMapper.selectById(fromId);
|
|
|
|
|
+ score = new FamilyRelationshipScore();
|
|
|
|
|
+ score.setFamilyId(familyId);
|
|
|
|
|
+ score.setFromMemberId(fromId);
|
|
|
|
|
+ score.setToMemberId(toId);
|
|
|
|
|
+ score.setTrustScore(from != null && from.getTrustScore() != null ? from.getTrustScore() : new java.math.BigDecimal("60.00"));
|
|
|
|
|
+ score.setIntimacyScore(from != null && from.getIntimacyScore() != null ? from.getIntimacyScore() : new java.math.BigDecimal("60.00"));
|
|
|
|
|
+ score.setCommunicationScore(from != null && from.getCommunicationScore() != null ? from.getCommunicationScore() : new java.math.BigDecimal("60.00"));
|
|
|
|
|
+ try {
|
|
|
|
|
+ familyRelationshipScoreMapper.insert(score);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ score = familyRelationshipScoreMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<FamilyRelationshipScore>()
|
|
|
|
|
+ .eq(FamilyRelationshipScore::getFamilyId, familyId)
|
|
|
|
|
+ .eq(FamilyRelationshipScore::getFromMemberId, fromId)
|
|
|
|
|
+ .eq(FamilyRelationshipScore::getToMemberId, toId));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (score == null) return;
|
|
|
|
|
+ if (trustDelta != 0) score.setTrustScore(score.getTrustScore().add(java.math.BigDecimal.valueOf(trustDelta)));
|
|
|
|
|
+ if (intimacyDelta != 0) score.setIntimacyScore(score.getIntimacyScore().add(java.math.BigDecimal.valueOf(intimacyDelta)));
|
|
|
|
|
+ if (commDelta != 0) score.setCommunicationScore(score.getCommunicationScore().add(java.math.BigDecimal.valueOf(commDelta)));
|
|
|
|
|
+ familyRelationshipScoreMapper.updateById(score);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|