diff --git a/src/main/java/com/ai/da/controller/AffiliateController.java b/src/main/java/com/ai/da/controller/AffiliateController.java index 853580bf..587cf18d 100644 --- a/src/main/java/com/ai/da/controller/AffiliateController.java +++ b/src/main/java/com/ai/da/controller/AffiliateController.java @@ -22,6 +22,7 @@ import javax.annotation.Resource; import javax.validation.Valid; import java.math.BigDecimal; import java.util.List; +import java.util.Map; @Slf4j @RestController @@ -100,7 +101,7 @@ public class AffiliateController { return Response.success(affiliateService.getEachAffiliateGeneratedRevenue(affiliateQueryDTO)); } - @ApiOperation(value = "获取所有的referral") + @ApiOperation(value = "分页获取所有的referral") @PostMapping("/getReferrals") public Response> getReferrals(@RequestBody ReferralPageQueryDTO referralPageQueryDTO) { return Response.success(referralService.queryByPage(referralPageQueryDTO)); @@ -120,5 +121,11 @@ public class AffiliateController { return Response.success(); } + @ApiOperation(value = "获取所有affiliate用户名") + @GetMapping("/getAllAffiliateUsername") + public Response>> getAllAffiliateUsername() { + return Response.success(affiliateService.getAllAffiliateUsername()); + } + } diff --git a/src/main/java/com/ai/da/mapper/primary/AffiliateMapper.java b/src/main/java/com/ai/da/mapper/primary/AffiliateMapper.java index 7454d50f..b2e39101 100644 --- a/src/main/java/com/ai/da/mapper/primary/AffiliateMapper.java +++ b/src/main/java/com/ai/da/mapper/primary/AffiliateMapper.java @@ -16,4 +16,6 @@ public interface AffiliateMapper extends BaseMapper { int queryAffiliateTotalCount(String status, String startTime, String endTime, Long affiliateId); + List> selectAllAffiliateUsername(); + } diff --git a/src/main/java/com/ai/da/service/AffiliateService.java b/src/main/java/com/ai/da/service/AffiliateService.java index f75111f5..64b21f5a 100644 --- a/src/main/java/com/ai/da/service/AffiliateService.java +++ b/src/main/java/com/ai/da/service/AffiliateService.java @@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import java.math.BigDecimal; +import java.util.List; +import java.util.Map; public interface AffiliateService extends IService { @@ -37,4 +39,6 @@ public interface AffiliateService extends IService { void commissionCalculation(Integer year, Integer month); void calcCouponsCommission(); + + List> getAllAffiliateUsername(); } 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 97feb56f..2fcc14e4 100644 --- a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java @@ -439,5 +439,10 @@ public class AffiliateServiceImpl extends ServiceImpl> getAllAffiliateUsername(){ + return baseMapper.selectAllAffiliateUsername(); + } + } diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index bfc5f0a1..e67d4567 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -2555,47 +2555,62 @@ public class UserLikeGroupServiceImpl extends ServiceImpl collectionElementRelModels = collectionElementMapper.selectByProject(projectId); + // 入参中的模特 List mannequin = moduleSaveDTO.getMannequin(); - List inputMannequinId = mannequin.stream().map(MannequinDTO::getCollectionElementId).collect(Collectors.toList()); + + // 新增的模特只有id,没有collectionElementId + List inputMannequinIds = mannequin.stream().map(MannequinDTO::getId).collect(Collectors.toList()); + // 既有id又有collectionElementId的,为保持原状的模特(都没有的且又存在于数据库的,即为被删除的模特) + List inputCollectionElementIds = mannequin.stream().map(MannequinDTO::getCollectionElementId).collect(Collectors.toList()); // 创建relationId到Model的映射 Map relationIdToModelMap = collectionElementRelModels.stream() + .collect(Collectors.toMap( + CollectionElementRelModel::getRelationId, + java.util.function.Function.identity(), + (existing, replacement) -> existing + )); + // 创建collectionElementId到Model的映射 + Map collectionElementToModelMap = collectionElementRelModels.stream() .collect(Collectors.toMap( CollectionElementRelModel::getCollectionElementId, java.util.function.Function.identity(), (existing, replacement) -> existing )); List newReletionIds = new ArrayList<>(); - List toBeDeletedRelationIds = new ArrayList<>(); + List toBeDeletedCollectionElementIds = new ArrayList<>(); if (collectionElementRelModels.isEmpty()) { // 如果原本没有记录,所有输入的Mannequin都是新的 - newReletionIds = inputMannequinId; + newReletionIds = inputMannequinIds; } else { - // 获取所有已有的relationId集合 + // 获取db中所有的relationId集合 Set relationIds = relationIdToModelMap.keySet(); + // 获取db中所有的collectionElementId集合 + Set collectionElementIds = collectionElementToModelMap.keySet(); - // 1. 找出需要删除的:relationIds中有但inputMannequinId中没有的 - toBeDeletedRelationIds = relationIds.stream() - .filter(id -> !inputMannequinId.contains(id)) + // 1. 找出需要删除的:collectionElementIds中有但inputCollectionElementIds中没有的 + toBeDeletedCollectionElementIds = collectionElementIds.stream() + .filter(id -> !inputCollectionElementIds.contains(id)) .collect(Collectors.toList()); - // 2. 找出新增的:inputMannequinId中有但relationIds中没有的 - newReletionIds = inputMannequinId.stream() + // 2. 找出新增的:inputMannequinId中有但relationIds中没有的(一定程度避免重复) + newReletionIds = inputMannequinIds.stream() .filter(id -> !relationIds.contains(id)) .collect(Collectors.toList()); } - if (!toBeDeletedRelationIds.isEmpty()){ - Set toBeDeletedElementIdList = toBeDeletedRelationIds.stream() + if (!toBeDeletedCollectionElementIds.isEmpty()){ + /*Set toBeDeletedElementIdList = toBeDeletedCollectionElementIds.stream() .map(relationIdToModelMap::get) // 获取对应的Model .filter(Objects::nonNull) // 过滤掉可能为null的情况 .map(CollectionElementRelModel::getCollectionElementId) // 提取collectionElementId - .collect(Collectors.toSet()); - collectionElementMapper.deleteBatchIds(toBeDeletedElementIdList); + .collect(Collectors.toSet());*/ + collectionElementMapper.deleteBatchIds(toBeDeletedCollectionElementIds); // 删除关联关系 - deleteByCollectionElementIdList(toBeDeletedElementIdList); + deleteByCollectionElementIdList(toBeDeletedCollectionElementIds); } for (MannequinDTO dto : mannequin) { @@ -2678,7 +2693,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl old) { + private void deleteByCollectionElementIdList(java.util.Collection old) { QueryWrapper qw = new QueryWrapper<>(); qw.lambda().in(CollectionElementRelModel::getCollectionElementId, old); collectionElementRelModelMapper.delete(qw); diff --git a/src/main/resources/mapper/primary/AffiliateMapper.xml b/src/main/resources/mapper/primary/AffiliateMapper.xml index 853bf59d..666c6f32 100644 --- a/src/main/resources/mapper/primary/AffiliateMapper.xml +++ b/src/main/resources/mapper/primary/AffiliateMapper.xml @@ -84,4 +84,13 @@ + + +