修改导入套餐

This commit is contained in:
wuweihua
2026-09-30 11:30:34 +08:00
parent ea23fb0e55
commit 998aac74c8
7 changed files with 132 additions and 114 deletions
@@ -78,6 +78,7 @@ price.set.import.fixedOnly=\u4ec5\u56fa\u5b9a\u4ef7\u5957\u9910\u652f\u6301\u5bf
price.set.import.noDetails=\u5957\u9910\u6682\u65e0\u4ef7\u683c\u660e\u7ec6\uff0c\u8bf7\u5148\u62c9\u53d6\u4ea7\u54c1\u4ef7
price.set.import.noPriceRows=\u4ef7\u8868\u672a\u89e3\u6790\u5230\u6709\u6548\u4ef7\u683c\u884c
price.set.import.success=\u5bfc\u5165\u5b8c\u6210\uff1a\u66f4\u65b0 {0} \u6761\uff0c\u672a\u5339\u914d {1} \u6761\uff0c\u5957\u9910\u65e0\u5bf9\u5e94\u4ea7\u54c1 {2} \u4e2a
price.set.import.noDetailWritten=\u672a\u5199\u5165\u4efb\u4f55\u5957\u9910\u660e\u7ec6\uff08\u4ef7\u8868\u65e0\u53ef\u7528\u91cd\u91cf\u6bb5\u6216\u5747\u4e3a\u7a7a\u8fd0\u8d39/\u6302\u53f7\u8d39\u4e14\u65e0\u53ef\u66f4\u65b0\u884c\uff09
price.set.import.upsertSuccess=\u5bfc\u5165\u5b8c\u6210\uff1a\u65b0\u589e {0} \u6761\uff0c\u66f4\u65b0 {1} \u6761\uff0c\u8df3\u8fc7\u7a7a\u8fd0\u8d39/\u6302\u53f7\u8d39 {2} \u6761
price.set.pull.success=\u62c9\u53d6\u5b8c\u6210\uff1a\u5df2\u5199\u5165 {0} \u6761\u5957\u9910\u660e\u7ec6
price.set.customer.notExists=客户绑定不存在
@@ -44,7 +44,7 @@ public class PrcPriceSet extends BaseEntity
private List<PrcCustomerPriceSet> customers;
/** async save task id (not persisted) */
private String saveTaskId;
/** Y: backend joins product library into details (skip front pull) */
/** Y: ignored on save; library pull only via /detail/pullFromLibrary */
private String pullFromLibrary;
/** Y: even if version already has details, delete+re-pull from library */
private String forcePullLibrary;
@@ -892,7 +892,8 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
set.setUpdateBy(operName);
set.setCreateBy(operName);
set.setSaveTaskId(taskId);
set.setPullFromLibrary("Y");
// Dedicated pull API — does not go through savePrcPriceSet.
set.setPullFromLibrary(null);
set.setForcePullLibrary(force ? "Y" : "N");
if (psvId == null)
{
@@ -1004,6 +1005,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
List<PrcPriceSetDetail> hits = matchImportDetails(candidates, row);
if (!hits.isEmpty())
{
// Existing band: only skip when Excel left both fees blank (keep old prices).
if (freight == null && registration == null)
{
skippedFee++;
@@ -1029,11 +1031,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
continue;
}
if (freight == null && registration == null)
{
skippedFee++;
continue;
}
// New band: always insert weight/country row (fees may be null; editable later).
PrcPriceSetDetail created = buildDetailFromImportRow(
priceSetId, psvId, productCode, productName, row, freight, registration);
created.setPspId(pspId);
@@ -1043,11 +1041,19 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
touched.add(created.getPsdId());
}
if (freight == null && registration == null)
{
skippedFee++;
}
inserted++;
}
}
setProductMapper.bindDetailPspByPsvId(psvId);
reportImportProgress(taskId, priceSetId, 95, "finishing");
if (inserted == 0 && updated == 0)
{
throw new ServiceException(MessageUtils.message("price.set.import.noDetailWritten"));
}
return MessageUtils.message("price.set.import.upsertSuccess",
Integer.valueOf(inserted), Integer.valueOf(updated), Integer.valueOf(skippedFee));
}
@@ -1086,16 +1092,16 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
PrcPriceSetDetail d = new PrcPriceSetDetail();
d.setPriceSetId(priceSetId);
d.setPsvId(psvId);
d.setProductCode(productCode);
d.setProductName(productName);
d.setProductCode(trimToLen(productCode, 20));
d.setProductName(trimToLen(productName, 50));
d.setCountryCode(row.getCountryCode());
d.setCountryName(row.getCountryName());
d.setCountryName(trimToLen(row.getCountryName(), 50));
d.setZoneId(row.getZoneId());
d.setZoneCode(row.getZoneCode());
d.setZoneName(row.getZoneName());
d.setZoneName(trimToLen(row.getZoneName(), 100));
d.setWeightMin(row.getWeightMin());
d.setWeightMax(row.getWeightMax());
d.setWeightLabel(formatWeightLabel(row.getWeightMin(), row.getWeightMax()));
d.setWeightLabel(trimToLen(formatWeightLabel(row.getWeightMin(), row.getWeightMax()), 50));
d.setProductCountryId(row.getDetailId());
d.setFvValue(freight);
d.setFvRegistrationFee(registration);
@@ -1105,6 +1111,20 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
return d;
}
private static String trimToLen(String s, int max)
{
if (s == null)
{
return null;
}
String t = s.trim();
if (t.length() <= max)
{
return t;
}
return t.substring(0, max);
}
private void reportImportProgress(String taskId, Long priceSetId, int percent, String message)
{
if (StringUtils.isEmpty(taskId) || saveAsyncRunner == null)
@@ -2136,12 +2156,12 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
private void saveOrUpdateVersion(PrcPriceSet set)
{
PrcPriceSetVersion version = resolveSaveVersion(set);
boolean pullLibrary = "Y".equalsIgnoreCase(set.getPullFromLibrary());
// null details = leave existing rows alone; empty list = clear / replace with nothing
// null details = leave existing rows alone; empty list = clear / replace with nothing.
// Library pull must NOT run here — only via pullFromLibrary() / Excel import on Step 2.
boolean detailsProvided = set.getDetails() != null;
List<PrcPriceSetDetail> details = filterDetails(set.getDetails());
// Allow creating an empty draft version when client sends version (Step1 -> Step2).
if (version == null && !detailsProvided && !pullLibrary)
if (version == null && !detailsProvided)
{
return;
}
@@ -2192,11 +2212,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
versionMapper.updatePrcPriceSetVersion(version);
}
set.setVersion(version);
if (pullLibrary)
{
replaceVersionDetailsFromLibrary(set, version);
}
else if (detailsProvided)
if (detailsProvided)
{
upsertVersionDetails(set, version, details);
reportSaveProgress(set, 85, "saving surcharges");
@@ -0,0 +1,3 @@
-- Widen prc_price_set_detail.product_code to match product / set_product (varchar 20).
ALTER TABLE prc_price_set_detail
MODIFY COLUMN product_code varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '产品代码';