From 94c0e81335b3eec2051cc6f96e4f44bfc154605f Mon Sep 17 00:00:00 2001 From: xupei Date: Tue, 25 Nov 2025 10:10:14 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20=E6=89=93=E5=BC=80=E4=BD=A3=E9=87=91?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/AffiliateServiceImpl.java | 79 ++++++++++++++----- .../service/impl/DesignItemServiceImpl.java | 6 -- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java index 49ac6658..ad43b76b 100644 --- a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java @@ -1,6 +1,7 @@ package com.ai.da.service.impl; import com.ai.da.common.config.exception.BusinessException; +import com.ai.da.common.constant.AffiliateConstants; import com.ai.da.common.constant.CommonConstant; import com.ai.da.common.context.UserContext; import com.ai.da.common.response.PageBaseResponse; @@ -82,7 +83,7 @@ public class AffiliateServiceImpl extends ServiceImpl 激活 | Inactive -> 关闭 | Delete -> 删除 + // 构建更新条件 + UpdateWrapper updateWrapper = buildUpdateWrapper(affiliate, commission, operationType); + baseMapper.update(null, updateWrapper); + } + + private UpdateWrapper buildUpdateWrapper(Affiliate affiliate, Float commission, String operationType) { + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.lambda() + .eq(Affiliate::getId, affiliate.getId()) + .set(Affiliate::getUpdateTime, LocalDateTime.now()); + + // 处理佣金更新 + handleCommissionUpdate(affiliate, commission, updateWrapper); + + // 处理操作类型 if (!StringUtil.isNullOrEmpty(operationType)) { - if (operationType.equals("Delete") || operationType.equals("Active") || operationType.equals("Inactive")) { - affiliate.setStatus(operationType); - } else { - throw new BusinessException("unknown.operationType"); - } + handleOperationType(affiliate, operationType, updateWrapper); } - affiliate.setUpdateTime(LocalDateTime.now()); - baseMapper.updateById(affiliate); - if (operationType.equals("Delete")) { - baseMapper.deleteById(id); + return updateWrapper; + } + + private void handleCommissionUpdate(Affiliate affiliate, Float commission, + UpdateWrapper updateWrapper) { + if (commission != null && !Objects.equals(affiliate.getCommissionPercent(), commission)) { + updateWrapper.lambda().set(Affiliate::getCommissionPercent, commission); + } + } + + private void handleOperationType(Affiliate affiliate, String operationType, + UpdateWrapper updateWrapper) { + switch (operationType) { + case AffiliateConstants.STATUS_DELETE: + updateWrapper.lambda() + .set(Affiliate::getStatus, AffiliateConstants.STATUS_DELETE) + .set(Affiliate::getIsDeleted, AffiliateConstants.DELETED); + break; + + case AffiliateConstants.STATUS_ACTIVE: + case AffiliateConstants.STATUS_INACTIVE: + updateWrapper.lambda().set(Affiliate::getStatus, operationType); + // 激活时生成链接 + if (AffiliateConstants.STATUS_ACTIVE.equals(operationType) && + StringUtil.isNullOrEmpty(affiliate.getLink())) { + updateWrapper.lambda().set(Affiliate::getLink, + CommonConstant.AFFILIATE_LINK + affiliate.getId()); + } + break; + + default: + throw new BusinessException("unknown.operationType"); } } @@ -402,7 +443,7 @@ public class AffiliateServiceImpl extends ServiceImpl