新增解散家族接口
This commit is contained in:
parent
63df01e213
commit
0073bf8e2c
@ -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"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 投入宝箱金币.
|
||||
*/
|
||||
|
||||
@ -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<FamilyMemberInfo> members, Long familyId) {
|
||||
if (CollectionUtils.isEmpty(members)) {
|
||||
return;
|
||||
}
|
||||
|
||||
members.forEach(member -> {
|
||||
familyCommon.removeGroup(familyId, member.getMemberUserId());
|
||||
userProfileGateway.removeCacheAll(member.getMemberUserId());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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<FamilyNewsCO> 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
}
|
||||
@ -180,4 +180,9 @@ public interface FamilyService {
|
||||
* 家族动态列表.
|
||||
*/
|
||||
PageResult<FamilyNewsCO> familyNewsList(FamilyNewsListCmd cmd);
|
||||
|
||||
/**
|
||||
* 解散家族.
|
||||
*/
|
||||
void disbandFamily(DisbandFamilyCmd cmd);
|
||||
}
|
||||
|
||||
@ -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) + "...";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user