Просмотр исходного кода

fix: DailyCheckinService.updateCheckin改为Map参数,deleteCheckin增加userId参数

- DailyCheckinService.updateCheckin(): (Long, DailyHealthCheckin) → (Long, Map<String,Object>)
- DailyCheckinService.deleteCheckin(): (Long) → (Long, Long)
- DailyCheckinController: update(Map)/delete(Map)适配新的service签名

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Xiaogang Liao 2 месяцев назад
Родитель
Сommit
f108e3917e

+ 10 - 8
cfc-backend/src/main/java/com/etotem/cfc/controller/DailyCheckinController.java

@@ -56,13 +56,13 @@ public class DailyCheckinController {
         if (id == null) {
             return Result.error("id不能为空");
         }
-        DailyHealthCheckin checkin = new DailyHealthCheckin();
-        if (params.get("dietScore") != null) checkin.setDietScore(Integer.valueOf(params.get("dietScore").toString()));
-        if (params.get("exerciseScore") != null) checkin.setExerciseScore(Integer.valueOf(params.get("exerciseScore").toString()));
-        if (params.get("sleepScore") != null) checkin.setSleepScore(Integer.valueOf(params.get("sleepScore").toString()));
-        if (params.get("waterIntake") != null) checkin.setWaterIntake(Integer.valueOf(params.get("waterIntake").toString()));
-        if (params.get("moodScore") != null) checkin.setMoodScore(Integer.valueOf(params.get("moodScore").toString()));
-        return Result.success(dailyCheckinService.updateCheckin(id, checkin));
+        java.util.Map<String, Object> updates = new java.util.HashMap<>();
+        for (Map.Entry<String, Object> entry : params.entrySet()) {
+            if (!"id".equals(entry.getKey())) {
+                updates.put(entry.getKey(), entry.getValue());
+            }
+        }
+        return Result.success(dailyCheckinService.updateCheckin(id, updates));
     }
 
     @Operation(summary = "删除打卡记录")
@@ -70,10 +70,12 @@ public class DailyCheckinController {
     public Result<String> delete(@RequestBody Map<String, Object> params) {
         Long id = params.get("id") != null
                 ? Long.valueOf(params.get("id").toString()) : null;
+        Long userId = params.get("userId") != null
+                ? Long.valueOf(params.get("userId").toString()) : null;
         if (id == null) {
             return Result.error("id不能为空");
         }
-        dailyCheckinService.deleteCheckin(id);
+        dailyCheckinService.deleteCheckin(id, userId);
         return Result.success("删除成功");
     }
 }

+ 39 - 5
cfc-backend/src/main/java/com/etotem/cfc/service/DailyCheckinService.java

@@ -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;
     }
 }