From a4f1935475de6d36539e3af41f507e8a2d665789 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Tue, 22 Oct 2024 21:16:02 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=94=B6=E8=B4=B9=E6=96=B9=E5=BC=8F=E5=92=8C?= =?UTF-8?q?=E8=BD=A6=E5=9E=8B=E7=9A=84=E6=96=B0=E5=A2=9E=E5=92=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/EtFeeRuleController.java | 55 ++++++++++++++++++- .../controller/system/EtModelController.java | 36 ++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtFeeRuleController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtFeeRuleController.java index 7a7b006..b7c499d 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtFeeRuleController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtFeeRuleController.java @@ -3,6 +3,7 @@ package com.ruoyi.web.controller.system; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.alibaba.fastjson2.JSON; import com.ruoyi.common.core.domain.entity.SysDept; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; @@ -74,25 +75,75 @@ public class EtFeeRuleController extends BaseController /** * 新增收费方式 */ -// @PreAuthorize("@ss.hasPermi('system:fee:add')") @Log(title = "收费方式", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody EtFeeRule etFeeRule) { + logger.info("新增收费方式:{}", JSON.toJSON(etFeeRule)); + // 校验收费方式 + String validationResult = verifyFeeRule(etFeeRule); + if (validationResult != null) { + return AjaxResult.error(validationResult); // 校验失败,返回错误信息 + } return toAjax(etFeeRuleService.insertEtFeeRule(etFeeRule)); } /** * 修改收费方式 */ -// @PreAuthorize("@ss.hasPermi('system:fee:edit')") @Log(title = "收费方式", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody EtFeeRule etFeeRule) { + logger.info("修改收费方式:{}", JSON.toJSON(etFeeRule)); + String validationResult = verifyFeeRule(etFeeRule); + if (validationResult != null) { + return AjaxResult.error(validationResult); // 校验失败,返回错误信息 + } return toAjax(etFeeRuleService.updateEtFeeRule(etFeeRule)); } + /** + * 校验 EtFeeRule 的必填项 + */ + private String verifyFeeRule(EtFeeRule etFeeRule) { + // 校验套餐名称 + if (etFeeRule.getName() == null || etFeeRule.getName().trim().isEmpty()) { + return "套餐名称为必填项"; + } + // 校验运营商 + if (etFeeRule.getDeptId() == null) { + return "代理商为必填项"; + } + // 校验说明 + if (etFeeRule.getInstructions() == null || etFeeRule.getInstructions().trim().isEmpty()) { + return "说明为必填项"; + } + // 校验免费骑行时长 + if (etFeeRule.getFreeRideTime() == null) { + return "免费骑行为必填项"; + } + // 校验租赁单位 + if (etFeeRule.getRentalUnit() == null || etFeeRule.getRentalUnit().trim().isEmpty()) { + return "租赁单位为必填项"; + } + // 校验计费规则 + if (etFeeRule.getRidingRule() == null || etFeeRule.getRidingRule().trim().isEmpty()) { + return "计费规则为必填项"; + } + // 校验计费周期 + if (etFeeRule.getChargingCycle() == null || etFeeRule.getChargingCycle().trim().isEmpty()) { + return "计费周期为必填项"; + } + // 校验封顶金额 + if (etFeeRule.getCappedAmount() == null) { + return "封顶金额为必填项"; + } + // 如果所有必填项都校验通过,返回 null + return null; + } + + /** * 删除收费方式 */ diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java index 9aff827..6b58530 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtModelController.java @@ -102,9 +102,40 @@ public class EtModelController extends BaseController @PostMapping public AjaxResult add(@RequestBody EtModel etModel) { + logger.info("新增车辆型号:{}", JSON.toJSON(etModel)); + // 校验方法 + String validationResult = verifyModel(etModel); + if (validationResult != null) { + return AjaxResult.error(validationResult); // 校验失败,返回错误信息 + } return toAjax(etModelService.insertEtModel(etModel)); } + private String verifyModel(EtModel etModel) { + // 校验必填字段 + if (etModel.getModel() == null || etModel.getModel().trim().isEmpty()) { + return "车型为必填项"; + } + if (etModel.getOperator() == null) { + return "代理商为必填项"; + } + if (etModel.getAreaId() == null) { + return "运营区为必填项"; + } + if (etModel.getFullVoltage() == null) { + return "满电电压为必填项"; + } + if (etModel.getLowVoltage() == null) { + return "亏电电压为必填项"; + } + if (etModel.getFullEndurance() == null) { + return "满电续航为必填项"; + } + + // 校验通过,返回 null + return null; + } + /** * 修改车辆型号 */ @@ -114,6 +145,11 @@ public class EtModelController extends BaseController public AjaxResult edit(@RequestBody EtModel etModel) { logger.info("修改车辆型号:{}", JSON.toJSON(etModel)); + // 校验方法 + String validationResult = verifyModel(etModel); + if (validationResult != null) { + return AjaxResult.error(validationResult); // 校验失败,返回错误信息 + } return toAjax(etModelService.updateEtModel(etModel)); }