1
This commit is contained in:
@@ -248,6 +248,8 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
Map<String, Integer> globalModelCounts = new HashMap<>();
|
||||
Map<String, Double> globalPaymentAmounts = new HashMap<>();
|
||||
Map<String, Double> globalRebateAmounts = new HashMap<>();
|
||||
// 记录每个型号的最高单价订单
|
||||
Map<String, JDOrder> globalMaxPriceOrders = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, List<JDOrder>> e : dmEntries) {
|
||||
String dm = e.getKey() != null ? e.getKey() : "未提供";
|
||||
@@ -274,6 +276,18 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
Double rebateAmount = modelRebateAmounts.get(model);
|
||||
globalPaymentAmounts.put(model, globalPaymentAmounts.getOrDefault(model, 0.0) + (paymentAmount != null ? paymentAmount : 0.0));
|
||||
globalRebateAmounts.put(model, globalRebateAmounts.getOrDefault(model, 0.0) + (rebateAmount != null ? rebateAmount : 0.0));
|
||||
|
||||
// 找到该型号价格最高的订单
|
||||
for (JDOrder order : orders) {
|
||||
if (model.equals(order.getModelNumber())) {
|
||||
JDOrder currentMax = globalMaxPriceOrders.get(model);
|
||||
if (currentMax == null ||
|
||||
(order.getPaymentAmount() != null &&
|
||||
(currentMax.getPaymentAmount() == null || order.getPaymentAmount() > currentMax.getPaymentAmount()))) {
|
||||
globalMaxPriceOrders.put(model, order);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
summary.append("总计:").append(totalCount).append("\n详情:");
|
||||
|
||||
@@ -311,16 +325,25 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
// 输出金额计算(单台价格-返现+佣金=净价×数量=总价)
|
||||
double grandTotal = 0.0;
|
||||
StringBuilder calculationLines = new StringBuilder();
|
||||
List<Double> totalPricesList = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Integer> entry : sortedEntries) {
|
||||
String model = entry.getKey();
|
||||
double paymentAmount = globalPaymentAmounts.getOrDefault(model, 0.0);
|
||||
double rebateAmount = globalRebateAmounts.getOrDefault(model, 0.0);
|
||||
int count = entry.getValue();
|
||||
|
||||
// 计算单台价格(总付款金额 / 数量)用于显示
|
||||
double singlePayment = count > 0 ? paymentAmount / count : 0.0;
|
||||
double singleRebate = count > 0 ? rebateAmount / count : 0.0;
|
||||
// 获取该型号最高价格的订单
|
||||
JDOrder maxPriceOrder = globalMaxPriceOrders.get(model);
|
||||
double singlePayment = 0.0;
|
||||
double singleRebate = 0.0;
|
||||
|
||||
if (maxPriceOrder != null) {
|
||||
singlePayment = maxPriceOrder.getPaymentAmount() != null ? maxPriceOrder.getPaymentAmount() : 0.0;
|
||||
singleRebate = maxPriceOrder.getRebateAmount() != null ? maxPriceOrder.getRebateAmount() : 0.0;
|
||||
}
|
||||
|
||||
// 四舍五入到2位小数
|
||||
singlePayment = Math.round(singlePayment * 100.0) / 100.0;
|
||||
singleRebate = Math.round(singleRebate * 100.0) / 100.0;
|
||||
|
||||
// 从Redis获取佣金
|
||||
double commission = 0.0;
|
||||
@@ -333,20 +356,25 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
// 如果获取失败,佣金为0
|
||||
}
|
||||
|
||||
// 用总金额计算,避免精度损失:总价 = 总付款 - 总返现 + (佣金 × 数量)
|
||||
double totalPrice = paymentAmount - rebateAmount + (commission * count);
|
||||
grandTotal += totalPrice;
|
||||
// 计算净价(单台价格 - 返现 + 佣金)
|
||||
double netPrice = singlePayment - singleRebate + commission;
|
||||
// 四舍五入到2位小数
|
||||
netPrice = Math.round(netPrice * 100.0) / 100.0;
|
||||
|
||||
// 计算净价用于显示(总价 / 数量)
|
||||
double netPrice = count > 0 ? totalPrice / count : 0.0;
|
||||
// 计算总价
|
||||
double totalPrice = netPrice * count;
|
||||
// 四舍五入到2位小数
|
||||
totalPrice = Math.round(totalPrice * 100.0) / 100.0;
|
||||
totalPricesList.add(totalPrice);
|
||||
grandTotal += totalPrice;
|
||||
|
||||
// 格式:单台价格-返现+佣金=净价×数量=总价
|
||||
if (count == 1) {
|
||||
// 数量为1时,不显示×1
|
||||
calculationLines.append(String.format("%.1f-%.0f+%.0f=%.1f\n",
|
||||
calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f\n",
|
||||
singlePayment, singleRebate, commission, totalPrice));
|
||||
} else {
|
||||
calculationLines.append(String.format("%.1f-%.0f+%.0f=%.1f×%d=%.1f\n",
|
||||
calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f×%d=%.2f\n",
|
||||
singlePayment, singleRebate, commission, netPrice, count, totalPrice));
|
||||
}
|
||||
}
|
||||
@@ -357,33 +385,15 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
if (sortedEntries.size() > 1) {
|
||||
priceText.append("\n");
|
||||
// 构建汇总公式
|
||||
StringBuilder summaryFormula = new StringBuilder();
|
||||
for (int i = 0; i < sortedEntries.size(); i++) {
|
||||
Map.Entry<String, Integer> entry = sortedEntries.get(i);
|
||||
String model = entry.getKey();
|
||||
double paymentAmount = globalPaymentAmounts.getOrDefault(model, 0.0);
|
||||
double rebateAmount = globalRebateAmounts.getOrDefault(model, 0.0);
|
||||
int count = entry.getValue();
|
||||
|
||||
double commission = 0.0;
|
||||
try {
|
||||
com.ruoyi.jarvis.domain.ProductJdConfig config = productJdConfigService.selectProductJdConfigByModel(model);
|
||||
if (config != null && config.getCommission() != null) {
|
||||
commission = config.getCommission().doubleValue();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// 用总金额计算
|
||||
double totalPrice = paymentAmount - rebateAmount + (commission * count);
|
||||
|
||||
for (int i = 0; i < totalPricesList.size(); i++) {
|
||||
if (i > 0) {
|
||||
summaryFormula.append("+");
|
||||
priceText.append("+");
|
||||
}
|
||||
summaryFormula.append(String.format("%.1f", totalPrice));
|
||||
priceText.append(String.format("%.2f", totalPricesList.get(i)));
|
||||
}
|
||||
summaryFormula.append(String.format("=%.1f", grandTotal));
|
||||
priceText.append(summaryFormula);
|
||||
// 四舍五入汇总到2位小数
|
||||
grandTotal = Math.round(grandTotal * 100.0) / 100.0;
|
||||
priceText.append(String.format("=%.2f", grandTotal));
|
||||
}
|
||||
|
||||
outputs.add(priceText.toString().trim());
|
||||
|
||||
Reference in New Issue
Block a user