Ver código fonte

办卡界面保存时新增校验

xlq 4 semanas atrás
pai
commit
5723585267

+ 40 - 12
src/main/java/com/qmrb/system/controller/CarParkStoredCardController.java

@@ -1,12 +1,19 @@
 package com.qmrb.system.controller;
 
+import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.druid.sql.visitor.functions.If;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qmrb.system.common.exception.BusinessException;
+import com.qmrb.system.pojo.entity.BarnRecord;
 import com.qmrb.system.pojo.entity.CarParkStoredCard;
+import com.qmrb.system.pojo.form.BarnRecordForm;
+import com.qmrb.system.service.IBarnRecordService;
+import com.qmrb.system.service.ICarParkChargingRulesService;
 import org.springdoc.core.annotations.ParameterObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -50,12 +57,33 @@ import jakarta.validation.Valid;
 @RestController
 @RequestMapping("/api/v1/park_stored_card")
 @CrossOrigin
-public class CarParkStoredCardController{
+public class CarParkStoredCardController {
 
     @Autowired
     private ICarParkStoredCardService carParkStoredCardService;
+    @Autowired
+    private IBarnRecordService barnRecordService;
+    @Autowired
+    private ICarParkChargingRulesService rulesService;
+
+    @Operation(summary = "根据车牌号校验未结清费用", security = {@SecurityRequirement(name = "Authorization")})
+    @GetMapping("/getfeeByCarNumber")
+    public Result<?> getfeeByCarNumber(
+            @ParameterObject CarParkStoredCardQuery queryParams
+    ) {
+        List<BarnRecord> list = barnRecordService.list(new LambdaQueryWrapper<BarnRecord>()
+                .eq(BarnRecord::getCarNumber, queryParams.getPlateNumber())
+                .orderByDesc(BarnRecord::getCreateTime));
+        BigDecimal pendingAmount = BigDecimal.ZERO;
+        if (CollectionUtil.isNotEmpty(list)) {
+            // 计算未支付金额
+            pendingAmount = rulesService.calcuExpenses(list.get(0).getId(), queryParams.getPlateNumber(), true);
+        }
+
+        return Result.success(pendingAmount);
+    }
 
-	@Operation(summary = "停车储值卡分页列表", security = {@SecurityRequirement(name = "Authorization")})
+    @Operation(summary = "停车储值卡分页列表", security = {@SecurityRequirement(name = "Authorization")})
     @GetMapping("/page")
     public PageResult<CarParkStoredCardVO> getPage(
             @ParameterObject CarParkStoredCardQuery queryParams
@@ -63,7 +91,7 @@ public class CarParkStoredCardController{
         Page<CarParkStoredCardVO> result = carParkStoredCardService.getPage(queryParams);
         return PageResult.success(result);
     }
-    
+
     @Operation(summary = "停车储值卡分页列表", security = {@SecurityRequirement(name = "Authorization")})
     @GetMapping("/getPageByUserId")
     public Result<?> getPageByUserId(
@@ -74,10 +102,10 @@ public class CarParkStoredCardController{
         // }
         List<CarParkStoredCard> list = carParkStoredCardService.list(new LambdaQueryWrapper<CarParkStoredCard>()
                 // .eq(CarParkStoredCard::getUserId,queryParams.getUserId())
-                .eq(CarParkStoredCard::getPlateNumber,queryParams.getPlateNumber()));
+                .eq(CarParkStoredCard::getPlateNumber, queryParams.getPlateNumber()));
         return Result.success(list);
     }
-    
+
     @Operation(summary = "新增停车储值卡", security = {@SecurityRequirement(name = "Authorization")})
     @PostMapping
     @Resubmit
@@ -93,7 +121,7 @@ public class CarParkStoredCardController{
     public Result<CarParkStoredCardForm> getForm(
             @Parameter(description = "停车储值卡ID") @PathVariable Long id
     ) {
-    	CarParkStoredCardForm formData = carParkStoredCardService.getFormData(id);
+        CarParkStoredCardForm formData = carParkStoredCardService.getFormData(id);
         return Result.success(formData);
     }
 
@@ -102,8 +130,8 @@ public class CarParkStoredCardController{
     public Result<?> updateForm(
             @Parameter(description = "停车储值卡ID") @PathVariable Long id,
             @RequestBody @Validated CarParkStoredCardForm form) {
-    	
-        boolean result = carParkStoredCardService.updateForm(id,form);
+
+        boolean result = carParkStoredCardService.updateForm(id, form);
         return Result.judge(result);
     }
 
@@ -112,15 +140,15 @@ public class CarParkStoredCardController{
     public Result<?> deleteUsers(
             @Parameter(description = "停车储值卡ID,多个以英文逗号(,)分割") @PathVariable String ids
     ) {
-    	if(StrUtil.isBlank(ids)) {
-    		 return Result.failed(ResultCode.PARAM_ERROR, "删除的停车储值卡数据为空");
-    	}
+        if (StrUtil.isBlank(ids)) {
+            return Result.failed(ResultCode.PARAM_ERROR, "删除的停车储值卡数据为空");
+        }
         // 逻辑删除
         List<Long> idList = Arrays.asList(ids.split(",")).stream()
                 .map(idStr -> Long.parseLong(idStr)).collect(Collectors.toList());
         boolean result = carParkStoredCardService.removeByIds(idList);
         return Result.judge(result);
     }
-    
+
 
 }