feat: 部门改价配置功能完善

- 修复部门改价配置保存问题(Mapstruct转换失败)
- 添加部门改价比例和开关字段
- 实现自动改价功能(根据部门配置)
- 改价金额抹零到十位数(58->50, 65->60)
- 修复部门缓存清除问题
This commit is contained in:
huacracker
2026-03-11 12:03:48 +08:00
parent 259526b31b
commit 0d6efb3e4e
8 changed files with 114 additions and 19 deletions

View File

@@ -774,8 +774,26 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
SysUser user = sysUserMapper.selectById(userId);
// 获取默认改价比例10%
// 获取用户所属部门的改价配置
SysDept userDept = deptMapper.selectById(user.getDeptId());
// 默认不改价比例10%
boolean isAutoChangePrice = false;
BigDecimal discountRate = new BigDecimal("0.10");
if (userDept != null) {
// 检查部门类别是否为技术 (deptCategory = "3")
if ("3".equals(userDept.getDeptCategory())) {
// 是技术部门,检查是否开启自动改价 (2=是)
if (userDept.getIsAutoChangePrice() != null && userDept.getIsAutoChangePrice() == 2) {
isAutoChangePrice = true;
}
// 使用部门配置的改价比例
if (userDept.getChangePriceRate() != null && userDept.getChangePriceRate().compareTo(BigDecimal.ZERO) > 0) {
discountRate = userDept.getChangePriceRate();
}
}
}
// System.out.println("[部门改价配置] 用户ID=" + userId + ", 部门ID=" + user.getDeptId() + ", 类别=" + (userDept != null ? userDept.getDeptCategory() : "null") + ", 自动改价=" + isAutoChangePrice + ", 比例=" + discountRate + ", 部门改价比例=" + (userDept != null ? userDept.getChangePriceRate() : "null"));
List<TpOrder> orderList = new ArrayList<>();
for (Long orderId : orderIds){
@@ -787,34 +805,48 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
order.setDeptIdJs(dept.getDeptId());
order.setAncestorsJs(dept.getAncestors());
// ===== 自动改价逻辑开始 =====
// 启用自动改价
order.setIsC(2);
// 根据部门配置决定是否启用自动改价
if (isAutoChangePrice) {
order.setIsC(2);
} else {
order.setIsC(1);
}
// 计算自动改价价格优先使用jsPrice如果为空则使用price
BigDecimal basePrice = order.getJsPrice();
System.out.println("[自动改价调试] 订单ID=" + order.getId() + ", jsPrice=" + order.getJsPrice() + ", price=" + order.getPrice());
// System.out.println("[自动改价调试] 订单ID=" + order.getId() + ", jsPrice=" + order.getJsPrice() + ", price=" + order.getPrice());
if (basePrice == null || basePrice.compareTo(BigDecimal.ZERO) <= 0) {
basePrice = order.getPrice();
System.out.println("[自动改价调试] jsPrice为空或<=0使用price=" + basePrice);
// System.out.println("[自动改价调试] jsPrice为空或<=0使用price=" + basePrice);
}
if (basePrice != null && basePrice.compareTo(BigDecimal.ZERO) > 0) {
// 只有开启自动改价时才计算改价
if (isAutoChangePrice && basePrice != null && basePrice.compareTo(BigDecimal.ZERO) > 0) {
BigDecimal zGjPrice = basePrice.multiply(discountRate);
System.out.println("[自动改价调试] 计算改价: " + basePrice + " * 10% = " + zGjPrice);
// 10取整处理四舍五入到最接近的10的倍数
zGjPrice = roundToNearestTen(zGjPrice);
System.out.println("[自动改价调试] 取整后改价: " + zGjPrice);
// System.out.println("[自动改价调试] 计算改价: " + basePrice + " * " + discountRate + " = " + zGjPrice);
// 抹零到十位数(舍去个位数)
zGjPrice = zGjPrice.divide(new BigDecimal("10"), 0, BigDecimal.ROUND_DOWN).multiply(new BigDecimal("10"));
// System.out.println("[自动改价调试] 抹零到十位数后改价: " + zGjPrice);
order.setZGjPrice(zGjPrice);
order.setGjPrice(zGjPrice);
if (order.getPayState() != null && !order.getPayState().equals(1)) {
order.setGjPrice(zGjPrice);
BigDecimal jsBasePrice = order.getPrice().subtract(order.getCdPrice()).subtract(zGjPrice);
order.setJsPrice(jsBasePrice);
order.setGpay(getGjPayPrice(order.getPrice(), order.getPayPrice().add(order.getCoupon()), zGjPrice));
BigDecimal jsPayPrice = getJsPayPrice(order.getPrice(), order.getPayPrice(), jsBasePrice);
order.setJsPayPrice(jsPayPrice.subtract(order.getBreach()));
} else {
order.setGjPrice(zGjPrice);
BigDecimal jsBasePrice = order.getPrice().subtract(order.getCdPrice()).subtract(zGjPrice);
order.setJsPrice(jsBasePrice);
}
System.out.println("[自动改价调试] 设置成功: zGjPrice=" + zGjPrice + ", gjPrice=" + zGjPrice);
} else if (!isAutoChangePrice) {
System.out.println("[自动改价调试] 部门未开启自动改价,跳过改价计算");
} else {
System.out.println("[自动改价调试] 未设置改价: basePrice=" + basePrice);
}
// ===== 自动改价逻辑结束 =====
boolean res = saveOrderRecord(order.getId(),"订单分图","订单:"+order.getOrderId()+" 指派给"+user.getNickName()+" 成功",1,null);
if(!res){