增加专属报价功能
This commit is contained in:
@@ -15,12 +15,19 @@ public class PrcPriceSet extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** Ordinary package (default). */
|
||||
public static final String CATEGORY_PACKAGE = "PACKAGE";
|
||||
/** Boss exclusive quote. */
|
||||
public static final String CATEGORY_EXCLUSIVE = "EXCLUSIVE";
|
||||
|
||||
private Long priceSetId;
|
||||
private String priceSetCode;
|
||||
private String priceSetName;
|
||||
private String priceSetNote;
|
||||
/** FIXED / DISCOUNT */
|
||||
private String setType;
|
||||
/** PACKAGE=ordinary set / EXCLUSIVE=boss exclusive quote */
|
||||
private String setCategory;
|
||||
private BigDecimal defaultDiscount;
|
||||
private String defaultType;
|
||||
private String calculateSign;
|
||||
|
||||
@@ -59,10 +59,6 @@ public interface IBmsProductService
|
||||
|
||||
public java.util.Map<String, List<BmsProductCountry>> parseQuoteExcelByProduct(byte[] bytes, String filename) throws Exception;
|
||||
|
||||
/**
|
||||
* Parse single-country dedicated-line quote Excel (same format as product country import).
|
||||
* All weight rows are stamped with the selected country. Keys are upper-case product codes.
|
||||
*/
|
||||
public java.util.Map<String, List<BmsProductCountry>> parseCountryQuoteExcelByProduct(byte[] bytes, String filename,
|
||||
String countryCode) throws Exception;
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ public interface IPrcPriceSetService
|
||||
|
||||
public List<PrcPriceSet> selectPrcPriceSetList(PrcPriceSet set);
|
||||
|
||||
/** Fail if the package is not in the expected category (PACKAGE / EXCLUSIVE). */
|
||||
public void assertSetCategory(Long priceSetId, String expectedCategory);
|
||||
|
||||
public Long savePrcPriceSet(PrcPriceSet set);
|
||||
|
||||
public int updatePrcPriceSet(PrcPriceSet set);
|
||||
@@ -149,6 +152,13 @@ public interface IPrcPriceSetService
|
||||
boolean updateOnly, List<PrcPriceSetDetail> existingDetails, boolean replaceByProductCountry, String countryCode)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* @param exclusiveTemplate true = HALARA large-customer exclusive quote Excel (destination / handling fee)
|
||||
*/
|
||||
public Map<String, Object> previewImportDetailPricesMany(List<byte[]> bytesList, List<String> names,
|
||||
boolean updateOnly, List<PrcPriceSetDetail> existingDetails, boolean replaceByProductCountry, String countryCode,
|
||||
boolean exclusiveTemplate) throws Exception;
|
||||
|
||||
/**
|
||||
* Sync worker: parse bytes and upsert FIXED detail prices matched by
|
||||
* product + country + zone(if any) + weight band (insert when missing unless updateOnly).
|
||||
|
||||
+11
-9
@@ -2574,7 +2574,7 @@ public class BmsProductServiceImpl implements IBmsProductService
|
||||
|
||||
Date sheetEffective = parseSheetEffectiveDate(sheet);
|
||||
List<BmsProductCountry> list = new ArrayList<>();
|
||||
int[] countryHeader = findHeaderCell(sheet, "国家");
|
||||
int[] countryHeader = findHeaderCell(sheet, "\u56fd\u5bb6");
|
||||
if (countryHeader == null)
|
||||
{
|
||||
return list;
|
||||
@@ -2582,12 +2582,12 @@ public class BmsProductServiceImpl implements IBmsProductService
|
||||
int headerRowIdx = countryHeader[0];
|
||||
Row headerRow = sheet.getRow(headerRowIdx);
|
||||
int colCountry = countryHeader[1];
|
||||
int colWeight = findColByHeader(headerRow, "重量", colCountry + 1);
|
||||
int colFreight = findColByHeader(headerRow, "运费", colCountry + 1);
|
||||
int colRegister = findColByHeader(headerRow, "挂号", colCountry + 1);
|
||||
int colSize = findColByHeader(headerRow, "尺寸", colCountry + 1);
|
||||
int colLastMile = findColByHeader(headerRow, "尾程", colCountry + 1);
|
||||
int colLeadTime = findColByHeader(headerRow, "时效", colCountry + 1);
|
||||
int colWeight = findColByHeader(headerRow, "\u91cd\u91cf", colCountry + 1);
|
||||
int colFreight = findColByHeader(headerRow, "\u8fd0\u8d39", colCountry + 1);
|
||||
int colRegister = findColByHeader(headerRow, "\u6302\u53f7", colCountry + 1);
|
||||
int colSize = findColByHeader(headerRow, "\u5c3a\u5bf8", colCountry + 1);
|
||||
int colLastMile = findColByHeader(headerRow, "\u5c3e\u7a0b", colCountry + 1);
|
||||
int colLeadTime = findColByHeader(headerRow, "\u65f6\u6548", colCountry + 1);
|
||||
if (colWeight < 0)
|
||||
{
|
||||
colWeight = colCountry + 1;
|
||||
@@ -2627,7 +2627,8 @@ public class BmsProductServiceImpl implements IBmsProductService
|
||||
}
|
||||
String countryCell = cellString(row.getCell(colCountry));
|
||||
String weightLabel = cellString(row.getCell(colWeight));
|
||||
if ("国家".equals(countryCell) || weightLabel.contains("重量段"))
|
||||
if ("\u56fd\u5bb6".equals(countryCell)
|
||||
|| (weightLabel != null && weightLabel.contains("\u91cd\u91cf\u6bb5")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -2847,7 +2848,8 @@ public class BmsProductServiceImpl implements IBmsProductService
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Matcher m = WEIGHT_RANGE_PATTERN.matcher(label.replace(" ", ""));
|
||||
String compact = label.replace(" ", "").replace("\u3000", "");
|
||||
Matcher m = WEIGHT_RANGE_PATTERN.matcher(compact);
|
||||
if (!m.find())
|
||||
{
|
||||
return null;
|
||||
|
||||
+91
-4
@@ -47,6 +47,7 @@ import com.bms.price.mapper.PrcPriceSetVersionMapper;
|
||||
import com.bms.price.mapper.PrcSurchargeMapper;
|
||||
import com.bms.price.mapper.PrcSurchargeRelMapper;
|
||||
import com.bms.price.service.IBmsProductService;
|
||||
import com.bms.price.service.support.ExclusiveHalaraQuoteExcelParser;
|
||||
import com.bms.price.search.IBillSearchStore;
|
||||
import com.bms.price.search.PriceChangeEsLog;
|
||||
import com.bms.price.service.IPrcPriceExcelFileService;
|
||||
@@ -68,6 +69,8 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
private static final String STATUS_REJECT = "R";
|
||||
private static final String STATUS_STOP = "S";
|
||||
private static final String TYPE_FIXED = "FIXED";
|
||||
private static final String CATEGORY_PACKAGE = PrcPriceSet.CATEGORY_PACKAGE;
|
||||
private static final String CATEGORY_EXCLUSIVE = PrcPriceSet.CATEGORY_EXCLUSIVE;
|
||||
private static final String TYPE_DISCOUNT = "DISCOUNT";
|
||||
private static final String VER_DRAFT = "0";
|
||||
private static final String VER_EFFECT = "1";
|
||||
@@ -114,6 +117,9 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
@Autowired
|
||||
private IBmsProductService productService;
|
||||
|
||||
@Autowired
|
||||
private ExclusiveHalaraQuoteExcelParser exclusiveHalaraQuoteExcelParser;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private PrcPriceSetSaveAsyncRunner saveAsyncRunner;
|
||||
@@ -228,10 +234,11 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
{
|
||||
set.setSetType(TYPE_FIXED);
|
||||
}
|
||||
set.setSetCategory(normalizeSetCategory(set.getSetCategory()));
|
||||
setMapper.insertPrcPriceSet(set);
|
||||
if (StringUtils.isEmpty(set.getPriceSetCode()))
|
||||
{
|
||||
set.setPriceSetCode(String.format("SET%04d", set.getPriceSetId()));
|
||||
set.setPriceSetCode(buildPriceSetCode(set.getSetCategory(), set.getPriceSetId()));
|
||||
setMapper.updatePrcPriceSet(set);
|
||||
}
|
||||
}
|
||||
@@ -240,6 +247,8 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
PrcPriceSet db = requireSet(set.getPriceSetId());
|
||||
assertBasicEditable(db);
|
||||
set.setStatus(db.getStatus());
|
||||
// Category is immutable after create; keep DB value for name uniqueness scope.
|
||||
set.setSetCategory(normalizeSetCategory(db.getSetCategory()));
|
||||
setMapper.updatePrcPriceSet(set);
|
||||
}
|
||||
reportSaveProgress(set, 20, "saving version");
|
||||
@@ -275,6 +284,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
throw new ServiceException(MessageUtils.message("price.set.name.empty"));
|
||||
}
|
||||
set.setPriceSetName(set.getPriceSetName().trim());
|
||||
set.setSetCategory(normalizeSetCategory(db.getSetCategory()));
|
||||
if (setMapper.countByName(set) > 0)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.name.exists"));
|
||||
@@ -641,6 +651,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
copy.setPriceSetName(src.getPriceSetName() + "-副本");
|
||||
copy.setPriceSetNote(src.getPriceSetNote());
|
||||
copy.setSetType(src.getSetType());
|
||||
copy.setSetCategory(normalizeSetCategory(src.getSetCategory()));
|
||||
copy.setDefaultDiscount(src.getDefaultDiscount());
|
||||
copy.setDefaultType(src.getDefaultType());
|
||||
copy.setCalculateSign(src.getCalculateSign());
|
||||
@@ -731,8 +742,13 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
{
|
||||
set.setCustomers(db.getCustomers());
|
||||
}
|
||||
if (StringUtils.isEmpty(set.getSetCategory()))
|
||||
{
|
||||
set.setSetCategory(db.getSetCategory());
|
||||
}
|
||||
}
|
||||
}
|
||||
set.setSetCategory(normalizeSetCategory(set.getSetCategory()));
|
||||
|
||||
int nameCount = setMapper.countByName(set);
|
||||
if (StringUtils.isEmpty(set.getPriceSetName()))
|
||||
@@ -1201,9 +1217,18 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
@Override
|
||||
public Map<String, Object> previewImportDetailPrices(byte[] bytes, String filename, boolean updateOnly,
|
||||
List<PrcPriceSetDetail> existingDetails, boolean replaceByProductCountry, String countryCode) throws Exception
|
||||
{
|
||||
return previewImportDetailPrices(bytes, filename, updateOnly, existingDetails, replaceByProductCountry,
|
||||
countryCode, false);
|
||||
}
|
||||
|
||||
public Map<String, Object> previewImportDetailPrices(byte[] bytes, String filename, boolean updateOnly,
|
||||
List<PrcPriceSetDetail> existingDetails, boolean replaceByProductCountry, String countryCode,
|
||||
boolean exclusiveTemplate) throws Exception
|
||||
{
|
||||
boolean replaceScope = replaceByProductCountry || StringUtils.isNotEmpty(countryCode);
|
||||
Map<String, List<BmsProductCountry>> byProduct = parseSetImportExcel(bytes, filename, countryCode);
|
||||
Map<String, List<BmsProductCountry>> byProduct = parseSetImportExcel(bytes, filename, countryCode,
|
||||
exclusiveTemplate);
|
||||
if (byProduct == null || byProduct.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.import.noPriceRows"));
|
||||
@@ -1391,6 +1416,14 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
public Map<String, Object> previewImportDetailPricesMany(List<byte[]> bytesList, List<String> names,
|
||||
boolean updateOnly, List<PrcPriceSetDetail> existingDetails, boolean replaceByProductCountry, String countryCode)
|
||||
throws Exception
|
||||
{
|
||||
return previewImportDetailPricesMany(bytesList, names, updateOnly, existingDetails, replaceByProductCountry,
|
||||
countryCode, false);
|
||||
}
|
||||
|
||||
public Map<String, Object> previewImportDetailPricesMany(List<byte[]> bytesList, List<String> names,
|
||||
boolean updateOnly, List<PrcPriceSetDetail> existingDetails, boolean replaceByProductCountry, String countryCode,
|
||||
boolean exclusiveTemplate) throws Exception
|
||||
{
|
||||
if (bytesList == null || bytesList.isEmpty())
|
||||
{
|
||||
@@ -1407,7 +1440,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
{
|
||||
String filename = names != null && i < names.size() ? names.get(i) : null;
|
||||
last = previewImportDetailPrices(bytesList.get(i), filename, updateOnly, existing, replaceByProductCountry,
|
||||
countryCode);
|
||||
countryCode, exclusiveTemplate);
|
||||
Object details = last == null ? null : last.get("details");
|
||||
if (details instanceof List)
|
||||
{
|
||||
@@ -1429,6 +1462,21 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
private Map<String, List<BmsProductCountry>> parseSetImportExcel(byte[] bytes, String filename, String countryCode)
|
||||
throws Exception
|
||||
{
|
||||
return parseSetImportExcel(bytes, filename, countryCode, false);
|
||||
}
|
||||
|
||||
private Map<String, List<BmsProductCountry>> parseSetImportExcel(byte[] bytes, String filename, String countryCode,
|
||||
boolean exclusiveTemplate) throws Exception
|
||||
{
|
||||
if (exclusiveTemplate)
|
||||
{
|
||||
if (StringUtils.isNotEmpty(countryCode))
|
||||
{
|
||||
throw new ServiceException(
|
||||
"\u4e13\u5c5e\u62a5\u4ef7\u4e0d\u652f\u6301\u5355\u56fd\u5bfc\u5165\uff0c\u8bf7\u4e0a\u4f20\u5b8c\u6574\u5927\u5ba2\u6298\u6263\u62a5\u4ef7\u8868");
|
||||
}
|
||||
return exclusiveHalaraQuoteExcelParser.parse(bytes, filename);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(countryCode))
|
||||
{
|
||||
return productService.parseCountryQuoteExcelByProduct(bytes, filename, countryCode);
|
||||
@@ -1551,7 +1599,9 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
}
|
||||
reportImportProgress(taskId, priceSetId, 20, "parsing excel");
|
||||
boolean replaceScope = replaceByProductCountry || StringUtils.isNotEmpty(countryCode);
|
||||
Map<String, List<BmsProductCountry>> byProduct = parseSetImportExcel(bytes, filename, countryCode);
|
||||
boolean exclusiveTemplate = CATEGORY_EXCLUSIVE.equals(normalizeSetCategory(db.getSetCategory()));
|
||||
Map<String, List<BmsProductCountry>> byProduct = parseSetImportExcel(bytes, filename, countryCode,
|
||||
exclusiveTemplate);
|
||||
if (byProduct == null || byProduct.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.import.noPriceRows"));
|
||||
@@ -2746,6 +2796,15 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
throw new ServiceException(MessageUtils.message("price.set.discount.range"));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(set.getSetCategory()) && set.getPriceSetId() != null)
|
||||
{
|
||||
PrcPriceSet db = setMapper.selectPrcPriceSetHeaderById(set.getPriceSetId());
|
||||
if (db != null)
|
||||
{
|
||||
set.setSetCategory(db.getSetCategory());
|
||||
}
|
||||
}
|
||||
set.setSetCategory(normalizeSetCategory(set.getSetCategory()));
|
||||
if (setMapper.countByName(set) > 0)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.name.exists"));
|
||||
@@ -2756,6 +2815,34 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
|
||||
}
|
||||
}
|
||||
|
||||
/** PACKAGE (default) or EXCLUSIVE. */
|
||||
public static String normalizeSetCategory(String setCategory)
|
||||
{
|
||||
if (CATEGORY_EXCLUSIVE.equalsIgnoreCase(StringUtils.trim(setCategory)))
|
||||
{
|
||||
return CATEGORY_EXCLUSIVE;
|
||||
}
|
||||
return CATEGORY_PACKAGE;
|
||||
}
|
||||
|
||||
private static String buildPriceSetCode(String setCategory, Long priceSetId)
|
||||
{
|
||||
String prefix = CATEGORY_EXCLUSIVE.equals(normalizeSetCategory(setCategory)) ? "EXC" : "SET";
|
||||
return String.format("%s%04d", prefix, priceSetId);
|
||||
}
|
||||
|
||||
/** Ensure the package belongs to the expected module category. */
|
||||
public void assertSetCategory(Long priceSetId, String expectedCategory)
|
||||
{
|
||||
PrcPriceSet db = requireSet(priceSetId);
|
||||
String actual = normalizeSetCategory(db.getSetCategory());
|
||||
String expect = normalizeSetCategory(expectedCategory);
|
||||
if (!expect.equals(actual))
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.set.notExists"));
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDetail(PrcPriceSet set, PrcPriceSetDetail detail)
|
||||
{
|
||||
if (StringUtils.isEmpty(detail.getProductCode()))
|
||||
|
||||
+913
@@ -0,0 +1,913 @@
|
||||
package com.bms.price.service.support;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.bms.common.exception.ServiceException;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.price.domain.BmsProduct;
|
||||
import com.bms.price.domain.BmsProductCountry;
|
||||
import com.bms.price.domain.PrcZone;
|
||||
import com.bms.price.mapper.PrcZoneMapper;
|
||||
import com.bms.price.util.ZoneCodeAbbrevs;
|
||||
import com.bms.system.domain.BmsRegion;
|
||||
import com.bms.system.mapper.BmsRegionMapper;
|
||||
|
||||
/**
|
||||
* Exclusive / large-customer (HALARA) quote Excel parser.
|
||||
* Completely separate from ordinary package / product quote Excel parsing.
|
||||
*
|
||||
* Catalog columns: category / country / level / product name / price sheet / product code / feature / lead time.
|
||||
* Price sheets: destination / origin / weight / freight(CNY/KG) / handling(CNY/PCS).
|
||||
*/
|
||||
@Component
|
||||
public class ExclusiveHalaraQuoteExcelParser
|
||||
{
|
||||
private static final String CATALOG_SHEET = "\u4ea7\u54c1\u76ee\u5f55";
|
||||
|
||||
/** Parse 0.01<=W<=0.5 / 0.3<W<=1 */
|
||||
private static final Pattern WEIGHT_W_PATTERN = Pattern.compile(
|
||||
"(\\d+(?:\\.\\d+)?)\\s*[<\u2264]=?\\s*W\\s*[<\u2264]=?\\s*(\\d+(?:\\.\\d+)?)",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/** Parse HALARA bands: 0-0.3kg / 0kg-1kg / 1.01kg-2kg */
|
||||
private static final Pattern WEIGHT_DASH_PATTERN = Pattern.compile(
|
||||
"(?i)(\\d+(?:\\.\\d+)?)\\s*(?:kg)?\\s*[-~\uFF5E\u2014\u2013]\\s*(\\d+(?:\\.\\d+)?)\\s*(?:kg)?");
|
||||
|
||||
@Autowired
|
||||
private BmsRegionMapper regionMapper;
|
||||
|
||||
@Autowired
|
||||
private PrcZoneMapper zoneMapper;
|
||||
|
||||
public Map<String, List<BmsProductCountry>> parse(byte[] bytes, String filename) throws Exception
|
||||
{
|
||||
if (bytes == null || bytes.length == 0)
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u5bfc\u5165\u6587\u4ef6\u4e3a\u7a7a");
|
||||
}
|
||||
if (filename == null || !(filename.toLowerCase(Locale.ROOT).endsWith(".xlsx")
|
||||
|| filename.toLowerCase(Locale.ROOT).endsWith(".xls")))
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u4ec5\u652f\u6301 .xls / .xlsx");
|
||||
}
|
||||
try (InputStream is = new ByteArrayInputStream(bytes); Workbook workbook = WorkbookFactory.create(is))
|
||||
{
|
||||
assertHalaraFormat(workbook);
|
||||
Sheet catalog = workbook.getSheet(CATALOG_SHEET);
|
||||
if (catalog == null)
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u7f3a\u5c11\u300c\u4ea7\u54c1\u76ee\u5f55\u300d");
|
||||
}
|
||||
List<BmsProduct> products = dedupeByCode(parseCatalog(catalog));
|
||||
if (products.isEmpty())
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u4ea7\u54c1\u76ee\u5f55\u65e0\u6709\u6548\u4ea7\u54c1");
|
||||
}
|
||||
|
||||
Map<String, List<BmsProduct>> ownersBySheet = new LinkedHashMap<String, List<BmsProduct>>();
|
||||
for (BmsProduct product : products)
|
||||
{
|
||||
if (product == null || StringUtils.isEmpty(product.getProductCode()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Sheet productSheet = findSheetForProduct(workbook, product);
|
||||
if (productSheet == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<BmsProduct> owners = ownersBySheet.get(productSheet.getSheetName());
|
||||
if (owners == null)
|
||||
{
|
||||
owners = new ArrayList<BmsProduct>();
|
||||
ownersBySheet.put(productSheet.getSheetName(), owners);
|
||||
}
|
||||
owners.add(product);
|
||||
}
|
||||
|
||||
Map<String, BmsRegion> regionByNameCn = loadRegionByNameCn();
|
||||
List<BmsRegion> euRegions = loadEuRegions(regionByNameCn);
|
||||
Map<String, PrcZone> zoneByCountryAndCode = loadZoneByCountryAndCode();
|
||||
Map<String, List<BmsProductCountry>> out = new LinkedHashMap<String, List<BmsProductCountry>>();
|
||||
List<String> dupTips = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++)
|
||||
{
|
||||
String sheetName = workbook.getSheetName(i);
|
||||
if (shouldSkipSheet(sheetName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Sheet sheet = workbook.getSheetAt(i);
|
||||
if (sheet == null || findHeaderCell(sheet, "\u76ee\u7684\u5730") == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<BmsProduct> owners = ownersBySheet.get(sheetName);
|
||||
if (owners == null || owners.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (BmsProduct owner : owners)
|
||||
{
|
||||
List<BmsProductCountry> rows = parsePriceSheet(sheet, owner, regionByNameCn, euRegions,
|
||||
zoneByCountryAndCode);
|
||||
String tip = dupCountryWeightTip(owner, rows);
|
||||
if (StringUtils.isNotEmpty(tip))
|
||||
{
|
||||
dupTips.add(tip);
|
||||
}
|
||||
if (rows == null || rows.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String key = owner.getProductCode().trim().toUpperCase(Locale.ROOT);
|
||||
List<BmsProductCountry> existing = out.get(key);
|
||||
if (existing == null)
|
||||
{
|
||||
out.put(key, new ArrayList<BmsProductCountry>(rows));
|
||||
}
|
||||
else
|
||||
{
|
||||
existing.addAll(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dupTips.isEmpty())
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u5b58\u5728\u91cd\u590d\u56fd\u5bb6+\u91cd\u91cf\u6bb5\uff1a<br/>" + String.join("<br/>", dupTips));
|
||||
}
|
||||
if (out.isEmpty())
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u672a\u89e3\u6790\u5230\u6709\u6548\u4ef7\u683c\u884c");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
private void assertHalaraFormat(Workbook workbook)
|
||||
{
|
||||
boolean hasDest = false;
|
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++)
|
||||
{
|
||||
String sheetName = workbook.getSheetName(i);
|
||||
if (shouldSkipSheet(sheetName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Sheet sheet = workbook.getSheetAt(i);
|
||||
if (sheet != null && findHeaderCell(sheet, "\u76ee\u7684\u5730") != null)
|
||||
{
|
||||
hasDest = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasDest)
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u4ec5\u652f\u6301\u5927\u5ba2\u6298\u6263\u62a5\u4ef7\u8868\uff08\u542b\u300c\u76ee\u7684\u5730\u300d\u300c\u8fd0\u8d39\u300d\u300c\u64cd\u4f5c\u8d39\u300d\u5217\uff09\uff0c\u8bf7\u52ff\u4f7f\u7528\u666e\u901a\u5957\u9910 Excel");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldSkipSheet(String name)
|
||||
{
|
||||
if (StringUtils.isEmpty(name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
String n = name.trim();
|
||||
if (CATALOG_SHEET.equals(n))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ("Sheet1".equalsIgnoreCase(n) || "Sheet2".equalsIgnoreCase(n))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (n.contains("\u90ae\u7f16") || n.contains("\u8d54\u507f") || n.contains("\u9000\u4ef6")
|
||||
|| n.contains("\u7533\u62a5"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return n.contains("\u7a0e\u7387") || n.toUpperCase(Locale.ROOT).contains("VAT");
|
||||
}
|
||||
|
||||
private List<BmsProduct> parseCatalog(Sheet sheet)
|
||||
{
|
||||
List<BmsProduct> list = new ArrayList<BmsProduct>();
|
||||
int[] header = findHeaderCell(sheet, "\u4ea7\u54c1\u4ee3\u7801");
|
||||
if (header == null)
|
||||
{
|
||||
header = findHeaderCell(sheet, "\u4ea7\u54c1\u540d\u79f0");
|
||||
}
|
||||
if (header == null)
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u300c\u4ea7\u54c1\u76ee\u5f55\u300d\u672a\u627e\u5230\u8868\u5934\u300c\u4ea7\u54c1\u4ee3\u7801\u300d/\u300c\u4ea7\u54c1\u540d\u79f0\u300d");
|
||||
}
|
||||
int headerRowIdx = header[0];
|
||||
Row head = sheet.getRow(headerRowIdx);
|
||||
int colCode = findColByHeader(head, "\u4ea7\u54c1\u4ee3\u7801", 0);
|
||||
int colName = findColByHeader(head, "\u4ea7\u54c1\u540d\u79f0", 0);
|
||||
int colLevel = findColByHeader(head, "\u7b49\u7ea7", 0);
|
||||
if (colLevel < 0)
|
||||
{
|
||||
colLevel = findColByHeader(head, "\u65f6\u6548", 0);
|
||||
}
|
||||
int colCargo = findColByHeader(head, "\u4ea7\u54c1\u7279\u6027", 0);
|
||||
if (colCargo < 0)
|
||||
{
|
||||
colCargo = findColByHeader(head, "\u8d70\u8d27\u5c5e\u6027", 0);
|
||||
}
|
||||
int colDest = findColByHeader(head, "\u56fd\u5bb6", 0);
|
||||
if (colDest < 0)
|
||||
{
|
||||
colDest = findColByHeader(head, "\u76ee\u7684", 0);
|
||||
}
|
||||
int colLead = findColByHeader(head, "\u53c2\u8003\u65f6\u6548", 0);
|
||||
if (colCode < 0 && colName < 0)
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u300c\u4ea7\u54c1\u76ee\u5f55\u300d\u7f3a\u5c11\u300c\u4ea7\u54c1\u4ee3\u7801\u300d/\u300c\u4ea7\u54c1\u540d\u79f0\u300d\u5217");
|
||||
}
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int i = headerRowIdx + 1; i <= lastRow; i++)
|
||||
{
|
||||
Row row = sheet.getRow(i);
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String rawCode = colCode >= 0 ? cellString(row.getCell(colCode)) : "";
|
||||
String name = colName >= 0 ? cellString(row.getCell(colName)) : "";
|
||||
if (StringUtils.isEmpty(rawCode) && StringUtils.isEmpty(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ("\u4ea7\u54c1\u4ee3\u7801".equals(rawCode) || "\u4ea7\u54c1\u540d\u79f0".equals(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String code = normalizeCode(rawCode);
|
||||
if (StringUtils.isEmpty(code))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BmsProduct p = new BmsProduct();
|
||||
p.setProductCode(code);
|
||||
p.setProductName(StringUtils.isNotEmpty(name) ? name : code);
|
||||
if (colLevel >= 0)
|
||||
{
|
||||
p.setServiceLevel(cellString(row.getCell(colLevel)));
|
||||
}
|
||||
if (colCargo >= 0)
|
||||
{
|
||||
p.setCargoAttr(cellString(row.getCell(colCargo)));
|
||||
}
|
||||
if (colDest >= 0)
|
||||
{
|
||||
p.setDestRegion(cellString(row.getCell(colDest)));
|
||||
}
|
||||
if (colLead >= 0)
|
||||
{
|
||||
p.setUpdateNote(cellString(row.getCell(colLead)));
|
||||
}
|
||||
list.add(p);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** Keep dots in codes such as GB.PEXP / DE.PEXP. */
|
||||
private static String normalizeCode(String raw)
|
||||
{
|
||||
if (StringUtils.isEmpty(raw))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String s = raw.trim().replaceAll("[\\(\\uFF08][^\\)\\uFF09]*[\\)\\uFF09]", "").trim();
|
||||
if (StringUtils.isEmpty(s))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Matcher m = Pattern.compile("(?i)^([A-Z0-9._-]+)").matcher(s);
|
||||
if (!m.find())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return m.group(1).toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private List<BmsProduct> dedupeByCode(List<BmsProduct> products)
|
||||
{
|
||||
Map<String, BmsProduct> map = new LinkedHashMap<String, BmsProduct>();
|
||||
for (BmsProduct p : products)
|
||||
{
|
||||
if (p == null || StringUtils.isEmpty(p.getProductCode()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String key = p.getProductCode().trim().toUpperCase(Locale.ROOT);
|
||||
if (!map.containsKey(key))
|
||||
{
|
||||
map.put(key, p);
|
||||
}
|
||||
}
|
||||
return new ArrayList<BmsProduct>(map.values());
|
||||
}
|
||||
|
||||
private Sheet findSheetForProduct(Workbook workbook, BmsProduct product)
|
||||
{
|
||||
if (workbook == null || product == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String wantName = product.getProductName();
|
||||
String wantCode = product.getProductCode();
|
||||
if (StringUtils.isNotEmpty(wantName))
|
||||
{
|
||||
Sheet exact = workbook.getSheet(wantName.trim());
|
||||
if (exact != null && !shouldSkipSheet(exact.getSheetName()))
|
||||
{
|
||||
return exact;
|
||||
}
|
||||
}
|
||||
String nameKey = normalizeKey(wantName);
|
||||
String codeKey = normalizeKey(wantCode);
|
||||
String nameBase = sheetNameBase(nameKey);
|
||||
Sheet best = null;
|
||||
int bestScore = 0;
|
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++)
|
||||
{
|
||||
String sheetName = workbook.getSheetName(i);
|
||||
if (shouldSkipSheet(sheetName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String key = normalizeKey(sheetName);
|
||||
if (StringUtils.isEmpty(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int score = 0;
|
||||
if (StringUtils.isNotEmpty(nameKey) && key.equals(nameKey))
|
||||
{
|
||||
return workbook.getSheetAt(i);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(nameKey) && key.contains(nameKey))
|
||||
{
|
||||
score = 100;
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(nameKey) && nameKey.contains(key) && key.length() >= 4)
|
||||
{
|
||||
score = 80;
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(nameBase) && sheetNameBase(key).equals(nameBase)
|
||||
&& nameBase.length() >= 2)
|
||||
{
|
||||
// e.g. catalog "DE express-general" -> sheet "DE express"
|
||||
score = 70;
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(codeKey) && key.contains(codeKey))
|
||||
{
|
||||
score = 60;
|
||||
}
|
||||
if (score > bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
best = workbook.getSheetAt(i);
|
||||
}
|
||||
}
|
||||
return bestScore >= 60 ? best : null;
|
||||
}
|
||||
|
||||
private static String normalizeKey(String s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
String out = s.trim().toLowerCase(Locale.ROOT);
|
||||
out = out.replace('\u2013', '-').replace('\u2014', '-').replace('\uFF0D', '-');
|
||||
out = out.replace(" ", "").replace("\u3000", "");
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String sheetNameBase(String normalizedKey)
|
||||
{
|
||||
if (StringUtils.isEmpty(normalizedKey))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
int idx = normalizedKey.lastIndexOf('-');
|
||||
if (idx <= 0)
|
||||
{
|
||||
return normalizedKey;
|
||||
}
|
||||
return normalizedKey.substring(0, idx);
|
||||
}
|
||||
|
||||
private List<BmsProductCountry> parsePriceSheet(Sheet sheet, BmsProduct product,
|
||||
Map<String, BmsRegion> regionByNameCn, List<BmsRegion> euRegions,
|
||||
Map<String, PrcZone> zoneByCountryAndCode)
|
||||
{
|
||||
List<BmsProductCountry> list = new ArrayList<BmsProductCountry>();
|
||||
if (sheet == null)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
int[] destHeader = findHeaderCell(sheet, "\u76ee\u7684\u5730");
|
||||
if (destHeader == null)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
int headerRowIdx = destHeader[0];
|
||||
Row headerRow = sheet.getRow(headerRowIdx);
|
||||
int colDest = destHeader[1];
|
||||
int colWeight = findColByHeader(headerRow, "\u91cd\u91cf", colDest + 1);
|
||||
int colFreight = findColByHeader(headerRow, "\u8fd0\u8d39", colDest + 1);
|
||||
int colHandle = findColByHeader(headerRow, "\u64cd\u4f5c\u8d39", colDest + 1);
|
||||
if (colHandle < 0)
|
||||
{
|
||||
colHandle = findColByHeader(headerRow, "\u6302\u53f7", colDest + 1);
|
||||
}
|
||||
int colLead = findColByHeader(headerRow, "\u65f6\u6548", colDest + 1);
|
||||
int colFeature = findColByHeader(headerRow, "\u4ea7\u54c1\u7279\u6027", colDest + 1);
|
||||
int colRemark = findColByHeader(headerRow, "\u5907\u6ce8", colDest + 1);
|
||||
if (colWeight < 0)
|
||||
{
|
||||
colWeight = colDest + 2;
|
||||
}
|
||||
if (colFreight < 0)
|
||||
{
|
||||
colFreight = colDest + 3;
|
||||
}
|
||||
if (colHandle < 0)
|
||||
{
|
||||
colHandle = colDest + 4;
|
||||
}
|
||||
|
||||
String currentDest = null;
|
||||
String currentLead = null;
|
||||
String currentRemark = null;
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int i = headerRowIdx + 1; i <= lastRow; i++)
|
||||
{
|
||||
Row row = sheet.getRow(i);
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String destCell = cellString(row.getCell(colDest));
|
||||
String weightLabel = cellString(row.getCell(colWeight));
|
||||
if ("\u76ee\u7684\u5730".equals(destCell) || (weightLabel != null && weightLabel.contains("\u91cd\u91cf\u6bb5")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(destCell))
|
||||
{
|
||||
currentDest = destCell;
|
||||
currentLead = colLead >= 0 ? emptyToNull(cellString(row.getCell(colLead))) : null;
|
||||
currentRemark = colRemark >= 0 ? emptyToNull(cellString(row.getCell(colRemark))) : null;
|
||||
}
|
||||
if (StringUtils.isEmpty(currentDest))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (currentDest.startsWith("\u4ea7\u54c1\u5b9a\u4e49") || currentDest.startsWith("\u4e00\u3001")
|
||||
|| currentDest.startsWith("\u4e8c\u3001") || currentDest.contains("\u670d\u52a1\u6761\u4ef6"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
BigDecimal[] range = parseWeightRange(weightLabel);
|
||||
if (range == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BigDecimal freight = cellDecimal(row.getCell(colFreight));
|
||||
BigDecimal handling = cellDecimal(row.getCell(colHandle));
|
||||
ZoneCodeAbbrevs.CountryZoneParts parts = ZoneCodeAbbrevs.splitCountryZone(currentDest);
|
||||
if (parts == null || StringUtils.isEmpty(parts.countryName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String baseCountry = parts.countryName;
|
||||
String zoneLabel = parts.zoneLabel;
|
||||
String feature = colFeature >= 0 ? emptyToNull(cellString(row.getCell(colFeature))) : null;
|
||||
String sizeOrRemark = feature != null ? feature : currentRemark;
|
||||
|
||||
BmsRegion region = resolveRegion(baseCountry, regionByNameCn);
|
||||
if (region != null)
|
||||
{
|
||||
list.add(buildRow(product, region.getCountryNameCn(), region.getCountryCode2(), zoneLabel,
|
||||
zoneByCountryAndCode, range, freight, handling, sizeOrRemark, currentRemark, currentLead));
|
||||
continue;
|
||||
}
|
||||
if (isEuName(baseCountry) && StringUtils.isEmpty(zoneLabel))
|
||||
{
|
||||
if (euRegions == null || euRegions.isEmpty())
|
||||
{
|
||||
throw new ServiceException("\u4e13\u5c5e\u62a5\u4ef7\u89e3\u6790\u5230\u300c\u6b27\u76df\u300d\u4f46\u533a\u57df\u5e93\u65e0\u6b27\u76df\u56fd\u5bb6");
|
||||
}
|
||||
for (BmsRegion eu : euRegions)
|
||||
{
|
||||
list.add(buildRow(product, eu.getCountryNameCn(), eu.getCountryCode2(), null,
|
||||
zoneByCountryAndCode, range, freight, handling, sizeOrRemark, currentRemark, currentLead));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
list.add(buildRow(product, baseCountry, null, zoneLabel, zoneByCountryAndCode, range, freight, handling,
|
||||
sizeOrRemark, currentRemark, currentLead));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private BmsProductCountry buildRow(BmsProduct product, String countryName, String countryCode, String zoneLabel,
|
||||
Map<String, PrcZone> zoneByCountryAndCode, BigDecimal[] range, BigDecimal freight, BigDecimal handling,
|
||||
String sizeLimit, String lastMile, String leadTime)
|
||||
{
|
||||
BmsProductCountry c = new BmsProductCountry();
|
||||
if (product != null)
|
||||
{
|
||||
c.setProductCode(product.getProductCode());
|
||||
c.setProductName(product.getProductName());
|
||||
}
|
||||
c.setCountryName(countryName);
|
||||
c.setCountryCode(countryCode);
|
||||
applyZone(c, countryCode, zoneLabel, zoneByCountryAndCode);
|
||||
c.setWeightMin(range[0]);
|
||||
c.setWeightMax(range[1]);
|
||||
c.setFreightPrice(freight);
|
||||
c.setRegistrationFee(handling);
|
||||
c.setSizeLimit(sizeLimit);
|
||||
c.setLastMile(lastMile);
|
||||
c.setLeadTime(leadTime);
|
||||
return c;
|
||||
}
|
||||
|
||||
private void applyZone(BmsProductCountry c, String countryCode, String zoneLabel,
|
||||
Map<String, PrcZone> zoneByCountryAndCode)
|
||||
{
|
||||
if (StringUtils.isEmpty(zoneLabel))
|
||||
{
|
||||
c.setZoneId(null);
|
||||
c.setZoneCode(null);
|
||||
c.setZoneName(null);
|
||||
return;
|
||||
}
|
||||
String zoneCode = ZoneCodeAbbrevs.toAbbrev(zoneLabel);
|
||||
c.setZoneCode(zoneCode);
|
||||
PrcZone zone = null;
|
||||
if (StringUtils.isNotEmpty(countryCode) && zoneByCountryAndCode != null)
|
||||
{
|
||||
zone = zoneByCountryAndCode.get(countryCode.trim().toUpperCase(Locale.ROOT) + "|"
|
||||
+ zoneCode.trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
if (zone != null)
|
||||
{
|
||||
c.setZoneId(zone.getZoneId());
|
||||
c.setZoneCode(zone.getZoneCode());
|
||||
c.setZoneName(zone.getZoneName());
|
||||
}
|
||||
else
|
||||
{
|
||||
c.setZoneId(null);
|
||||
c.setZoneName(StringUtils.isNotEmpty(c.getCountryName())
|
||||
? c.getCountryName() + "(" + zoneCode + ")"
|
||||
: zoneCode);
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal[] parseWeightRange(String label)
|
||||
{
|
||||
if (StringUtils.isEmpty(label))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String compact = label.replace(" ", "").replace("\u3000", "");
|
||||
Matcher m = WEIGHT_W_PATTERN.matcher(compact);
|
||||
if (!m.find())
|
||||
{
|
||||
m = WEIGHT_DASH_PATTERN.matcher(compact);
|
||||
if (!m.find())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
BigDecimal min = new BigDecimal(m.group(1));
|
||||
BigDecimal max = new BigDecimal(m.group(2));
|
||||
if (min.compareTo(max) > 0)
|
||||
{
|
||||
BigDecimal tmp = min;
|
||||
min = max;
|
||||
max = tmp;
|
||||
}
|
||||
return new BigDecimal[] { min, max };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String dupCountryWeightTip(BmsProduct product, List<BmsProductCountry> rows)
|
||||
{
|
||||
if (rows == null || rows.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Set<String> seen = new HashSet<String>();
|
||||
for (BmsProductCountry r : rows)
|
||||
{
|
||||
if (r == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String key = String.valueOf(r.getCountryCode()) + "|" + String.valueOf(r.getCountryName())
|
||||
+ "|" + String.valueOf(r.getZoneCode()) + "|"
|
||||
+ (r.getWeightMin() == null ? "" : r.getWeightMin().toPlainString()) + "-"
|
||||
+ (r.getWeightMax() == null ? "" : r.getWeightMax().toPlainString());
|
||||
if (!seen.add(key))
|
||||
{
|
||||
String name = product == null ? "" : product.getProductName();
|
||||
String code = product == null ? "" : product.getProductCode();
|
||||
return (StringUtils.isNotEmpty(name) ? name : code) + " \u91cd\u590d\u56fd\u5bb6+\u91cd\u91cf\u6bb5";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, BmsRegion> loadRegionByNameCn()
|
||||
{
|
||||
BmsRegion query = new BmsRegion();
|
||||
query.setStatus("0");
|
||||
List<BmsRegion> regions = regionMapper.selectRegionList(query);
|
||||
Map<String, BmsRegion> map = new HashMap<String, BmsRegion>();
|
||||
if (regions == null)
|
||||
{
|
||||
return map;
|
||||
}
|
||||
for (BmsRegion region : regions)
|
||||
{
|
||||
if (region == null || StringUtils.isEmpty(region.getCountryNameCn()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
map.put(region.getCountryNameCn().trim(), region);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private List<BmsRegion> loadEuRegions(Map<String, BmsRegion> regionByNameCn)
|
||||
{
|
||||
List<BmsRegion> list = new ArrayList<BmsRegion>();
|
||||
if (regionByNameCn == null)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
Set<String> seen = new HashSet<String>();
|
||||
for (BmsRegion region : regionByNameCn.values())
|
||||
{
|
||||
if (region == null || !"1".equals(region.getIsEu()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isEmpty(region.getCountryCode2()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String code = region.getCountryCode2().toUpperCase(Locale.ROOT);
|
||||
if (seen.add(code))
|
||||
{
|
||||
list.add(region);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Map<String, PrcZone> loadZoneByCountryAndCode()
|
||||
{
|
||||
Map<String, PrcZone> map = new HashMap<String, PrcZone>();
|
||||
List<PrcZone> list = zoneMapper.selectPrcZoneList(new PrcZone());
|
||||
if (list == null)
|
||||
{
|
||||
return map;
|
||||
}
|
||||
for (PrcZone zone : list)
|
||||
{
|
||||
if (zone == null || StringUtils.isEmpty(zone.getZoneCode()) || StringUtils.isEmpty(zone.getCountryCode()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
map.put(zone.getCountryCode().trim().toUpperCase(Locale.ROOT) + "|"
|
||||
+ zone.getZoneCode().trim().toUpperCase(Locale.ROOT), zone);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private BmsRegion resolveRegion(String excelName, Map<String, BmsRegion> regionByNameCn)
|
||||
{
|
||||
if (StringUtils.isEmpty(excelName) || regionByNameCn == null || regionByNameCn.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String name = excelName.trim();
|
||||
BmsRegion exact = regionByNameCn.get(name);
|
||||
if (exact != null)
|
||||
{
|
||||
return exact;
|
||||
}
|
||||
List<BmsRegion> candidates = new ArrayList<BmsRegion>();
|
||||
for (Map.Entry<String, BmsRegion> e : regionByNameCn.entrySet())
|
||||
{
|
||||
String cn = e.getKey();
|
||||
if (cn == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (cn.contains(name) || name.contains(cn))
|
||||
{
|
||||
candidates.add(e.getValue());
|
||||
}
|
||||
}
|
||||
if (candidates.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (candidates.size() == 1)
|
||||
{
|
||||
return candidates.get(0);
|
||||
}
|
||||
BmsRegion best = candidates.get(0);
|
||||
for (int i = 1; i < candidates.size(); i++)
|
||||
{
|
||||
String cn = candidates.get(i).getCountryNameCn();
|
||||
if (cn != null && cn.length() > best.getCountryNameCn().length())
|
||||
{
|
||||
best = candidates.get(i);
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static boolean isEuName(String name)
|
||||
{
|
||||
if (StringUtils.isEmpty(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String n = name.trim();
|
||||
return "\u6b27\u76df".equals(n) || "EU".equalsIgnoreCase(n) || "\u6b27\u6d32\u8054\u76df".equals(n)
|
||||
|| "\u6b27\u76df\u56fd\u5bb6".equals(n) || "\u4e1c\u6b27".equals(n);
|
||||
}
|
||||
|
||||
private static int[] findHeaderCell(Sheet sheet, String headerText)
|
||||
{
|
||||
if (sheet == null || StringUtils.isEmpty(headerText))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int lastRow = Math.min(sheet.getLastRowNum(), 30);
|
||||
int[] containsHit = null;
|
||||
for (int r = 0; r <= lastRow; r++)
|
||||
{
|
||||
Row row = sheet.getRow(r);
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int maxCol = Math.min(Math.max(row.getLastCellNum(), 12), 20);
|
||||
for (int c = 0; c < maxCol; c++)
|
||||
{
|
||||
String v = cellString(row.getCell(c));
|
||||
if (StringUtils.isEmpty(v))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (headerText.equals(v))
|
||||
{
|
||||
return new int[] { r, c };
|
||||
}
|
||||
if (containsHit == null && v.contains(headerText))
|
||||
{
|
||||
containsHit = new int[] { r, c };
|
||||
}
|
||||
}
|
||||
}
|
||||
return containsHit;
|
||||
}
|
||||
|
||||
private static int findColByHeader(Row headerRow, String keyword, int fromCol)
|
||||
{
|
||||
if (headerRow == null || StringUtils.isEmpty(keyword))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int maxCol = Math.min(Math.max(headerRow.getLastCellNum(), fromCol + 8), 20);
|
||||
for (int c = Math.max(fromCol, 0); c < maxCol; c++)
|
||||
{
|
||||
String v = cellString(headerRow.getCell(c));
|
||||
if (StringUtils.isNotEmpty(v) && v.contains(keyword))
|
||||
{
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static String cellString(Cell cell)
|
||||
{
|
||||
if (cell == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
CellType type = cell.getCellType();
|
||||
if (type == CellType.FORMULA)
|
||||
{
|
||||
type = cell.getCachedFormulaResultType();
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case STRING:
|
||||
return cell.getStringCellValue() == null ? "" : cell.getStringCellValue().trim();
|
||||
case NUMERIC:
|
||||
if (DateUtil.isCellDateFormatted(cell))
|
||||
{
|
||||
Date d = cell.getDateCellValue();
|
||||
return d == null ? "" : new SimpleDateFormat("yyyy-MM-dd").format(d);
|
||||
}
|
||||
double num = cell.getNumericCellValue();
|
||||
if (Math.floor(num) == num)
|
||||
{
|
||||
return String.valueOf((long) num);
|
||||
}
|
||||
return String.valueOf(num);
|
||||
case BOOLEAN:
|
||||
return String.valueOf(cell.getBooleanCellValue());
|
||||
case BLANK:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static BigDecimal cellDecimal(Cell cell)
|
||||
{
|
||||
if (cell == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CellType type = cell.getCellType();
|
||||
if (type == CellType.FORMULA)
|
||||
{
|
||||
type = cell.getCachedFormulaResultType();
|
||||
}
|
||||
try
|
||||
{
|
||||
if (type == CellType.NUMERIC)
|
||||
{
|
||||
return BigDecimal.valueOf(cell.getNumericCellValue());
|
||||
}
|
||||
String s = cellString(cell);
|
||||
if (StringUtils.isEmpty(s))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
s = s.replace(",", "").replace("\uFFE5", "").replace("CNY", "").trim();
|
||||
if (StringUtils.isEmpty(s))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new BigDecimal(s);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String emptyToNull(String s)
|
||||
{
|
||||
return StringUtils.isEmpty(s) ? null : s;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="priceSetName" column="price_set_name" />
|
||||
<result property="priceSetNote" column="price_set_note" />
|
||||
<result property="setType" column="set_type" />
|
||||
<result property="setCategory" column="set_category" />
|
||||
<result property="defaultDiscount" column="default_discount" />
|
||||
<result property="defaultType" column="default_type" />
|
||||
<result property="calculateSign" column="calculate_sign" />
|
||||
@@ -26,7 +27,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<sql id="selectPrcPriceSetVo">
|
||||
select s.price_set_id, s.price_set_code, s.price_set_name, s.price_set_note,
|
||||
s.set_type, s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.set_type, ifnull(s.set_category, 'PACKAGE') as set_category,
|
||||
s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.status, s.tms_id,
|
||||
s.created_by, s.create_time, s.updated_by, s.update_time,
|
||||
(select count(distinct p.product_code)
|
||||
@@ -52,7 +54,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectPrcPriceSetHeaderById" parameterType="Long" resultMap="PrcPriceSetResult">
|
||||
select s.price_set_id, s.price_set_code, s.price_set_name, s.price_set_note,
|
||||
s.set_type, s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.set_type, ifnull(s.set_category, 'PACKAGE') as set_category,
|
||||
s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.status, s.tms_id,
|
||||
s.created_by, s.create_time, s.updated_by, s.update_time,
|
||||
null as product_count, null as customer_count, null as bound_customers
|
||||
@@ -66,6 +69,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="setType != null and setType != ''">
|
||||
AND s.set_type = #{setType}
|
||||
</if>
|
||||
<if test="setCategory != null and setCategory != ''">
|
||||
AND ifnull(s.set_category, 'PACKAGE') = #{setCategory}
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND s.status = #{status}
|
||||
</if>
|
||||
@@ -126,6 +132,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tmsId != null">
|
||||
AND tms_id = #{tmsId}
|
||||
</if>
|
||||
<if test="setCategory != null and setCategory != ''">
|
||||
AND ifnull(set_category, 'PACKAGE') = #{setCategory}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<insert id="insertPrcPriceSet" parameterType="PrcPriceSet" useGeneratedKeys="true" keyProperty="priceSetId">
|
||||
@@ -134,6 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="priceSetName != null and priceSetName != ''">price_set_name,</if>
|
||||
<if test="priceSetNote != null">price_set_note,</if>
|
||||
<if test="setType != null and setType != ''">set_type,</if>
|
||||
<if test="setCategory != null and setCategory != ''">set_category,</if>
|
||||
<if test="defaultDiscount != null">default_discount,</if>
|
||||
<if test="defaultType != null">default_type,</if>
|
||||
<if test="calculateSign != null">calculate_sign,</if>
|
||||
@@ -146,6 +156,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="priceSetName != null and priceSetName != ''">#{priceSetName},</if>
|
||||
<if test="priceSetNote != null">#{priceSetNote},</if>
|
||||
<if test="setType != null and setType != ''">#{setType},</if>
|
||||
<if test="setCategory != null and setCategory != ''">#{setCategory},</if>
|
||||
<if test="defaultDiscount != null">#{defaultDiscount},</if>
|
||||
<if test="defaultType != null">#{defaultType},</if>
|
||||
<if test="calculateSign != null">#{calculateSign},</if>
|
||||
@@ -163,6 +174,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="priceSetName != null and priceSetName != ''">price_set_name = #{priceSetName},</if>
|
||||
<if test="priceSetNote != null">price_set_note = #{priceSetNote},</if>
|
||||
<if test="setType != null and setType != ''">set_type = #{setType},</if>
|
||||
<if test="setCategory != null and setCategory != ''">set_category = #{setCategory},</if>
|
||||
default_discount = #{defaultDiscount},
|
||||
<if test="defaultType != null">default_type = #{defaultType},</if>
|
||||
<if test="calculateSign != null">calculate_sign = #{calculateSign},</if>
|
||||
|
||||
Reference in New Issue
Block a user