Commit 8809b50dd058e8ce4638b16f970b6d6b7d6f81e9

Authored by YunaiV
2 parents b7fab264 2f5c9fa1

Merge commit '2f5c9fa1baedf046fbaece14dd901d8e09065c10' into master-jdk17

yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractProductMapper.java
@@ -20,4 +20,8 @@ public interface CrmContractProductMapper extends BaseMapperX<CrmContractProduct @@ -20,4 +20,8 @@ public interface CrmContractProductMapper extends BaseMapperX<CrmContractProduct
20 return selectList(new LambdaQueryWrapperX<CrmContractProductDO>().eq(CrmContractProductDO::getContractId, contractId)); 20 return selectList(new LambdaQueryWrapperX<CrmContractProductDO>().eq(CrmContractProductDO::getContractId, contractId));
21 } 21 }
22 22
  23 + default int deleteByContractId(Long contractId) {
  24 + return delete(new LambdaQueryWrapperX<CrmContractProductDO>().eq(CrmContractProductDO::getContractId, contractId));
  25 + }
  26 +
23 } 27 }
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
@@ -240,7 +240,9 @@ public class CrmContractServiceImpl implements CrmContractService { @@ -240,7 +240,9 @@ public class CrmContractServiceImpl implements CrmContractService {
240 240
241 // 2.1 删除合同 241 // 2.1 删除合同
242 contractMapper.deleteById(id); 242 contractMapper.deleteById(id);
243 - // 2.2 删除数据权限 243 + // 2.2 删除合同产品明细,避免残留明细仍计入产品引用计数、把关联产品的删除路径锁死
  244 + contractProductMapper.deleteByContractId(id);
  245 + // 2.3 删除数据权限
244 crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTRACT.getType(), id); 246 crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTRACT.getType(), id);
245 247
246 // 3. 记录操作日志上下文 248 // 3. 记录操作日志上下文
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java
@@ -190,7 +190,8 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { @@ -190,7 +190,8 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
190 return null; 190 return null;
191 } 191 }
192 CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(planId); 192 CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(planId);
193 - return receivablePlan.getPeriod(); 193 + // 计划已被删除时查询返回 null:期数返回 null,避免 NPE 导致删除/更新回款失败
  194 + return receivablePlan == null ? null : receivablePlan.getPeriod();
194 } 195 }
195 196
196 @Override 197 @Override
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/enums/ErrorCodeConstants.java
@@ -136,6 +136,9 @@ ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_00 @@ -136,6 +136,9 @@ ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_00
136 ErrorCode PRODUCT_DELETE_FAIL_SALE_ORDER_EXISTS = new ErrorCode(1_030_500_005, "产品已被销售订单引用,无法删除"); 136 ErrorCode PRODUCT_DELETE_FAIL_SALE_ORDER_EXISTS = new ErrorCode(1_030_500_005, "产品已被销售订单引用,无法删除");
137 ErrorCode PRODUCT_DELETE_FAIL_SALE_OUT_EXISTS = new ErrorCode(1_030_500_006, "产品已被销售出库单引用,无法删除"); 137 ErrorCode PRODUCT_DELETE_FAIL_SALE_OUT_EXISTS = new ErrorCode(1_030_500_006, "产品已被销售出库单引用,无法删除");
138 ErrorCode PRODUCT_DELETE_FAIL_SALE_RETURN_EXISTS = new ErrorCode(1_030_500_007, "产品已被销售退货单引用,无法删除"); 138 ErrorCode PRODUCT_DELETE_FAIL_SALE_RETURN_EXISTS = new ErrorCode(1_030_500_007, "产品已被销售退货单引用,无法删除");
  139 + ErrorCode PRODUCT_DELETE_FAIL_STOCK_IN_EXISTS = new ErrorCode(1_030_500_008, "产品已被其它入库单引用,无法删除");
  140 + ErrorCode PRODUCT_DELETE_FAIL_STOCK_OUT_EXISTS = new ErrorCode(1_030_500_009, "产品已被其它出库单引用,无法删除");
  141 + ErrorCode PRODUCT_DELETE_FAIL_STOCK_CHECK_EXISTS = new ErrorCode(1_030_500_010, "产品已被盘点单引用,无法删除");
139 142
140 // ========== ERP 产品分类 1-030-501-000 ========== 143 // ========== ERP 产品分类 1-030-501-000 ==========
141 ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在"); 144 ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在");
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java
@@ -18,6 +18,9 @@ import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseReturnService; @@ -18,6 +18,9 @@ import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseReturnService;
18 import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOrderService; 18 import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOrderService;
19 import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOutService; 19 import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOutService;
20 import cn.iocoder.yudao.module.erp.service.sale.ErpSaleReturnService; 20 import cn.iocoder.yudao.module.erp.service.sale.ErpSaleReturnService;
  21 +import cn.iocoder.yudao.module.erp.service.stock.ErpStockCheckService;
  22 +import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
  23 +import cn.iocoder.yudao.module.erp.service.stock.ErpStockOutService;
21 import jakarta.annotation.Resource; 24 import jakarta.annotation.Resource;
22 import org.springframework.context.annotation.Lazy; 25 import org.springframework.context.annotation.Lazy;
23 import org.springframework.stereotype.Service; 26 import org.springframework.stereotype.Service;
@@ -63,6 +66,15 @@ public class ErpProductServiceImpl implements ErpProductService { @@ -63,6 +66,15 @@ public class ErpProductServiceImpl implements ErpProductService {
63 @Resource 66 @Resource
64 @Lazy // 延迟加载,避免循环依赖 67 @Lazy // 延迟加载,避免循环依赖
65 private ErpSaleReturnService saleReturnService; 68 private ErpSaleReturnService saleReturnService;
  69 + @Resource
  70 + @Lazy // 延迟加载,避免循环依赖
  71 + private ErpStockInService stockInService;
  72 + @Resource
  73 + @Lazy // 延迟加载,避免循环依赖
  74 + private ErpStockOutService stockOutService;
  75 + @Resource
  76 + @Lazy // 延迟加载,避免循环依赖
  77 + private ErpStockCheckService stockCheckService;
66 78
67 @Override 79 @Override
68 public Long createProduct(ProductSaveReqVO createReqVO) { 80 public Long createProduct(ProductSaveReqVO createReqVO) {
@@ -107,6 +119,15 @@ public class ErpProductServiceImpl implements ErpProductService { @@ -107,6 +119,15 @@ public class ErpProductServiceImpl implements ErpProductService {
107 if (saleReturnService.getSaleReturnItemCountByProductId(id) > 0) { 119 if (saleReturnService.getSaleReturnItemCountByProductId(id) > 0) {
108 throw exception(PRODUCT_DELETE_FAIL_SALE_RETURN_EXISTS); 120 throw exception(PRODUCT_DELETE_FAIL_SALE_RETURN_EXISTS);
109 } 121 }
  122 + if (stockInService.getStockInItemCountByProductId(id) > 0) {
  123 + throw exception(PRODUCT_DELETE_FAIL_STOCK_IN_EXISTS);
  124 + }
  125 + if (stockOutService.getStockOutItemCountByProductId(id) > 0) {
  126 + throw exception(PRODUCT_DELETE_FAIL_STOCK_OUT_EXISTS);
  127 + }
  128 + if (stockCheckService.getStockCheckItemCountByProductId(id) > 0) {
  129 + throw exception(PRODUCT_DELETE_FAIL_STOCK_CHECK_EXISTS);
  130 + }
110 // 删除 131 // 删除
111 productMapper.deleteById(id); 132 productMapper.deleteById(id);
112 } 133 }
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockCheckService.java
@@ -81,4 +81,12 @@ public interface ErpStockCheckService { @@ -81,4 +81,12 @@ public interface ErpStockCheckService {
81 */ 81 */
82 List<ErpStockCheckItemDO> getStockCheckItemListByCheckIds(Collection<Long> checkIds); 82 List<ErpStockCheckItemDO> getStockCheckItemListByCheckIds(Collection<Long> checkIds);
83 83
  84 + /**
  85 + * 获得指定产品的库存盘点单项数量(产品删除前的引用校验)
  86 + *
  87 + * @param productId 产品编号
  88 + * @return 库存盘点单项数量
  89 + */
  90 + Long getStockCheckItemCountByProductId(Long productId);
  91 +
84 } 92 }
85 \ No newline at end of file 93 \ No newline at end of file
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockCheckServiceImpl.java
@@ -229,4 +229,9 @@ public class ErpStockCheckServiceImpl implements ErpStockCheckService { @@ -229,4 +229,9 @@ public class ErpStockCheckServiceImpl implements ErpStockCheckService {
229 return stockCheckItemMapper.selectListByCheckIds(checkIds); 229 return stockCheckItemMapper.selectListByCheckIds(checkIds);
230 } 230 }
231 231
  232 + @Override
  233 + public Long getStockCheckItemCountByProductId(Long productId) {
  234 + return stockCheckItemMapper.selectCount(ErpStockCheckItemDO::getProductId, productId);
  235 + }
  236 +
232 } 237 }
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInService.java
@@ -81,4 +81,12 @@ public interface ErpStockInService { @@ -81,4 +81,12 @@ public interface ErpStockInService {
81 */ 81 */
82 List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds); 82 List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds);
83 83
  84 + /**
  85 + * 获得指定产品的其它入库单项数量(产品删除前的引用校验)
  86 + *
  87 + * @param productId 产品编号
  88 + * @return 其它入库单项数量
  89 + */
  90 + Long getStockInItemCountByProductId(Long productId);
  91 +
84 } 92 }
85 \ No newline at end of file 93 \ No newline at end of file
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java
@@ -225,4 +225,9 @@ public class ErpStockInServiceImpl implements ErpStockInService { @@ -225,4 +225,9 @@ public class ErpStockInServiceImpl implements ErpStockInService {
225 return stockInItemMapper.selectListByInIds(inIds); 225 return stockInItemMapper.selectListByInIds(inIds);
226 } 226 }
227 227
  228 + @Override
  229 + public Long getStockInItemCountByProductId(Long productId) {
  230 + return stockInItemMapper.selectCount(ErpStockInItemDO::getProductId, productId);
  231 + }
  232 +
228 } 233 }
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutService.java
@@ -81,4 +81,12 @@ public interface ErpStockOutService { @@ -81,4 +81,12 @@ public interface ErpStockOutService {
81 */ 81 */
82 List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> outIds); 82 List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> outIds);
83 83
  84 + /**
  85 + * 获得指定产品的其它出库单项数量(产品删除前的引用校验)
  86 + *
  87 + * @param productId 产品编号
  88 + * @return 其它出库单项数量
  89 + */
  90 + Long getStockOutItemCountByProductId(Long productId);
  91 +
84 } 92 }
85 \ No newline at end of file 93 \ No newline at end of file
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java
@@ -225,4 +225,9 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { @@ -225,4 +225,9 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
225 return stockOutItemMapper.selectListByOutIds(outIds); 225 return stockOutItemMapper.selectListByOutIds(outIds);
226 } 226 }
227 227
  228 + @Override
  229 + public Long getStockOutItemCountByProductId(Long productId) {
  230 + return stockOutItemMapper.selectCount(ErpStockOutItemDO::getProductId, productId);
  231 + }
  232 +
228 } 233 }
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageReqVO.java
@@ -45,7 +45,7 @@ public class AppProductSpuPageReqVO extends PageParam { @@ -45,7 +45,7 @@ public class AppProductSpuPageReqVO extends PageParam {
45 if (StrUtil.isEmpty(sortField)) { 45 if (StrUtil.isEmpty(sortField)) {
46 return true; 46 return true;
47 } 47 }
48 - return StrUtil.equalsAny(sortField, SORT_FIELD_PRICE, SORT_FIELD_SALES_COUNT); 48 + return StrUtil.equalsAny(sortField, SORT_FIELD_PRICE, SORT_FIELD_SALES_COUNT, SORT_FIELD_CREATE_TIME);
49 } 49 }
50 50
51 } 51 }
yudao-module-mall/yudao-module-trade/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
@@ -190,9 +190,10 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @@ -190,9 +190,10 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
190 190
191 // 2.1 计算手续费 191 // 2.1 计算手续费
192 Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent()); 192 Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent());
193 - // 2.2 创建佣金提现记录 193 + // 2.2 创建佣金提现记录(初始状态显式置为「审核中」,不依赖 DDL 列默认值——否则列 DEFAULT NULL 时建单 status 为空,审核恒拒)
194 BrokerageWithdrawDO withdraw = BeanUtils.toBean(createReqVO, BrokerageWithdrawDO.class) 194 BrokerageWithdrawDO withdraw = BeanUtils.toBean(createReqVO, BrokerageWithdrawDO.class)
195 - .setUserId(userId).setFeePrice(feePrice); 195 + .setUserId(userId).setFeePrice(feePrice)
  196 + .setStatus(BrokerageWithdrawStatusEnum.AUDITING.getStatus());
196 brokerageWithdrawMapper.insert(withdraw); 197 brokerageWithdrawMapper.insert(withdraw);
197 198
198 // 3. 创建用户佣金记录 199 // 3. 创建用户佣金记录