From 43d819b9f596b133317be00c8e098224ed949d9dfced8302dd9bb79b1e9ce775 Mon Sep 17 00:00:00 2001 From: attiya <2413103649@qq.com> Date: Thu, 16 Oct 2025 09:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E6=B1=A0=E6=89=B9=E9=87=8F=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EbikeBatteryInfoController.java | 20 ++++++++++++++----- .../controller/EbikeEcuInfoController.java | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBatteryInfoController.java b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBatteryInfoController.java index a83db4b..d554fde 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBatteryInfoController.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBatteryInfoController.java @@ -51,11 +51,14 @@ public class EbikeBatteryInfoController { * @return {@code true} 添加成功,{@code false} 添加失败 */ @GetMapping("bind") - public JsonResult bind(@RequestParam("batteryId")Long batteryId){ + public JsonResult bind(@RequestParam("batteryId") Long batteryId) { EbikeBatteryInfo batteryInfo = ebikeBatteryInfoService.getById(batteryId); if (batteryInfo == null) { throw new EbikeException("电池ID错误"); } + if (batteryInfo.getStatus() == BatteryStatus.BIND) { + throw new EbikeException("该电池已绑定"); + } batteryInfo.setStatus(BatteryStatus.BIND); ebikeBatteryInfoService.updateById(batteryInfo); return JsonResult.success(); @@ -68,7 +71,14 @@ public class EbikeBatteryInfoController { * @return {@code true} 添加成功,{@code false} 添加失败 */ @GetMapping("batchBind") - public JsonResult batchBind(@RequestBody EbikeBatteryInfoIdVo ids){ + public JsonResult batchBind(@RequestBody EbikeBatteryInfoIdVo ids) { + QueryWrapper queryWrapper = QueryWrapper.create() + .where(EBIKE_BATTERY_INFO.BATTERY_ID.in(ids.getBatteryIds())) + .where(EBIKE_BATTERY_INFO.STATUS.eq(BatteryStatus.BIND)); + long count = ebikeBatteryInfoService.count(queryWrapper); + if (count > 0) { + throw new EbikeException("选择电池集合中包含已绑定电池"); + } UpdateChain.of(EbikeBatteryInfo.class) .set(EbikeBatteryInfo::getStatus, BatteryStatus.BIND) .where(EbikeBatteryInfo::getBatteryId).in(ids.getBatteryIds()); @@ -81,7 +91,7 @@ public class EbikeBatteryInfoController { * @param batteryId 主键 * @return {@code true} 删除成功,{@code false} 删除失败 */ - @PostMapping("remove") + @GetMapping("remove") public JsonResult remove(@RequestParam(value = "batteryId") Long batteryId) { ebikeBatteryInfoService.removeById(batteryId); return JsonResult.success(); @@ -106,10 +116,10 @@ public class EbikeBatteryInfoController { * @return 分页对象 */ @GetMapping("page") - public JsonResult page(PageParam pageParam,Integer status) { + public JsonResult page(PageParam pageParam, Integer status) { QueryWrapper queryWrapper = QueryWrapper.create() .where(EBIKE_BATTERY_INFO.STATUS.eq(status, Objects.nonNull(status))); - Page page = ebikeBatteryInfoService.page(pageParam.getPage(),queryWrapper); + Page page = ebikeBatteryInfoService.page(pageParam.getPage(), queryWrapper); return JsonResult.success(page); } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java index 98d4c1f..8b9dddc 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java @@ -75,6 +75,7 @@ public class EbikeEcuInfoController { return JsonResult.success(); } + /** * 查询所有中控基本信息。 *