Commit ad77fc20 by chenxi

优加门店上架导入改动提交,新增草稿不会复用逻辑

1 parent c9922cd1
...@@ -314,7 +314,7 @@ public class StoreImportServiceImpl implements StoreImportService { ...@@ -314,7 +314,7 @@ public class StoreImportServiceImpl implements StoreImportService {
} }
/** /**
* 落库为草稿:按「门店 × 业务场景」拆分为多条记录。 * 落库为草稿:按「门店 × 业务场景」拆分为多条记录,每次导入都创建新记录。
* *
* <p>由 {@code TransactionTemplate} 调用,仅在全部校验通过后开启事务。</p> * <p>由 {@code TransactionTemplate} 调用,仅在全部校验通过后开启事务。</p>
*/ */
...@@ -329,23 +329,21 @@ public class StoreImportServiceImpl implements StoreImportService { ...@@ -329,23 +329,21 @@ public class StoreImportServiceImpl implements StoreImportService {
for (Map.Entry<String, List<StoreImportRowDTO>> entry : byScene.entrySet()) { for (Map.Entry<String, List<StoreImportRowDTO>> entry : byScene.entrySet()) {
String sceneCode = entry.getKey(); String sceneCode = entry.getKey();
List<StoreImportRowDTO> rows = entry.getValue(); List<StoreImportRowDTO> rows = entry.getValue();
StoreListing listing = saveOrUpdateDraft(sceneCode, rows, remark, level1RoleCode); StoreListing listing = insertDraft(sceneCode, rows, remark, level1RoleCode);
listingIds.add(listing.getListingId()); listingIds.add(listing.getListingId());
} }
return listingIds; return listingIds;
} }
private StoreListing saveOrUpdateDraft(String sceneCode, List<StoreImportRowDTO> rows, /**
* 落库为草稿:每次导入都创建<b>新记录</b>(不复用已有草稿的 ID、不覆盖旧数据)。
*
* <p>同一门店同一场景如果已有「待审批」记录则整单拦截;已有的旧草稿保持原样
* (DRAFT 为操作态、列表查询已排除,不会出现在列表里,但会留在库中)。</p>
*/
private StoreListing insertDraft(String sceneCode, List<StoreImportRowDTO> rows,
String remark, String level1RoleCode) { String remark, String level1RoleCode) {
StoreImportRowDTO first = rows.get(0); StoreImportRowDTO first = rows.get(0);
// ⚠️ 查询条件必须用 business_scene_code(编码列):business_scene 存的是文本,
// 拿编码去比文本永远不相等 → 永远查不到已有草稿 → 每次导入都插重复记录
StoreListing existing = storeListingMapper.selectOne(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getMerchantNo, first.getMerchantNo())
.eq(StoreListing::getBusinessSceneCode, sceneCode)
.eq(StoreListing::getStatus, StoreStatusEnum.DRAFT.getCode())
.last("limit 1"));
// 已有待审批记录 → 整表拦截 // 已有待审批记录 → 整表拦截
Long pendingCount = storeListingMapper.selectCount(new LambdaQueryWrapper<StoreListing>() Long pendingCount = storeListingMapper.selectCount(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getMerchantNo, first.getMerchantNo()) .eq(StoreListing::getMerchantNo, first.getMerchantNo())
...@@ -361,18 +359,12 @@ public class StoreImportServiceImpl implements StoreImportService { ...@@ -361,18 +359,12 @@ public class StoreImportServiceImpl implements StoreImportService {
BigDecimal monthly = nullToZero(first.getCostMonthly()); BigDecimal monthly = nullToZero(first.getCostMonthly());
BigDecimal labor = nullToZero(first.getCostLabor()); BigDecimal labor = nullToZero(first.getCostLabor());
StoreListing listing; StoreListing listing = new StoreListing();
if (existing != null) {
listing = existing;
listing.setVersion(existing.getVersion());
} else {
listing = new StoreListing();
listing.setMerchantNo(first.getMerchantNo()); listing.setMerchantNo(first.getMerchantNo());
listing.setStatus(StoreStatusEnum.DRAFT.getCode()); listing.setStatus(StoreStatusEnum.DRAFT.getCode());
listing.setIsEffective(CommonConstants.NO); listing.setIsEffective(CommonConstants.NO);
listing.setChangeCount(0); listing.setChangeCount(0);
listing.setVersion(0); listing.setVersion(0);
}
listing.setStoreName(first.getStoreName()); listing.setStoreName(first.getStoreName());
// 场景文本与编码分列存储:business_scene 出文本、business_scene_code 出编码 // 场景文本与编码分列存储:business_scene 出文本、business_scene_code 出编码
listing.setBusinessScene(first.getBusinessScene()); listing.setBusinessScene(first.getBusinessScene());
...@@ -393,13 +385,7 @@ public class StoreImportServiceImpl implements StoreImportService { ...@@ -393,13 +385,7 @@ public class StoreImportServiceImpl implements StoreImportService {
listing.setRemark(remark); listing.setRemark(remark);
listing.setRejectReason(null); listing.setRejectReason(null);
if (existing == null) {
storeListingMapper.insert(listing); storeListingMapper.insert(listing);
} else {
storeListingMapper.updateById(listing);
storeListingItemMapper.delete(new LambdaQueryWrapper<StoreListingItem>()
.eq(StoreListingItem::getListingId, listing.getListingId()));
}
for (StoreImportRowDTO row : rows) { for (StoreImportRowDTO row : rows) {
storeListingItemMapper.insert(toItem(listing.getListingId(), row)); storeListingItemMapper.insert(toItem(listing.getListingId(), row));
...@@ -457,7 +443,8 @@ public class StoreImportServiceImpl implements StoreImportService { ...@@ -457,7 +443,8 @@ public class StoreImportServiceImpl implements StoreImportService {
} }
/** /**
* 提交实际处理:草稿 → 待审批。已提交过的记录幂等跳过。 * 提交实际处理:草稿 → 待审批。已提交(待审批)或其它非草稿状态的记录直接抛异常,
* 不做幂等跳过;异常在事务内抛出,同批已处理的记录一并回滚。
* *
* <p>由 {@code TransactionTemplate} 调用,避免同类内部调用导致 {@code @Transactional} 失效。</p> * <p>由 {@code TransactionTemplate} 调用,避免同类内部调用导致 {@code @Transactional} 失效。</p>
*/ */
...@@ -470,9 +457,9 @@ public class StoreImportServiceImpl implements StoreImportService { ...@@ -470,9 +457,9 @@ public class StoreImportServiceImpl implements StoreImportService {
throw new BusinessException(ResultCode.STORE_LISTING_NOT_FOUND, "上架记录不存在:" + listingId); throw new BusinessException(ResultCode.STORE_LISTING_NOT_FOUND, "上架记录不存在:" + listingId);
} }
if (StoreStatusEnum.PENDING.getCode().equals(listing.getStatus())) { if (StoreStatusEnum.PENDING.getCode().equals(listing.getStatus())) {
// 幂等:已提交过则跳过 // 重复提交拦截:已提交(待审批)的记录不允许再次提交
submitted.add(listingId); throw new BusinessException(ResultCode.STORE_LISTING_STATUS_ILLEGAL,
continue; "上架记录[" + listingId + "]已提交审批,请勿重复提交");
} }
if (!StoreStatusEnum.DRAFT.getCode().equals(listing.getStatus())) { if (!StoreStatusEnum.DRAFT.getCode().equals(listing.getStatus())) {
throw new BusinessException(ResultCode.STORE_LISTING_STATUS_ILLEGAL, throw new BusinessException(ResultCode.STORE_LISTING_STATUS_ILLEGAL,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!