From cdbc6aef584c6c8275d1cc60ab2afc5b7130b98a Mon Sep 17 00:00:00 2001 From: 19173159168 Date: Thu, 25 Sep 2025 00:23:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=97=E9=A4=90=E8=AE=BE=E7=BD=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ZcRentCarRuleController.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/operation/controller/ZcRentCarRuleController.java b/ruoyi-admin/src/main/java/com/ruoyi/operation/controller/ZcRentCarRuleController.java index c6eb4f3..533b672 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/operation/controller/ZcRentCarRuleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/operation/controller/ZcRentCarRuleController.java @@ -112,7 +112,7 @@ public class ZcRentCarRuleController extends BaseController @Log(title = "租车计费规则", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody - public AjaxResult addSave(@RequestParam("batteryRules") List batteryRuleIds, ZcRentCarRule zcRentCarRule) + public AjaxResult addSave(@RequestParam(value = "batteryRules",required = false) List batteryRuleIds, ZcRentCarRule zcRentCarRule) { // 如果是按天租,验证选择的租电套餐支持天数是否一致 if("3".equals(zcRentCarRule.getRentalType())){ @@ -131,17 +131,19 @@ public class ZcRentCarRuleController extends BaseController int flag = zcRentCarRuleService.insertZcRentCarRule(zcRentCarRule); - // 保存关联表 ZcRentCarRuleBattery 数据 - List ruleBatteryList = new ArrayList<>(); - for (Long batteryRuleId : batteryRuleIds) { - ZcRentCarRuleBattery ruleBattery = new ZcRentCarRuleBattery(); - ruleBattery.setCarRuleId(zcRentCarRule.getId()); - ruleBattery.setBatteryRuleId(batteryRuleId); - ruleBattery.setCreateTime(new Date()); - ruleBatteryList.add(ruleBattery); - } - if (!ruleBatteryList.isEmpty()) { - zcRentCarRuleBatteryService.batchInsert(ruleBatteryList); + if (batteryRuleIds != null && !batteryRuleIds.isEmpty()) { + // 保存关联表 ZcRentCarRuleBattery 数据 + List ruleBatteryList = new ArrayList<>(); + for (Long batteryRuleId : batteryRuleIds) { + ZcRentCarRuleBattery ruleBattery = new ZcRentCarRuleBattery(); + ruleBattery.setCarRuleId(zcRentCarRule.getId()); + ruleBattery.setBatteryRuleId(batteryRuleId); + ruleBattery.setCreateTime(new Date()); + ruleBatteryList.add(ruleBattery); + } + if (!ruleBatteryList.isEmpty()) { + zcRentCarRuleBatteryService.batchInsert(ruleBatteryList); + } } return toAjax(flag); }