diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/controller/KitchenWasteDealController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/controller/KitchenWasteDealController.java index d4dd922..26bdf71 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/controller/KitchenWasteDealController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/controller/KitchenWasteDealController.java @@ -1,6 +1,8 @@ package com.bonus.canteen.core.kitchen.controller; +import java.math.BigDecimal; import java.util.List; +import java.util.Objects; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; @@ -89,6 +91,22 @@ public class KitchenWasteDealController extends BaseController { @PostMapping public AjaxResult add(@RequestBody KitchenWasteDeal kitchenWasteDeal) { try { + if(Objects.nonNull(kitchenWasteDeal.getWeight())) { + if(kitchenWasteDeal.getWeight().compareTo(new BigDecimal("9999.99")) > 0) { + return error("重量超过最大值"); + } + if(kitchenWasteDeal.getWeight().compareTo(BigDecimal.ZERO) < 0) { + return error("重量不能小于0"); + } + } + if(Objects.nonNull(kitchenWasteDeal.getSaleAmount())) { + if(kitchenWasteDeal.getSaleAmount().compareTo(new BigDecimal("999999.99")) > 0) { + return error("售卖金额超过最大值"); + } + if(kitchenWasteDeal.getSaleAmount().compareTo(BigDecimal.ZERO) < 0) { + return error("售卖金额不能小于0"); + } + } return toAjax(kitchenWasteDealService.insertKitchenWasteDeal(kitchenWasteDeal)); } catch (Exception e) { log.error("新增厨房废弃物处置失败", e); @@ -106,6 +124,22 @@ public class KitchenWasteDealController extends BaseController { @PostMapping("/edit") public AjaxResult edit(@RequestBody KitchenWasteDeal kitchenWasteDeal) { try { + if(Objects.nonNull(kitchenWasteDeal.getWeight())) { + if(kitchenWasteDeal.getWeight().compareTo(new BigDecimal("9999.99")) > 0) { + return error("重量超过最大值"); + } + if(kitchenWasteDeal.getWeight().compareTo(BigDecimal.ZERO) < 0) { + return error("重量不能小于0"); + } + } + if(Objects.nonNull(kitchenWasteDeal.getSaleAmount())) { + if(kitchenWasteDeal.getSaleAmount().compareTo(new BigDecimal("999999.99")) > 0) { + return error("售卖金额超过最大值"); + } + if(kitchenWasteDeal.getSaleAmount().compareTo(BigDecimal.ZERO) < 0) { + return error("售卖金额不能小于0"); + } + } return toAjax(kitchenWasteDealService.updateKitchenWasteDeal(kitchenWasteDeal)); } catch (Exception e) { log.error("修改厨房废弃物处置失败", e);