From 758759f78012121a0b3ae641e034db27cf72e13b Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 4 Feb 2026 10:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=A8=E6=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=80=BB=E8=BE=91=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../delete/DynamicContentDelCmdExe.java | 29 ++++++- .../src/test/java/user/UserProfileTest.java | 75 ++++++++++++++++++- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/delete/DynamicContentDelCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/delete/DynamicContentDelCmdExe.java index 61359cfa..f6c419cf 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/delete/DynamicContentDelCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/delete/DynamicContentDelCmdExe.java @@ -1,16 +1,22 @@ package com.red.circle.other.app.command.dynamic.delete; +import com.red.circle.common.business.core.enums.ApprovalStatusEnum; import com.red.circle.common.business.core.enums.DynamicEventTypeEnum; import com.red.circle.common.business.dto.cmd.IdLongCmd; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.mq.business.model.event.dynamic.DynamicEvent; import com.red.circle.mq.rocket.business.producer.DynamicMqMessage; +import com.red.circle.other.app.enums.violation.ViolationTypeEnum; import com.red.circle.other.infra.database.mongo.service.dynamic.DynamicPopularService; +import com.red.circle.other.infra.database.rds.entity.approval.ApprovalDynamicContent; import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicContent; import com.red.circle.other.infra.database.rds.service.approval.ApprovalDynamicContentService; import com.red.circle.other.infra.database.rds.service.dynamic.DynamicContentService; +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.inner.asserts.DynamicErrorCode; +import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; import java.util.Objects; import lombok.RequiredArgsConstructor; @@ -32,13 +38,32 @@ public class DynamicContentDelCmdExe { private final DynamicContentService dynamicContentService; private final DynamicPopularService dynamicPopularService; private final ApprovalDynamicContentService approvalDynamicContentService; + private final AdministratorService administratorService; + private final AdministratorAuthService administratorAuthService; public void execute(IdLongCmd cmd) { DynamicContent dynamicContent = dynamicContentService.getById(cmd.getId()); ResponseAssert.notNull(DynamicErrorCode.CONTENT_IS_NULL, dynamicContent); - ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION, - Objects.equals(dynamicContent.getCreateUser(), cmd.getReqUserId())); + + boolean isOwn = Objects.equals(dynamicContent.getCreateUser(), cmd.getReqUserId()); + boolean isAdminAuth = administratorService.existsAdmin(cmd.getReqUserId()) && + administratorAuthService.existsAuth(cmd.requiredReqUserId(), ViolationTypeEnum.DELETE_CONTENT.name()); + ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION, isOwn || isAdminAuth); + + // 管理员删除别人的 送入待审核 + if (isAdminAuth && !isOwn) { + ApprovalDynamicContent approvalDynamicContent = new ApprovalDynamicContent(); + approvalDynamicContent.setUserId(cmd.getReqUserId()); + approvalDynamicContent.setDynamicId(dynamicContent.getId()); + approvalDynamicContent.setApproveStatus(ApprovalStatusEnum.PENDING.name()); + approvalDynamicContent.setSysOrigin(dynamicContent.getSysOrigin()); + approvalDynamicContent.setCreateTime(TimestampUtils.now()); + approvalDynamicContent.setCreateUser(cmd.getReqUserId()); + approvalDynamicContentService.save(approvalDynamicContent); + return; + } + dynamicContent.setDel(Boolean.TRUE); dynamicContent.setUpdateUser(cmd.getReqUserId()); diff --git a/rc-service/rc-service-other/other-start/src/test/java/user/UserProfileTest.java b/rc-service/rc-service-other/other-start/src/test/java/user/UserProfileTest.java index 41d3469d..618ee2f1 100644 --- a/rc-service/rc-service-other/other-start/src/test/java/user/UserProfileTest.java +++ b/rc-service/rc-service-other/other-start/src/test/java/user/UserProfileTest.java @@ -1,25 +1,96 @@ package user; +import com.mongodb.bulk.BulkWriteResult; import com.red.circle.OtherServiceApplication; import com.red.circle.framework.dto.ResultResponse; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.model.user.UserProfile; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMemberTarget; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberTargetService; +import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.tool.core.date.TimestampUtils; +import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.mongodb.core.BulkOperations; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + @SpringBootTest(classes = OtherServiceApplication.class) @RunWith(SpringRunner.class) +@Slf4j public class UserProfileTest { @Autowired private UserProfileClient userProfileClient; + @Autowired + private TeamProfileService teamProfileService; + @Autowired + private UserProfileGateway userProfileGateway; + @Autowired + private MongoTemplate mongoTemplate; @Test - public void userProfileTest(){ - ResultResponse byUserId = userProfileClient.getByUserId(1999166404179394561L); + public void test(){ + List teamProfiles = teamProfileService.listStatusAvailable(); + if (teamProfiles.isEmpty()) { + log.info("没有需要更新的团队"); + return; + } + + Set userIds = teamProfiles.stream() + .map(TeamProfile::getOwnUserId) + .collect(Collectors.toSet()); + Map userProfileMap = userProfileGateway.mapByUserIds(userIds); + + BulkOperations bulkOps = mongoTemplate.bulkOps( + BulkOperations.BulkMode.UNORDERED, + TeamMemberTarget.class + ); + + int updateCount = 0; + for (TeamProfile teamProfile : teamProfiles) { + UserProfile userProfile = userProfileMap.get(teamProfile.getOwnUserId()); + + if (userProfile == null) { + log.warn("团队 {} 的团队长 {} 用户资料不存在", + teamProfile.getId(), teamProfile.getOwnUserId()); + continue; + } + + if (teamProfile.getRegion() == null || userProfile.getCountryCode() == null) { + log.warn("团队 {} 的区域或国家代码为空", teamProfile.getId()); + continue; + } + + bulkOps.updateMulti( + Query.query(Criteria.where("teamId").is(teamProfile.getId())), + new Update() + .set("region", teamProfile.getRegion()) + .set("countryCode", userProfile.getCountryCode()) + ); + updateCount++; + } + + if (updateCount > 0) { + BulkWriteResult result = bulkOps.execute(); + log.info("批量更新完成,影响 {} 条记录", result.getModifiedCount()); + } else { + log.info("没有需要更新的有效数据"); + } } }