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)); }