Przeglądaj źródła

分装对外方法

wangzhijun 2 dni temu
rodzic
commit
6fbd7010dc

+ 8 - 0
nightFragrance-massage/src/main/java/com/ylx/fareSetting/service/IMaProjectFareSettingService.java

@@ -6,6 +6,9 @@ import com.ylx.fareSetting.domian.dto.FareCalculateDTO;
 import com.ylx.fareSetting.domian.vo.FareCalculateResultVO;
 import com.ylx.massage.domain.dto.DriverFeeDTO;
 
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
 public interface IMaProjectFareSettingService extends IService<MaProjectFareSetting> {
     FareCalculateResultVO calculateFare(FareCalculateDTO dto);
 
@@ -17,4 +20,9 @@ public interface IMaProjectFareSettingService extends IService<MaProjectFareSett
      * @return
      */
     void saveOrUpdateFee(DriverFeeDTO dto);
+
+    boolean isDayTimePeriod(LocalDateTime localDateTime);
+
+    BigDecimal getMerchantFreeKm(Long merchantId, Long projectId, boolean isDay);
+
 }

+ 63 - 49
nightFragrance-massage/src/main/java/com/ylx/fareSetting/service/impl/MaProjectFareSettingServiceImpl.java

@@ -76,53 +76,9 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
         boolean isDay = isDayTimePeriod(appointmentStartTime);
 
         // 4. 获取商户车费配置
-        LambdaQueryWrapper<MaProjectFareSetting> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(MaProjectFareSetting::getMerchantId, dto.getMerchantId())
-                .eq(MaProjectFareSetting::getIsDelete, 0);
-        List<MaProjectFareSetting> configList = this.baseMapper.selectList(wrapper);
-
-        MaProjectFareSetting finalConfig = null;
-
-        if (CollUtil.isNotEmpty(configList)) {
-            // 先查找是否存在统一配置 (isUnified = 1)
-            Optional<MaProjectFareSetting> unifiedOpt = configList.stream()
-                    .filter(c -> ObjectUtil.equals(1, c.getIsUnified()))
-                    .findFirst();
+        BigDecimal merchantFreeKm = getMerchantFreeKm(dto.getMerchantId(), dto.getProjectId(), isDay);
 
-            if (unifiedOpt.isPresent()) {
-                finalConfig = unifiedOpt.get();
-            } else {
-                // 查找匹配的项目配置
-                log.info("商户[{}]不存在统一配置,根据projectId[{}]进行匹配", dto.getMerchantId(), dto.getProjectId());
-
-                Optional<MaProjectFareSetting> projectConfigOpt = configList.stream()
-                        .filter(item -> item.getProjectId() != null && item.getProjectId().equals(dto.getProjectId()))
-                        .findFirst();
-
-                if (projectConfigOpt.isPresent()) {
-                    // 找到了对应项目的配置
-                    finalConfig = projectConfigOpt.get();
-                }
-            }
-        }
-
-        BigDecimal merchantFreeKm = BigDecimal.ZERO;
-        
-        if (ObjectUtil.isNotNull(finalConfig)) {
-
-            // 商户配置的免车费距离(用于扣减)
-            merchantFreeKm = isDay ? finalConfig.getDayFreeKm() : finalConfig.getNightFreeKm();
-
-            if (ObjectUtil.isNull(merchantFreeKm) || merchantFreeKm.compareTo(BigDecimal.ZERO) <= 0) {
-                merchantFreeKm = BigDecimal.ZERO;
-                log.info("商户[{}]配置的免车费距离为 null 或 <= 0, 视为 0", dto.getMerchantId());
-            } else {
-                log.info("商户[{}]使用配置ID={}, 免费公里数: {}", dto.getMerchantId(), finalConfig.getId(), merchantFreeKm);
-            }
-        }
-
-
-        // 4. 计算【打车距离】(即计费里程)
+        // 5. 计算【打车距离】(即计费里程)
         BigDecimal straightLineBigDecimal = new BigDecimal(straightLineKm).setScale(6, RoundingMode.HALF_UP);
         BigDecimal effectiveDistance = straightLineBigDecimal.subtract(merchantFreeKm);
         if (effectiveDistance.compareTo(BigDecimal.ZERO) < 0) {
@@ -131,13 +87,13 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
         log.info("直线距离 {} km, 商户免车费距离 {} km -> 打车距离 {} km",
                 straightLineKm, merchantFreeKm, effectiveDistance);
 
-        // 5. 获取城市车费规则(用于最终计费)
+        // 6. 获取城市车费规则(用于最终计费)
         TFareSettingVo cityFare = fareSettingService.getFareSetting(appointmentStartTime, dto.getCityCode());
         if (ObjectUtil.isNull(cityFare)) {
             throw new ServiceException("未找到城市[" + dto.getCityCode() + "]的车费配置");
         }
 
-        // 6. 使用城市规则计算费用
+        // 7. 使用城市规则计算费用
         BigDecimal baseFare = cityFare.getBaseFare();          // 起步价
         BigDecimal baseDistance = cityFare.getBaseDistance();  // 起步距离(公里)
         BigDecimal additionalFarePer = cityFare.getAdditionalFarePer(); // 超出后每公里价格
@@ -164,7 +120,7 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
             }
         }
 
-        // 7. 设置结果
+        // 8. 设置结果
         result.setFreeKm(merchantFreeKm);
         result.setBaseFare(baseFare);
         result.setBaseDistance(baseDistance);
@@ -182,6 +138,7 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
      * @param appointmentStartTime 预约开始时间
      * @return true表示是白天时间段,false表示不是白天时间段(可能是夜间或其他时间段)
      */
+    @Override
     public boolean isDayTimePeriod(LocalDateTime appointmentStartTime) {
         // 提取预约时间的小时和分钟,仅用于时间段比较
         LocalTime appointmentTime = appointmentStartTime.toLocalTime();
@@ -307,4 +264,61 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
             }
         }
     }
+
+    /**
+     * 获取商户当前适用的免车费距离
+     *
+     * @param merchantId 商户ID
+     * @param projectId  项目ID
+     * @param isDay      是否为白天 (true: 白天, false: 夜间)
+     * @return 适用的免车费距离,如果未配置或配置无效则返回 BigDecimal.ZERO
+     */
+    @Override
+    public BigDecimal getMerchantFreeKm(Long merchantId, Long projectId, boolean isDay) {
+        LambdaQueryWrapper<MaProjectFareSetting> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(MaProjectFareSetting::getMerchantId, merchantId)
+                .eq(MaProjectFareSetting::getIsDelete, 0);
+        List<MaProjectFareSetting> configList = this.baseMapper.selectList(wrapper);
+
+        MaProjectFareSetting finalConfig = null;
+
+        if (CollUtil.isNotEmpty(configList)) {
+            // 先查找是否存在统一配置 (isUnified = 1)
+            Optional<MaProjectFareSetting> unifiedOpt = configList.stream()
+                    .filter(c -> ObjectUtil.equals(1, c.getIsUnified()))
+                    .findFirst();
+
+            if (unifiedOpt.isPresent()) {
+                finalConfig = unifiedOpt.get();
+            } else {
+                // 查找匹配的项目配置
+                log.info("商户[{}]不存在统一配置,根据projectId[{}]进行匹配", merchantId, projectId);
+
+                Optional<MaProjectFareSetting> projectConfigOpt = configList.stream()
+                        .filter(item -> item.getProjectId() != null && item.getProjectId().equals(projectId))
+                        .findFirst();
+
+                if (projectConfigOpt.isPresent()) {
+                    // 找到了对应项目的配置
+                    finalConfig = projectConfigOpt.get();
+                }
+            }
+        }
+
+        BigDecimal merchantFreeKm = BigDecimal.ZERO;
+
+        if (ObjectUtil.isNotNull(finalConfig)) {
+
+            // 商户配置的免车费距离(用于扣减)
+            merchantFreeKm = isDay ? finalConfig.getDayFreeKm() : finalConfig.getNightFreeKm();
+
+            if (ObjectUtil.isNull(merchantFreeKm) || merchantFreeKm.compareTo(BigDecimal.ZERO) <= 0) {
+                merchantFreeKm = BigDecimal.ZERO;
+                log.info("商户[{}]配置的免车费距离为 null 或 <= 0, 视为 0", merchantId);
+            } else {
+                log.info("商户[{}]使用配置ID={}, 免费公里数: {}", merchantId, finalConfig.getId(), merchantFreeKm);
+            }
+        }
+        return merchantFreeKm;
+    }
 }