Переглянути джерело

fix: 车辆删除 ID 精度丢失,Long 转 String 传递

前端 JavaScript Number 无法安全表示 19 位 Snowflake ID,导致
删除/设默认时 ID 截断。listUserCars 返回 id 为 String,
Controller 接收 String 后解析为 Long。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 1 день тому
батько
коміт
0685291dcb

+ 5 - 13
car-wash-miniapp/src/main/java/com/kym/miniapp/controller/CarsController.java

@@ -7,14 +7,6 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.Map;
 
-/**
- * <p>
- * 车辆表 前端控制器
- * </p>
- *
- * @author skyline
- * @since 2023-07-26
- */
 @RestController
 @RequestMapping("/cars")
 public class CarsController {
@@ -40,16 +32,16 @@ public class CarsController {
     }
 
     @PostMapping("/setDefault/{id}")
-    public R<?> setDefault(@PathVariable Long id) {
+    public R<?> setDefault(@PathVariable String id) {
         var userId = StpUtil.getLoginIdAsLong();
-        carsService.setDefault(userId, id);
+        carsService.setDefault(userId, Long.parseLong(id));
         return R.success();
     }
 
-    @DeleteMapping("/delete/{id}")
-    public R<?> delete(@PathVariable Long id) {
+    @PostMapping("/delete/{id}")
+    public R<?> delete(@PathVariable String id) {
         var userId = StpUtil.getLoginIdAsLong();
-        carsService.deleteCar(userId, id);
+        carsService.deleteCar(userId, Long.parseLong(id));
         return R.success();
     }
 }

+ 2 - 2
car-wash-mp/src/pages-user/profile/index.vue

@@ -113,7 +113,7 @@
 <script setup>
 import {onLoad, onShow} from "@dcloudio/uni-app";
 import {ref, computed, nextTick} from "vue";
-import {body, get, del} from "@/utils/https";
+import {body, get} from "@/utils/https";
 
 const plateChars = ref(['粤', '', '', '', '', '', '', '']);
 const restStr = ref('');
@@ -221,7 +221,7 @@ const handleDelete = (car) => {
     success: (res) => {
       if (res.confirm) {
         uni.showLoading({ title: "删除中" });
-        del(`/cars/delete/${car.id}`).then(() => {
+        body(`/cars/delete/${car.id}`).then(() => {
           uni.hideLoading();
           uni.showToast({ icon: "success", title: "已删除" });
           fetchCarList();

+ 1 - 1
car-wash-service/src/main/java/com/kym/service/impl/CarsServiceImpl.java

@@ -30,7 +30,7 @@ public class CarsServiceImpl extends MPJBaseServiceImpl<CarsMapper, Cars> implem
                 .list()
                 .stream()
                 .map(car -> Map.<String, Object>of(
-                        "id", car.getId(),
+                        "id", car.getId().toString(),
                         "plateNo", car.getPlateNo(),
                         "isDefault", car.getIsDefault() != null && car.getIsDefault()
                 ))