|
|
@@ -1,12 +1,17 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.Activity;
|
|
|
import com.etotem.cfc.entity.ActivityFeedback;
|
|
|
import com.etotem.cfc.mapper.ActivityFeedbackMapper;
|
|
|
+import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import com.etotem.cfc.util.SortUtil;
|
|
|
@@ -16,17 +21,59 @@ public class ActivityFeedbackService {
|
|
|
|
|
|
@Resource
|
|
|
private ActivityFeedbackMapper activityFeedbackMapper;
|
|
|
+ @Resource
|
|
|
+ private TaskMapper taskMapper;
|
|
|
+ @Resource
|
|
|
+ private ActivityRegistrationService registrationService;
|
|
|
+ @Resource
|
|
|
+ private ActivityService activityService;
|
|
|
|
|
|
public Result<?> submit(Long activityId, Long userId, Long memberId, String ratings, String comment) {
|
|
|
- ActivityFeedback feedback = new ActivityFeedback();
|
|
|
- feedback.setActivityId(activityId);
|
|
|
- feedback.setUserId(userId);
|
|
|
- feedback.setChildId(memberId);
|
|
|
- feedback.setRatings(ratings);
|
|
|
- feedback.setComment(comment);
|
|
|
- feedback.setStatus(0);
|
|
|
- feedback.setCreatedAt(new Date());
|
|
|
- activityFeedbackMapper.insert(feedback);
|
|
|
+ // Gate: 活动必须已结束(status=ended 或 endTime < now)
|
|
|
+ Activity activity = activityService.getById(activityId);
|
|
|
+ if (activity == null) return Result.error("活动不存在");
|
|
|
+ if (!"ended".equals(activity.getStatus())) {
|
|
|
+ Date now = new Date();
|
|
|
+ if (activity.getEndTime() != null && !now.after(activity.getEndTime())) {
|
|
|
+ return Result.error("活动尚未结束,暂不能评价");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Gate: 已报名且已签到
|
|
|
+ if (memberId == null || !registrationService.isApproved(activityId, memberId)) {
|
|
|
+ return Result.error("请先报名此活动后再评价");
|
|
|
+ }
|
|
|
+ boolean hasCheckedIn = taskMapper.selectCount(new LambdaQueryWrapper<com.etotem.cfc.entity.Task>()
|
|
|
+ .eq(com.etotem.cfc.entity.Task::getSourceType, "activity")
|
|
|
+ .eq(com.etotem.cfc.entity.Task::getSourceId, activityId)
|
|
|
+ .eq(com.etotem.cfc.entity.Task::getChildId, memberId)
|
|
|
+ .eq(com.etotem.cfc.entity.Task::getStatus, "completed")) > 0;
|
|
|
+ if (!hasCheckedIn) {
|
|
|
+ return Result.error("请先完成签到后再评价");
|
|
|
+ }
|
|
|
+ // Dedup: 同一 activityId + childId 只保留一条;重复提交则更新
|
|
|
+ ActivityFeedback existing = activityFeedbackMapper.selectOne(new LambdaQueryWrapper<ActivityFeedback>()
|
|
|
+ .eq(ActivityFeedback::getActivityId, activityId)
|
|
|
+ .eq(ActivityFeedback::getChildId, memberId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ ActivityFeedback feedback;
|
|
|
+ if (existing != null) {
|
|
|
+ feedback = existing;
|
|
|
+ feedback.setRatings(ratings);
|
|
|
+ feedback.setComment(comment);
|
|
|
+ feedback.setStatus(1);
|
|
|
+ feedback.setUpdatedAt(new Date());
|
|
|
+ activityFeedbackMapper.updateById(feedback);
|
|
|
+ } else {
|
|
|
+ feedback = new ActivityFeedback();
|
|
|
+ feedback.setActivityId(activityId);
|
|
|
+ feedback.setUserId(userId);
|
|
|
+ feedback.setChildId(memberId);
|
|
|
+ feedback.setRatings(ratings);
|
|
|
+ feedback.setComment(comment);
|
|
|
+ feedback.setStatus(1);
|
|
|
+ feedback.setCreatedAt(new Date());
|
|
|
+ activityFeedbackMapper.insert(feedback);
|
|
|
+ }
|
|
|
return Result.success("提交评价成功", feedback.getId());
|
|
|
}
|
|
|
|