1
This commit is contained in:
@@ -2,6 +2,8 @@ package com.ruoyi.jarvis.service;
|
||||
|
||||
import com.ruoyi.jarvis.domain.JDOrder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单利润/售价:按分销标识规则计算并写回订单对象(由列表保存前调用)。
|
||||
*/
|
||||
@@ -14,4 +16,11 @@ public interface IJDOrderProfitService {
|
||||
* 会修改传入的 {@code order}。
|
||||
*/
|
||||
void recalculate(JDOrder order);
|
||||
|
||||
/**
|
||||
* 对「利润未手动锁定」的订单按当前库内数据重算售价/利润字段;仅当计算结果与库中不一致时才 UPDATE。
|
||||
*
|
||||
* @return 实际执行 UPDATE 的条数
|
||||
*/
|
||||
int syncAutoProfitIfChanged(List<Long> ids);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.jarvis.service.impl;
|
||||
|
||||
import com.ruoyi.jarvis.domain.JDOrder;
|
||||
import com.ruoyi.jarvis.domain.ProductJdConfig;
|
||||
import com.ruoyi.jarvis.mapper.JDOrderMapper;
|
||||
import com.ruoyi.jarvis.service.IJDOrderProfitService;
|
||||
import com.ruoyi.jarvis.service.IProductJdConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -9,15 +10,23 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class JDOrderProfitServiceImpl implements IJDOrderProfitService {
|
||||
|
||||
private static final double XIANYU_NET_FACTOR = 0.984;
|
||||
private static final double MONEY_EPS = 0.009;
|
||||
|
||||
@Autowired
|
||||
private IProductJdConfigService productJdConfigService;
|
||||
|
||||
@Autowired
|
||||
private JDOrderMapper jdOrderMapper;
|
||||
|
||||
@Override
|
||||
public void recalculate(JDOrder order) {
|
||||
if (order == null) {
|
||||
@@ -116,4 +125,55 @@ public class JDOrderProfitServiceImpl implements IJDOrderProfitService {
|
||||
order.setProfit(BigDecimal.valueOf(netReceipt - cost)
|
||||
.setScale(2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int syncAutoProfitIfChanged(List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
Set<Long> seen = new HashSet<>();
|
||||
int updated = 0;
|
||||
for (Long id : ids) {
|
||||
if (id == null || !seen.add(id)) {
|
||||
continue;
|
||||
}
|
||||
JDOrder order = jdOrderMapper.selectJDOrderById(id);
|
||||
if (order == null) {
|
||||
continue;
|
||||
}
|
||||
if (order.getProfitManual() != null && order.getProfitManual() == 1) {
|
||||
continue;
|
||||
}
|
||||
String oldType = order.getSellingPriceType();
|
||||
Double oldSp = order.getSellingPrice();
|
||||
Double oldProfit = order.getProfit();
|
||||
|
||||
recalculate(order);
|
||||
|
||||
if (sameNullableString(oldType, order.getSellingPriceType())
|
||||
&& sameMoney(oldSp, order.getSellingPrice())
|
||||
&& sameMoney(oldProfit, order.getProfit())) {
|
||||
continue;
|
||||
}
|
||||
order.getParams().put("applyProfitFields", Boolean.TRUE);
|
||||
updated += jdOrderMapper.updateJDOrder(order);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
private static boolean sameNullableString(String a, String b) {
|
||||
String x = a == null ? "" : a.trim();
|
||||
String y = b == null ? "" : b.trim();
|
||||
return Objects.equals(x, y);
|
||||
}
|
||||
|
||||
private static boolean sameMoney(Double a, Double b) {
|
||||
if (a == null && b == null) {
|
||||
return true;
|
||||
}
|
||||
if (a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
return Math.abs(a - b) < MONEY_EPS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user