修复注册审核记录不可见问题

This commit is contained in:
2026-10-26 23:58:51 +08:00
parent 50af9b3fb0
commit 44dda21976
5 changed files with 236 additions and 15 deletions
@@ -201,7 +201,11 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
public List<WorkbenchRegistrationReviewVO> listForReviewer(Long reviewerId, boolean platformAdmin) {
List<WorkbenchRegistrationApplicationDO> applications;
if (platformAdmin) {
applications = applicationMapper.selectList(Wrappers.lambdaQuery(WorkbenchRegistrationApplicationDO.class).eq(WorkbenchRegistrationApplicationDO::getStatus, WorkbenchRegistrationStatus.PENDING_ADMIN).eq(WorkbenchRegistrationApplicationDO::getIsDelete, 0).orderByAsc(WorkbenchRegistrationApplicationDO::getCreateTime));
applications = applicationMapper.selectList(Wrappers.lambdaQuery(WorkbenchRegistrationApplicationDO.class)
.eq(WorkbenchRegistrationApplicationDO::getRoleType, WorkbenchRegistrationRole.MANAGER)
.eq(WorkbenchRegistrationApplicationDO::getStatus, WorkbenchRegistrationStatus.PENDING_ADMIN)
.eq(WorkbenchRegistrationApplicationDO::getIsDelete, 0)
.orderByAsc(WorkbenchRegistrationApplicationDO::getCreateTime));
} else {
UserDO reviewer = requireManager(reviewerId);
applications = applicationMapper.selectList(Wrappers.lambdaQuery(WorkbenchRegistrationApplicationDO.class).eq(WorkbenchRegistrationApplicationDO::getStatus, WorkbenchRegistrationStatus.PENDING_MANAGER).eq(WorkbenchRegistrationApplicationDO::getShopId, reviewer.getShopId()).eq(WorkbenchRegistrationApplicationDO::getIsDelete, 0).orderByAsc(WorkbenchRegistrationApplicationDO::getCreateTime));
@@ -222,15 +226,6 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
? Map.of()
: contentModerationRecordMapper.selectBatchIds(moderationIds).stream()
.collect(Collectors.toMap(ContentModerationRecordDO::getId, Function.identity()));
if (platformAdmin) {
applications = applications.stream()
.filter(application -> {
ContentModerationRecordDO moderation = application.getContentModerationRecordId() == null
? null : moderationById.get(application.getContentModerationRecordId());
return moderation != null && "APPROVED".equals(moderation.getStatus());
})
.collect(Collectors.toList());
}
return applications.stream()
.map(application -> toReviewVO(application, applicants.get(application.getUserId()),
application.getContentModerationRecordId() == null
@@ -0,0 +1,208 @@
package com.xiaowang.jayucloud.salon.core.modules.registration.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.xiaowang.jayucloud.salon.core.modules.integration.service.WechatMiniAuthService;
import com.xiaowang.jayucloud.salon.core.modules.privacy.entity.ContentModerationRecordDO;
import com.xiaowang.jayucloud.salon.core.modules.privacy.mapper.ContentModerationRecordMapper;
import com.xiaowang.jayucloud.salon.core.modules.privacy.service.ContentModerationService;
import com.xiaowang.jayucloud.salon.core.modules.registration.entity.WorkbenchRegistrationApplicationDO;
import com.xiaowang.jayucloud.salon.core.modules.registration.entity.WorkbenchRegistrationStatus;
import com.xiaowang.jayucloud.salon.core.modules.registration.mapper.WorkbenchRegistrationApplicationMapper;
import com.xiaowang.jayucloud.salon.core.modules.registration.vo.WorkbenchRegistrationReviewSummaryVO;
import com.xiaowang.jayucloud.salon.core.modules.registration.vo.WorkbenchRegistrationReviewVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessExpiryService;
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.UserShopBindingMapper;
import com.xiaowang.jayucloud.salon.core.modules.shop.support.UserShopBindingSupport;
import com.xiaowang.jayucloud.salon.core.modules.system.service.SystemParameterConfigService;
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.transaction.PlatformTransactionManager;
import java.util.Collection;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class WorkbenchRegistrationServiceImplTest {
@Mock private WorkbenchRegistrationApplicationMapper applicationMapper;
@Mock private UserMapper userMapper;
@Mock private ShopMapper shopMapper;
@Mock private UserService userService;
@Mock private UserShopBindingSupport userShopBindingSupport;
@Mock private UserShopBindingMapper userShopBindingMapper;
@Mock private WechatMiniAuthService wechatMiniAuthService;
@Mock private SystemParameterConfigService systemParameterConfigService;
@Mock private ContentModerationService contentModerationService;
@Mock private ContentModerationRecordMapper contentModerationRecordMapper;
@Mock private ShopBusinessExpiryService shopBusinessExpiryService;
@Mock private PlatformTransactionManager transactionManager;
private WorkbenchRegistrationServiceImpl service;
@BeforeEach
void setUp() {
service = new WorkbenchRegistrationServiceImpl(applicationMapper, userMapper, shopMapper, userService,
userShopBindingSupport, userShopBindingMapper, wechatMiniAuthService, systemParameterConfigService,
contentModerationService, contentModerationRecordMapper, shopBusinessExpiryService, transactionManager);
}
@Test
void returnsManagerReviewSummaryFromCurrentShopAndSwitch() {
UserDO manager = manager(7L, 21L);
when(userMapper.selectById(7L)).thenReturn(manager);
when(applicationMapper.selectCount(any(Wrapper.class))).thenReturn(3L);
when(systemParameterConfigService.getEnabledValue("WORKBENCH", "MANAGER_REGISTRATION_REVIEW_NOTICE"))
.thenReturn("true");
WorkbenchRegistrationReviewSummaryVO summary = service.getReviewSummary(7L);
assertEquals(3L, summary.getPendingCount());
assertEquals(true, summary.isNoticeEnabled());
}
@Test
void rejectsSummaryForNonManager() {
UserDO staff = new UserDO();
staff.setId(8L);
staff.setType(3);
staff.setShopId(21L);
when(userMapper.selectById(8L)).thenReturn(staff);
assertThrows(IllegalArgumentException.class, () -> service.getReviewSummary(8L));
}
@Test
void enrichesReviewListWithApplicantProfile() {
when(userMapper.selectById(7L)).thenReturn(manager(7L, 21L));
WorkbenchRegistrationApplicationDO application = new WorkbenchRegistrationApplicationDO();
application.setId(31L);
application.setUserId(9L);
application.setApplicationNo("SALON-001");
application.setStatus(WorkbenchRegistrationStatus.PENDING_MANAGER);
application.setShopId(21L);
when(applicationMapper.selectList(any(Wrapper.class))).thenReturn(List.of(application));
UserDO applicant = new UserDO();
applicant.setId(9L);
applicant.setNickname("小周");
applicant.setPhone("13812345678");
when(userMapper.selectBatchIds(any(Collection.class))).thenReturn(List.of(applicant));
List<WorkbenchRegistrationReviewVO> result = service.listForReviewer(7L, false);
assertEquals(1, result.size());
assertEquals("小周", result.get(0).getApplicantNickname());
assertEquals("138****5678", result.get(0).getApplicantMaskedPhone());
}
@Test
void locksApplicationAndRejectsAlreadyProcessedReview() {
WorkbenchRegistrationApplicationDO application = new WorkbenchRegistrationApplicationDO();
application.setId(31L);
application.setShopId(21L);
application.setStatus(WorkbenchRegistrationStatus.APPROVED);
when(applicationMapper.selectByIdForUpdate(31L)).thenReturn(application);
when(userMapper.selectById(7L)).thenReturn(manager(7L, 21L));
assertThrows(IllegalArgumentException.class, () -> service.approve(7L, false, 31L));
verify(applicationMapper).selectByIdForUpdate(31L);
}
@Test
void managerApplicationCannotBeApprovedBeforeContentModerationPasses() {
WorkbenchRegistrationApplicationDO application = new WorkbenchRegistrationApplicationDO();
application.setId(32L);
application.setUserId(9L);
application.setShopId(21L);
application.setRoleType("MANAGER");
application.setStatus(WorkbenchRegistrationStatus.PENDING_ADMIN);
application.setContentModerationRecordId(81L);
ContentModerationRecordDO moderation = new ContentModerationRecordDO();
moderation.setId(81L);
moderation.setStatus("PENDING");
when(applicationMapper.selectByIdForUpdate(32L)).thenReturn(application);
when(contentModerationRecordMapper.selectById(81L)).thenReturn(moderation);
assertThrows(IllegalArgumentException.class, () -> service.approve(1L, true, 32L));
verify(shopMapper, org.mockito.Mockito.never()).updateById(any());
verify(userMapper, org.mockito.Mockito.never()).updateById(any());
}
@Test
void platformAdminListShowsManagerApplicationsWhileContentReviewIsPending() {
WorkbenchRegistrationApplicationDO application = new WorkbenchRegistrationApplicationDO();
application.setId(33L);
application.setUserId(9L);
application.setRoleType("MANAGER");
application.setShopId(21L);
application.setStatus(WorkbenchRegistrationStatus.PENDING_ADMIN);
application.setContentModerationRecordId(82L);
ContentModerationRecordDO moderation = new ContentModerationRecordDO();
moderation.setId(82L);
moderation.setStatus("PENDING");
when(applicationMapper.selectList(any(Wrapper.class))).thenReturn(List.of(application));
when(userMapper.selectBatchIds(any(Collection.class))).thenReturn(List.of(new UserDO()));
when(contentModerationRecordMapper.selectBatchIds(any(Collection.class))).thenReturn(List.of(moderation));
List<WorkbenchRegistrationReviewVO> result = service.listForReviewer(1L, true);
assertEquals(1, result.size());
assertEquals(WorkbenchRegistrationStatus.PENDING_ADMIN, result.get(0).getStatus());
assertEquals("PENDING", result.get(0).getContentModerationStatus());
}
@Test
void autoApprovesManagerOnlyWhenLinkedShopContentPassed() {
WorkbenchRegistrationApplicationDO application = new WorkbenchRegistrationApplicationDO();
application.setId(34L);
application.setUserId(9L);
application.setShopId(21L);
application.setRoleType("MANAGER");
application.setStatus(WorkbenchRegistrationStatus.PENDING_ADMIN);
application.setContentModerationRecordId(83L);
ContentModerationRecordDO moderation = new ContentModerationRecordDO();
moderation.setId(83L);
moderation.setContentType("SHOP");
moderation.setUserId(9L);
moderation.setStatus("APPROVED");
UserDO applicant = new UserDO();
applicant.setId(9L);
ShopDO shop = new ShopDO();
shop.setId(21L);
when(applicationMapper.selectByIdForUpdate(34L)).thenReturn(application);
when(contentModerationRecordMapper.selectById(83L)).thenReturn(moderation);
when(systemParameterConfigService.getEnabledValue("WORKBENCH", "MANAGER_REGISTRATION_AUTO_APPROVE"))
.thenReturn("true");
when(userMapper.selectById(9L)).thenReturn(applicant);
when(shopMapper.selectById(21L)).thenReturn(shop);
service.processManagerModeration(34L);
assertEquals(WorkbenchRegistrationStatus.APPROVED, application.getStatus());
verify(shopBusinessExpiryService).startDefaultValidity(org.mockito.ArgumentMatchers.eq(21L), any());
verify(userShopBindingSupport).updateBindingStatus(9L, 21L, 1);
verify(userService).syncManagedPermissions(9L);
}
private UserDO manager(Long id, Long shopId) {
UserDO manager = new UserDO();
manager.setId(id);
manager.setType(2);
manager.setShopId(shopId);
return manager;
}
}