收口(去重库读侧): 按行 company_id 认公司——代导入/上传者已删两族归位
控制方 2026-10-09 截图:admin 在「先锋」tab 代导入的行(company_id=3、 uploader=admin 属公司 1)在先锋 tab 看不见、反而出现在米椿花 tab。读侧 (列表/导出/公司超管)自 V145 起一直按"上传账号"认公司,与写侧(5ccf3c89 起一律显式落 company_id、V154 已摘 DEFAULT)两套口径打架;切换前先把存量 兜底行修对:V156 把组 33/uid=1188(「先锋」,账号已硬删)的 1452 行 company_id 1→3——否则切完它们整批冒给米椿花,且当前正参与米椿花的去重 比对(5ccf3c89 已按 company_id 收窄),先锋自己反而拿不到这批值。 - DataReadScope 新增第五道正门 superAdminScopedCompanyId:与 superAdminScopedUserIds 同形"只对站点超管收窄",维度从上传账号集换成 行 company_id;非超管恒 null(不叠那一刀,可见集仍锁在账号/分组上) - Service applyCompanyScope 由 uploader_user_id IN (成员) 改 eq(company_id); company_super_admin 的 wholeCompany 分支同批切换(1206 从此看得到代导入 行与上传者已删行,例:admin 代导入 14 行 + 组 33 历史 1452 行) - G2 护栏加第五道门 + 正/负三枚探针;单测新增四条(超管切公司、公司超管 全公司、门非超管恒 null、service 层 wrapper 两面) DedupeTotalDataController 的换门接线已随 2a4d15b8(文案批)入库。 影响面(生产只读实查):切后米椿花 tab −14 行、先锋 tab +14+1452 行; 公司超管仅 1206 一个账号。全量 4209 测绿。
This commit is contained in:
+46
-34
@@ -172,12 +172,12 @@ public class DedupeTotalDataService {
|
||||
/**
|
||||
* @param lastId keyset 游标(上一页返回的 nextLastId);非空时忽略 page 偏移,
|
||||
* 直接按 id 倒序取"比它小"的一页,避免深分页 offset 扫索引的代价
|
||||
* @param companyMemberIds 公司 tab 收窄后的成员账号集({@code DataReadScope} 给出);
|
||||
* null = 不筛(超管没选公司 / 非超管走会话范围)
|
||||
* @param scopedCompanyId 公司 tab 收窄后的公司 id({@code DataReadScope#superAdminScopedCompanyId} 给出);
|
||||
* null = 不筛(超管没选公司 / 非超管走会话范围)
|
||||
*/
|
||||
public DedupeTotalDataPageVo page(long page, long pageSize, String keyword, String username,
|
||||
LocalDate startDate, LocalDate endDate, Long groupId, String country,
|
||||
Long lastId, Long operatorId, List<Long> companyMemberIds) {
|
||||
Long lastId, Long operatorId, Long scopedCompanyId) {
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class DedupeTotalDataService {
|
||||
endDate == null ? null : endDate.plusDays(1).atStartOfDay())
|
||||
.orderByDesc(DedupeTotalDataEntity::getId);
|
||||
applyGroupScope(query, scope, groupId);
|
||||
applyCompanyScope(query, companyMemberIds);
|
||||
applyCompanyScope(query, scopedCompanyId);
|
||||
Long total = dedupeTotalDataMapper.selectCount(query);
|
||||
boolean keyset = lastId != null && lastId > 0;
|
||||
if (keyset) {
|
||||
@@ -275,7 +275,7 @@ public class DedupeTotalDataService {
|
||||
Long groupId,
|
||||
String country,
|
||||
Long operatorId,
|
||||
List<Long> companyMemberIds) {
|
||||
Long scopedCompanyId) {
|
||||
if (outputStream == null) {
|
||||
throw new BusinessException("导出输出流不能为空");
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public class DedupeTotalDataService {
|
||||
String safeUsername = username == null ? "" : username.trim();
|
||||
AccessScope scope = resolveAccessScope(operatorId);
|
||||
buildExportWorkbook(outputStream, safeUsername, startDate, endDate, groupId, country, scope, false,
|
||||
companyMemberIds);
|
||||
scopedCompanyId);
|
||||
}
|
||||
|
||||
public void writeMonthlyZipExport(OutputStream outputStream,
|
||||
@@ -314,12 +314,12 @@ public class DedupeTotalDataService {
|
||||
Long groupId,
|
||||
String country,
|
||||
Long operatorId,
|
||||
List<Long> companyMemberIds) {
|
||||
Long scopedCompanyId) {
|
||||
if (outputStream == null) {
|
||||
throw new BusinessException("导出文件写入失败,请稍后重试");
|
||||
}
|
||||
if (startDate == null || endDate == null || YearMonth.from(startDate).equals(YearMonth.from(endDate))) {
|
||||
writeExport(outputStream, username, startDate, endDate, groupId, country, operatorId, companyMemberIds);
|
||||
writeExport(outputStream, username, startDate, endDate, groupId, country, operatorId, scopedCompanyId);
|
||||
return;
|
||||
}
|
||||
if (startDate.isAfter(endDate)) {
|
||||
@@ -343,7 +343,7 @@ public class DedupeTotalDataService {
|
||||
LocalDate entryEndDate = endDate.isBefore(monthEnd) ? endDate : monthEnd;
|
||||
zipOutputStream.putNextEntry(new ZipEntry(monthlyExportEntryName(currentMonth)));
|
||||
buildExportWorkbook(zipOutputStream, safeUsername, entryStartDate, entryEndDate,
|
||||
groupId, safeCountry, scope, groupPrevalidated, companyMemberIds);
|
||||
groupId, safeCountry, scope, groupPrevalidated, scopedCompanyId);
|
||||
zipOutputStream.closeEntry();
|
||||
currentMonth = currentMonth.plusMonths(1);
|
||||
}
|
||||
@@ -373,7 +373,7 @@ public class DedupeTotalDataService {
|
||||
String country,
|
||||
AccessScope scope,
|
||||
boolean groupPrevalidated,
|
||||
List<Long> companyMemberIds) {
|
||||
Long scopedCompanyId) {
|
||||
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
|
||||
Sheet sheet = workbook.createSheet("DedupeTotalData");
|
||||
Row header = sheet.createRow(0);
|
||||
@@ -387,7 +387,7 @@ public class DedupeTotalDataService {
|
||||
int rowIndex = 1;
|
||||
while (true) {
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> pageQuery = buildExportQuery(
|
||||
username, startDate, endDate, groupId, country, scope, groupPrevalidated, companyMemberIds);
|
||||
username, startDate, endDate, groupId, country, scope, groupPrevalidated, scopedCompanyId);
|
||||
if (lastId != null) {
|
||||
pageQuery.lt(DedupeTotalDataEntity::getId, lastId);
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public class DedupeTotalDataService {
|
||||
String country,
|
||||
AccessScope scope,
|
||||
boolean groupPrevalidated,
|
||||
List<Long> companyMemberIds) {
|
||||
Long scopedCompanyId) {
|
||||
String safeUsername = username == null ? "" : username.trim();
|
||||
String safeCountry = country == null ? "" : country.trim();
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> query = new LambdaQueryWrapper<DedupeTotalDataEntity>()
|
||||
@@ -459,7 +459,7 @@ public class DedupeTotalDataService {
|
||||
endDate == null ? null : endDate.plusDays(1).atStartOfDay())
|
||||
.orderByDesc(DedupeTotalDataEntity::getId);
|
||||
applyGroupScope(query, scope, groupId, groupPrevalidated);
|
||||
applyCompanyScope(query, companyMemberIds);
|
||||
applyCompanyScope(query, scopedCompanyId);
|
||||
return query;
|
||||
}
|
||||
|
||||
@@ -1258,7 +1258,7 @@ public class DedupeTotalDataService {
|
||||
private AccessScope resolveAccessScope(Long operatorId) {
|
||||
AdminUserEntity operator = getOperator(operatorId);
|
||||
if (isSuperAdmin(operator)) {
|
||||
return new AccessScope(true, Set.of(), Set.of(), false);
|
||||
return new AccessScope(true, Set.of(), Set.of(), false, null);
|
||||
}
|
||||
if ("company_super_admin".equals(operator.getRole() == null
|
||||
? "" : operator.getRole().trim().toLowerCase(Locale.ROOT))) {
|
||||
@@ -1273,7 +1273,8 @@ public class DedupeTotalDataService {
|
||||
// allUsers 与 groupIds 两样,读侧才走 wholeCompany 那一支。这里留空集的表现是
|
||||
// 「下拉选得到自己公司的分组、提交必 403」,而 403 是 HTTP 状态不是中文文案。
|
||||
Set<Long> companyGroupIds = shopManageGroupService.listCompanyGroupIds(List.copyOf(companyUserIds));
|
||||
return new AccessScope(false, companyGroupIds, Set.copyOf(companyUserIds), true);
|
||||
return new AccessScope(false, companyGroupIds, Set.copyOf(companyUserIds), true,
|
||||
operator.getCompanyId());
|
||||
}
|
||||
List<Long> accessibleGroupIds = shopManageGroupMapper.selectAccessibleGroupIds(operator.getId());
|
||||
LinkedHashSet<Long> visibleUserIds = new LinkedHashSet<>();
|
||||
@@ -1296,7 +1297,8 @@ public class DedupeTotalDataService {
|
||||
false,
|
||||
Set.copyOf(accessibleGroupIds == null ? List.of() : accessibleGroupIds),
|
||||
Set.copyOf(visibleUserIds),
|
||||
false);
|
||||
false,
|
||||
null);
|
||||
}
|
||||
|
||||
private void applyGroupScope(LambdaQueryWrapper<DedupeTotalDataEntity> query,
|
||||
@@ -1317,8 +1319,16 @@ public class DedupeTotalDataService {
|
||||
return;
|
||||
}
|
||||
if (scope.wholeCompany()) {
|
||||
// 公司超管:整家公司成员上传的行全可见,不再按 group_id 切
|
||||
query.in(DedupeTotalDataEntity::getUploaderUserId, scope.userIds());
|
||||
// 公司超管:整家公司名下的行全可见,不再按 group_id 切。
|
||||
// 2026-10-09 与 tab 收窄同批从"成员上传"切到行 company_id:原口径漏
|
||||
// 「代导入行」(uploader 不属本公司)与「上传账号已删的行」(JOIN 不上成员集),
|
||||
// 先锋公司超管(uid=1206)对这两族一行都看不到。companyId 空属异常态
|
||||
// (company_super_admin 必挂公司),给不可能命中的条件而不是"不筛"。
|
||||
if (scope.companyId() == null) {
|
||||
query.eq(DedupeTotalDataEntity::getId, -1L);
|
||||
return;
|
||||
}
|
||||
query.eq(DedupeTotalDataEntity::getCompanyId, scope.companyId());
|
||||
return;
|
||||
}
|
||||
query.and(wrapper -> {
|
||||
@@ -1332,24 +1342,22 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司 tab 收窄:本表按「上传账号」认公司——{@code uploader_user_id} 是 NOT NULL(V75 先回灌再收紧),
|
||||
* 且有 idx_uploader_user_id_id 可走点查。
|
||||
* 公司 tab 收窄:按行自己的 {@code company_id} 筛(V145 物化的列、uk_company_data_value 的第一列)。
|
||||
*
|
||||
* <p>不按 V145 加的 company_id 筛:那一列对 V145 之前的历史行全部是 DEFAULT 兜的 1,没有区分力。
|
||||
* 写侧现已显式落值(create 与 insertBatchIgnore 都带 company_id),但读侧一旦改用它,历史行会整批归到
|
||||
* 公司 1——所以那列只供写入留存与 uk_company_data_value 使用,读侧口径维持按上传账号推导。</p>
|
||||
* <p>2026-10-09 从"按上传账号推导"切到这里(控制方截图为证:超管 admin 在「先锋」tab 代导入的
|
||||
* 行 uploader=admin,读侧整批出现在 admin 自己那一家、目标 tab 反而看不到)。切换的历史行风险
|
||||
* 已逐项处置:V145 第 2 段迁移当时就按上传账号反推过一遍(非公司 1 账号的行 company_id 已是真值);
|
||||
* 写侧自 39de5035 起 create/insertBatchIgnore/导入一律显式落值、V154 已摘 DEFAULT,漏传即报错
|
||||
* 而不会兜进公司 1;剩余一批"上传账号被硬删、归属兜成 1"的历史行(组 33「先锋」,1452 行)
|
||||
* 由 V156 回填到真实归属。切换后本表读、写、去重比对、唯一键四侧同一口径。</p>
|
||||
*
|
||||
* <p>空集给一条不可能命中的条件而不是"不筛":tab 选了这家公司却看得到全平台,比看不到更坏。</p>
|
||||
* <p>{@code null} = 不筛(超管没选公司 / 非超管走会话范围)。</p>
|
||||
*/
|
||||
private void applyCompanyScope(LambdaQueryWrapper<DedupeTotalDataEntity> query, List<Long> companyMemberIds) {
|
||||
if (companyMemberIds == null) {
|
||||
private void applyCompanyScope(LambdaQueryWrapper<DedupeTotalDataEntity> query, Long scopedCompanyId) {
|
||||
if (scopedCompanyId == null) {
|
||||
return;
|
||||
}
|
||||
if (companyMemberIds.isEmpty()) {
|
||||
query.eq(DedupeTotalDataEntity::getId, -1L);
|
||||
return;
|
||||
}
|
||||
query.in(DedupeTotalDataEntity::getUploaderUserId, companyMemberIds);
|
||||
query.eq(DedupeTotalDataEntity::getCompanyId, scopedCompanyId);
|
||||
}
|
||||
|
||||
private ShopManageGroupEntity resolveWritableGroup(Long groupId, AdminUserEntity operator) {
|
||||
@@ -1524,9 +1532,13 @@ public class DedupeTotalDataService {
|
||||
|
||||
/**
|
||||
* @param allUsers 超管直通
|
||||
* @param wholeCompany 公司超管:不做分组维度裁剪,userIds = 本公司全体成员,
|
||||
* 查询条件退化为 uploader_user_id IN (成员)——公司超管的"组"就是整家公司
|
||||
* @param wholeCompany 公司超管:不做分组维度裁剪,查询条件退化为 company_id = companyId
|
||||
* (2026-10-09 起按行归属列;见 {@code applyGroupScope} 该分支的切换理由)。
|
||||
* 公司超管的"组"就是整家公司;userIds 仅剩写侧闸门(ensureRecordAccess 的
|
||||
* group_id IS NULL 那一支)在用
|
||||
* @param companyId 公司超管所属公司;仅 wholeCompany=true 时有值
|
||||
*/
|
||||
record AccessScope(boolean allUsers, Set<Long> groupIds, Set<Long> userIds, boolean wholeCompany) {
|
||||
record AccessScope(boolean allUsers, Set<Long> groupIds, Set<Long> userIds, boolean wholeCompany,
|
||||
Long companyId) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user