|
@@ -42,9 +42,6 @@ public class TaskService {
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public Long createTask(Long userId, CreateTaskDTO dto) {
|
|
public Long createTask(Long userId, CreateTaskDTO dto) {
|
|
|
User currentUser = userService.getUserInfo(userId);
|
|
User currentUser = userService.getUserInfo(userId);
|
|
|
- Task task = new Task();
|
|
|
|
|
- task.setFamilyId(currentUser.getFamilyId());
|
|
|
|
|
- task.setCreatorId(userId);
|
|
|
|
|
|
|
|
|
|
// 处理执行者类型 - 支持孩子任务和家长任务
|
|
// 处理执行者类型 - 支持孩子任务和家长任务
|
|
|
String executorType = dto.getExecutorType();
|
|
String executorType = dto.getExecutorType();
|
|
@@ -52,12 +49,53 @@ public class TaskService {
|
|
|
// 兼容旧版:默认给孩子创建任务
|
|
// 兼容旧版:默认给孩子创建任务
|
|
|
executorType = "child";
|
|
executorType = "child";
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 支持多孩子:为每个孩子创建独立任务实例
|
|
|
|
|
+ List<Long> childIds = dto.getChildIds();
|
|
|
|
|
+ if (childIds == null || childIds.isEmpty()) {
|
|
|
|
|
+ // 兼容旧版:使用单个childId
|
|
|
|
|
+ if (dto.getChildId() != null) {
|
|
|
|
|
+ childIds = Collections.singletonList(dto.getChildId());
|
|
|
|
|
+ } else if (dto.getExecutorId() != null && "child".equals(executorType)) {
|
|
|
|
|
+ childIds = Collections.singletonList(dto.getExecutorId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ childIds = Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果有多个孩子,为每个孩子创建任务
|
|
|
|
|
+ if (!childIds.isEmpty() && childIds.size() > 1) {
|
|
|
|
|
+ Long firstChildId = childIds.get(0);
|
|
|
|
|
+ Task task = createSingleTask(currentUser, userId, executorType, firstChildId, dto);
|
|
|
|
|
+ taskMapper.insert(task);
|
|
|
|
|
+ // 为其他孩子创建任务实例
|
|
|
|
|
+ for (int i = 1; i < childIds.size(); i++) {
|
|
|
|
|
+ Task additionalTask = createSingleTask(currentUser, userId, executorType, childIds.get(i), dto);
|
|
|
|
|
+ taskMapper.insert(additionalTask);
|
|
|
|
|
+ }
|
|
|
|
|
+ return task.getId();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 单个孩子或无孩子
|
|
|
|
|
+ Long childId = childIds.isEmpty() ? null : childIds.get(0);
|
|
|
|
|
+ Task task = createSingleTask(currentUser, userId, executorType, childId, dto);
|
|
|
|
|
+ taskMapper.insert(task);
|
|
|
|
|
+ return task.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建单个任务实例
|
|
|
|
|
+ */
|
|
|
|
|
+ private Task createSingleTask(User currentUser, Long userId, String executorType, Long childId, CreateTaskDTO dto) {
|
|
|
|
|
+ Task task = new Task();
|
|
|
|
|
+ task.setFamilyId(currentUser.getFamilyId());
|
|
|
|
|
+ task.setCreatorId(userId);
|
|
|
task.setExecutorType(executorType);
|
|
task.setExecutorType(executorType);
|
|
|
|
|
|
|
|
if ("child".equals(executorType)) {
|
|
if ("child".equals(executorType)) {
|
|
|
// 给孩子安排的任务
|
|
// 给孩子安排的任务
|
|
|
- task.setExecutorId(dto.getChildId() != null ? dto.getChildId() : dto.getExecutorId());
|
|
|
|
|
- task.setChildId(dto.getChildId() != null ? dto.getChildId() : dto.getExecutorId());
|
|
|
|
|
|
|
+ task.setExecutorId(childId);
|
|
|
|
|
+ task.setChildId(childId);
|
|
|
} else {
|
|
} else {
|
|
|
// 给家长安排的任务
|
|
// 给家长安排的任务
|
|
|
task.setExecutorId(dto.getExecutorId() != null ? dto.getExecutorId() : userId);
|
|
task.setExecutorId(dto.getExecutorId() != null ? dto.getExecutorId() : userId);
|
|
@@ -67,32 +105,43 @@ public class TaskService {
|
|
|
task.setTitle(dto.getTitle());
|
|
task.setTitle(dto.getTitle());
|
|
|
task.setDescription(dto.getDescription());
|
|
task.setDescription(dto.getDescription());
|
|
|
task.setPoints(dto.getPoints() != null ? dto.getPoints() : 2);
|
|
task.setPoints(dto.getPoints() != null ? dto.getPoints() : 2);
|
|
|
-task.setDeadline(dto.getDeadline());
|
|
|
|
|
-task.setRepeatType(dto.getRepeatType() != null ? dto.getRepeatType() : "none");
|
|
|
|
|
-task.setCategory(dto.getCategory());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 如果没有指定截止时间,默认今天23:59
|
|
|
|
|
+ if (dto.getDeadline() == null) {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
|
|
+ cal.set(Calendar.MINUTE, 59);
|
|
|
|
|
+ cal.set(Calendar.SECOND, 59);
|
|
|
|
|
+ task.setDeadline(cal.getTime());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ task.setDeadline(dto.getDeadline());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ task.setRepeatType(dto.getRepeatType() != null ? dto.getRepeatType() : "none");
|
|
|
|
|
+ task.setCategory(dto.getCategory());
|
|
|
|
|
|
|
|
-// TASK-004: 如果是重复任务,标记为模板
|
|
|
|
|
-if (!"none".equals(task.getRepeatType())) {
|
|
|
|
|
-task.setIsTemplate(1); // 模板任务
|
|
|
|
|
-} else {
|
|
|
|
|
-task.setIsTemplate(0);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ // 如果是重复任务,标记为模板
|
|
|
|
|
+ if (!"none".equals(task.getRepeatType())) {
|
|
|
|
|
+ task.setIsTemplate(1); // 模板任务
|
|
|
|
|
+ } else {
|
|
|
|
|
+ task.setIsTemplate(0);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-// 家长给孩子安排任务需要审核,孩子给家长安排任务也需要审核
|
|
|
|
|
-if ("child".equals(executorType)) {
|
|
|
|
|
-task.setNeedReview(dto.getNeedReview() != null ? dto.getNeedReview() : 0);
|
|
|
|
|
-} else {
|
|
|
|
|
-// 孩子给家长安排任务,默认需要审核
|
|
|
|
|
-task.setNeedReview(dto.getNeedReview() != null ? dto.getNeedReview() : 1);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ // 家长给孩子安排任务需要审核,孩子给家长安排任务也需要审核
|
|
|
|
|
+ if ("child".equals(executorType)) {
|
|
|
|
|
+ task.setNeedReview(dto.getNeedReview() != null ? dto.getNeedReview() : 0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 孩子给家长安排任务,默认需要审核
|
|
|
|
|
+ task.setNeedReview(dto.getNeedReview() != null ? dto.getNeedReview() : 1);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-task.setReviewByCategory(dto.getReviewByCategory() != null ? dto.getReviewByCategory() : 0);
|
|
|
|
|
-task.setStatus("pending");
|
|
|
|
|
-task.setCreatedAt(new Date());
|
|
|
|
|
-task.setUpdatedAt(new Date());
|
|
|
|
|
-taskMapper.insert(task);
|
|
|
|
|
-return task.getId();
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ task.setReviewByCategory(dto.getReviewByCategory() != null ? dto.getReviewByCategory() : 0);
|
|
|
|
|
+ task.setStatus("pending");
|
|
|
|
|
+ task.setCreatedAt(new Date());
|
|
|
|
|
+ task.setUpdatedAt(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ return task;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public List<Task> getTodayTasks(Long childId) {
|
|
public List<Task> getTodayTasks(Long childId) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
Calendar calendar = Calendar.getInstance();
|