|
|
@@ -8,18 +8,8 @@ import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
-import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomDao;
|
|
|
-import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomListDao;
|
|
|
-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.PurcInquiry;
|
|
|
-import com.uas.platform.b2c.trade.seek.model.PurcInquiryItem;
|
|
|
-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.SeekPurchaseBomList;
|
|
|
-import com.uas.platform.b2c.trade.seek.model.SeekPurchaseByBatch;
|
|
|
+import com.uas.platform.b2c.trade.seek.dao.*;
|
|
|
+import com.uas.platform.b2c.trade.seek.model.*;
|
|
|
import com.uas.platform.b2c.trade.seek.service.SeekPurchaseBomService;
|
|
|
import com.uas.platform.b2c.trade.seek.utils.DateUtils;
|
|
|
import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
@@ -30,25 +20,6 @@ import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.util.HttpUtil;
|
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.text.DateFormat;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-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;
|
|
|
@@ -64,9 +35,24 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
/**
|
|
|
+ * bom求购实现类
|
|
|
+ *
|
|
|
* @author liusw
|
|
|
* @version 2018/1/19 15:06
|
|
|
*/
|
|
|
@@ -111,9 +97,24 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
|
|
|
private static final UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
|
|
|
- private int mallColNum = 8;
|
|
|
+ private int mallColNum = 10;
|
|
|
private int mallRowNum = 500;
|
|
|
|
|
|
+ /**
|
|
|
+ * excel列名
|
|
|
+ */
|
|
|
+ public static final int CODENUM = 0;
|
|
|
+ public static final int BRANDNUM = 1;
|
|
|
+ public static final int DEADLINENUM = 2;
|
|
|
+ public static final int AMOUNTNUM = 3;
|
|
|
+ public static final int CURRENCYNUM = 4;
|
|
|
+ public static final int UNITPRICENUM = 5;
|
|
|
+ public static final int ENCAPSULATIONNUM = 8;
|
|
|
+ public static final int PRODUCEDATENUM = 9;
|
|
|
+ public static final int KINDNUM = 6;
|
|
|
+ public static final int SPECNUM = 7;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 导入bom
|
|
|
* @param workbook
|
|
|
@@ -142,7 +143,6 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
seekPurchaseBom = seekPurchaseBomDao.save(seekPurchaseBom);
|
|
|
// 获取第一行的信息
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
- int total = 0;
|
|
|
int blankNum = 0;
|
|
|
if (headerRow != null) {
|
|
|
// 验证是否为商城模板
|
|
|
@@ -168,7 +168,12 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
seekPurchaseByBatchList.add(seekPurchaseByBatch);
|
|
|
}
|
|
|
}
|
|
|
- seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
|
|
|
+ if (CollectionUtils.isEmpty(seekPurchaseByBatchList)) {
|
|
|
+ seekPurchaseBomDao.delete(seekPurchaseBom.getId());
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "上传的excel内容为空,请填写完整后上传");
|
|
|
+ } else {
|
|
|
+ seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
|
|
|
+ }
|
|
|
}
|
|
|
return ResultMap.success(seekPurchaseBom.getId());
|
|
|
}
|
|
|
@@ -179,16 +184,16 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean vaidSample(Row row) {
|
|
|
- Object codeCellObj = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 0);
|
|
|
+ Object codeCellObj = readWorkBookCell(row.getCell(CODENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, CODENUM);
|
|
|
String codeString = StringUtilB2C.getStr(codeCellObj);
|
|
|
- Object brandCellObj = readWorkBookCell(row.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 1);
|
|
|
+ Object brandCellObj = readWorkBookCell(row.getCell(BRANDNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, BRANDNUM);
|
|
|
String brandString = StringUtilB2C.getStr(brandCellObj);
|
|
|
- Object produceDateCellObj = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 7);
|
|
|
+ Object produceDateCellObj = readWorkBookCell(row.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, PRODUCEDATENUM);
|
|
|
String produceDateString = StringUtilB2C.getStr(produceDateCellObj);
|
|
|
- if ("只能填数字、英文、英文特殊符号".equals(codeString) || "请勿用中文特殊符号".equals(brandCellObj) || "不超过6个汉字或12个字符".equals(produceDateString)) {
|
|
|
+ if ("只能填数字、英文、英文特殊符号".equals(codeString) || "请勿用中文特殊符号".equals(brandString) || "不超过6个汉字或12个字符".equals(produceDateString)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -200,23 +205,23 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean vaildTemplete(Row headerRow) {
|
|
|
- Object codeCellObj = readWorkBookCell(headerRow.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 0);
|
|
|
+ Object codeCellObj = readWorkBookCell(headerRow.getCell(CODENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, CODENUM);
|
|
|
if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
|
|
|
return false;
|
|
|
}
|
|
|
- Object brandCellObj = readWorkBookCell(headerRow.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 1);
|
|
|
+ Object brandCellObj = readWorkBookCell(headerRow.getCell(BRANDNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, BRANDNUM);
|
|
|
if (!"品牌名称".equals(StringUtilB2C.getStr(brandCellObj))) {
|
|
|
return false;
|
|
|
}
|
|
|
- Object deadlineCellObj = readWorkBookCell(headerRow.getCell(2), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 2);
|
|
|
+ Object deadlineCellObj = readWorkBookCell(headerRow.getCell(DEADLINENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, DEADLINENUM);
|
|
|
if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
|
|
|
return false;
|
|
|
}
|
|
|
- Object produceDateCellObj = readWorkBookCell(headerRow.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
- 0, 7);
|
|
|
+ Object produceDateCellObj = readWorkBookCell(headerRow.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ 0, PRODUCEDATENUM);
|
|
|
if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -234,14 +239,17 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
// 统计为空的个数
|
|
|
int result = 0;
|
|
|
// 型号
|
|
|
- Object codeValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 0);
|
|
|
+ Object codeValue = readWorkBookCell(row.getCell(CODENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, CODENUM);
|
|
|
if (StringUtils.isEmpty(codeValue)) {
|
|
|
result += 1;
|
|
|
} else {
|
|
|
String code = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(codeValue));
|
|
|
try {
|
|
|
code = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(code, 100);
|
|
|
+ if (!match(code)) {
|
|
|
+ code = null;
|
|
|
+ }
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -249,23 +257,26 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
}
|
|
|
|
|
|
// 品牌
|
|
|
- Object brandValue = readWorkBookCell(row.getCell(1), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 1);
|
|
|
+ Object brandValue = readWorkBookCell(row.getCell(BRANDNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, BRANDNUM);
|
|
|
if (StringUtils.isEmpty(brandValue)) {
|
|
|
result += 1;
|
|
|
} else {
|
|
|
String brand = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue));
|
|
|
try {
|
|
|
brand = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(brand, 50);
|
|
|
+ if (!match(brand)) {
|
|
|
+ brand = null;
|
|
|
+ }
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- seekPurchaseByBatch.setBrand(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue)));
|
|
|
+ seekPurchaseByBatch.setBrand(brand);
|
|
|
}
|
|
|
|
|
|
// 截止日期
|
|
|
- Object deadlineValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 2);
|
|
|
+ Object deadlineValue = readWorkBookCell(row.getCell(DEADLINENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, DEADLINENUM);
|
|
|
if (StringUtils.isEmpty(deadlineValue)) {
|
|
|
result += 1;
|
|
|
} else {
|
|
|
@@ -293,8 +304,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
}
|
|
|
|
|
|
// 求购数量
|
|
|
- Object amountValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 3);
|
|
|
+ Object amountValue = readWorkBookCell(row.getCell(AMOUNTNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, AMOUNTNUM);
|
|
|
if (!StringUtils.isEmpty(amountValue)) {
|
|
|
try {
|
|
|
Double amount = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
|
|
|
@@ -309,8 +320,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
}
|
|
|
|
|
|
// 币别
|
|
|
- Object currencyValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 4);
|
|
|
+ Object currencyValue = readWorkBookCell(row.getCell(CURRENCYNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, CURRENCYNUM);
|
|
|
if (!StringUtils.isEmpty(currencyValue)) {
|
|
|
try {
|
|
|
String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
|
|
|
@@ -321,8 +332,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
}
|
|
|
|
|
|
// 单价
|
|
|
- Object unitPriceValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 5);
|
|
|
+ Object unitPriceValue = readWorkBookCell(row.getCell(UNITPRICENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, UNITPRICENUM);
|
|
|
if (!StringUtils.isEmpty(unitPriceValue)) {
|
|
|
try {
|
|
|
Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
|
|
|
@@ -340,8 +351,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
}
|
|
|
|
|
|
// 封装
|
|
|
- Object encapsulationValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 6);
|
|
|
+ Object encapsulationValue = readWorkBookCell(row.getCell(ENCAPSULATIONNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, ENCAPSULATIONNUM);
|
|
|
if (!StringUtils.isEmpty(encapsulationValue)) {
|
|
|
try {
|
|
|
String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
|
|
|
@@ -354,8 +365,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
|
|
|
|
|
|
// 生产日期
|
|
|
- Object produceDateValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
|
|
|
- rowNum, 7);
|
|
|
+ Object produceDateValue = readWorkBookCell(row.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, PRODUCEDATENUM);
|
|
|
if (!StringUtils.isEmpty(produceDateValue)) {
|
|
|
try {
|
|
|
String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
|
|
|
@@ -365,9 +376,53 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
seekPurchaseByBatch.setProduceDate(null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 规格
|
|
|
+ Object specValue = readWorkBookCell(row.getCell(SPECNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, SPECNUM);
|
|
|
+ if (!StringUtils.isEmpty(specValue)) {
|
|
|
+ try {
|
|
|
+ String spec = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(specValue));
|
|
|
+ spec = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(spec, 50);
|
|
|
+ if (!match(spec)) {
|
|
|
+ spec = null;
|
|
|
+ }
|
|
|
+ seekPurchaseByBatch.setSpec(spec);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setSpec(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 类目
|
|
|
+ Object kindValue = readWorkBookCell(row.getCell(KINDNUM), Cell.CELL_TYPE_STRING,
|
|
|
+ rowNum, KINDNUM);
|
|
|
+ if (!StringUtils.isEmpty(kindValue)) {
|
|
|
+ try {
|
|
|
+ String kind = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(kindValue));
|
|
|
+ kind = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(kind, 20);
|
|
|
+ seekPurchaseByBatch.setKind(kind);
|
|
|
+ } catch (Exception e) {
|
|
|
+ seekPurchaseByBatch.setKind(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断输入是否合法
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean match(String code) {
|
|
|
+ List<String> filterList = Arrays.asList("空", "没", "无", "—", "-", "null", "#N/A");
|
|
|
+ for (String s : filterList) {
|
|
|
+ if (s.equals(code)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 读取excel
|
|
|
* @return
|
|
|
@@ -464,9 +519,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
SeekPurchase seekPurchase = new SeekPurchase();
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
now.add(Calendar.DAY_OF_MONTH, 91);
|
|
|
- //Date deadlineMax = DateUtils.addTime(new Date(System.currentTimeMillis()), 90, 23, 59 ,59);
|
|
|
if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand()) && !StringUtils.isEmpty(batch.getDeadline()) && batch.getDeadline().compareTo(now.getTime()) != 1) {
|
|
|
- //seekPurchase = (SeekPurchase) batch;
|
|
|
PurcInquiryItem inquiryItem = new PurcInquiryItem();
|
|
|
inquiryItem.setProdTitle(batch.getCode());
|
|
|
inquiryItem.setUserUU(user.getUserUU());
|
|
|
@@ -481,6 +534,8 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
|
|
|
inquiryItem.setProduceDate(batch.getProduceDate());
|
|
|
inquiryItem.setDate(new Date());
|
|
|
inquiryItem.setEndDate(batch.getDeadline());
|
|
|
+ inquiryItem.setProdTitle(batch.getKind());
|
|
|
+ inquiryItem.setSpec(batch.getSpec());
|
|
|
if (StringUtils.isEmpty(endDate)) {
|
|
|
endDate = batch.getDeadline();
|
|
|
} else {
|