|
@@ -4,14 +4,18 @@ import com.iamberry.rst.core.order.EfastOrder;
|
|
import com.iamberry.rst.core.order.ProductColor;
|
|
import com.iamberry.rst.core.order.ProductColor;
|
|
import com.iamberry.rst.core.pts.PtsBomComponents;
|
|
import com.iamberry.rst.core.pts.PtsBomComponents;
|
|
import com.iamberry.rst.faces.cm.SalesOrderService;
|
|
import com.iamberry.rst.faces.cm.SalesOrderService;
|
|
|
|
+import com.iamberry.rst.faces.dm.DealerChannelService;
|
|
|
|
+import com.iamberry.rst.faces.dm.DealerProductService;
|
|
import com.iamberry.wechat.tools.AddrUtil;
|
|
import com.iamberry.wechat.tools.AddrUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -36,6 +40,10 @@ public class ExcelUtil {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SalesOrderService salesOrderService;
|
|
private SalesOrderService salesOrderService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DealerChannelService dealerChannelService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DealerProductService dealerProductService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 读取Excel文件头
|
|
* 读取Excel文件头
|
|
@@ -371,8 +379,8 @@ public class ExcelUtil {
|
|
|
|
|
|
|
|
|
|
public List<EfastOrder> readCell(String filePath, String productName, String[] maps,
|
|
public List<EfastOrder> readCell(String filePath, String productName, String[] maps,
|
|
- String[] infos, String tel, String name, String platformOrder, String num, String discount, String remark,
|
|
|
|
- Map<String, ProductColor> price, String postType, String orderStoreInfoSt, Integer isOtherStore, String[] storeArray, Integer selfOperated)
|
|
|
|
|
|
+ String[] infos, String tel, String name,String platformOrder, String num, String discount,String remark,
|
|
|
|
+ Map<String, ProductColor> price, String postType, String orderStoreInfoSt, Integer isOtherStore,String[] storeArray)
|
|
throws IOException {
|
|
throws IOException {
|
|
Map<String, String> map = new HashMap<>();
|
|
Map<String, String> map = new HashMap<>();
|
|
for (String t : maps) {
|
|
for (String t : maps) {
|
|
@@ -463,15 +471,22 @@ public class ExcelUtil {
|
|
cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
|
|
cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
|
|
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
|
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
|
|
|
|
|
|
|
+ EfastOrder remmendOrder = new EfastOrder();
|
|
|
|
+
|
|
// 读取数据
|
|
// 读取数据
|
|
int oid = 0;
|
|
int oid = 0;
|
|
int errorNum = 0;
|
|
int errorNum = 0;
|
|
|
|
+ int rowNum=0;
|
|
while (rows.hasNext()) {
|
|
while (rows.hasNext()) {
|
|
|
|
+ rowNum ++;
|
|
Row temp = rows.next();
|
|
Row temp = rows.next();
|
|
try {
|
|
try {
|
|
if (errorNum > 5) {
|
|
if (errorNum > 5) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ //判断当前行是否
|
|
|
|
+ Integer isRowHaveVal = 0,sonErrorNum=0;
|
|
|
|
+
|
|
EfastOrder order = new EfastOrder();
|
|
EfastOrder order = new EfastOrder();
|
|
// 读取name
|
|
// 读取name
|
|
String nameValue = getValue(temp.getCell(nameColumnIndex));
|
|
String nameValue = getValue(temp.getCell(nameColumnIndex));
|
|
@@ -484,22 +499,28 @@ public class ExcelUtil {
|
|
// 读取对应的产品id
|
|
// 读取对应的产品id
|
|
String OrderProductBarCodeValue = map.get(getValue(temp.getCell(productColumnIndex)).trim());
|
|
String OrderProductBarCodeValue = map.get(getValue(temp.getCell(productColumnIndex)).trim());
|
|
if (StringUtils.isEmpty(nameValue)) {
|
|
if (StringUtils.isEmpty(nameValue)) {
|
|
- errorNum++;
|
|
|
|
|
|
+ sonErrorNum++;
|
|
order.setReturnStatus("error");
|
|
order.setReturnStatus("error");
|
|
order.setReturnMsg("姓名为空-交易号:" + platformOrderIdValue);
|
|
order.setReturnMsg("姓名为空-交易号:" + platformOrderIdValue);
|
|
order.setPlatformOrderId("1");
|
|
order.setPlatformOrderId("1");
|
|
|
|
+ isRowHaveVal++;
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(userTel)) {
|
|
if (StringUtils.isEmpty(userTel)) {
|
|
- errorNum++;
|
|
|
|
|
|
+ sonErrorNum++;
|
|
order.setReturnStatus("error");
|
|
order.setReturnStatus("error");
|
|
order.setReturnMsg("手机号码为空-交易号:" + platformOrderIdValue);
|
|
order.setReturnMsg("手机号码为空-交易号:" + platformOrderIdValue);
|
|
order.setPlatformOrderId("1");
|
|
order.setPlatformOrderId("1");
|
|
|
|
+ isRowHaveVal++;
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(OrderProductBarCodeValue)) {
|
|
if (StringUtils.isEmpty(OrderProductBarCodeValue)) {
|
|
- errorNum++;
|
|
|
|
|
|
+ sonErrorNum++;
|
|
order.setReturnStatus("error");
|
|
order.setReturnStatus("error");
|
|
order.setReturnMsg("交易号出错-交易号:" + platformOrderIdValue);
|
|
order.setReturnMsg("交易号出错-交易号:" + platformOrderIdValue);
|
|
order.setPlatformOrderId("1");
|
|
order.setPlatformOrderId("1");
|
|
|
|
+ isRowHaveVal++;
|
|
|
|
+ }
|
|
|
|
+ if(sonErrorNum > 2){
|
|
|
|
+ errorNum ++;
|
|
}
|
|
}
|
|
|
|
|
|
order.setOrderAddressName(nameValue);
|
|
order.setOrderAddressName(nameValue);
|
|
@@ -529,6 +550,7 @@ public class ExcelUtil {
|
|
order.setReturnMsg("手机号码不正确");
|
|
order.setReturnMsg("手机号码不正确");
|
|
order.setPlatformOrderId("1");
|
|
order.setPlatformOrderId("1");
|
|
}
|
|
}
|
|
|
|
+
|
|
order.setOrderAddressTel(userTel.trim());
|
|
order.setOrderAddressTel(userTel.trim());
|
|
|
|
|
|
Integer orderNumByInt = 1; //数量
|
|
Integer orderNumByInt = 1; //数量
|
|
@@ -550,32 +572,13 @@ public class ExcelUtil {
|
|
}
|
|
}
|
|
order.setOrderRemark(orderRemark);
|
|
order.setOrderRemark(orderRemark);
|
|
|
|
|
|
- String colorDiscount = "0";
|
|
|
|
- if (selfOperated == 1) {
|
|
|
|
- colorDiscount = getValue(temp.getCell(discountColumnIndex)).trim();
|
|
|
|
- if (colorDiscount != null && !"".equals(colorDiscount)) {
|
|
|
|
- colorDiscount = colorDiscount.replaceAll("\\r|\\r|\\n", "");
|
|
|
|
- }
|
|
|
|
- if (colorDiscount == null || "".equals(colorDiscount)) {
|
|
|
|
- order.setReturnStatus("error");
|
|
|
|
- order.setReturnMsg("价格不正确");
|
|
|
|
- // 读取购买数量
|
|
|
|
- order.setOrderProductDiscount(0);
|
|
|
|
- order.setOrderProductPrice(0);
|
|
|
|
- } else {
|
|
|
|
- // 读取购买数量
|
|
|
|
- Double colorDiscountDou = Double.valueOf(colorDiscount);
|
|
|
|
- colorDiscountDou = colorDiscountDou * 100 / orderNumByInt;
|
|
|
|
- order.setOrderProductDiscount(colorDiscountDou.intValue());
|
|
|
|
- order.setOrderProductPrice(colorDiscountDou.intValue());
|
|
|
|
- Double orderTotal = Double.valueOf(colorDiscount);
|
|
|
|
- orderTotal = orderTotal * 100;
|
|
|
|
- order.setOrderTotal(orderTotal.intValue());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- order.setOrderProductDiscount(0);
|
|
|
|
- order.setOrderProductPrice(0);
|
|
|
|
- order.setOrderTotal(0);
|
|
|
|
|
|
+ if(isRowHaveVal >= 2){
|
|
|
|
+ BeanUtils.copyProperties(remmendOrder,order);
|
|
|
|
+ order.setOrderProductBarCode(OrderProductBarCodeValue);
|
|
|
|
+ order.setOrderNum(orderNumByInt);
|
|
|
|
+ order.setOrderProductName(price.get(order.getOrderProductBarCode()).getColorName());
|
|
|
|
+ orderEfasts.add(order);
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -586,14 +589,14 @@ public class ExcelUtil {
|
|
if (addrInfo == null || "".equals(addrInfo)) {
|
|
if (addrInfo == null || "".equals(addrInfo)) {
|
|
// 地址为空
|
|
// 地址为空
|
|
cell.setCellStyle(cellStyle);
|
|
cell.setCellStyle(cellStyle);
|
|
- continue;
|
|
|
|
|
|
+ throw new Exception("地址为空");
|
|
}
|
|
}
|
|
// 处理地址信息
|
|
// 处理地址信息
|
|
String[] addrs = splitAddress(addrInfo);
|
|
String[] addrs = splitAddress(addrInfo);
|
|
if (addrs == null && addrs.length < 4) {
|
|
if (addrs == null && addrs.length < 4) {
|
|
// 地址不合法
|
|
// 地址不合法
|
|
cell.setCellStyle(cellStyle);
|
|
cell.setCellStyle(cellStyle);
|
|
- continue;
|
|
|
|
|
|
+ throw new Exception("地址不合法");
|
|
}
|
|
}
|
|
order.setOrderProvince(addrs[0].trim());
|
|
order.setOrderProvince(addrs[0].trim());
|
|
order.setOrderCity(addrs[1].trim());
|
|
order.setOrderCity(addrs[1].trim());
|
|
@@ -611,12 +614,13 @@ public class ExcelUtil {
|
|
order.setOrderArea(getValue(temp.getCell(infoColumnIndex[1])).trim());
|
|
order.setOrderArea(getValue(temp.getCell(infoColumnIndex[1])).trim());
|
|
order.setOrderAddress(getValue(temp.getCell(infoColumnIndex[2])).trim());
|
|
order.setOrderAddress(getValue(temp.getCell(infoColumnIndex[2])).trim());
|
|
} else {
|
|
} else {
|
|
- for (int i : infoColumnIndex) {
|
|
|
|
- temp.getCell(infoColumnIndex[i]).setCellStyle(cellStyle);
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
|
|
+// for (int i : infoColumnIndex) {
|
|
|
|
+// temp.getCell(infoColumnIndex[i]).setCellStyle(cellStyle);
|
|
|
|
+// }
|
|
|
|
+ throw new Exception("地址错误");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
+
|
|
order.setReturnStatus("error");
|
|
order.setReturnStatus("error");
|
|
order.setReturnMsg("地址错误");
|
|
order.setReturnMsg("地址错误");
|
|
order.setPlatformOrderId("1");
|
|
order.setPlatformOrderId("1");
|
|
@@ -644,6 +648,98 @@ public class ExcelUtil {
|
|
//店铺
|
|
//店铺
|
|
order.setStoreId(Integer.valueOf(storeArray[0]));
|
|
order.setStoreId(Integer.valueOf(storeArray[0]));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //-- 获取价格 --
|
|
|
|
+ order.setOrderTotal(-1);
|
|
|
|
+ String colorDiscount = "-1";
|
|
|
|
+ colorDiscount = getValue(temp.getCell(discountColumnIndex)).trim();
|
|
|
|
+ if(colorDiscount != null && !"".equals(colorDiscount)){
|
|
|
|
+ colorDiscount = colorDiscount.replaceAll("\\r|\\r|\\n","");
|
|
|
|
+ }
|
|
|
|
+ if(colorDiscount == null || "".equals(colorDiscount)){
|
|
|
|
+ order.setReturnStatus("error");
|
|
|
|
+ order.setReturnMsg("价格不正确"+"。");
|
|
|
|
+ order.setPlatformOrderId("1");
|
|
|
|
+ }else{
|
|
|
|
+ //赋值小结
|
|
|
|
+ Double orderTotal = Double.valueOf(colorDiscount);
|
|
|
|
+ orderTotal = orderTotal*100;
|
|
|
|
+ order.setOrderTotal(orderTotal.intValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(order.getOrderTotal() < 0){
|
|
|
|
+ Map megerMap = isMergedRegion(sheet,rowNum,discountColumnIndex);
|
|
|
|
+ boolean merged = (boolean) megerMap.get("merged");
|
|
|
|
+ if(merged){
|
|
|
|
+ BeanUtils.copyProperties(remmendOrder,order);
|
|
|
|
+ order.setOrderProductBarCode(OrderProductBarCodeValue);
|
|
|
|
+ order.setOrderNum(orderNumByInt);
|
|
|
|
+ order.setOrderProductName(price.get(order.getOrderProductBarCode()).getColorName());
|
|
|
|
+ orderEfasts.add(order);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* DealerChannel dealerChannel = new DealerChannel();
|
|
|
|
+ boolean flag = true;
|
|
|
|
+ if(order.getStoreId() != null){
|
|
|
|
+ dealerChannel.setStoreId(order.getStoreId());
|
|
|
|
+ List<DealerChannel> dealerChannelList = dealerChannelService.getDealerChannelList(dealerChannel);
|
|
|
|
+ if(dealerChannelList!= null && dealerChannelList.size() > 0){
|
|
|
|
+ dealerChannel = dealerChannelList.get(0);
|
|
|
|
+ }else{
|
|
|
|
+ order.setReturnStatus("error");
|
|
|
|
+ order.setReturnMsg("订单导入失败-查询店铺对应客户信息失败,店铺ID:"+order.getStoreId()+"。");
|
|
|
|
+ order.setPlatformOrderId("1");
|
|
|
|
+ flag = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(flag){
|
|
|
|
+ if(1 == dealerChannel.getDealerSelfOperated()){
|
|
|
|
+ //是否自营 1:自营
|
|
|
|
+ }else{
|
|
|
|
+ //2:非自营
|
|
|
|
+ DealerProduct dealerProduct = new DealerProduct();
|
|
|
|
+ dealerProduct.setDealerId(dealerChannel.getDealerId());
|
|
|
|
+ dealerProduct.setColorBar(OrderProductBarCodeValue);
|
|
|
|
+ List<DealerProduct> dealerProductList = dealerProductService.getDealerProductAndStoreList(dealerProduct);
|
|
|
|
+ if(dealerProductList != null && dealerProductList.size() > 0){
|
|
|
|
+ for (DealerProduct dp:dealerProductList) {
|
|
|
|
+ if(1 == dp.getDealProdStoreArea()){
|
|
|
|
+ // 1:全部店铺
|
|
|
|
+ order.setOrderProductDiscount(dp.getDealProdPrice());
|
|
|
|
+ order.setOrderProductPrice(dp.getDealProdPrice());
|
|
|
|
+ order.setOrderTotal(dp.getDealProdPrice()*orderNumByInt);
|
|
|
|
+ }else{
|
|
|
|
+ // 2:部分店铺
|
|
|
|
+ for (DealerProductStore dps:dp.getDealerProductStoreList()) {
|
|
|
|
+ if(order.getStoreId().equals(dps.getStoreId())){
|
|
|
|
+ order.setOrderProductDiscount(dp.getDealProdPrice());
|
|
|
|
+ order.setOrderProductPrice(dp.getDealProdPrice());
|
|
|
|
+ order.setOrderTotal(dp.getDealProdPrice()*orderNumByInt);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ order.setReturnStatus("error");
|
|
|
|
+ order.setReturnMsg("订单导入-未能从该客户中获取到对应产品的信息,客户名称:"+dealerChannel.getDealerName()+",产品SKU:"+ OrderProductBarCodeValue+"。");
|
|
|
|
+ order.setPlatformOrderId("1");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ order.setReturnStatus("error");
|
|
|
|
+ order.setReturnMsg("订单导入-获取店铺ID失败,店铺ID:"+order.getStoreId()+"。");
|
|
|
|
+ order.setPlatformOrderId("1");
|
|
|
|
+ }*/
|
|
|
|
+// if(order.getOrderTotal() == null || order.getOrderTotal() < 0){
|
|
|
|
+// order.setReturnStatus("error");
|
|
|
|
+// order.setReturnMsg("订单导入-未能从该客户中获取店铺对应的产品价格,客户名称:"+dealerChannel.getDealerName()+",产品SKU:"+ OrderProductBarCodeValue+"店铺ID:"+order.getStoreId()+"。");
|
|
|
|
+// order.setPlatformOrderId("1");
|
|
|
|
+// }
|
|
|
|
+
|
|
order.setOid(oid);
|
|
order.setOid(oid);
|
|
try {
|
|
try {
|
|
if (postType.equals("ems")) {
|
|
if (postType.equals("ems")) {
|
|
@@ -660,8 +756,10 @@ public class ExcelUtil {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
logger.info("匹配快递公司失败");
|
|
logger.info("匹配快递公司失败");
|
|
}
|
|
}
|
|
|
|
+
|
|
// 保存
|
|
// 保存
|
|
orderEfasts.add(order);
|
|
orderEfasts.add(order);
|
|
|
|
+ BeanUtils.copyProperties(order,remmendOrder);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
row.getCell(0).setCellStyle(cellStyle);
|
|
row.getCell(0).setCellStyle(cellStyle);
|
|
errorNum++;
|
|
errorNum++;
|
|
@@ -678,6 +776,35 @@ public class ExcelUtil {
|
|
return orderEfasts;
|
|
return orderEfasts;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 判断这个单元格是否合并
|
|
|
|
+ * @param sheet
|
|
|
|
+ * @param row
|
|
|
|
+ * @param column
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Map isMergedRegion(Sheet sheet,int row ,int column) {
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
+ int sheetMergeCount = sheet.getNumMergedRegions();
|
|
|
|
+ for (int i = 0; i < sheetMergeCount; i++) {
|
|
|
|
+ CellRangeAddress range = sheet.getMergedRegion(i);
|
|
|
|
+ int firstColumn = range.getFirstColumn();
|
|
|
|
+ int lastColumn = range.getLastColumn();
|
|
|
|
+ int firstRow = range.getFirstRow();
|
|
|
|
+ int lastRow = range.getLastRow();
|
|
|
|
+ if (row >= firstRow && row <= lastRow) {
|
|
|
|
+ if (column >= firstColumn && column <= lastColumn) {
|
|
|
|
+ map.put("merged", true);
|
|
|
|
+ map.put("startRow", firstRow + 1);
|
|
|
|
+ map.put("endRow", lastRow + 1);
|
|
|
|
+ map.put("startCol", firstColumn + 1);
|
|
|
|
+ map.put("endCol", lastColumn + 1);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 读取Excel内容(上传excel文档)
|
|
* 读取Excel内容(上传excel文档)
|
|
@@ -929,7 +1056,7 @@ public class ExcelUtil {
|
|
if (DateUtil.isCellDateFormatted(cell)) {
|
|
if (DateUtil.isCellDateFormatted(cell)) {
|
|
return fmt.format(cell.getDateCellValue()); //日期型
|
|
return fmt.format(cell.getDateCellValue()); //日期型
|
|
}
|
|
}
|
|
- DecimalFormat df = new DecimalFormat("#");
|
|
|
|
|
|
+ DecimalFormat df = new DecimalFormat("#.##");
|
|
return df.format(new Double(cell.getNumericCellValue())); //数字
|
|
return df.format(new Double(cell.getNumericCellValue())); //数字
|
|
case Cell.CELL_TYPE_BOOLEAN: //布尔型
|
|
case Cell.CELL_TYPE_BOOLEAN: //布尔型
|
|
return String.valueOf(cell.getBooleanCellValue());
|
|
return String.valueOf(cell.getBooleanCellValue());
|