From 0d6efb3e4e48a4da4a8b263a3ba627db5489f6e6 Mon Sep 17 00:00:00 2001 From: huacracker <39215559+huacracker@users.noreply.github.com> Date: Wed, 11 Mar 2026 12:03:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=83=A8=E9=97=A8=E6=94=B9=E4=BB=B7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复部门改价配置保存问题(Mapstruct转换失败) - 添加部门改价比例和开关字段 - 实现自动改价功能(根据部门配置) - 改价金额抹零到十位数(58->50, 65->60) - 修复部门缓存清除问题 --- ruoyi-admin/pom.xml | 1 + .../src/main/resources/application-dev.yml | 10 ++- .../controller/system/SysDeptController.java | 1 + .../org/dromara/system/domain/SysDept.java | 14 +++++ .../dromara/system/domain/bo/SysDeptBo.java | 12 ++++ .../dromara/system/domain/vo/SysDeptVo.java | 11 ++++ .../service/impl/SysDeptServiceImpl.java | 22 ++++++- .../work/service/impl/TpOrderServiceImpl.java | 62 ++++++++++++++----- 8 files changed, 114 insertions(+), 19 deletions(-) diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index b46bfb3..e288e76 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -130,6 +130,7 @@ true true + org.dromara.XgtAdminApplication diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 5d32716..cd5e780 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -80,13 +80,13 @@ spring: spring.data: redis: # 地址 - host: jcs-mysql.52o.site + host: 220.205.16.51 # 端口,默认为6379 port: 26739 # 数据库索引 database: 1 # redis 密码必须配置 - password: 3NpZYtRLr6EnfASr + password: yahsj5EpPJzpG4cY # 连接超时时间 timeout: 10s # 是否开启ssl @@ -102,6 +102,12 @@ redisson: nettyThreads: 8 # 单节点配置 singleServerConfig: + # 服务器地址 + address: redis://220.205.16.51:26739 + # 密码 + password: yahsj5EpPJzpG4cY + # 数据库 + database: 1 # 客户端名称 clientName: XGT-ADMIN # 最小空闲连接数 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDeptController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDeptController.java index aeb85c2..42c4298 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDeptController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDeptController.java @@ -88,6 +88,7 @@ public class SysDeptController extends BaseController { @Log(title = "部门管理", businessType = BusinessType.UPDATE) @PutMapping public R edit(@Validated @RequestBody SysDeptBo dept) { + // System.out.println("[Controller] 接收到的部门数据: deptId=" + dept.getDeptId() + ", isAutoChangePrice=" + dept.getIsAutoChangePrice() + ", changePriceRate=" + dept.getChangePriceRate()); Long deptId = dept.getDeptId(); deptService.checkDeptDataScope(deptId); if (!deptService.checkDeptNameUnique(dept)) { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysDept.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysDept.java index 9190e6b..32f3aa0 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysDept.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysDept.java @@ -1,5 +1,6 @@ package org.dromara.system.domain; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; @@ -8,6 +9,7 @@ import lombok.EqualsAndHashCode; import org.dromara.common.tenant.core.TenantEntity; import java.io.Serial; +import java.math.BigDecimal; /** * 部门表 sys_dept @@ -75,6 +77,18 @@ public class SysDept extends TenantEntity { @TableLogic private String delFlag; + /** + * 是否自动改价(1=否,2=是) + */ + @TableField("is_auto_change_price") + private Integer isAutoChangePrice; + + /** + * 改价比例(如0.1000表示10%) + */ + @TableField("change_price_rate") + private BigDecimal changePriceRate; + /** * 祖级列表 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java index e73a6a8..6ed92a4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java @@ -10,6 +10,8 @@ import lombok.EqualsAndHashCode; import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.system.domain.SysDept; +import java.math.BigDecimal; + /** * 部门业务对象 sys_dept * @@ -93,4 +95,14 @@ public class SysDeptBo extends BaseEntity { */ private Integer isNull; + /** + * 是否自动改价(1=否,2=是) + */ + private Integer isAutoChangePrice; + + /** + * 改价比例(如0.1000表示10%) + */ + private BigDecimal changePriceRate; + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java index da4d43e..da5a90c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java @@ -10,6 +10,7 @@ import org.dromara.system.domain.SysDept; import java.io.Serial; import java.io.Serializable; +import java.math.BigDecimal; import java.util.Date; /** @@ -99,4 +100,14 @@ public class SysDeptVo implements Serializable { @ExcelProperty(value = "创建时间") private Date createTime; + /** + * 是否自动改价(1=否,2=是) + */ + private Integer isAutoChangePrice; + + /** + * 改价比例(如0.1000表示10%) + */ + private BigDecimal changePriceRate; + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index 655ef5d..06022af 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -272,11 +272,28 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { */ @Caching(evict = { @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"), - @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true) + @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true), + @CacheEvict(cacheNames = CacheNames.SYS_DEPT, allEntries = true) }) @Override public int updateDept(SysDeptBo bo) { - SysDept dept = MapstructUtils.convert(bo, SysDept.class); + // 强制清除所有部门缓存,避免改价配置缓存问题 + CacheUtils.clear(CacheNames.SYS_DEPT); + // System.out.println("[部门更新] 接收到的数据: deptId=" + bo.getDeptId() + ", isAutoChangePrice=" + bo.getIsAutoChangePrice() + ", changePriceRate=" + bo.getChangePriceRate()); + SysDept dept = new SysDept(); + // 手动复制所有字段 + dept.setDeptId(bo.getDeptId()); + dept.setParentId(bo.getParentId()); + dept.setDeptName(bo.getDeptName()); + dept.setDeptCategory(bo.getDeptCategory()); + dept.setOrderNum(bo.getOrderNum()); + dept.setLeader(bo.getLeader()); + dept.setPhone(bo.getPhone()); + dept.setEmail(bo.getEmail()); + dept.setStatus(bo.getStatus()); + dept.setIsAutoChangePrice(bo.getIsAutoChangePrice()); + dept.setChangePriceRate(bo.getChangePriceRate()); + // System.out.println("[部门更新] 转换后的数据: isAutoChangePrice=" + dept.getIsAutoChangePrice() + ", changePriceRate=" + dept.getChangePriceRate()); SysDept oldDept = baseMapper.selectById(dept.getDeptId()); if (ObjectUtil.isNull(oldDept)) { throw new ServiceException("部门不存在,无法修改"); @@ -294,6 +311,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { } else { dept.setAncestors(oldDept.getAncestors()); } + // System.out.println("[部门更新] 即将执行updateById, dept=" + dept); int result = baseMapper.updateById(dept); if (SystemConstants.NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals(SystemConstants.NORMAL, dept.getAncestors())) { diff --git a/ruoyi-modules/ruoyi-work/src/main/java/org/dromara/work/service/impl/TpOrderServiceImpl.java b/ruoyi-modules/ruoyi-work/src/main/java/org/dromara/work/service/impl/TpOrderServiceImpl.java index 8d25971..5347b0b 100644 --- a/ruoyi-modules/ruoyi-work/src/main/java/org/dromara/work/service/impl/TpOrderServiceImpl.java +++ b/ruoyi-modules/ruoyi-work/src/main/java/org/dromara/work/service/impl/TpOrderServiceImpl.java @@ -774,8 +774,26 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl 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 orderList = new ArrayList<>(); for (Long orderId : orderIds){ @@ -787,34 +805,48 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl 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){