|
@@ -144,6 +144,23 @@ public class SysDeptRateServiceImpl implements ISysDeptRateService
|
|
|
*/
|
|
*/
|
|
|
private static void validateIntervalOverlap(List<SysDeptRate> rates) {
|
|
private static void validateIntervalOverlap(List<SysDeptRate> rates) {
|
|
|
if (rates.size() <= 1) {
|
|
if (rates.size() <= 1) {
|
|
|
|
|
+ SysDeptRate rate = rates.get(0);
|
|
|
|
|
+ Long begins = rate.getIntervalBegins();
|
|
|
|
|
+ Long ends = rate.getIntervalEnds();
|
|
|
|
|
+ // 检查区间有效性
|
|
|
|
|
+ if (begins == null || ends == null) {
|
|
|
|
|
+ throw new ServiceException("区间开始和结束值不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (begins >= ends) {
|
|
|
|
|
+ throw new ServiceException(String.format(
|
|
|
|
|
+ "%s、%s配置的区间开始值必须小于结束值", getCompanyName(rate.getCompanyType()), getProductName(rate.getProductType())));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (rate.getRate().compareTo(new BigDecimal("0")) == 0) {
|
|
|
|
|
+ throw new ServiceException(String.format(
|
|
|
|
|
+ "%s、%s的费率不能为0", getCompanyName(rate.getCompanyType()), getProductName(rate.getProductType())));
|
|
|
|
|
+ }
|
|
|
return; // 单个或空列表无需校验
|
|
return; // 单个或空列表无需校验
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -182,18 +199,23 @@ public class SysDeptRateServiceImpl implements ISysDeptRateService
|
|
|
|
|
|
|
|
if (isOverlap) {
|
|
if (isOverlap) {
|
|
|
throw new ServiceException(String.format(
|
|
throw new ServiceException(String.format(
|
|
|
- "物流公司%s、产品类型%s的区间配置存在重叠:区间%d(%d,%d] 与区间%d(%d,%d]",
|
|
|
|
|
- rates.get(i).getCompanyType(),
|
|
|
|
|
- rates.get(i).getProductType(),
|
|
|
|
|
|
|
+ "%s、%s的区间配置存在重叠:区间%d(%d,%d] 与区间%d(%d,%d]",
|
|
|
|
|
+ getCompanyName(rates.get(i).getCompanyType()),
|
|
|
|
|
+ getProductName(rates.get(i).getProductType()),
|
|
|
i + 1, begins1, ends1,
|
|
i + 1, begins1, ends1,
|
|
|
j + 1, begins2, ends2));
|
|
j + 1, begins2, ends2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (rate1.getRate().compareTo(new BigDecimal("0")) == 0) {
|
|
|
|
|
+ throw new ServiceException(String.format(
|
|
|
|
|
+ "%s、%s的费率不能为0", getCompanyName(rate1.getCompanyType()), getProductName(rate1.getProductType())));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (rate1.getRate().compareTo(rate2.getRate()) < 0) {
|
|
if (rate1.getRate().compareTo(rate2.getRate()) < 0) {
|
|
|
throw new ServiceException(String.format(
|
|
throw new ServiceException(String.format(
|
|
|
- "物流公司%s、产品类型%s的费率配置有误:区间%d(%d,%d] 与区间%d(%d,%d]",
|
|
|
|
|
- rates.get(i).getCompanyType(),
|
|
|
|
|
- rates.get(i).getProductType(),
|
|
|
|
|
|
|
+ "%s、%s的费率配置有误:区间%d(%d,%d] 与区间%d(%d,%d]",
|
|
|
|
|
+ getCompanyName(rates.get(i).getCompanyType()),
|
|
|
|
|
+ getProductName(rates.get(i).getProductType()),
|
|
|
i + 1, begins1, ends1,
|
|
i + 1, begins1, ends1,
|
|
|
j + 1, begins2, ends2));
|
|
j + 1, begins2, ends2));
|
|
|
}
|
|
}
|
|
@@ -201,41 +223,32 @@ public class SysDeptRateServiceImpl implements ISysDeptRateService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
|
- List<SysDeptRate> rates = new ArrayList<>();
|
|
|
|
|
- SysDeptRate a = new SysDeptRate();
|
|
|
|
|
- SysDeptRate b = new SysDeptRate();
|
|
|
|
|
- SysDeptRate c = new SysDeptRate();
|
|
|
|
|
-
|
|
|
|
|
- a.setCompanyType("JD");
|
|
|
|
|
- a.setProductType("ed-m-0001");
|
|
|
|
|
- a.setIntervalBegins(0L);
|
|
|
|
|
- a.setIntervalEnds(100L);
|
|
|
|
|
- a.setRate(new BigDecimal("0.1"));
|
|
|
|
|
-
|
|
|
|
|
- b.setCompanyType("JD");
|
|
|
|
|
- b.setProductType("ed-m-0001");
|
|
|
|
|
- b.setIntervalBegins(100L);
|
|
|
|
|
- b.setIntervalEnds(200L);
|
|
|
|
|
- b.setRate(new BigDecimal("0.2"));
|
|
|
|
|
-
|
|
|
|
|
- c.setCompanyType("JD");
|
|
|
|
|
- c.setProductType("ed-m-0002");
|
|
|
|
|
- c.setIntervalBegins(200L);
|
|
|
|
|
- c.setIntervalEnds(300L);
|
|
|
|
|
- c.setRate(new BigDecimal("0.3"));
|
|
|
|
|
-
|
|
|
|
|
- rates.add(c);
|
|
|
|
|
- rates.add(b);
|
|
|
|
|
- rates.add(a);
|
|
|
|
|
-
|
|
|
|
|
- List<SysDeptRate> collect = rates.stream()
|
|
|
|
|
- .sorted(
|
|
|
|
|
- Comparator.comparing(SysDeptRate::getCompanyType)
|
|
|
|
|
- .thenComparing(SysDeptRate::getProductType)
|
|
|
|
|
- .thenComparing(SysDeptRate::getIntervalBegins)
|
|
|
|
|
- )
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- System.out.println(1);
|
|
|
|
|
|
|
+ private static String getCompanyName(String companyType) {
|
|
|
|
|
+ if (companyType == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (companyType.equals("1")) {
|
|
|
|
|
+ return "京东";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (companyType.equals("2")) {
|
|
|
|
|
+ return "顺丰";
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String getProductName(String productType) {
|
|
|
|
|
+ if (productType == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (productType.equals("ed-m-0001")) {
|
|
|
|
|
+ return "京东标快";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (productType.equals("ed-m-0002")) {
|
|
|
|
|
+ return "京东特快";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (productType.equals("fr-m-0004")) {
|
|
|
|
|
+ return "特快重货";
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|