|
|
@@ -1,7 +1,9 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
import com.etotem.cfc.entity.DailyHealthCheckin;
|
|
|
+import com.etotem.cfc.entity.EmotionCheckin;
|
|
|
import com.etotem.cfc.mapper.DailyCheckinMapper;
|
|
|
+import com.etotem.cfc.mapper.EmotionCheckinMapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -21,6 +23,9 @@ public class DailyCheckinService {
|
|
|
@Resource
|
|
|
private PointsService pointsService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private EmotionCheckinMapper emotionCheckinMapper;
|
|
|
+
|
|
|
public List<DailyHealthCheckin> getCheckinsByMember(Long memberId) {
|
|
|
return dailyCheckinMapper.selectList(new LambdaQueryWrapper<DailyHealthCheckin>()
|
|
|
.eq(DailyHealthCheckin::getMemberId, memberId)
|
|
|
@@ -43,9 +48,61 @@ public class DailyCheckinService {
|
|
|
} catch (Exception e) {
|
|
|
log.warn("打卡积分发放失败,不影响打卡记录: {}", e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
+ // 心情打卡同步到情绪日记(如有 moodScore)
|
|
|
+ try {
|
|
|
+ if (checkin.getMoodScore() != null) {
|
|
|
+ syncToEmotionDiary(checkin);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("心情打卡同步情绪日记失败,不影响主流程: {}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
return checkin;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将心情打卡记录同步到情绪日记(emotion_checkin 表)。
|
|
|
+ * 有今日记录则更新,否则新建。
|
|
|
+ */
|
|
|
+ private void syncToEmotionDiary(DailyHealthCheckin checkin) {
|
|
|
+ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateStr = sdf.format(checkin.getCheckinDate());
|
|
|
+ Date todayDate = sdf.parse(dateStr);
|
|
|
+
|
|
|
+ EmotionCheckin existing = emotionCheckinMapper.selectByChildIdAndDate(checkin.getMemberId(), todayDate);
|
|
|
+
|
|
|
+ EmotionCheckin ec = new EmotionCheckin();
|
|
|
+ ec.setChildId(checkin.getMemberId());
|
|
|
+ ec.setMoodScore(checkin.getMoodScore());
|
|
|
+ ec.setNote(checkin.getRemark());
|
|
|
+ ec.setMoodWeather(mapMoodToWeather(checkin.getMoodScore()));
|
|
|
+ ec.setCheckinDate(todayDate);
|
|
|
+
|
|
|
+ if (existing != null) {
|
|
|
+ ec.setId(existing.getId());
|
|
|
+ ec.setCreatedAt(existing.getCreatedAt());
|
|
|
+ emotionCheckinMapper.updateById(ec);
|
|
|
+ log.info("心情打卡同步情绪日记(更新): memberId={}, moodScore={}", checkin.getMemberId(), checkin.getMoodScore());
|
|
|
+ } else {
|
|
|
+ ec.setEnergyAwarded(0);
|
|
|
+ emotionCheckinMapper.insert(ec);
|
|
|
+ log.info("心情打卡同步情绪日记(新建): memberId={}, moodScore={}", checkin.getMemberId(), checkin.getMoodScore());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * moodScore 1-10 → moodWeather
|
|
|
+ * 8-10: sunny, 5-7: cloudy, 3-4: rainy, 1-2: stormy
|
|
|
+ */
|
|
|
+ private String mapMoodToWeather(Integer moodScore) {
|
|
|
+ if (moodScore == null) return null;
|
|
|
+ if (moodScore >= 8) return "sunny";
|
|
|
+ if (moodScore >= 5) return "cloudy";
|
|
|
+ if (moodScore >= 3) return "rainy";
|
|
|
+ return "stormy";
|
|
|
+ }
|
|
|
+
|
|
|
public DailyHealthCheckin updateCheckin(Long checkinId, Map<String, Object> updates) {
|
|
|
DailyHealthCheckin checkin = dailyCheckinMapper.selectById(checkinId);
|
|
|
if (checkin == null) {
|