|
|
|
@ -14,6 +14,7 @@ import com.xujie.modules.sys.vo.PartSkuInitialImportSaveVo; |
|
|
|
import com.xujie.modules.sys.vo.SupplierPriceInitialImportPreviewResultVo; |
|
|
|
import com.xujie.modules.sys.vo.SupplierPriceInitialImportRowVo; |
|
|
|
import com.xujie.modules.sys.vo.SupplierPriceInitialImportSaveVo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.poi.ss.usermodel.BorderStyle; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
@ -58,6 +59,7 @@ import java.util.Locale; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
|
|
|
|
@ -264,6 +266,11 @@ public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
savedCount++; |
|
|
|
} |
|
|
|
} catch (RuntimeException ex) { |
|
|
|
// rqrq - 页面只返回简短提示;后台保留完整异常链及行号,避免 SQL 配置等问题被误判为 Excel 格式错误。 |
|
|
|
SupplierPriceInitialImportRowVo failedRow = data.getRows().get(index); |
|
|
|
log.error("供应商价格期初导入保存失败 - rqrq,site={},Excel行号={},Item={},供应商简称={}", |
|
|
|
site, index + 2, failedRow == null ? null : failedRow.getRawCode(), |
|
|
|
failedRow == null ? null : failedRow.getSupplier(), ex); |
|
|
|
throw new RuntimeException("Excel第" + (index + 2) + "行:" |
|
|
|
+ PoImportFieldLengthSupport.simplifySaveError(ex), ex); |
|
|
|
} |
|
|
|
@ -369,6 +376,10 @@ public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
} |
|
|
|
LocalDate newPriceDate = parseImportDate(row.getStartDate()); |
|
|
|
|
|
|
|
// 历史表没有“供应商 + 物料 + 价格日期”的唯一索引。先锁定本业务组合的历史范围, |
|
|
|
// 直到外层事务结束,避免并发导入同时判断不存在后产生同日重复快照。 |
|
|
|
initialImportMapper.lockSupplierPriceHistory(site, supplierNo, partNo); |
|
|
|
|
|
|
|
SupplierPartTierPriceQueryVo query = new SupplierPartTierPriceQueryVo(); |
|
|
|
query.setSite(site); |
|
|
|
query.setSupplierCode(supplierNo); |
|
|
|
@ -392,6 +403,9 @@ public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
submitBy, |
|
|
|
newTierPrices |
|
|
|
); |
|
|
|
// 首次导入、同日重导、换日导入都必须留下本次价格快照;价格日期取 START DATE, |
|
|
|
// 不取导入当天。历史主从表与当前价共用 saveSupplierPrice 的事务,失败整体回滚。 |
|
|
|
archiveCurrentTierPrice(site, supplierNo, partNo, submitBy, newPriceDate, newTierPrices); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -575,6 +589,13 @@ public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 写入价格日期对应的完整历史快照,供旧当前价归档和本次导入价快照共用。 |
|
|
|
* 覆盖范围严格限定为 site + supplier_code + part_no + price_date(自然日)。 |
|
|
|
* 先删除当天旧阶梯明细及主记录,再写入新主记录和完整档位,保证档位减少时无残留; |
|
|
|
* 没有同日记录时删除影响零行,直接新增。其他业务组合、其他日期不受影响。 |
|
|
|
* 调用方须已取得业务组合锁,且整个过程必须在外层导入事务中执行。 |
|
|
|
*/ |
|
|
|
private void archiveCurrentTierPrice(String site, |
|
|
|
String supplierNo, |
|
|
|
String partNo, |
|
|
|
@ -585,6 +606,11 @@ public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
String versionNo = generateInitialImportVersionNo(); |
|
|
|
String attachmentRefs = resolveAttachmentRefs(currentTierPrices); |
|
|
|
|
|
|
|
// rqrq - 每次 Mapper 调用只提交一条 SQL,兼容 Druid Wall 的多语句限制。 |
|
|
|
// 必须先删明细再删主记录:明细删除还需引用旧主记录 ID;任一步失败都由外层导入事务回滚。 |
|
|
|
initialImportMapper.deleteSupplierPriceHistoryDetailsByDate(site, supplierNo, partNo, priceDate.toString()); |
|
|
|
initialImportMapper.deleteSupplierPriceHistoryMainByDate(site, supplierNo, partNo, priceDate.toString()); |
|
|
|
|
|
|
|
SupplierPartTierPriceHistoryMainVo historyMain = new SupplierPartTierPriceHistoryMainVo(); |
|
|
|
historyMain.setSite(site); |
|
|
|
historyMain.setSupplierCode(supplierNo); |
|
|
|
@ -597,7 +623,7 @@ public class SysInitialImportServiceImpl implements SysInitialImportService { |
|
|
|
historyMain.setAttachmentRefs(attachmentRefs); |
|
|
|
supplierPartMoqPriceMapper.insertHistoryTierPriceMain(historyMain); |
|
|
|
if (historyMain.getId() == null) { |
|
|
|
throw new RuntimeException("当前价格归档失败"); |
|
|
|
throw new RuntimeException("价格历史快照保存失败"); |
|
|
|
} |
|
|
|
|
|
|
|
supplierPartMoqPriceMapper.insertHistoryTierPriceBatch( |
|
|
|
|