|
|
@@ -1,6 +1,7 @@
|
|
|
package com.uas.platform.b2c.trade.seek.service.impl;
|
|
|
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
+import com.uas.platform.b2c.common.search.service.SearcherService;
|
|
|
import com.uas.platform.b2c.core.utils.StringUtilB2C;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
@@ -30,7 +31,6 @@ 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.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@@ -53,6 +53,7 @@ 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.core.convert.converter.Converter;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
@@ -105,6 +106,11 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
@Autowired
|
|
|
private SeekPurchaseBomListDao seekPurchaseBomListDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SearcherService searcherService;
|
|
|
+
|
|
|
+ private static Long deadlineTime = Long.valueOf(90 * 24 * 60 * 60 * 1000);
|
|
|
+
|
|
|
@Override
|
|
|
public Page<SeekPurchase> getSeekPageInfo(final PageInfo pageInfo, String keyWord) {
|
|
|
// 关键字
|
|
|
@@ -213,6 +219,9 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
SeekPurchase seekPurchase = seekPurchasedao.findOne(spId);
|
|
|
seekPurchase.setStatus(Status.ACCEPTED.getValue());
|
|
|
seekPurchase.setBoughtAmount(purchaseQuantity);
|
|
|
+ if (seekPurchase.getAmount() == null) {
|
|
|
+ seekPurchase.setAmount(Integer.valueOf(purchaseQuantity.intValue()));
|
|
|
+ }
|
|
|
seekPurchase.setDeadline(new Date(System.currentTimeMillis()));
|
|
|
seekPurchasedao.save(seekPurchase);
|
|
|
// 修改报价表的状态
|
|
|
@@ -277,6 +286,7 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
if (bomId != null) {
|
|
|
pageInfo.filter("bomId", bomId);
|
|
|
}
|
|
|
+
|
|
|
pageInfo.sorting("releaseDate", Direction.DESC);
|
|
|
Page<SeekPurchaseGoods> pageSeeks = seekPurchaseGoodsDao.findAll(new Specification<SeekPurchaseGoods>() {
|
|
|
public Predicate toPredicate(Root<SeekPurchaseGoods> root, CriteriaQuery<?> query,
|
|
|
@@ -292,7 +302,7 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
public SeekPurchase confirmSeekPurchase(Long spId, Double purchaseQuantity) {
|
|
|
SeekPurchase seekPurchase = seekPurchasedao.findOne(spId);
|
|
|
// 求购数量
|
|
|
- Integer amount = seekPurchase.getAmount();
|
|
|
+ Integer amount = seekPurchase.getAmount() == null ? 0 : seekPurchase.getAmount();
|
|
|
Double boughtAmount = seekPurchase.getBoughtAmount() + purchaseQuantity;
|
|
|
if (boughtAmount >= amount) {
|
|
|
seekPurchase.setDeadline(new Date(System.currentTimeMillis()));
|
|
|
@@ -306,9 +316,12 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
// 获取第一个工作表
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ if (colNum != 8) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "表格模板不正确!请重新下载最新模板");
|
|
|
+ }
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
if (rowNum > 500) {
|
|
|
- throw new IllegalOperatorException("您上传的信息超过500条,请拆分成2000以再在上传");
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息超过500条,请拆分成2000以再在上传");
|
|
|
}
|
|
|
// 插入Bom求购中
|
|
|
SeekPurchaseBom seekPurchaseBom = new SeekPurchaseBom();
|
|
|
@@ -318,20 +331,38 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
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) {
|
|
|
// 验证是否为商城模板
|
|
|
+ Object codeCellObj = readWorkBookCell(headerRow.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 0);
|
|
|
+ if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ Object brandCellObj = readWorkBookCell(headerRow.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 1);
|
|
|
+ if (!"品牌名称".equals(StringUtilB2C.getStr(brandCellObj))) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ Object deadlineCellObj = readWorkBookCell(headerRow.getCell(2), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 2);
|
|
|
+ if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ Object produceDateCellObj = readWorkBookCell(headerRow.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, 7);
|
|
|
+ if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
List<SeekPurchaseByBatch> seekPurchaseByBatchList = new ArrayList<>();
|
|
|
- for (int r = 2; r <= rowNum; r++) {
|
|
|
+ for (int r = 3; r <= rowNum; r++) {
|
|
|
Row row = sheet.getRow(r);
|
|
|
if (row != null) {
|
|
|
SeekPurchaseByBatch seekPurchaseByBatch = new SeekPurchaseByBatch();
|
|
|
- blankNum = convertValueToSeekPurchase(row, seekPurchaseByBatch, r);
|
|
|
+ blankNum = convertValueToSeekPurchaseByBatch(row, seekPurchaseByBatch, r);
|
|
|
seekPurchaseByBatch.setBomId(seekPurchaseBom.getId());
|
|
|
seekPurchaseByBatch.setReleaseDate(new Date(System.currentTimeMillis()));
|
|
|
|
|
|
@@ -343,7 +374,14 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
return ResultMap.success(seekPurchaseBom.getId());
|
|
|
}
|
|
|
|
|
|
- private int convertValueToSeekPurchase(Row row, SeekPurchaseByBatch seekPurchaseByBatch, int rowNum) {
|
|
|
+ /**
|
|
|
+ * 将列信息注入到求购临时实体中
|
|
|
+ * @param row
|
|
|
+ * @param seekPurchaseByBatch
|
|
|
+ * @param rowNum
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int convertValueToSeekPurchaseByBatch(Row row, SeekPurchaseByBatch seekPurchaseByBatch, int rowNum) {
|
|
|
// 统计为空的个数
|
|
|
int result = 0;
|
|
|
// 型号
|
|
|
@@ -372,46 +410,63 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
} else {
|
|
|
String deadline = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue));
|
|
|
try {
|
|
|
- deadline = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(deadline, 12);
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ deadline = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(deadline, 10);
|
|
|
+ seekPurchaseByBatch.setDeadline(addTime(new Date(deadline)));
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setDeadline(addTime(new Date(System.currentTimeMillis())));
|
|
|
}
|
|
|
- seekPurchaseByBatch.setDeadline(addTime(new Date(deadline)));
|
|
|
}
|
|
|
|
|
|
// 求购数量
|
|
|
Object amountValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING,
|
|
|
rowNum, 3);
|
|
|
if (!StringUtils.isEmpty(amountValue)) {
|
|
|
- Integer amount = Integer.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
|
|
|
- seekPurchaseByBatch.setAmount(amount);
|
|
|
+ try {
|
|
|
+ Integer amount = Integer.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
|
|
|
+ seekPurchaseByBatch.setAmount(amount);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ seekPurchaseByBatch.setAmount(null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 币别
|
|
|
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);
|
|
|
+ try {
|
|
|
+ String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
|
|
|
+ seekPurchaseByBatch.setCurrency(currency);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setCurrency("RMB");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 单价
|
|
|
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);
|
|
|
+ try {
|
|
|
+ Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
|
|
|
+ seekPurchaseByBatch.setUnitPrice(unitPrice);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ seekPurchaseByBatch.setUnitPrice(null);
|
|
|
+ }
|
|
|
}
|
|
|
// 如果填了单价又不选币种,导入的时候系统就默认人民币吧
|
|
|
if (!StringUtils.isEmpty(unitPriceValue) && StringUtils.isEmpty(currencyValue)) {
|
|
|
seekPurchaseByBatch.setCurrency("RMB");
|
|
|
}
|
|
|
+
|
|
|
// 封装
|
|
|
Object encapsulationValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING,
|
|
|
rowNum, 6);
|
|
|
if (!StringUtils.isEmpty(encapsulationValue)) {
|
|
|
- String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
|
|
|
- seekPurchaseByBatch.setEncapsulation(encapsulation);
|
|
|
+ try {
|
|
|
+ String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
|
|
|
+ seekPurchaseByBatch.setEncapsulation(encapsulation);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setEncapsulation(null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -419,8 +474,12 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
Object produceDateValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
rowNum, 7);
|
|
|
if (!StringUtils.isEmpty(produceDateValue)) {
|
|
|
- String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
|
|
|
- seekPurchaseByBatch.setProduceDate(produceDate);
|
|
|
+ try {
|
|
|
+ String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
|
|
|
+ seekPurchaseByBatch.setProduceDate(produceDate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setProduceDate(null);
|
|
|
+ }
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -484,6 +543,14 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
return null;
|
|
|
}
|
|
|
}, pageInfo);
|
|
|
+ List<SeekPurchaseByBatch> seekPurchaseByBatchList = pageSeeks.getContent();
|
|
|
+ for (int i = 0;i < seekPurchaseByBatchList.size(); i++) {
|
|
|
+ if (!StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getCode()) && !StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getBrand())) {
|
|
|
+ seekPurchaseByBatchList.get(i).setCodeWord(searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getCode()));
|
|
|
+ seekPurchaseByBatchList.get(i).setBrandWord(searcherService.getSimilarBrands(seekPurchaseByBatchList.get(i).getBrand()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageSeeks = (Page<SeekPurchaseByBatch>) seekPurchaseByBatchList;
|
|
|
return pageSeeks;
|
|
|
}
|
|
|
|
|
|
@@ -508,7 +575,11 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
|
|
|
SeekPurchase seekPurchase = new SeekPurchase();
|
|
|
if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand()) && !StringUtils.isEmpty(batch.getDeadline())) {
|
|
|
//seekPurchase = (SeekPurchase) batch;
|
|
|
- seekPurchase.setDeadline(batch.getDeadline());
|
|
|
+ if (batch.getDeadline().getTime() - System.currentTimeMillis() > deadlineTime) {
|
|
|
+ seekPurchase.setDeadline(new Date(System.currentTimeMillis() + deadlineTime));
|
|
|
+ } else {
|
|
|
+ seekPurchase.setDeadline(batch.getDeadline());
|
|
|
+ }
|
|
|
seekPurchase.setCurrency(batch.getCurrency());
|
|
|
seekPurchase.setReleaseDate(batch.getReleaseDate());
|
|
|
seekPurchase.setCode(batch.getCode());
|