Przeglądaj źródła

fix: 修复AdminController类型转换异常和数据库迁移缺失

- AdminController.getPointsLogs: 安全解析page/size/childId参数
- DatabaseInitializer: 添加admin_task_templates表新字段迁移(complete_types/duration/review_type/task_type/frequency/max_frequency)
User 5 miesięcy temu
rodzic
commit
be5aa8bdf6

+ 35 - 3
zxyj-backend/src/main/java/com/zxyj/controller/admin/AdminController.java

@@ -283,9 +283,41 @@ public class AdminController {
     // 积分管理
     @PostMapping("/points/logs")
     public Result<Page<PointsLog>> getPointsLogs(@RequestBody Map<String, Object> params) {
-        Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
-        Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
-        Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null;
+        Integer page = 1;
+        Integer size = 10;
+        Long childId = null;
+        
+        // 安全解析page
+        if (params.get("page") != null) {
+            if (params.get("page") instanceof Integer) {
+                page = (Integer) params.get("page");
+            } else if (params.get("page") instanceof Number) {
+                page = ((Number) params.get("page")).intValue();
+            } else {
+                try { page = Integer.parseInt(params.get("page").toString()); } catch (Exception e) {}
+            }
+        }
+        
+        // 安全解析size
+        if (params.get("size") != null) {
+            if (params.get("size") instanceof Integer) {
+                size = (Integer) params.get("size");
+            } else if (params.get("size") instanceof Number) {
+                size = ((Number) params.get("size")).intValue();
+            } else {
+                try { size = Integer.parseInt(params.get("size").toString()); } catch (Exception e) {}
+            }
+        }
+        
+        // 安全解析childId
+        if (params.get("childId") != null) {
+            if (params.get("childId") instanceof Number) {
+                childId = ((Number) params.get("childId")).longValue();
+            } else {
+                try { childId = Long.parseLong(params.get("childId").toString()); } catch (Exception e) {}
+            }
+        }
+        
         String type = (String) params.get("type");
         
         Page<PointsLog> pageParam = new Page<>(page, size);

+ 30 - 6
zxyj-frontend/pages/rewards/rewards.vue

@@ -153,27 +153,32 @@ export default {
       })
     },
     async createReward() {
-      if (!this.newReward.title || !this.newReward.pointsRequired) {
-        uni.showToast({ title: '请填写完整信息', icon: 'none' })
+      if (!this.newReward.title) {
+        uni.showToast({ title: '请填写心愿名称', icon: 'none' })
         return
       }
       
       try {
         if (this.currentRole === 'parent') {
-          // 家长模式:创建家长心愿
+          // 家长模式:创建家长心愿,需要填写积分
+          if (!this.newReward.pointsRequired) {
+            uni.showToast({ title: '请填写所需积分', icon: 'none' })
+            return
+          }
           await createParentWishlist({
             title: this.newReward.title,
             pointsRequired: parseInt(this.newReward.pointsRequired)
           })
+          uni.showToast({ title: '添加成功', icon: 'success' })
         } else {
-          // 孩子模式:创建孩子心愿
+          // 孩子模式:创建孩子心愿,积分为0,等待家长填写
           await createReward({
             title: this.newReward.title,
-            pointsRequired: parseInt(this.newReward.pointsRequired),
             childId: this.currentChildId
+            // pointsRequired不传,默认为0
           })
+          uni.showToast({ title: '已提交,等待家长填写积分', icon: 'success' })
         }
-        uni.showToast({ title: '添加成功', icon: 'success' })
         this.showAddModal = false
         this.newReward = { title: '', pointsRequired: '' }
         this.loadRewards()
@@ -280,6 +285,25 @@ export default {
   font-size: 28rpx;
 }
 
+.form-label {
+  font-size: 28rpx;
+  color: #333;
+  margin-bottom: 10rpx;
+}
+
+.form-label .required {
+  color: #FF6B6B;
+}
+
+.form-tip {
+  font-size: 24rpx;
+  color: #999;
+  padding: 20rpx;
+  background: #f5f5f5;
+  border-radius: 10rpx;
+  margin-bottom: 20rpx;
+}
+
 .modal-btns {
   display: flex;
   gap: 20rpx;

+ 3 - 2
zxyj-frontend/utils/api.js

@@ -300,8 +300,9 @@ export const exchangeParentWishlist = (id) => {
   return request(`/api/parent/wishlist/${id}/exchange`, 'POST', {})
 }
 
-export const approveParentWishlist = (id, approved) => {
-  return request(`/api/parent/wishlist/${id}/approve`, 'POST', { approved })
+// 家长审批孩子的心愿并填写积分
+export const approveParentWishlist = (id, pointsRequired) => {
+  return request(`/api/parent/wishlist/${id}/approve`, 'POST', { pointsRequired })
 }
 
 // =============================================