|
|
@@ -2,8 +2,10 @@ package com.uas.platform.b2c.trade.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.platform.b2c.core.constant.ReleaseStatus;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.StringUtilB2C;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.ErrorInfoConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.constant.UploadConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ReleaseProductByBatchDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
|
|
|
@@ -17,6 +19,7 @@ import com.uas.platform.core.util.HttpUtil;
|
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import com.uas.ps.entity.Product;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
@@ -73,14 +76,12 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
* 通过excel批量导入个人物料
|
|
|
*
|
|
|
* @param workbook Workbook 对象
|
|
|
- * @param selfSale the self sale 自营还是寄售
|
|
|
- * @param currency 币别
|
|
|
* @param ignoreImport 是覆盖导入,还是忽略导入 1是忽略导入,0是覆盖导入
|
|
|
* @return ResultMap
|
|
|
* @see ResultMap
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResultMap releasePersonalProductByExcel(Workbook workbook, Boolean selfSale, String currency, Integer ignoreImport) {
|
|
|
+ public ResultMap releasePersonalProductByExcel(Workbook workbook, Integer ignoreImport) {
|
|
|
// 先判断表格式
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
if (sheet.getRow(0) == null) {
|
|
|
@@ -102,18 +103,16 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
if (null != headerRow) {
|
|
|
int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
- // 非个人用户
|
|
|
- boolean isAPerson = false;
|
|
|
- // 非Pcb商品
|
|
|
- boolean isPcb = false;
|
|
|
// 验证模板是否为商城模板
|
|
|
- releaseProductByBatchService.validateTemplate(headerRow, colNum, currency, isAPerson, isPcb);
|
|
|
+ validateTemplate(headerRow, colNum);
|
|
|
// 去重后的数据
|
|
|
List<ReleaseProductByBatch> uniqueBatchList = new ArrayList<>();
|
|
|
// 为空的个数
|
|
|
int blankNum;
|
|
|
// 本次上传总数
|
|
|
int total = 0;
|
|
|
+ // 批号
|
|
|
+ String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
|
|
|
for (int r = minExcelNumber; r <= rowNum; r++) {
|
|
|
Row row = sheet.getRow(r);
|
|
|
// 英文品牌名称
|
|
|
@@ -123,25 +122,23 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
continue;
|
|
|
}
|
|
|
ReleaseProductByBatch releaseProductByBatch = new ReleaseProductByBatch();
|
|
|
+ // 初始化默认信息
|
|
|
+ setProductDefaultInfo(releaseProductByBatch, batch);
|
|
|
// 将excel内容对应到ReleaseProductByBatch的字段当中
|
|
|
- blankNum = releaseProductByBatchService.convertValueToProduct(row, releaseProductByBatch, r, isAPerson, isPcb);
|
|
|
+ blankNum = convertValueToProduct(row, releaseProductByBatch, r);
|
|
|
if (blankNum != 4) {
|
|
|
// 验证表格中数据是否重复,重复的取第一条数据
|
|
|
ReleaseProductByBatch uniquerProduct = validateRepeatInExcel(releaseProductByBatchArrayList, releaseProductByBatch);
|
|
|
if (null != uniquerProduct) {
|
|
|
uniqueBatchList.add(uniquerProduct);
|
|
|
}
|
|
|
- total++;
|
|
|
releaseProductByBatchArrayList.add(releaseProductByBatch);
|
|
|
+ total++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
|
|
|
- releaseProductByBatchService.judgeSameReleaseProductByBatch(releaseProductByBatchArrayList);
|
|
|
// 保存临时表信息
|
|
|
releaseProductByBatchDao.save(releaseProductByBatchArrayList);
|
|
|
- // 批号
|
|
|
- String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
|
|
|
Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
// 验证数据信息是否重复
|
|
|
releaseProductByBatchDao.callReleaseExistValidProcedure(batch, enUU);
|
|
|
@@ -149,9 +146,12 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
// 处理上传数据
|
|
|
assignmentProductInfo(enUU, modelMap, batch);
|
|
|
// 验证成功后进行绑定处理
|
|
|
- Integer assignNumber = assignBatch(uniqueBatchList);
|
|
|
- modelMap.put("assignNumber", assignNumber);
|
|
|
- modelMap.put("failure", total - assignNumber);
|
|
|
+ Integer assignNumber = 0;
|
|
|
+ if (!CollectionUtils.isEmpty(uniqueBatchList)) {
|
|
|
+ assignNumber = assignBatch(uniqueBatchList);
|
|
|
+ }
|
|
|
+ modelMap.put("assignSuccess", assignNumber);
|
|
|
+ modelMap.put("assignFailure", total - assignNumber);
|
|
|
modelMap.put("total", total);
|
|
|
modelMap.put("batch", batch);
|
|
|
return ResultMap.success(modelMap);
|
|
|
@@ -159,6 +159,108 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
return ResultMap.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化赋值
|
|
|
+ *
|
|
|
+ * @param aProduct 批量上传商品建立临时表存储相关信息
|
|
|
+ * @param batch 批号
|
|
|
+ */
|
|
|
+ private void setProductDefaultInfo(ReleaseProductByBatch aProduct, String batch) {
|
|
|
+ // 设置初始状态
|
|
|
+ aProduct.setReleaseCode(ReleaseStatus.success.value());
|
|
|
+ aProduct.setReleaseStatus(ReleaseStatus.success.getPhrase());
|
|
|
+ aProduct.setRelbatchid(batch);
|
|
|
+ aProduct.setUnit("PCS");
|
|
|
+ // 设置发布人信息
|
|
|
+ aProduct.setPublisherName(SystemSession.getUser().getUserName());
|
|
|
+ aProduct.setPublisherTel(SystemSession.getUser().getUserTel());
|
|
|
+ aProduct.setPublisherUu(SystemSession.getUser().getUserUU());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化product信息,将excel内容转换为product字段值
|
|
|
+ *
|
|
|
+ * @param row 行对象
|
|
|
+ * @param aProduct 验证单行数据
|
|
|
+ * @param rowNum 行数
|
|
|
+ */
|
|
|
+ private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum) {
|
|
|
+ // 统计为空的个数
|
|
|
+ int result = 0;
|
|
|
+ aProduct.setNum(rowNum - 2);
|
|
|
+ // 品牌
|
|
|
+ Object brandValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.BRAND_ENGLISH), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.BRAND_ENGLISH);
|
|
|
+ if (StringUtils.isEmpty(brandValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ aProduct.setBrandEnByExcel(brandValue);
|
|
|
+
|
|
|
+ // 类目
|
|
|
+ Object kindValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.KIND), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.KIND);
|
|
|
+ if (StringUtils.isEmpty(kindValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ aProduct.setKindByExcel(kindValue);
|
|
|
+
|
|
|
+ // 型号
|
|
|
+ Object codeValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.PRODUCT_CODE);
|
|
|
+ if (StringUtils.isEmpty(codeValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ aProduct.setCodeByExcel(codeValue);
|
|
|
+
|
|
|
+ // 规格
|
|
|
+ Object specValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.SPEC), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UploadConstant.SPEC);
|
|
|
+ aProduct.setSpecByExcel(specValue);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人物料上传模板校验
|
|
|
+ *
|
|
|
+ * @param headerRow 表头
|
|
|
+ * @param colNum 列数
|
|
|
+ */
|
|
|
+ private void validateTemplate(Row headerRow, int colNum) {
|
|
|
+ if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
|
|
|
+ Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
|
|
|
+ Object errorCellObj = releaseProductByBatchService.readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
|
|
|
+ String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
|
|
|
+ String errorMsg = "错误提示";
|
|
|
+ if (StringUtils.isEmpty(errorHead) || !(errorMsg.equals(errorHead))) {
|
|
|
+ throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 品牌
|
|
|
+ Object brandCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.BRAND_ENGLISH), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.BRAND_ENGLISH);
|
|
|
+ if (!UploadConstant.PRODUCT_BRAND_NAME.equals(StringUtilB2C.getStr(brandCellObj))) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ // 物料名称
|
|
|
+ Object titleCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.KIND), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.KIND);
|
|
|
+ if (!UploadConstant.PRODUCT_KIND_NAME.equals(StringUtilB2C.getStr(titleCellObj))) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ // 型号
|
|
|
+ Object codeCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.PRODUCT_CODE);
|
|
|
+ if (!UploadConstant.PRODUCT_CMPCODE_NAME.equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ // 规格
|
|
|
+ Object specCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.SPEC), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, UploadConstant.SPEC);
|
|
|
+ if (!UploadConstant.PRODUCT_SPEC_NAME.equals(StringUtilB2C.getStr(specCellObj))) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 将去重的数据批量绑定到个人物料库
|
|
|
*
|
|
|
@@ -210,6 +312,16 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
if (StringUtils.isEmpty(each.getErrmsg()) && !each.equals(aBatch)) {
|
|
|
return aBatch;
|
|
|
}
|
|
|
+ if (aBatch.compareSameProductTagInfo(each)) {
|
|
|
+ aBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
|
|
|
+ aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
|
|
|
+ aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
|
|
|
+ if (aBatch.getErrmsg().substring(0, 1).equals(",")) {
|
|
|
+ aBatch.setErrmsg(aBatch.getErrmsg().substring(1));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return aBatch;
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -228,6 +340,11 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
product.setBrand(batch.getBrandNameEn() != null ? batch.getBrandNameEn() : batch.getBrandNameCn());
|
|
|
product.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
product.setCode(batch.getCode());
|
|
|
+ // 没有编号设置编号
|
|
|
+ if (null == product.getCode()) {
|
|
|
+ String code = "B2CPR" + StringUtilB2C.getRandomNumber(6);
|
|
|
+ product.setCode(code);
|
|
|
+ }
|
|
|
// 交期默认赋值为0
|
|
|
Double leadTime = 0D;
|
|
|
product.setLeadTime(leadTime);
|
|
|
@@ -236,6 +353,7 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
product.setKind(batch.getKindName());
|
|
|
product.setUnit(batch.getUnit());
|
|
|
+ product.setTitle(batch.getKindName());
|
|
|
productList.add(product);
|
|
|
});
|
|
|
return productList;
|