From c064ae8568e48e4c768fdbbd07476ff1dad2c01c Mon Sep 17 00:00:00 2001 From: zhx Date: Fri, 17 Jul 2026 19:55:04 +0800 Subject: [PATCH] fix: unbind coin seller from actual manager relation --- .../sys/api/AdministratorClientApi.java | 18 +++++++++ .../AdminRechargeAgentRelationUnbindCmd.java | 32 ++++++++++++++++ .../team/AdminRechargeAgentRelationDTO.java | 33 +++++++++++++++++ .../app/user/UserFreightRestController.java | 4 +- .../user/UserFreightBalanceServiceImpl.java | 21 ++++++----- .../user/FreightSubSellerParentCO.java | 2 +- .../service/app/user/UserFreightService.java | 8 ++-- .../AdminRechargeAgentRelationService.java | 10 +++++ ...AdminRechargeAgentRelationServiceImpl.java | 18 +++++++++ .../sys/AdministratorClientEndpoint.java | 16 ++++++++ .../sys/AdministratorClientService.java | 12 ++++++ .../impl/AdministratorClientServiceImpl.java | 37 +++++++++++++++++++ 12 files changed, 194 insertions(+), 17 deletions(-) create mode 100644 rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/team/AdminRechargeAgentRelationUnbindCmd.java create mode 100644 rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/team/AdminRechargeAgentRelationDTO.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/sys/api/AdministratorClientApi.java b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/sys/api/AdministratorClientApi.java index a42ab30a..860bfb4e 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/sys/api/AdministratorClientApi.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/sys/api/AdministratorClientApi.java @@ -7,11 +7,14 @@ import com.red.circle.other.inner.model.cmd.sys.AppUserDetailsQryCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthResourceCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorChangeStatusCmd; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; import com.red.circle.other.inner.model.dto.sys.AdministratorDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorAuthResourceDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorInfoDTO; +import com.red.circle.other.inner.model.dto.team.AdminRechargeAgentRelationDTO; import java.util.List; import java.util.Set; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -35,6 +38,21 @@ public interface AdministratorClientApi { @GetMapping("/getByUserId") ResultResponse getByUserId(@RequestParam("userId") Long userId); + /** + * 获取充值代理当前绑定的管理员关系. + */ + @GetMapping("/getRechargeAgentRelation") + ResultResponse getRechargeAgentRelation( + @RequestParam("sysOrigin") String sysOrigin, + @RequestParam("userId") Long userId); + + /** + * 后台解绑充值代理当前绑定的管理员. + */ + @PostMapping("/unbindRechargeAgentRelation") + ResultResponse unbindRechargeAgentRelation( + @RequestBody @Validated AdminRechargeAgentRelationUnbindCmd cmd); + /** * 是否可用. * diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/team/AdminRechargeAgentRelationUnbindCmd.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/team/AdminRechargeAgentRelationUnbindCmd.java new file mode 100644 index 00000000..00bcb126 --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/team/AdminRechargeAgentRelationUnbindCmd.java @@ -0,0 +1,32 @@ +package com.red.circle.other.inner.model.cmd.team; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 后台解绑管理员与充值代理关系. + */ +@Data +@Accessors(chain = true) +public class AdminRechargeAgentRelationUnbindCmd implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @NotNull + @JsonSerialize(using = ToStringSerializer.class) + private Long relationId; + + @NotBlank + private String sysOrigin; + + @NotNull + @JsonSerialize(using = ToStringSerializer.class) + private Long childUserId; +} diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/team/AdminRechargeAgentRelationDTO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/team/AdminRechargeAgentRelationDTO.java new file mode 100644 index 00000000..d5cd9afb --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/team/AdminRechargeAgentRelationDTO.java @@ -0,0 +1,33 @@ +package com.red.circle.other.inner.model.dto.team; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import java.io.Serial; +import java.io.Serializable; +import java.sql.Timestamp; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 管理员与充值代理关系. + */ +@Data +@Accessors(chain = true) +public class AdminRechargeAgentRelationDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @JsonSerialize(using = ToStringSerializer.class) + private Long relationId; + + private String sysOrigin; + + @JsonSerialize(using = ToStringSerializer.class) + private Long adminUserId; + + @JsonSerialize(using = ToStringSerializer.class) + private Long userId; + + private Timestamp createTime; +} diff --git a/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserFreightRestController.java b/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserFreightRestController.java index c085f605..2df14723 100644 --- a/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserFreightRestController.java +++ b/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserFreightRestController.java @@ -13,9 +13,9 @@ import com.red.circle.console.inner.error.ConsoleErrorCode; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; import com.red.circle.other.inner.model.cmd.user.UserFreightBalanceCmd; import com.red.circle.wallet.inner.model.cmd.UpdateFreightBalanceInfoCmd; -import com.red.circle.wallet.inner.model.cmd.FreightSubSellerUnbindCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalancePageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExportQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd; @@ -198,7 +198,7 @@ public class UserFreightRestController extends BaseController { @OpsOperationReqLog("货运代理-解绑币商上级") @PostMapping("/sub-seller-parent/unbind") public void unbindFreightSubSellerParent( - @RequestBody @Validated FreightSubSellerUnbindCmd cmd) { + @RequestBody @Validated AdminRechargeAgentRelationUnbindCmd cmd) { userFreightService.unbindFreightSubSellerParent(cmd); } diff --git a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/user/UserFreightBalanceServiceImpl.java b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/user/UserFreightBalanceServiceImpl.java index eb830c33..b71b2a91 100644 --- a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/user/UserFreightBalanceServiceImpl.java +++ b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/user/UserFreightBalanceServiceImpl.java @@ -16,6 +16,7 @@ import com.red.circle.order.inner.endpoint.UserFreightRechargeRecordClient; import com.red.circle.other.inner.asserts.ImErrorCode; import com.red.circle.other.inner.endpoint.material.props.BadgeBackpackClient; import com.red.circle.other.inner.endpoint.material.props.BadgeSourceClient; +import com.red.circle.other.inner.endpoint.sys.AdministratorClient; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.DateFormatConstant; import com.red.circle.tool.core.date.LocalDateTimeUtils; @@ -26,13 +27,14 @@ import com.red.circle.other.inner.endpoint.user.region.UserRegionClient; import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; import com.red.circle.other.inner.model.cmd.user.UserFreightBalanceCmd; import com.red.circle.other.inner.model.cmd.user.UserRegionConfigMapCmd; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; +import com.red.circle.other.inner.model.dto.team.AdminRechargeAgentRelationDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.reigon.RegionConfigDTO; import com.red.circle.wallet.inner.endpoint.freight.FreightGoldClient; import com.red.circle.wallet.inner.error.WalletErrorCode; import com.red.circle.wallet.inner.model.cmd.AddFreightBalanceRunningWaterCmd; import com.red.circle.wallet.inner.model.cmd.FreightAgentReviewCmd; -import com.red.circle.wallet.inner.model.cmd.FreightSubSellerUnbindCmd; import com.red.circle.wallet.inner.model.cmd.UpdateFreightBalanceInfoCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalancePageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExportQryCmd; @@ -41,7 +43,6 @@ import com.red.circle.wallet.inner.model.cmd.UserFreightSellerCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightSellerRunningWaterPageQryCmd; import com.red.circle.wallet.inner.model.dto.UserFreightBalanceDTO; import com.red.circle.wallet.inner.model.dto.UserFreightBalanceRunningWaterDTO; -import com.red.circle.wallet.inner.model.dto.FreightSubSellerRelationDTO; import com.red.circle.wallet.inner.model.enums.FreightBalanceOrigin; import java.math.BigDecimal; import java.math.RoundingMode; @@ -73,6 +74,7 @@ public class UserFreightBalanceServiceImpl implements private final RedisService redisService; private final UserRegionClient userRegionClient; private final UserProfileClient userProfileClient; + private final AdministratorClient administratorClient; private final FreightGoldClient freightGoldClient; private final BadgeSourceClient badgeSourceClient; private final WalletAppConvertor walletAppConvertor; @@ -552,27 +554,26 @@ public class UserFreightBalanceServiceImpl implements @Override public FreightSubSellerParentCO getFreightSubSellerParent(String sysOrigin, Long childUserId) { - FreightSubSellerRelationDTO relation = ResponseAssert.requiredSuccess( - freightGoldClient.getFreightSubSellerRelation(sysOrigin, childUserId)); + AdminRechargeAgentRelationDTO relation = ResponseAssert.requiredSuccess( + administratorClient.getRechargeAgentRelation(sysOrigin, childUserId)); if (Objects.isNull(relation)) { return null; } UserProfileDTO parentUser = ResponseAssert.requiredSuccess( - userProfileClient.getByUserId(relation.getParentUserId())); + userProfileClient.getByUserId(relation.getAdminUserId())); return new FreightSubSellerParentCO() .setRelationId(relation.getRelationId()) .setSysOrigin(relation.getSysOrigin()) - .setParentFreightId(relation.getParentFreightId()) - .setParentUserId(relation.getParentUserId()) - .setChildUserId(relation.getChildUserId()) + .setParentUserId(relation.getAdminUserId()) + .setChildUserId(relation.getUserId()) .setCreateTime(relation.getCreateTime()) .setParentUserBaseInfo(parentUser); } @Override - public void unbindFreightSubSellerParent(FreightSubSellerUnbindCmd cmd) { - ResponseAssert.requiredSuccess(freightGoldClient.unbindFreightSubSellerRelation(cmd)); + public void unbindFreightSubSellerParent(AdminRechargeAgentRelationUnbindCmd cmd) { + ResponseAssert.requiredSuccess(administratorClient.unbindRechargeAgentRelation(cmd)); } } diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/user/FreightSubSellerParentCO.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/user/FreightSubSellerParentCO.java index e6ea5751..d4ea565c 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/user/FreightSubSellerParentCO.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/user/FreightSubSellerParentCO.java @@ -10,7 +10,7 @@ import lombok.Data; import lombok.experimental.Accessors; /** - * 后台展示的子 coin seller 上级绑定信息. + * 后台展示的充值代理/币商上级经理绑定信息. */ @Data @Accessors(chain = true) diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/user/UserFreightService.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/user/UserFreightService.java index 1bbef62a..e396530a 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/user/UserFreightService.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/user/UserFreightService.java @@ -4,9 +4,9 @@ import com.red.circle.console.app.dto.clienobject.user.UserFreightBalanceCO; import com.red.circle.console.app.dto.clienobject.user.UserFreightBalanceRunningWaterCO; import com.red.circle.console.app.dto.clienobject.user.FreightSubSellerParentCO; import com.red.circle.framework.dto.PageResult; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; import com.red.circle.other.inner.model.cmd.user.UserFreightBalanceCmd; import com.red.circle.wallet.inner.model.cmd.UpdateFreightBalanceInfoCmd; -import com.red.circle.wallet.inner.model.cmd.FreightSubSellerUnbindCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalancePageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExportQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd; @@ -121,12 +121,12 @@ public interface UserFreightService { void updateFreightBalanceInfo(UpdateFreightBalanceInfoCmd cmd); /** - * 查询子 coin seller 当前绑定的上级超级经销商. + * 查询充值代理/币商当前绑定的上级经理. */ FreightSubSellerParentCO getFreightSubSellerParent(String sysOrigin, Long childUserId); /** - * 解绑子 coin seller 当前的上级超级经销商. + * 解绑充值代理/币商当前绑定的上级经理. */ - void unbindFreightSubSellerParent(FreightSubSellerUnbindCmd cmd); + void unbindFreightSubSellerParent(AdminRechargeAgentRelationUnbindCmd cmd); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java index d779715a..eeda5d6c 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java @@ -22,6 +22,11 @@ public interface AdminRechargeAgentRelationService extends BaseService getByUserId(Long userId); + /** + * 根据平台和充值代理用户ID查询当前关系. + */ + AdminRechargeAgentRelation getByUserId(String sysOrigin, Long userId); + /** * 检查用户是否是充值代理. * @@ -37,6 +42,11 @@ public interface AdminRechargeAgentRelationService extends BaseService() @@ -38,6 +47,15 @@ public class AdminRechargeAgentRelationServiceImpl extends save(relation); } + @Override + public boolean removeBinding(Long relationId, String sysOrigin, Long userId) { + // 关系ID、平台和充值代理必须同时匹配,防止并发换绑后误删新上级关系. + return remove(new LambdaQueryWrapper() + .eq(AdminRechargeAgentRelation::getId, relationId) + .eq(AdminRechargeAgentRelation::getSysOrigin, sysOrigin) + .eq(AdminRechargeAgentRelation::getUserId, userId)); + } + @Override public IPage pageRechargeAgentByAdmin(Long adminUserId, Page page) { return page(page, new LambdaQueryWrapper() diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/sys/AdministratorClientEndpoint.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/sys/AdministratorClientEndpoint.java index 42b6781c..933ab200 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/sys/AdministratorClientEndpoint.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/sys/AdministratorClientEndpoint.java @@ -9,9 +9,11 @@ import com.red.circle.other.inner.model.cmd.sys.AppUserDetailsQryCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthResourceCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorChangeStatusCmd; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; import com.red.circle.other.inner.model.dto.sys.AdministratorDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorAuthResourceDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorInfoDTO; +import com.red.circle.other.inner.model.dto.team.AdminRechargeAgentRelationDTO; import java.util.List; import java.util.Set; import lombok.RequiredArgsConstructor; @@ -38,6 +40,20 @@ public class AdministratorClientEndpoint implements AdministratorClientApi { return ResultResponse.success(administratorClientService.getByUserId(userId)); } + @Override + public ResultResponse getRechargeAgentRelation(String sysOrigin, + Long userId) { + return ResultResponse.success( + administratorClientService.getRechargeAgentRelation(sysOrigin, userId)); + } + + @Override + public ResultResponse unbindRechargeAgentRelation( + AdminRechargeAgentRelationUnbindCmd cmd) { + administratorClientService.unbindRechargeAgentRelation(cmd); + return ResultResponse.success(); + } + @Override public ResultResponse existsAvailable(Set userIds) { return ResultResponse.success(administratorClientService.existsAvailable(userIds)); diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/AdministratorClientService.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/AdministratorClientService.java index e05a242a..ef492345 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/AdministratorClientService.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/AdministratorClientService.java @@ -6,9 +6,11 @@ import com.red.circle.other.inner.model.cmd.sys.AppUserDetailsQryCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthResourceCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorChangeStatusCmd; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; import com.red.circle.other.inner.model.dto.sys.AdministratorDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorAuthResourceDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorInfoDTO; +import com.red.circle.other.inner.model.dto.team.AdminRechargeAgentRelationDTO; import java.util.List; import java.util.Set; @@ -24,6 +26,16 @@ public interface AdministratorClientService { */ AdministratorDTO getByUserId(Long userId); + /** + * 获取充值代理当前绑定的管理员关系. + */ + AdminRechargeAgentRelationDTO getRechargeAgentRelation(String sysOrigin, Long userId); + + /** + * 后台解绑充值代理当前绑定的管理员. + */ + void unbindRechargeAgentRelation(AdminRechargeAgentRelationUnbindCmd cmd); + /** * 是否可用. * diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/AdministratorClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/AdministratorClientServiceImpl.java index 68cdbf41..a36d8b74 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/AdministratorClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/AdministratorClientServiceImpl.java @@ -3,6 +3,7 @@ package com.red.circle.other.app.inner.service.sys.impl; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.framework.dto.PageResult; +import com.red.circle.component.redis.service.RedisService; import com.red.circle.mq.business.model.event.BadgeOperateEvent; import com.red.circle.mq.rocket.business.producer.UserMqMessageService; import com.red.circle.other.app.inner.convertor.sys.AdministratorInnerConvertor; @@ -12,9 +13,11 @@ import com.red.circle.other.app.inner.service.sys.BadgeConfigClientService; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.infra.database.rds.entity.sys.Administrator; import com.red.circle.other.infra.database.rds.entity.sys.AdministratorAuth; +import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation; import com.red.circle.other.infra.database.rds.service.sys.AdministratorAuthResourceService; import com.red.circle.other.infra.database.rds.service.sys.AdministratorAuthService; import com.red.circle.other.infra.database.rds.service.sys.AdministratorService; +import com.red.circle.other.infra.database.rds.service.team.AdminRechargeAgentRelationService; import com.red.circle.other.inner.enums.material.BadgeKeyEnum; import com.red.circle.other.inner.enums.sys.appmanager.RoomRolesEnum; import com.red.circle.other.inner.model.cmd.sys.AddSysAdministratorCmd; @@ -22,9 +25,11 @@ import com.red.circle.other.inner.model.cmd.sys.AppUserDetailsQryCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthResourceCmd; import com.red.circle.other.inner.model.cmd.sys.SysAdministratorChangeStatusCmd; +import com.red.circle.other.inner.model.cmd.team.AdminRechargeAgentRelationUnbindCmd; import com.red.circle.other.inner.model.dto.sys.AdministratorDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorAuthResourceDTO; import com.red.circle.other.inner.model.dto.sys.SysAdministratorInfoDTO; +import com.red.circle.other.inner.model.dto.team.AdminRechargeAgentRelationDTO; import com.red.circle.tool.core.text.StringUtils; import java.util.*; @@ -42,7 +47,9 @@ import org.springframework.stereotype.Service; public class AdministratorClientServiceImpl implements AdministratorClientService { private final UserProfileGateway userProfileGateway; + private final RedisService redisService; private final AdministratorService administratorService; + private final AdminRechargeAgentRelationService adminRechargeAgentRelationService; private final AdministratorAuthService administratorAuthService; private final BadgeConfigClientService badgeConfigClientService; private final BadgeBackpackClientService badgeBackpackClientService; @@ -57,6 +64,36 @@ public class AdministratorClientServiceImpl implements AdministratorClientServic ); } + @Override + public AdminRechargeAgentRelationDTO getRechargeAgentRelation(String sysOrigin, Long userId) { + AdminRechargeAgentRelation relation = + adminRechargeAgentRelationService.getByUserId(sysOrigin, userId); + if (Objects.isNull(relation)) { + return null; + } + return new AdminRechargeAgentRelationDTO() + .setRelationId(relation.getId()) + .setSysOrigin(relation.getSysOrigin()) + .setAdminUserId(relation.getAdminUserId()) + .setUserId(relation.getUserId()) + .setCreateTime(java.sql.Timestamp.valueOf(relation.getCreateTime())); + } + + @Override + public void unbindRechargeAgentRelation(AdminRechargeAgentRelationUnbindCmd cmd) { + AdminRechargeAgentRelation relation = + adminRechargeAgentRelationService.getByUserId(cmd.getSysOrigin(), cmd.getChildUserId()); + ResponseAssert.isTrue(CommonErrorCode.NOT_FOUND_RECORD_INFO, + Objects.nonNull(relation) && Objects.equals(relation.getId(), cmd.getRelationId())); + + ResponseAssert.isTrue(CommonErrorCode.DELETE_FAILURE, + adminRechargeAgentRelationService.removeBinding(cmd.getRelationId(), cmd.getSysOrigin(), + cmd.getChildUserId())); + + // H5 管理员团队汇总缓存包含充值代理数量,解绑成功后立即失效旧上级缓存. + redisService.delete("bdteam:summary:" + relation.getAdminUserId()); + } + @Override public boolean existsAvailable(Set userIds) { return administratorService.existsAvailable(userIds);