|
|
@@ -1,11 +1,15 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
+import com.ruoyi.logistics.constant.JDDictConstants;
|
|
|
+import com.ruoyi.logistics.domain.SysDeptRate;
|
|
|
+import com.ruoyi.logistics.service.ISysDeptRateService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -40,6 +44,9 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
@Autowired
|
|
|
private SysRoleMapper roleMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptRateService deptRateService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询部门管理数据
|
|
|
*
|
|
|
@@ -388,6 +395,33 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
failureMsg.append(String.format("第%d行:%s 部门已存在;", rowNum, dept.getDeptName())); } else {
|
|
|
// 新增部门
|
|
|
this.insertDept(dept);
|
|
|
+
|
|
|
+ // 处理费率配置
|
|
|
+ try {
|
|
|
+ List<SysDeptRate> rateList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 解析京东费率配置
|
|
|
+ if (StringUtils.isNotBlank(importDTO.getJdRateConfig())) {
|
|
|
+ List<SysDeptRate> jdRates = parseRateConfig(importDTO.getJdRateConfig(), "1", rowNum);
|
|
|
+ rateList.addAll(jdRates);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析顺丰费率配置
|
|
|
+ if (StringUtils.isNotBlank(importDTO.getSfRateConfig())) {
|
|
|
+ List<SysDeptRate> sfRates = parseRateConfig(importDTO.getSfRateConfig(), "2", rowNum);
|
|
|
+ rateList.addAll(sfRates);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有费率配置,进行校验并保存
|
|
|
+ if (!rateList.isEmpty()) {
|
|
|
+ deptRateService.insertSysDeptRate(rateList, dept.getDeptId());
|
|
|
+ }
|
|
|
+ } catch (Exception rateEx) {
|
|
|
+ // 费率配置失败,回滚部门创建
|
|
|
+ this.deleteDeptById(dept.getDeptId());
|
|
|
+ throw rateEx;
|
|
|
+ }
|
|
|
+
|
|
|
successNum++;
|
|
|
successMsg.append(String.format("%1$s、导入成功;", dept.getDeptName()));
|
|
|
}
|
|
|
@@ -431,4 +465,109 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
dept.setCreateTime(DateUtils.getNowDate());
|
|
|
return dept;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析费率配置字符串
|
|
|
+ * 格式:快递产品,费率区间开始-费率区间结束,折扣;快递产品,费率区间开始-费率区间结束,折扣
|
|
|
+ * 示例:京东标快,0-100,9.1;京东标快,100-200,9.0
|
|
|
+ *
|
|
|
+ * @param rateConfig 费率配置字符串
|
|
|
+ * @param companyType 公司类型(1-京东,2-顺丰)
|
|
|
+ * @param rowNum 行号
|
|
|
+ * @return SysDeptRate 对象列表
|
|
|
+ */
|
|
|
+ private List<SysDeptRate> parseRateConfig(String rateConfig, String companyType, int rowNum) {
|
|
|
+ List<SysDeptRate> rateList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 按分号分割多个配置项
|
|
|
+ String[] configItems = rateConfig.split(";");
|
|
|
+
|
|
|
+ for (String item : configItems) {
|
|
|
+ if (StringUtils.isBlank(item)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按逗号分割:快递产品,费率区间开始-费率区间结束,折扣
|
|
|
+ String[] parts = item.split(",");
|
|
|
+ if (parts.length != 3) {
|
|
|
+ throw new ServiceException(String.format("第%d行:费率配置格式错误,正确格式为:快递产品,费率区间开始-费率区间结束,折扣", rowNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ String productName = parts[0].trim();
|
|
|
+ String intervalStr = parts[1].trim();
|
|
|
+ String rateStr = parts[2].trim();
|
|
|
+
|
|
|
+ // 解析产品类型
|
|
|
+ String productType = parseProductType(productName, companyType, rowNum);
|
|
|
+
|
|
|
+ // 解析区间
|
|
|
+ String[] intervals = intervalStr.split("-");
|
|
|
+ if (intervals.length != 2) {
|
|
|
+ throw new ServiceException(String.format("第%d行:费率区间格式错误,正确格式为:开始-结束", rowNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ Long intervalBegins;
|
|
|
+ Long intervalEnds;
|
|
|
+ try {
|
|
|
+ intervalBegins = Long.parseLong(intervals[0].trim());
|
|
|
+ intervalEnds = Long.parseLong(intervals[1].trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new ServiceException(String.format("第%d行:费率区间必须为数字", rowNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析折扣
|
|
|
+ BigDecimal rate;
|
|
|
+ try {
|
|
|
+ rate = new BigDecimal(rateStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new ServiceException(String.format("第%d行:折扣必须为数字", rowNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建 SysDeptRate 对象
|
|
|
+ SysDeptRate deptRate = new SysDeptRate();
|
|
|
+ deptRate.setCompanyType(companyType);
|
|
|
+ deptRate.setProductType(productType);
|
|
|
+ deptRate.setIntervalBegins(intervalBegins);
|
|
|
+ deptRate.setIntervalEnds(intervalEnds);
|
|
|
+ deptRate.setRate(rate);
|
|
|
+
|
|
|
+ rateList.add(deptRate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return rateList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析产品类型名称为编码
|
|
|
+ *
|
|
|
+ * @param productName 产品名称
|
|
|
+ * @param companyType 公司类型(1-京东,2-顺丰)
|
|
|
+ * @param rowNum 行号
|
|
|
+ * @return 产品类型编码
|
|
|
+ */
|
|
|
+ private String parseProductType(String productName, String companyType, int rowNum) {
|
|
|
+ if ("1".equals(companyType)) {
|
|
|
+ // 京东产品类型
|
|
|
+ if ("京东标快".equals(productName)) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_ED_M_0001;
|
|
|
+ } else if ("京东特快".equals(productName)) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_ED_M_0002;
|
|
|
+ } else if ("特快重货".equals(productName)) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_FR_M_0004;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(String.format("第%d行:未知的京东产品类型:%s", rowNum, productName));
|
|
|
+ }
|
|
|
+ } else if ("2".equals(companyType)) {
|
|
|
+ // 顺丰产品类型
|
|
|
+ if ("顺丰特快".equals(productName)) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_SF_01;
|
|
|
+ } else if ("顺丰标快".equals(productName)) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_SF_02;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(String.format("第%d行:未知的顺丰产品类型:%s", rowNum, productName));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(String.format("第%d行:未知的公司类型:%s", rowNum, companyType));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|