feat(admin): 公司tab条按平台分侧+京东分组作用域只认jd档(2026-11-17 用户口径「亚马逊侧别挂京东-团队,同理京东那边也是」)
- company-tab store:目录按当前平台 tab 拉(loadedPlatform 对撞早退),切台重拉;旧选中仍在新清单则保住,不在回落 id 最小启用公司;新增 refresh() 强制档(公司翻档/启停后 18 页 tab 条同步)
This commit is contained in:
+40
-27
@@ -8,6 +8,7 @@ import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.model.entity.ShopManageGroupEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.AdminPlatformScope;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.modules.company.mapper.CompanyMapper;
|
||||
import com.nanri.aiimage.modules.company.model.entity.CompanyEntity;
|
||||
@@ -27,11 +28,13 @@ import java.util.Set;
|
||||
* 京东数据库分类的「当前分组」作用域解析(V203,2026-11-16 用户口径)。
|
||||
*
|
||||
* <p>口径:「组」=公司内的<b>数据权限分组</b>({@code biz_shop_manage_group}),公司→组两级隔离。
|
||||
* 四档:</p>
|
||||
* 2026-11-17 用户口径「同理京东那边也是」加一条平台闸:<b>只有京东档({@code platform='jd'},
|
||||
* V206 列)的分组才进京东侧作用域</b>——亚马逊档与 NULL 一律不进下拉(四档角色先各自圈完
|
||||
* 可见集,最后统一过这道闸)。四档:</p>
|
||||
* <ul>
|
||||
* <li><b>平台超管</b>:全部公司全部组可读可写;</li>
|
||||
* <li><b>公司超管</b>:本公司全部组可读可写(与「公司超管看本公司全部成员」同源);</li>
|
||||
* <li><b>管理员(组长)</b>:可见=自己带的组 + 自己所属组的组长;可写=自己带的组;</li>
|
||||
* <li><b>平台超管</b>:全部公司全部<b>京东档</b>组可读可写;</li>
|
||||
* <li><b>公司超管</b>:本公司全部<b>京东档</b>组可读可写(与「公司超管看本公司全部成员」同源);</li>
|
||||
* <li><b>管理员(组长)</b>:可见=自己带的组 + 自己所属组的组长(过平台闸后);可写=自己带的组;</li>
|
||||
* <li><b>普通号</b>:可见同上,可写空(能开弹窗看,不能增删改分类、不能归类)。</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -144,39 +147,49 @@ public class JdCategoryScopeService {
|
||||
String role = adminAuthSupport.currentRole(user);
|
||||
Map<Long, ShopManageGroupEntity> visible = new LinkedHashMap<>();
|
||||
Set<Long> writable = new LinkedHashSet<>();
|
||||
if (dataReadScope.isPlatformSuperAdmin(user)) {
|
||||
boolean platformSuperAdmin = dataReadScope.isPlatformSuperAdmin(user);
|
||||
if (platformSuperAdmin) {
|
||||
collect(visible, shopManageGroupMapper.selectAllGroups());
|
||||
writable.addAll(visible.keySet());
|
||||
return assemble(true, user.getCompanyId(), visible, writable);
|
||||
}
|
||||
if (DeviceSessionPolicy.isCompanySuperAdmin(role)) {
|
||||
} else if (DeviceSessionPolicy.isCompanySuperAdmin(role)) {
|
||||
Long companyId = user.getCompanyId();
|
||||
if (companyId != null && companyId > 0) {
|
||||
collect(visible, companyGroups(companyId));
|
||||
writable.addAll(visible.keySet());
|
||||
}
|
||||
return assemble(false, companyId, visible, writable);
|
||||
}
|
||||
// 管理员(组长):自己带的组可写;自己所属组的组长带的分组只读可见。
|
||||
List<ShopManageGroupEntity> led = ledGroups(user.getId());
|
||||
collect(visible, led);
|
||||
if ("admin".equals(role)) {
|
||||
for (ShopManageGroupEntity group : led) {
|
||||
if (group.getId() != null) {
|
||||
writable.add(group.getId());
|
||||
} else {
|
||||
// 管理员(组长):自己带的组可写;自己所属组的组长带的分组只读可见。
|
||||
List<ShopManageGroupEntity> led = ledGroups(user.getId());
|
||||
collect(visible, led);
|
||||
if ("admin".equals(role)) {
|
||||
for (ShopManageGroupEntity group : led) {
|
||||
if (group.getId() != null) {
|
||||
writable.add(group.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (user.getCreatedById() != null && user.getCreatedById() > 0) {
|
||||
collect(visible, ledGroups(user.getCreatedById()));
|
||||
}
|
||||
List<Long> memberOfLeaders = shopManageGroupMapper.selectLeaderIdsByMemberUserId(user.getId());
|
||||
if (memberOfLeaders != null) {
|
||||
for (Long leaderId : memberOfLeaders) {
|
||||
collect(visible, ledGroups(leaderId));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (user.getCreatedById() != null && user.getCreatedById() > 0) {
|
||||
collect(visible, ledGroups(user.getCreatedById()));
|
||||
}
|
||||
List<Long> memberOfLeaders = shopManageGroupMapper.selectLeaderIdsByMemberUserId(user.getId());
|
||||
if (memberOfLeaders != null) {
|
||||
for (Long leaderId : memberOfLeaders) {
|
||||
collect(visible, ledGroups(leaderId));
|
||||
}
|
||||
}
|
||||
return assemble(false, user.getCompanyId(), visible, writable);
|
||||
// 2026-11-17 用户口径「同理京东那边也是」:京东侧作用域只认京东档(platform='jd')的
|
||||
// 数据权限分组——亚马逊档与 NULL 一律不进下拉。V206 存量默认 amazon、京东侧数据由编辑
|
||||
// 弹窗翻档,这里不做「NULL/缺列当 jd」的宽判:宽了会把没翻档的存量整批带进京东侧,
|
||||
// 等于平台分侧白做。
|
||||
retainJdPlatformGroups(visible, writable);
|
||||
return assemble(platformSuperAdmin, user.getCompanyId(), visible, writable);
|
||||
}
|
||||
|
||||
/** 只留京东档分组,并让可写集跟着可见集收缩(writable ⊆ visible 的既有不变量保持)。 */
|
||||
private static void retainJdPlatformGroups(Map<Long, ShopManageGroupEntity> visible, Set<Long> writable) {
|
||||
visible.values().removeIf(group -> !AdminPlatformScope.JD.equals(group.getPlatform()));
|
||||
writable.retainAll(visible.keySet());
|
||||
}
|
||||
|
||||
private List<ShopManageGroupEntity> companyGroups(Long companyId) {
|
||||
|
||||
+77
-1
@@ -30,7 +30,8 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* 京东数据库分类「当前分组」作用域判据(V203;2026-11-16 用户口径)。
|
||||
*
|
||||
* <p>四档矩阵:平台超管=全部公司全部组可读可写;公司超管=本公司全部组;
|
||||
* <p>四档矩阵(2026-11-17 起各档可见集最后统一过「只留京东档 platform='jd' 分组」的平台闸):
|
||||
* 平台超管=全部公司全部组可读可写;公司超管=本公司全部组;
|
||||
* 管理员(组长)=自己带的组可写、自己所属组的组长带的分组只读;
|
||||
* 普通号=与管理员同可见、<b>零可写</b>(能开弹窗看,不能增删改分类、不能归类)。
|
||||
* 另钉三条收敛语义:不可见组读 403(不做空结果降级)、无分组上下文读回 null(页面照常可用)、
|
||||
@@ -86,6 +87,70 @@ class JdCategoryScopeServiceTest {
|
||||
assertThat(scope.canWrite(20L)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 2026-11-17 用户口径「同理京东那边也是」:京东侧下拉只认京东档(platform='jd')分组。
|
||||
* 亚马逊档与 NULL 档(未翻档的存量)一律滤掉,可写集跟着收缩;过滤后只剩一家公司 ⇒
|
||||
* 组名不带公司前缀(既有「单公司不啰嗦」口径不变)。
|
||||
*/
|
||||
@Test
|
||||
void 平台超管_只显示京东档分组_亚马逊档与NULL档不进下拉() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(true);
|
||||
when(shopManageGroupMapper.selectAllGroups()).thenReturn(List.of(
|
||||
group(10L, 1L, "A组"),
|
||||
amazonGroup(20L, 2L, "B组"),
|
||||
groupOfPlatform(30L, 3L, "C组", null)));
|
||||
CompanyEntity first = new CompanyEntity();
|
||||
first.setId(1L);
|
||||
first.setCompanyName("甲公司");
|
||||
when(companyMapper.selectBatchIds(any())).thenReturn(List.of(first));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.writableGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.defaultGroupId()).isEqualTo(10L);
|
||||
assertThat(scope.groups()).extracting(JdCategoryGroupOptionVo::getLabel)
|
||||
.containsExactly("A组");
|
||||
// 亚马逊档组读/写双拒(不是 403,是压根不可见)。
|
||||
assertThat(scope.canRead(20L)).isFalse();
|
||||
assertThat(scope.canWrite(20L)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 公司超管_本公司亚马逊档组同样被滤掉() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectList(any())).thenReturn(List.of(
|
||||
group(10L, COMPANY_ID, "A组"), amazonGroup(11L, COMPANY_ID, "B组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.writableGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.groups()).extracting(JdCategoryGroupOptionVo::getLabel)
|
||||
.containsExactly("A组");
|
||||
verify(companyMapper, never()).selectBatchIds(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 组长_带的组全是亚马逊档时空作用域不报错() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("admin");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID))
|
||||
.thenReturn(List.of(amazonGroup(10L, COMPANY_ID, "自己的组")));
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).isEmpty();
|
||||
assertThat(scope.writableGroupIds()).isEmpty();
|
||||
assertThat(scope.defaultGroupId()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 公司超管_本公司全部组可读可写() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
@@ -319,10 +384,20 @@ class JdCategoryScopeServiceTest {
|
||||
}
|
||||
|
||||
private static ShopManageGroupEntity group(long id, long companyId, String name) {
|
||||
return groupOfPlatform(id, companyId, name, "jd");
|
||||
}
|
||||
|
||||
/** 亚马逊档组(V206 存量默认档):2026-11-17 起不进京东侧作用域。 */
|
||||
private static ShopManageGroupEntity amazonGroup(long id, long companyId, String name) {
|
||||
return groupOfPlatform(id, companyId, name, "amazon");
|
||||
}
|
||||
|
||||
private static ShopManageGroupEntity groupOfPlatform(long id, long companyId, String name, String platform) {
|
||||
ShopManageGroupEntity group = new ShopManageGroupEntity();
|
||||
group.setId(id);
|
||||
group.setCompanyId(companyId);
|
||||
group.setGroupName(name);
|
||||
group.setPlatform(platform);
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -331,6 +406,7 @@ class JdCategoryScopeServiceTest {
|
||||
ShopManageGroupEntity group = new ShopManageGroupEntity();
|
||||
group.setId(id);
|
||||
group.setGroupName(name);
|
||||
group.setPlatform("jd");
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user