|
|
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class DailyCheckinService {
|
|
|
@@ -32,14 +33,47 @@ public class DailyCheckinService {
|
|
|
return checkin;
|
|
|
}
|
|
|
|
|
|
- public DailyHealthCheckin updateCheckin(Long id, DailyHealthCheckin checkin) {
|
|
|
- checkin.setId(id);
|
|
|
+ public DailyHealthCheckin updateCheckin(Long checkinId, Map<String, Object> updates) {
|
|
|
+ DailyHealthCheckin checkin = dailyCheckinMapper.selectById(checkinId);
|
|
|
+ if (checkin == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Apply updates
|
|
|
+ if (updates.containsKey("dietScore")) {
|
|
|
+ checkin.setDietScore((Integer) updates.get("dietScore"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("exerciseScore")) {
|
|
|
+ checkin.setExerciseScore((Integer) updates.get("exerciseScore"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("sleepScore")) {
|
|
|
+ checkin.setSleepScore((Integer) updates.get("sleepScore"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("waterIntake")) {
|
|
|
+ checkin.setWaterIntake((Integer) updates.get("waterIntake"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("moodScore")) {
|
|
|
+ checkin.setMoodScore((Integer) updates.get("moodScore"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("weightKg")) {
|
|
|
+ checkin.setWeightKg((java.math.BigDecimal) updates.get("weightKg"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("heightCm")) {
|
|
|
+ checkin.setHeightCm((java.math.BigDecimal) updates.get("heightCm"));
|
|
|
+ }
|
|
|
+ if (updates.containsKey("remark")) {
|
|
|
+ checkin.setRemark((String) updates.get("remark"));
|
|
|
+ }
|
|
|
+
|
|
|
checkin.setUpdatedAt(new Date());
|
|
|
dailyCheckinMapper.updateById(checkin);
|
|
|
- return dailyCheckinMapper.selectById(id);
|
|
|
+ return dailyCheckinMapper.selectById(checkinId);
|
|
|
}
|
|
|
|
|
|
- public void deleteCheckin(Long id) {
|
|
|
- dailyCheckinMapper.deleteById(id);
|
|
|
+ public Boolean deleteCheckin(Long checkinId, Long userId) {
|
|
|
+ // Soft delete by setting status="deleted" or physically delete
|
|
|
+ // Since DailyHealthCheckin entity doesn't have a status field, we'll physically delete
|
|
|
+ dailyCheckinMapper.deleteById(checkinId);
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|