|
|
@@ -1,34 +1,54 @@
|
|
|
package com.uas.platform.b2c.trade.seek.service.impl;
|
|
|
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.UploadConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.Component;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomDao;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseByBatchDao;
|
|
|
import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseDao;
|
|
|
import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseGoodsDao;
|
|
|
import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseOfferDao;
|
|
|
import com.uas.platform.b2c.trade.seek.model.SeekPurchase;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBom;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseByBatch;
|
|
|
import com.uas.platform.b2c.trade.seek.model.SeekPurchaseGoods;
|
|
|
import com.uas.platform.b2c.trade.seek.model.SeekPurchaseOffer;
|
|
|
import com.uas.platform.b2c.trade.seek.service.SeekPurchaseService;
|
|
|
import com.uas.platform.b2c.trade.seek.status.Status;
|
|
|
import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.persistence.criteria.CriterionExpression.Operator;
|
|
|
import com.uas.platform.core.persistence.criteria.LogicalExpression;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+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;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
@@ -68,6 +88,12 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
@Autowired
|
|
|
private SeekPurchaseGoodsDao seekPurchaseGoodsDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseBomDao seekPurchaseBomDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SeekPurchaseByBatchDao seekPurchaseByBatchDao;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<SeekPurchase> getSeekPageInfo(final PageInfo pageInfo, String keyWord) {
|
|
|
// 关键字
|
|
|
@@ -246,4 +272,157 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
seekPurchase.setBoughtAmount(boughtAmount);
|
|
|
return seekPurchasedao.save(seekPurchase);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap importBom(Workbook workbook, String bomName, User user) {
|
|
|
+ // 获取第一个工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ if (rowNum > 500) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息超过500条,请拆分成2000以再在上传");
|
|
|
+ }
|
|
|
+ // 插入Bom求购中
|
|
|
+ SeekPurchaseBom seekPurchaseBom = new SeekPurchaseBom();
|
|
|
+ seekPurchaseBom.setReleaseDate(new Date(System.currentTimeMillis()));
|
|
|
+ seekPurchaseBom.setEnuu(user.getEnterprise().getUu());
|
|
|
+ seekPurchaseBom.setUu(user.getUserUU());
|
|
|
+ seekPurchaseBom.setName(bomName);
|
|
|
+ seekPurchaseBom.setStatus(0);
|
|
|
+ seekPurchaseBom = seekPurchaseBomDao.save(seekPurchaseBom);
|
|
|
+ // 创造唯一标识
|
|
|
+ //String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
|
|
|
+ // 获取第一行的信息
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
+ int total = 0;
|
|
|
+ int blankNum = 0;
|
|
|
+ if (headerRow != null) {
|
|
|
+ // 验证是否为商城模板
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatchList = new ArrayList<>();
|
|
|
+ for (int r = 2; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row != null) {
|
|
|
+ SeekPurchaseByBatch seekPurchaseByBatch = new SeekPurchaseByBatch();
|
|
|
+ blankNum = convertValueToSeekPurchase(row, seekPurchaseByBatch, r);
|
|
|
+ seekPurchaseByBatch.setBomId(seekPurchaseBom.getId());
|
|
|
+ seekPurchaseByBatchList.add(seekPurchaseByBatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
|
|
|
+ }
|
|
|
+ return ResultMap.success(seekPurchaseBom.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ private int convertValueToSeekPurchase(Row row, SeekPurchaseByBatch seekPurchaseByBatch, int rowNum) {
|
|
|
+ // 统计为空的个数
|
|
|
+ int result = 0;
|
|
|
+ Object codeValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 0);
|
|
|
+ if (StringUtils.isEmpty(codeValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ seekPurchaseByBatch.setCode(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(codeValue)));
|
|
|
+
|
|
|
+ Object brandValue = readWorkBookCell(row.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 1);
|
|
|
+ if (StringUtils.isEmpty(brandValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ seekPurchaseByBatch.setBrand(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue)));
|
|
|
+
|
|
|
+ Object deadlineValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 2);
|
|
|
+ if (StringUtils.isEmpty(deadlineValue)) {
|
|
|
+ result += 1;
|
|
|
+ }
|
|
|
+ seekPurchaseByBatch.setDeadline(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue)));
|
|
|
+
|
|
|
+ Object amountValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 3);
|
|
|
+ if (!StringUtils.isEmpty(amountValue)) {
|
|
|
+ Integer amount = Integer.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue)));
|
|
|
+ seekPurchaseByBatch.setAmount(amount);
|
|
|
+ }
|
|
|
+
|
|
|
+ Object currencyValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 4);
|
|
|
+ if (!StringUtils.isEmpty(currencyValue)) {
|
|
|
+ String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
|
|
|
+ seekPurchaseByBatch.setCurrency(currency);
|
|
|
+ }
|
|
|
+
|
|
|
+ Object unitPriceValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 5);
|
|
|
+ if (!StringUtils.isEmpty(unitPriceValue)) {
|
|
|
+ Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
|
|
|
+ seekPurchaseByBatch.setUnitPrice(unitPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+ Object encapsulationValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 7);
|
|
|
+ if (!StringUtils.isEmpty(encapsulationValue)) {
|
|
|
+ String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
|
|
|
+ seekPurchaseByBatch.setEncapsulation(encapsulation);
|
|
|
+ }
|
|
|
+
|
|
|
+ Object produceDateValue = readWorkBookCell(row.getCell(8), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, 8);
|
|
|
+ if (!StringUtils.isEmpty(produceDateValue)) {
|
|
|
+ String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
|
|
|
+ seekPurchaseByBatch.setProduceDate(produceDate);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
|
|
|
+ Object obj = null;
|
|
|
+ try {
|
|
|
+ if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ switch (cellType) {
|
|
|
+ case Cell.CELL_TYPE_STRING :
|
|
|
+ cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
+ String str = cell.getStringCellValue().trim();
|
|
|
+ if (str.indexOf("\u00A0") > 0) {
|
|
|
+ str= str.replaceAll("\u00A0", "");
|
|
|
+ }
|
|
|
+ str = StringUtilB2C.replaceTabAndLineBreak(str);
|
|
|
+ obj = str.trim();
|
|
|
+ break;
|
|
|
+ case Cell.CELL_TYPE_NUMERIC :
|
|
|
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
+ obj = cell.getNumericCellValue();
|
|
|
+ if (obj != null) {
|
|
|
+ if (obj.toString().indexOf("E") > 0) {
|
|
|
+ BigDecimal b = new BigDecimal(obj.toString());
|
|
|
+ obj = b.toPlainString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default :
|
|
|
+ if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
|
|
+ String productTime = cell.getStringCellValue();
|
|
|
+ Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
|
|
+ Matcher m = p.matcher(productTime);
|
|
|
+ String time = m.replaceAll("");
|
|
|
+ if (time.indexOf("\u00A0") > 0){
|
|
|
+ time= time.replaceAll("\u00A0", "");
|
|
|
+ }
|
|
|
+ DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ obj = format1.parse(time);
|
|
|
+ } else if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
|
|
+ obj = cell.getDateCellValue();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IllegalOperatorException("读取表格中" + r + "行" + (n + 1) + "列的内容错误,有可能是该单元格的格式不正确");
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap confirmBom(Long bomId, User user) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|