|
|
@@ -111,14 +111,25 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
* @author hejq
|
|
|
*/
|
|
|
@Override
|
|
|
- public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency) {
|
|
|
+ public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency, Integer isPerson) {
|
|
|
+ // 是否上传个人物料
|
|
|
+ boolean isAPerson = false;
|
|
|
+ if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
+ isAPerson = true;
|
|
|
+ }
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
Set<ReleaseProductByBatch> releaseProductByBatchs = new HashSet<>();
|
|
|
// 获取第一个工作表
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
- if (colNum != UploadConstant.TOTAL_COLUMN && colNum != UploadConstant.MAX_TOTAL_COLUMN) {
|
|
|
- throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
+ if (isAPerson) {
|
|
|
+ if (colNum != UploadConstant.TOTAL_COLUMN_PERSON && colNum != UploadConstant.MAX_TOTAL_COLUMN_PERSON) {
|
|
|
+ throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (colNum != UploadConstant.TOTAL_COLUMN && colNum != UploadConstant.MAX_TOTAL_COLUMN) {
|
|
|
+ throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
+ }
|
|
|
}
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
if (rowNum > 2000) {
|
|
|
@@ -132,8 +143,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
int blankNum = 0;
|
|
|
if (headerRow != null) {
|
|
|
// 验证模板是否为商城模板
|
|
|
- validateTemplate(headerRow, colNum, currency);
|
|
|
-
|
|
|
+ validateTemplate(headerRow, colNum, currency, isAPerson);
|
|
|
for (int r = 2; r <= rowNum; r++) {
|
|
|
Row row = sheet.getRow(r);
|
|
|
// 英文品牌名称
|
|
|
@@ -145,14 +155,16 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
ReleaseProductByBatch releaseProductByBatch = new ReleaseProductByBatch();
|
|
|
// 初始化默认信息
|
|
|
setProductDefaultInfo(releaseProductByBatch, batch, currency, storeIn);
|
|
|
-
|
|
|
+// TODO 个人库验证
|
|
|
// 将excel内容对应到ReleaseProductByBatch的字段当中
|
|
|
- blankNum = convertValueToProduct(row, releaseProductByBatch, r);
|
|
|
-
|
|
|
- // 解析返回分段价格list
|
|
|
- List<GoodsQtyPrice> qtyPriceList = initQtyPriceByExcel(row, releaseProductByBatch, r);
|
|
|
- if (!CollectionUtils.isEmpty(qtyPriceList)) {
|
|
|
- releaseProductByBatch.setPrices(qtyPriceList);
|
|
|
+ blankNum = convertValueToProduct(row, releaseProductByBatch, r, isAPerson);
|
|
|
+// TODO 个人库验证
|
|
|
+ if (!isAPerson) {
|
|
|
+ // 解析返回分段价格list
|
|
|
+ List<GoodsQtyPrice> qtyPriceList = initQtyPriceByExcel(row, releaseProductByBatch, r);
|
|
|
+ if (!CollectionUtils.isEmpty(qtyPriceList)) {
|
|
|
+ releaseProductByBatch.setPrices(qtyPriceList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(releaseProductByBatch.getErrmsg())) {
|
|
|
@@ -213,36 +225,53 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
* @param colNum 总列
|
|
|
* @param currency 币别
|
|
|
*/
|
|
|
- private void validateTemplate(Row headerRow, int colNum, String currency) {
|
|
|
- if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
|
|
|
- Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
|
|
|
- Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
|
|
|
- String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
|
|
|
- if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
|
|
|
- throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
+ private void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson) {
|
|
|
+ if (isAPerson) {
|
|
|
+ if (colNum == UploadConstant.MAX_TOTAL_COLUMN_PERSON) {
|
|
|
+ Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN_PERSON - 1);
|
|
|
+ Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
|
|
|
+ String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
|
|
|
+ if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
|
|
|
+ throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Object codeCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.PRODUCT_CODE);
|
|
|
+ if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
}
|
|
|
- }
|
|
|
- Object codeCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
|
|
|
- 0, UploadConstant.PRODUCT_CODE);
|
|
|
- if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
- throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
- }
|
|
|
- Object priceCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRICE_START), Cell.CELL_TYPE_STRING,
|
|
|
- 0, UploadConstant.PRICE_START);
|
|
|
- if (StringUtils.isEmpty(priceCellObj)) {
|
|
|
- throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
} else {
|
|
|
- String title = StringUtilB2C.replaceLineBreak(priceCellObj.toString());
|
|
|
- if (Currency.USD.equals(currency)) {
|
|
|
- if (!title.equals("USD单价1")) {
|
|
|
- throw new IllegalOperatorException("您上传的文件表头与美金模板不符");
|
|
|
+ if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
|
|
|
+ Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
|
|
|
+ Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
|
|
|
+ String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
|
|
|
+ if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
|
|
|
+ throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
}
|
|
|
+ }
|
|
|
+ Object codeCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.PRODUCT_CODE);
|
|
|
+ if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ Object priceCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRICE_START), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.PRICE_START);
|
|
|
+ if (StringUtils.isEmpty(priceCellObj)) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
} else {
|
|
|
- if (!title.equals("RMB单价1")) {
|
|
|
- throw new IllegalOperatorException("您上传的文件表头与人民币模板不符");
|
|
|
+ String title = StringUtilB2C.replaceLineBreak(priceCellObj.toString());
|
|
|
+ if (Currency.USD.equals(currency)) {
|
|
|
+ if (!title.equals("USD单价1")) {
|
|
|
+ throw new IllegalOperatorException("您上传的文件表头与美金模板不符");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!title.equals("RMB单价1")) {
|
|
|
+ throw new IllegalOperatorException("您上传的文件表头与人民币模板不符");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -433,7 +462,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
* @param aProduct 验证单行数据
|
|
|
* @param rowNum 行数
|
|
|
*/
|
|
|
- private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum) {
|
|
|
+ private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum, boolean isAPerson) {
|
|
|
// 统计为空的个数
|
|
|
int result = 0;
|
|
|
Object codeValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
|
|
|
@@ -450,49 +479,52 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
}
|
|
|
aProduct.setBrandEnByExcel(brandValue);
|
|
|
|
|
|
- Object breakValue = readWorkBookCell(row.getCell(UploadConstant.BREAK_UP), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.BREAK_UP);
|
|
|
- aProduct.setBreakUpByExcel(breakValue);
|
|
|
+ if (!isAPerson) {
|
|
|
+ Object breakValue = readWorkBookCell(row.getCell(UploadConstant.BREAK_UP), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.BREAK_UP);
|
|
|
+ aProduct.setBreakUpByExcel(breakValue);
|
|
|
|
|
|
- Object reserveValue = readWorkBookCell(row.getCell(UploadConstant.RESERVE_NUMBER), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.RESERVE_NUMBER);
|
|
|
- if (StringUtils.isEmpty(reserveValue)) {
|
|
|
- result += 1;
|
|
|
- }
|
|
|
- aProduct.setReserveByExcel(reserveValue);
|
|
|
+ Object reserveValue = readWorkBookCell(row.getCell(UploadConstant.RESERVE_NUMBER), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.RESERVE_NUMBER);
|
|
|
+ if (StringUtils.isEmpty(reserveValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ aProduct.setReserveByExcel(reserveValue);
|
|
|
+
|
|
|
+ Object produceValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCE_DATE), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.PRODUCE_DATE);
|
|
|
+ aProduct.setProductDateByExcel(produceValue);
|
|
|
+
|
|
|
+ Object packageMethodValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_METHOD), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.PACKAGE_METHOD);
|
|
|
+ aProduct.setPackagingByExcel(packageMethodValue);
|
|
|
+
|
|
|
+ Object minValue = readWorkBookCell(row.getCell(UploadConstant.MIN_DELIVERY), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.MIN_DELIVERY);
|
|
|
+ Object maxValue = readWorkBookCell(row.getCell(UploadConstant.MAX_DELIVERY), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.MAX_DELIVERY);
|
|
|
+ aProduct.setDeliveryByExcel(minValue, maxValue);
|
|
|
+ if (!StringUtils.isEmpty(minValue) || !StringUtils.isEmpty(maxValue)) {
|
|
|
+ setDeliveryTime(aProduct, minValue, maxValue);
|
|
|
+ }
|
|
|
|
|
|
- Object produceValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCE_DATE), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.PRODUCE_DATE);
|
|
|
- aProduct.setProductDateByExcel(produceValue);
|
|
|
+ Object packageNumValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_NUMBER), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.PACKAGE_NUMBER);
|
|
|
+ aProduct.setMinPackageByExcel(packageNumValue);
|
|
|
|
|
|
- Object packageMethodValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_METHOD), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.PACKAGE_METHOD);
|
|
|
- aProduct.setPackagingByExcel(packageMethodValue);
|
|
|
+ Object buyQtyValue = readWorkBookCell(row.getCell(UploadConstant.BUY_MIN_QTY), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.BUY_MIN_QTY);
|
|
|
+ aProduct.setMinBuyQtyByExcel(buyQtyValue);
|
|
|
|
|
|
- Object minValue = readWorkBookCell(row.getCell(UploadConstant.MIN_DELIVERY), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.MIN_DELIVERY);
|
|
|
- Object maxValue = readWorkBookCell(row.getCell(UploadConstant.MAX_DELIVERY), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.MAX_DELIVERY);
|
|
|
- aProduct.setDeliveryByExcel(minValue, maxValue);
|
|
|
- if (!StringUtils.isEmpty(minValue) || !StringUtils.isEmpty(maxValue)) {
|
|
|
- setDeliveryTime(aProduct, minValue, maxValue);
|
|
|
+ Object tagValue = readWorkBookCell(row.getCell(UploadConstant.CUSTOM_LABEL), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.CUSTOM_LABEL);
|
|
|
+ aProduct.setTagByExcel(tagValue);
|
|
|
+ // 自定义标签不为null,则检查是否重复
|
|
|
+ if (aProduct.getCode() != null && aProduct.getBrandNameEn() != null && aProduct.getTag() != null) {
|
|
|
+ resetTag(aProduct);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- Object packageNumValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_NUMBER), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.PACKAGE_NUMBER);
|
|
|
- aProduct.setMinPackageByExcel(packageNumValue);
|
|
|
-
|
|
|
- Object buyQtyValue = readWorkBookCell(row.getCell(UploadConstant.BUY_MIN_QTY), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.BUY_MIN_QTY);
|
|
|
- aProduct.setMinBuyQtyByExcel(buyQtyValue);
|
|
|
-
|
|
|
- Object tagValue = readWorkBookCell(row.getCell(UploadConstant.CUSTOM_LABEL), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, UploadConstant.CUSTOM_LABEL);
|
|
|
- aProduct.setTagByExcel(tagValue);
|
|
|
- // 自定义标签不为null,则检查是否重复
|
|
|
- if (aProduct.getCode() != null && aProduct.getBrandNameEn() != null && aProduct.getTag() != null) {
|
|
|
- resetTag(aProduct);
|
|
|
- }
|
|
|
return result;
|
|
|
}
|
|
|
|