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(); } + /** * 查询所有中控基本信息。 *