电池批量绑定状态判断

This commit is contained in:
attiya 2025-10-16 09:42:11 +08:00
parent 7a84f80e84
commit 43d819b9f5
2 changed files with 16 additions and 5 deletions

View File

@ -56,6 +56,9 @@ public class EbikeBatteryInfoController {
if (batteryInfo == null) { if (batteryInfo == null) {
throw new EbikeException("电池ID错误"); throw new EbikeException("电池ID错误");
} }
if (batteryInfo.getStatus() == BatteryStatus.BIND) {
throw new EbikeException("该电池已绑定");
}
batteryInfo.setStatus(BatteryStatus.BIND); batteryInfo.setStatus(BatteryStatus.BIND);
ebikeBatteryInfoService.updateById(batteryInfo); ebikeBatteryInfoService.updateById(batteryInfo);
return JsonResult.success(); return JsonResult.success();
@ -69,6 +72,13 @@ public class EbikeBatteryInfoController {
*/ */
@GetMapping("batchBind") @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) UpdateChain.of(EbikeBatteryInfo.class)
.set(EbikeBatteryInfo::getStatus, BatteryStatus.BIND) .set(EbikeBatteryInfo::getStatus, BatteryStatus.BIND)
.where(EbikeBatteryInfo::getBatteryId).in(ids.getBatteryIds()); .where(EbikeBatteryInfo::getBatteryId).in(ids.getBatteryIds());
@ -81,7 +91,7 @@ public class EbikeBatteryInfoController {
* @param batteryId 主键 * @param batteryId 主键
* @return {@code true} 删除成功{@code false} 删除失败 * @return {@code true} 删除成功{@code false} 删除失败
*/ */
@PostMapping("remove") @GetMapping("remove")
public JsonResult<?> remove(@RequestParam(value = "batteryId") Long batteryId) { public JsonResult<?> remove(@RequestParam(value = "batteryId") Long batteryId) {
ebikeBatteryInfoService.removeById(batteryId); ebikeBatteryInfoService.removeById(batteryId);
return JsonResult.success(); return JsonResult.success();

View File

@ -75,6 +75,7 @@ public class EbikeEcuInfoController {
return JsonResult.success(); return JsonResult.success();
} }
/** /**
* 查询所有中控基本信息 * 查询所有中控基本信息
* *