fix(多租户): V152 摘 columns/biz_shop_key 的 company_id 列默认值,去重库写侧显式带归属
- V152:两条裸 ALTER COLUMN DROP DEFAULT(纯元数据、可重跑)。依据 V150 §6「合并成一版」 与 migration-inventory 取号;前提=V149/150/151 已于 10-06 17:32:29 落库、写侧三条通道 (PermissionMenuService create/copyTreeFromTemplate、ShopKeyService)均显式落列。 - 去重库:DedupeTotalDataMapper/Entity/Service 的 INSERT 显式写 company_id,不再靠列 DEFAULT 1 兜底(第二家公司开通后静默归错)。biz_dedupe_total_data 的 DEFAULT 摘除排在 本批上线并验证写入之后,不在本版。 - CompanyDefaultDropV152Test 9 例(含 V149/150/151 已应用字节的 CRC 冻结)+ dedupe 两支测试 + rollback-V152 人工补丁(默认档可直接执行)+ 盘点文档同步(取号起点改 V153)。
This commit is contained in:
+2
-2
@@ -28,10 +28,10 @@ public interface DedupeTotalDataMapper extends BaseMapper<DedupeTotalDataEntity>
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT IGNORE INTO biz_dedupe_total_data
|
||||
(data_value, country, group_id, uploader_user_id, uploader_username)
|
||||
(data_value, country, group_id, uploader_user_id, uploader_username, company_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.dataValue}, #{row.country}, #{row.groupId}, #{row.uploaderUserId}, #{row.uploaderUsername})
|
||||
(#{row.dataValue}, #{row.country}, #{row.groupId}, #{row.uploaderUserId}, #{row.uploaderUsername}, #{row.companyId})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
|
||||
+10
@@ -15,6 +15,16 @@ public class DedupeTotalDataEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
/**
|
||||
* 归属公司(V145 加列)。写侧一律显式落值——create 与 insertBatchIgnore 的入口都经
|
||||
* {@code CompanyScopeSupport.requireCompanyId(操作者)} 解析后带进每个 insert,不许依赖列上那条
|
||||
* 临时的 {@code DEFAULT 1}:V145 留它只为历史行与同批的旧 jar 不报 1364,待摘
|
||||
* (CompanyDefaultGuard 哨兵在喊)。
|
||||
*
|
||||
* <p>读侧仍按 {@code uploader_user_id} 认公司(见 DedupeTotalDataService.applyCompanyScope):
|
||||
* 历史行该列全部是 DEFAULT 兜的 1,对区分公司没有信息量。</p>
|
||||
*/
|
||||
private Long companyId;
|
||||
private String dataValue;
|
||||
private String country;
|
||||
private Long groupId;
|
||||
|
||||
+21
-11
@@ -468,6 +468,7 @@ public class DedupeTotalDataService {
|
||||
@Transactional
|
||||
public DedupeTotalDataItemVo create(DedupeTotalDataCreateRequest request, Long operatorId) {
|
||||
AdminUserEntity uploader = getOperator(operatorId);
|
||||
Long companyId = companyScopeSupport.requireCompanyId(uploader);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(request.getGroupId(), uploader);
|
||||
String dataValue = normalizeComparableValue(request.getDataValue());
|
||||
ensureUnique(dataValue, null);
|
||||
@@ -476,6 +477,7 @@ public class DedupeTotalDataService {
|
||||
entity.setGroupId(group.getId());
|
||||
entity.setUploaderUserId(uploader.getId());
|
||||
entity.setUploaderUsername(uploader.getUsername());
|
||||
entity.setCompanyId(companyId);
|
||||
dedupeTotalDataMapper.insert(entity);
|
||||
return toItemVo(getById(entity.getId()), group.getGroupName());
|
||||
}
|
||||
@@ -526,6 +528,7 @@ public class DedupeTotalDataService {
|
||||
throw new BusinessException("导入文件超过大小上限");
|
||||
}
|
||||
AdminUserEntity uploader = getOperator(operatorId);
|
||||
Long companyId = companyScopeSupport.requireCompanyId(uploader);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(groupId, uploader);
|
||||
if (!importSlots.tryAcquire()) {
|
||||
throw new BusinessException("导入任务过多,请稍后重试");
|
||||
@@ -546,7 +549,8 @@ public class DedupeTotalDataService {
|
||||
File tempFile = saveMultipartToTempFile(file);
|
||||
String filename = file.getOriginalFilename();
|
||||
Thread.ofVirtual().start(() -> runImportTask(
|
||||
importId, tempFile, filename, uploader.getId(), uploader.getUsername(), group.getId()));
|
||||
importId, tempFile, filename, uploader.getId(), uploader.getUsername(), group.getId(),
|
||||
companyId));
|
||||
} catch (Exception e) {
|
||||
importSlots.release();
|
||||
importProgressMap.remove(importId);
|
||||
@@ -660,7 +664,7 @@ public class DedupeTotalDataService {
|
||||
}
|
||||
|
||||
private void runImportTask(String importId, File tempFile, String filename,
|
||||
Long uploaderUserId, String uploaderUsername, Long groupId) {
|
||||
Long uploaderUserId, String uploaderUsername, Long groupId, Long companyId) {
|
||||
DedupeTotalDataImportProgressVo progress = importProgressMap.get(importId);
|
||||
if (progress == null) {
|
||||
importSlots.release();
|
||||
@@ -669,7 +673,7 @@ public class DedupeTotalDataService {
|
||||
progress.setStatus("running");
|
||||
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
|
||||
DedupeTotalDataImportVo result = importFromExcelInternal(
|
||||
inputStream, filename, progress, uploaderUserId, uploaderUsername, groupId);
|
||||
inputStream, filename, progress, uploaderUserId, uploaderUsername, groupId, companyId);
|
||||
progress.setTotalRows(result.getTotalRows());
|
||||
progress.setAsinCount(result.getAsinCount());
|
||||
progress.setInsertedCount(result.getInsertedCount());
|
||||
@@ -721,11 +725,12 @@ public class DedupeTotalDataService {
|
||||
throw new BusinessException("请上传 xlsx 文件");
|
||||
}
|
||||
AdminUserEntity uploader = getOperator(operatorId);
|
||||
Long companyId = companyScopeSupport.requireCompanyId(uploader);
|
||||
ShopManageGroupEntity group = resolveWritableGroup(groupId, uploader);
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
return importFromExcelInternal(
|
||||
inputStream, file.getOriginalFilename(), null, uploader.getId(), uploader.getUsername(),
|
||||
group.getId());
|
||||
group.getId(), companyId);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
@@ -759,7 +764,7 @@ public class DedupeTotalDataService {
|
||||
private DedupeTotalDataImportVo importFromExcelInternal(InputStream inputStream, String filename,
|
||||
DedupeTotalDataImportProgressVo progress,
|
||||
Long uploaderUserId, String uploaderUsername,
|
||||
Long groupId) {
|
||||
Long groupId, Long companyId) {
|
||||
String lowerFilename = filename == null ? "" : filename.toLowerCase();
|
||||
if (!(lowerFilename.endsWith(".xlsx") || lowerFilename.endsWith(".xls"))) {
|
||||
throw new BusinessException("仅支持 .xlsx 或 .xls 文件");
|
||||
@@ -769,7 +774,7 @@ public class DedupeTotalDataService {
|
||||
// 此前 WorkbookFactory.create 把整表读成 DOM(50 万行约 1~2GB 堆),且行数上限在
|
||||
// 加载完之后才校验(等于没有防线)。现在内存只保留单批待插入值与文件内去重集合,
|
||||
// 行数上限在迭代过程中即时生效。
|
||||
ImportSession session = new ImportSession(progress, groupId, uploaderUserId, uploaderUsername);
|
||||
ImportSession session = new ImportSession(progress, groupId, uploaderUserId, uploaderUsername, companyId);
|
||||
try {
|
||||
ExcelStreamReader.readFirstSheet(inputStream, new ExcelStreamReader.SheetRowHandler() {
|
||||
private Integer countryColumnIndex;
|
||||
@@ -845,6 +850,7 @@ public class DedupeTotalDataService {
|
||||
private final Long groupId;
|
||||
private final Long uploaderUserId;
|
||||
private final String uploaderUsername;
|
||||
private final Long companyId;
|
||||
private final Set<String> seenInFile = new HashSet<>();
|
||||
private final List<String> pendingValues = new ArrayList<>(IMPORT_BATCH_SIZE);
|
||||
private final Map<String, String> pendingCountries = new HashMap<>();
|
||||
@@ -855,11 +861,12 @@ public class DedupeTotalDataService {
|
||||
private int skippedCount;
|
||||
|
||||
private ImportSession(DedupeTotalDataImportProgressVo progress, Long groupId,
|
||||
Long uploaderUserId, String uploaderUsername) {
|
||||
Long uploaderUserId, String uploaderUsername, Long companyId) {
|
||||
this.progress = progress;
|
||||
this.groupId = groupId;
|
||||
this.uploaderUserId = uploaderUserId;
|
||||
this.uploaderUsername = uploaderUsername;
|
||||
this.companyId = companyId;
|
||||
}
|
||||
|
||||
private void acceptRow(Map<Integer, String> rowMap, Integer countryColumnIndex) {
|
||||
@@ -897,7 +904,7 @@ public class DedupeTotalDataService {
|
||||
return;
|
||||
}
|
||||
ImportBatchResult batch = insertImportBatch(
|
||||
pendingValues, pendingCountries, groupId, uploaderUserId, uploaderUsername);
|
||||
pendingValues, pendingCountries, groupId, uploaderUserId, uploaderUsername, companyId);
|
||||
insertedCount += batch.insertedCount();
|
||||
skippedCount += batch.skippedCount();
|
||||
pendingValues.clear();
|
||||
@@ -928,7 +935,8 @@ public class DedupeTotalDataService {
|
||||
Map<String, String> countriesByValue,
|
||||
Long groupId,
|
||||
Long uploaderUserId,
|
||||
String uploaderUsername) {
|
||||
String uploaderUsername,
|
||||
Long companyId) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
return new ImportBatchResult(0, 0);
|
||||
}
|
||||
@@ -944,6 +952,7 @@ public class DedupeTotalDataService {
|
||||
entity.setGroupId(groupId);
|
||||
entity.setUploaderUserId(uploaderUserId);
|
||||
entity.setUploaderUsername(uploaderUsername);
|
||||
entity.setCompanyId(companyId);
|
||||
rows.add(entity);
|
||||
}
|
||||
if (rows.isEmpty()) {
|
||||
@@ -1285,8 +1294,9 @@ public class DedupeTotalDataService {
|
||||
* 公司 tab 收窄:本表按「上传账号」认公司——{@code uploader_user_id} 是 NOT NULL(V75 先回灌再收紧),
|
||||
* 且有 idx_uploader_user_id_id 可走点查。
|
||||
*
|
||||
* <p>不读 V145 新加的 company_id:写入侧实体没有该字段、{@code insertBatchIgnore} 的列清单也不带,
|
||||
* 全靠 MySQL 的 DEFAULT 1 兜底,所以第 2 家账号新导入的行今天仍会被盖成公司 1。那一列不能当读侧依据。</p>
|
||||
* <p>不按 V145 加的 company_id 筛:那一列对 V145 之前的历史行全部是 DEFAULT 兜的 1,没有区分力。
|
||||
* 写侧现已显式落值(create 与 insertBatchIgnore 都带 company_id),但读侧一旦改用它,历史行会整批归到
|
||||
* 公司 1——所以那列只供写入留存与 uk_company_data_value 使用,读侧口径维持按上传账号推导。</p>
|
||||
*
|
||||
* <p>空集给一条不可能命中的条件而不是"不筛":tab 选了这家公司却看得到全平台,比看不到更坏。</p>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user