guoshuai 4 semanas atrás
pai
commit
6b978863e5

+ 6 - 1
src/main/java/com/qmrb/system/pojo/entity/BarnRecord.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.qmrb.system.common.base.BaseEntity;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -106,5 +107,9 @@ public class BarnRecord extends BaseEntity {
      */
     @TableField("emergency_flag")
     private String emergencyFlag;
-
+    /**
+     * 抵用
+     */
+    @TableField("discount_amount")
+    private BigDecimal discountAmount;
 }

+ 6 - 0
src/main/java/com/qmrb/system/pojo/form/BarnRecordForm.java

@@ -98,4 +98,10 @@ public class BarnRecordForm {
      */
     @Schema(description = "状态",type="Integer")
     private Integer status;
+
+    /**
+     * 抵用
+     */
+    @Schema(description = "抵用",type="BigDecimal")
+    private BigDecimal discountAmount;
 }

+ 6 - 0
src/main/java/com/qmrb/system/pojo/query/BarnRecordQuery.java

@@ -104,4 +104,10 @@ public class BarnRecordQuery extends BasePageQuery{
      * true: 办卡清算
      */
     private Boolean isMonthlyCardMode;
+
+    /**
+     * 抵用
+     */
+    @Schema(description = "抵用",type="BigDecimal")
+    private BigDecimal discountAmount;
 }

+ 6 - 0
src/main/java/com/qmrb/system/pojo/vo/BarnRecordVO.java

@@ -99,6 +99,12 @@ public class BarnRecordVO {
      */
     @Schema(description = "状态",type="Integer")
     private Integer status;
+
+    /**
+     * 抵用
+     */
+    @Schema(description = "抵用",type="BigDecimal")
+    private BigDecimal discountAmount;
 	@Schema(description = "子分类")
     private List<BarnRecordVO> children;
 

+ 10 - 1
src/main/java/com/qmrb/system/service/ICarParkStoredCardService.java

@@ -1,9 +1,11 @@
 package com.qmrb.system.service;
 
+import java.util.Date;
 import java.util.List;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmrb.system.pojo.entity.CarParkStoredCard;
+import com.qmrb.system.pojo.form.BarnRecordForm;
 import com.qmrb.system.pojo.form.CarParkStoredCardForm;
 import com.qmrb.system.pojo.vo.CarParkStoredCardVO;
 import com.qmrb.system.pojo.query.CarParkStoredCardQuery;
@@ -37,5 +39,12 @@ public interface ICarParkStoredCardService extends IService<CarParkStoredCard> {
 	/**获取表单数据
 	 * */
 	public CarParkStoredCardForm getFormData(Long id);
-	
+
+	/**
+	 * 根据停车记录计算计费开始时间
+	 * 只针对没有计费开始时间为空得情况,即第一次支付
+	 * @param form
+	 * @return
+	 */
+    Date getBillingStartTime(BarnRecordForm form);
 }

+ 15 - 7
src/main/java/com/qmrb/system/service/impl/BarnRecordServiceImpl.java

@@ -13,14 +13,13 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONUtil;
 import com.qmrb.system.mq.PickCarProducer;
 import com.qmrb.system.pojo.entity.CarPark;
+import com.qmrb.system.pojo.entity.CarParkStoredCard;
 import com.qmrb.system.pojo.entity.MyCarPlateNumber;
-import com.qmrb.system.service.IBarnRecordService;
-import com.qmrb.system.service.ICarParkChargingRulesService;
-import com.qmrb.system.service.ICarParkService;
-import com.qmrb.system.service.IMyCarPlateNumberService;
+import com.qmrb.system.service.*;
 import org.apache.rocketmq.client.exception.MQBrokerException;
 import org.apache.rocketmq.client.exception.MQClientException;
 import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -59,6 +58,9 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
     @Autowired
     private ICarParkService carParkService;
     
+    @Autowired
+    private ICarParkStoredCardService parkStoredCardService;
+    
     
     @Autowired
     private ICarParkChargingRulesService carParkChargingRulesService;
@@ -121,7 +123,11 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
             }
 
             if(record.getBillingStartTime() == null){
-                record.setBillingStartTime(record.getInTime());
+                BarnRecordForm form = new BarnRecordForm();
+                form.setInTime(record.getInTime());
+                form.setCarNumber(record.getCarNumber());
+                Date billingStartTime = parkStoredCardService.getBillingStartTime(form);
+                record.setBillingStartTime(billingStartTime);
             }
             // 计算计费时长
             if (record.getOutTime() != null) {
@@ -205,9 +211,11 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
 
         // 实体转换
         BarnRecordForm form = converter.entity2Form(entity);
-
+        
+        
         if(form.getBillingStartTime() == null){
-            form.setBillingStartTime(form.getInTime());
+            Date billingStartTime = parkStoredCardService.getBillingStartTime(form);
+            form.setBillingStartTime(billingStartTime);
         }
         // 计算计费时长
         if (form.getOutTime() != null) {

+ 1 - 1
src/main/java/com/qmrb/system/service/impl/CarParkChargingRulesServiceImpl.java

@@ -126,7 +126,7 @@ public class CarParkChargingRulesServiceImpl extends ServiceImpl<CarParkCharging
 	public BigDecimal calcuExpenses(Long recordId, String carNumber,Boolean isMonthlyCardMode) {
 		// 查询当前用户是否有月卡
 		List<CarParkStoredCard> list = parkStoredCardService.list(new LambdaQueryWrapper<CarParkStoredCard>().eq(CarParkStoredCard::getPlateNumber, carNumber)
-				.eq(CarParkStoredCard::getStatus,1).ge(CarParkStoredCard::getEndTime, LocalDateTime.now()));
+				.eq(CarParkStoredCard::getStatus,1).orderByDesc(CarParkStoredCard::getEndTime));
 		BarnRecord barnRecord = barnRecordMapper.selectById(recordId);
 		Assert.isTrue(barnRecord != null, "计费时停车记录不存在,id为"+recordId);
 		

+ 40 - 8
src/main/java/com/qmrb/system/service/impl/CarParkStoredCardServiceImpl.java

@@ -1,12 +1,11 @@
 package com.qmrb.system.service.impl;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
+import java.time.*;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import com.qmrb.system.pojo.entity.BarnRecord;
+import com.qmrb.system.pojo.form.BarnRecordForm;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -105,8 +104,41 @@ public class CarParkStoredCardServiceImpl extends ServiceImpl<CarParkStoredCardM
         CarParkStoredCardForm form = converter.entity2Form(entity);
         return form;
 	}
-	
-	
-	
-	
+
+	@Override
+	public Date getBillingStartTime(BarnRecordForm form) {
+
+		// 将 Date 转换为 Instant
+		Instant instant = form.getInTime().toInstant();
+
+		// 将 Instant 转换为 LocalDateTime(假设使用系统默认时区)
+		LocalDateTime inDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
+		
+		// 查询当前用户是否有结束日大于入场时间,小于当前时间的月卡
+		List<CarParkStoredCard> list = this.list(new LambdaQueryWrapper<CarParkStoredCard>().eq(CarParkStoredCard::getPlateNumber, form.getCarNumber())
+				.eq(CarParkStoredCard::getStatus,1).ge(CarParkStoredCard::getEndTime, inDateTime).le(CarParkStoredCard::getEndTime, LocalDateTime.now()));
+		if(CollectionUtil.isEmpty(list)){
+			return form.getInTime();
+		}
+		CarParkStoredCard carParkStoredCard = list.get(0);
+		LocalDate endDate = carParkStoredCard.getEndTime().toLocalDate();
+		// 将日期加一天
+		LocalDate nextDay = endDate.plusDays(1);
+		// 创建 LocalDateTime 对象,时分秒均设置为零
+		LocalDateTime nextDayStart = nextDay.atStartOfDay();
+		return convertToDate(nextDayStart);
+	}
+
+	public static Date convertToDate(LocalDateTime localDateTime) {
+		// 获取系统默认时区
+		ZoneId zoneId = ZoneId.systemDefault();
+		// 将 LocalDateTime 转换为 ZonedDateTime
+		ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
+		// 将 ZonedDateTime 转换为 Instant
+		java.time.Instant instant = zonedDateTime.toInstant();
+		// 将 Instant 转换为 Date
+		return Date.from(instant);
+	}
+
+
 }