diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/FamilyErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/FamilyErrorCode.java index c07549d1..aabeefb7 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/FamilyErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/FamilyErrorCode.java @@ -93,6 +93,11 @@ public enum FamilyErrorCode implements IResponseErrorCode { */ BOX_ALREADY_CLAIMED(2516, "You have already claimed this treasure box"), + /** + * 只有族长才能解散家族 + */ + ONLY_ADMIN_CAN_DISBAND_FAMILY(2517, "Only the patriarch can disband the family"), + ; diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/family/FamilyRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/family/FamilyRestController.java index 6c564e09..d9d9efe3 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/family/FamilyRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/family/FamilyRestController.java @@ -205,6 +205,19 @@ public class FamilyRestController extends BaseController { familyService.userExit(cmd); } + /** + * 解散家族. + * + * @eo.name 解散家族. + * @eo.url /disband + * @eo.method post + * @eo.request-type json + */ + @PostMapping("/disband") + public void disbandFamily(@RequestBody @Validated DisbandFamilyCmd cmd) { + familyService.disbandFamily(cmd); + } + /** * 投入宝箱金币. */ diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/DisbandFamilyCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/DisbandFamilyCmdExe.java new file mode 100644 index 00000000..4f411418 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/DisbandFamilyCmdExe.java @@ -0,0 +1,103 @@ +package com.red.circle.other.app.command.family; + +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.other.app.dto.cmd.family.DisbandFamilyCmd; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.infra.common.family.FamilyCommon; +import com.red.circle.other.infra.common.family.FamilyNewsRecorder; +import com.red.circle.other.infra.database.rds.entity.family.FamilyBaseInfo; +import com.red.circle.other.infra.database.rds.entity.family.FamilyMemberInfo; +import com.red.circle.other.infra.database.rds.service.family.FamilyBaseInfoService; +import com.red.circle.other.infra.database.rds.service.family.FamilyLevelExpService; +import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService; +import com.red.circle.other.infra.database.rds.service.family.FamilyMemberTotalExpService; +import com.red.circle.other.infra.database.rds.service.family.FamilyMemberWeekExpService; +import com.red.circle.other.infra.database.rds.service.family.FamilyMonthExpService; +import com.red.circle.other.infra.database.rds.service.family.FamilyWeekExpService; +import com.red.circle.other.infra.enums.family.FamilyNewsTypeEnum; +import com.red.circle.other.infra.enums.family.FamilyStatusEnum; +import com.red.circle.other.inner.asserts.FamilyErrorCode; +import com.red.circle.tool.core.collection.CollectionUtils; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +/** + * 解散家族 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class DisbandFamilyCmdExe { + + private final FamilyCommon familyCommon; + private final FamilyNewsRecorder familyNewsRecorder; + private final UserProfileGateway userProfileGateway; + private final FamilyBaseInfoService familyBaseInfoService; + private final FamilyMemberInfoService familyMemberInfoService; + private final FamilyWeekExpService familyWeekExpService; + private final FamilyMonthExpService familyMonthExpService; + private final FamilyLevelExpService familyLevelExpService; + private final FamilyMemberWeekExpService familyMemberWeekExpService; + private final FamilyMemberTotalExpService familyMemberTotalExpService; + + @Transactional(rollbackFor = Exception.class) + public void execute(DisbandFamilyCmd cmd) { + + FamilyMemberInfo memberInfo = familyMemberInfoService.getFamilyMemberByUserId(cmd.getReqUserId()); + ResponseAssert.notNull(FamilyErrorCode.NOT_EXIST_FAMILY_INFO_DATA, memberInfo); + ResponseAssert.isTrue(FamilyErrorCode.ONLY_ADMIN_CAN_DISBAND_FAMILY, familyCommon.isAdmin(memberInfo.getMemberRole())); + + Long familyId = memberInfo.getFamilyId(); + FamilyBaseInfo familyBaseInfo = familyBaseInfoService.getBaseInfoById(familyId); + ResponseAssert.notNull(FamilyErrorCode.NOT_EXIST_FAMILY_INFO_DATA, familyBaseInfo); + clearFamilyData(familyId); + +// disbandFamilyStatus(familyId); + +// recordDisbandNews(cmd.getReqSysOrigin().getOrigin(), familyId, familyBaseInfo.getFamilyName()); + + } + + private void clearFamilyData(Long familyId) { + + familyMemberInfoService.deleteByFamilyId(familyId); + + familyWeekExpService.deleteByFamilyId(familyId); + familyMonthExpService.deleteByFamilyId(familyId); + familyLevelExpService.deleteByFamilyId(familyId); + + familyMemberWeekExpService.deleteByFamilyId(familyId); + familyMemberTotalExpService.deleteByFamilyId(familyId); + } + + private void disbandFamilyStatus(Long familyId) { + familyBaseInfoService.delFamily(familyId); + } + + private void recordDisbandNews(String origin, Long familyId, String familyName) { + familyNewsRecorder.recordAndUpdateNotice( + origin, + familyId, + FamilyNewsTypeEnum.FAMILY_DISBANDED, + null, + familyName, + null, + null + ); + } + + private void notifyAllMembers(List members, Long familyId) { + if (CollectionUtils.isEmpty(members)) { + return; + } + + members.forEach(member -> { + familyCommon.removeGroup(familyId, member.getMemberUserId()); + userProfileGateway.removeCacheAll(member.getMemberUserId()); + }); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyCreateExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyCreateExe.java index 792ac2cc..eb4fb90c 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyCreateExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyCreateExe.java @@ -21,10 +21,7 @@ import com.red.circle.other.infra.database.rds.entity.family.FamilyCreateRules; import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig; import com.red.circle.other.infra.database.rds.entity.family.FamilyMemberInfo; import com.red.circle.other.infra.database.rds.service.approval.ApprovalUserSettingDataService; -import com.red.circle.other.infra.database.rds.service.family.FamilyBaseInfoService; -import com.red.circle.other.infra.database.rds.service.family.FamilyCreateRulesService; -import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService; -import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService; +import com.red.circle.other.infra.database.rds.service.family.*; import com.red.circle.other.infra.enums.family.FamilyRoleEnum; import com.red.circle.other.infra.enums.family.FamilyStatusEnum; import com.red.circle.other.inner.asserts.DynamicErrorCode; @@ -66,6 +63,7 @@ public class FamilyCreateExe { private final FamilyCreateRulesService familyCreateRulesService; private final FamilyLevelConfigService familyLevelConfigService; private final ApprovalUserSettingDataService approvalUserSettingDataService; + private final FamilyMessageService familyMessageService; @Transactional(rollbackFor = Exception.class) public Long execute(FamilyCreateCmd cmd) { @@ -89,7 +87,7 @@ public class FamilyCreateExe { checkCreateWhereAndPayCandy(cmd); -// addApproveRecord(cmd); + familyMessageService.cancelUserPendingMessages(cmd.getReqUserId()); return familyId; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/family/FamilyServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/family/FamilyServiceImpl.java index afa234e6..1f07a756 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/family/FamilyServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/family/FamilyServiceImpl.java @@ -34,6 +34,7 @@ import com.red.circle.other.app.command.family.FamilyBoxClaimExe; import com.red.circle.other.app.command.family.FamilyHomeListExe; import com.red.circle.other.app.command.family.FamilyMemberTop100Exe; import com.red.circle.other.app.command.family.FamilyNewsListExe; +import com.red.circle.other.app.command.family.DisbandFamilyCmdExe; import com.red.circle.other.app.dto.clientobject.family.*; import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO; import com.red.circle.other.app.dto.cmd.family.*; @@ -91,6 +92,7 @@ public class FamilyServiceImpl implements FamilyService { private final FamilyHomeListExe familyHomeListExe; private final FamilyMemberTop100Exe familyMemberTop100Exe; private final FamilyNewsListExe familyNewsListExe; + private final DisbandFamilyCmdExe disbandFamilyCmdExe; private final DistributedLockUtil distributedLockUtil; @Override @@ -276,4 +278,12 @@ public class FamilyServiceImpl implements FamilyService { public PageResult familyNewsList(FamilyNewsListCmd cmd) { return familyNewsListExe.execute(cmd); } + + @Override + public void disbandFamily(DisbandFamilyCmd cmd) { + String key = "FAMILY_DISBAND" + ":" + cmd.getReqUserId(); + distributedLockUtil.executeWithLock(key, () -> { + disbandFamilyCmdExe.execute(cmd); + }); + } } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/family/DisbandFamilyCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/family/DisbandFamilyCmd.java new file mode 100644 index 00000000..615471db --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/family/DisbandFamilyCmd.java @@ -0,0 +1,14 @@ +package com.red.circle.other.app.dto.cmd.family; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 解散家族 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class DisbandFamilyCmd extends AppExtCommand { + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/family/FamilyService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/family/FamilyService.java index 88fec4ae..bd964d0d 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/family/FamilyService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/family/FamilyService.java @@ -180,4 +180,9 @@ public interface FamilyService { * 家族动态列表. */ PageResult familyNewsList(FamilyNewsListCmd cmd); + + /** + * 解散家族. + */ + void disbandFamily(DisbandFamilyCmd cmd); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/family/FamilyNewsTypeEnum.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/family/FamilyNewsTypeEnum.java index 432535ac..a8f4bf90 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/family/FamilyNewsTypeEnum.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/family/FamilyNewsTypeEnum.java @@ -49,7 +49,12 @@ public enum FamilyNewsTypeEnum { /** * 家族公告修改 */ - FAMILY_NOTICE_EDIT("FAMILY_NOTICE_EDIT", "The family announcement has been updated."); + FAMILY_NOTICE_EDIT("FAMILY_NOTICE_EDIT", "The family announcement has been updated."), + + /** + * 家族解散 + */ + FAMILY_DISBANDED("FAMILY_DISBANDED", "The family [{targetFamilyName}] has been disbanded."); private final String code; private final String template; @@ -62,6 +67,10 @@ public enum FamilyNewsTypeEnum { return template; } + if (this == FAMILY_DISBANDED) { + return template.replace("{targetFamilyName}", targetUserName != null ? targetUserName : ""); + } + String displayName = targetUserName; if (targetUserName != null && targetUserName.length() > 12) { displayName = targetUserName.substring(0, 12) + "...";