|
@@ -140,10 +140,11 @@ public class ExcelUtil {
|
|
|
|
|
|
/**
|
|
|
* 读取Excel内容 -- 行数是否超过100,超过false 不超过true;
|
|
|
+ *
|
|
|
* @param filePath
|
|
|
* @return
|
|
|
*/
|
|
|
- public static boolean readExcelNumber(String filePath,Integer maxNuber) throws IOException {
|
|
|
+ public static boolean readExcelNumber(String filePath, Integer maxNuber) throws IOException {
|
|
|
// 判断文件是否存在
|
|
|
File file = new File(filePath);
|
|
|
if (!file.exists()) {
|
|
@@ -180,15 +181,15 @@ public class ExcelUtil {
|
|
|
}
|
|
|
|
|
|
if (cellValue != null && !"".equals(cellValue)) {
|
|
|
- number ++;
|
|
|
+ number++;
|
|
|
}
|
|
|
i++;
|
|
|
|
|
|
- if(number > maxNuber+1){
|
|
|
+ if (number > maxNuber + 1) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(i > maxNuber+1){
|
|
|
+ if (i > maxNuber + 1) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -226,7 +227,7 @@ public class ExcelUtil {
|
|
|
Cell cell = null;
|
|
|
cell = rows.getCell(1);//列
|
|
|
String bomName = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
bomName = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -234,7 +235,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(2);// 获取行
|
|
|
cell = rows.getCell(1);//列
|
|
|
String produceName = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
produceName = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -242,7 +243,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(3);// 获取行
|
|
|
cell = rows.getCell(1);//列
|
|
|
String bomVersion = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
bomVersion = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -250,7 +251,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(4);// 获取行
|
|
|
cell = rows.getCell(1);//列
|
|
|
String machineVersionNo = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
machineVersionNo = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -258,7 +259,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(5);// 获取行
|
|
|
cell = rows.getCell(1);//列
|
|
|
String bomRemarks = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
bomRemarks = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -267,24 +268,24 @@ public class ExcelUtil {
|
|
|
int i = 0;
|
|
|
while (rowss.hasNext()) {
|
|
|
Row ro = rowss.next();
|
|
|
- if(i>7){
|
|
|
+ if (i > 7) {
|
|
|
Iterator<Cell> cells = ro.cellIterator();
|
|
|
- if(ro == null){
|
|
|
+ if (ro == null) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- int j=0;
|
|
|
+ int j = 0;
|
|
|
PtsBomComponents bomComponents = new PtsBomComponents();
|
|
|
String componentsNo = "";
|
|
|
String bomComponentsQuantity = "";
|
|
|
while (cells.hasNext()) {
|
|
|
Cell ce = cells.next();
|
|
|
- if (ce == null){
|
|
|
+ if (ce == null) {
|
|
|
break;
|
|
|
}
|
|
|
- if(j == 0){
|
|
|
+ if (j == 0) {
|
|
|
componentsNo = ce.getStringCellValue();
|
|
|
- }else if(j == 1){
|
|
|
+ } else if (j == 1) {
|
|
|
bomComponentsQuantity = ce.getStringCellValue();
|
|
|
}
|
|
|
j++;
|
|
@@ -296,20 +297,17 @@ public class ExcelUtil {
|
|
|
i++;
|
|
|
}
|
|
|
|
|
|
- Map<String,Object> map = new HashMap<String, Object>();
|
|
|
- map.put("bomName",bomName);
|
|
|
- map.put("produceName",produceName);
|
|
|
- map.put("bomVersion",bomVersion);
|
|
|
- map.put("machineVersionNo",machineVersionNo);
|
|
|
- map.put("bomRemarks",bomRemarks);
|
|
|
- map.put("componentsList",componentsList);
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("bomName", bomName);
|
|
|
+ map.put("produceName", produceName);
|
|
|
+ map.put("bomVersion", bomVersion);
|
|
|
+ map.put("machineVersionNo", machineVersionNo);
|
|
|
+ map.put("bomRemarks", bomRemarks);
|
|
|
+ map.put("componentsList", componentsList);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 读取Excel内容
|
|
|
* 不去除重复
|
|
@@ -373,8 +371,8 @@ public class ExcelUtil {
|
|
|
|
|
|
|
|
|
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, Integer selfOperated)
|
|
|
throws IOException {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
for (String t : maps) {
|
|
@@ -471,7 +469,7 @@ public class ExcelUtil {
|
|
|
while (rows.hasNext()) {
|
|
|
Row temp = rows.next();
|
|
|
try {
|
|
|
- if(errorNum > 5){
|
|
|
+ if (errorNum > 5) {
|
|
|
break;
|
|
|
}
|
|
|
EfastOrder order = new EfastOrder();
|
|
@@ -485,41 +483,41 @@ public class ExcelUtil {
|
|
|
String userTel = String.valueOf(getExcelCell(telCell));
|
|
|
// 读取对应的产品id
|
|
|
String OrderProductBarCodeValue = map.get(getValue(temp.getCell(productColumnIndex)).trim());
|
|
|
- if(StringUtils.isEmpty(nameValue)){
|
|
|
- errorNum ++;
|
|
|
+ if (StringUtils.isEmpty(nameValue)) {
|
|
|
+ errorNum++;
|
|
|
order.setReturnStatus("error");
|
|
|
- order.setReturnMsg("姓名为空-交易号:"+platformOrderIdValue);
|
|
|
+ order.setReturnMsg("姓名为空-交易号:" + platformOrderIdValue);
|
|
|
order.setPlatformOrderId("1");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(userTel) ){
|
|
|
- errorNum ++;
|
|
|
+ if (StringUtils.isEmpty(userTel)) {
|
|
|
+ errorNum++;
|
|
|
order.setReturnStatus("error");
|
|
|
- order.setReturnMsg("手机号码为空-交易号:"+platformOrderIdValue);
|
|
|
+ order.setReturnMsg("手机号码为空-交易号:" + platformOrderIdValue);
|
|
|
order.setPlatformOrderId("1");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(OrderProductBarCodeValue)){
|
|
|
- errorNum ++;
|
|
|
+ if (StringUtils.isEmpty(OrderProductBarCodeValue)) {
|
|
|
+ errorNum++;
|
|
|
order.setReturnStatus("error");
|
|
|
- order.setReturnMsg("交易号出错-交易号:"+platformOrderIdValue);
|
|
|
+ order.setReturnMsg("交易号出错-交易号:" + platformOrderIdValue);
|
|
|
order.setPlatformOrderId("1");
|
|
|
}
|
|
|
|
|
|
order.setOrderAddressName(nameValue);
|
|
|
- if(!StringUtils.isEmpty(platformOrderIdValue)){
|
|
|
+ if (!StringUtils.isEmpty(platformOrderIdValue)) {
|
|
|
|
|
|
// if (!ValidateUtil.checkString(platformOrderIdValue.trim())) {
|
|
|
// order.setReturnStatus("error");
|
|
|
// order.setReturnMsg("交易号出错-交易号:"+platformOrderIdValue);
|
|
|
// order.setPlatformOrderId("1");
|
|
|
// }else{
|
|
|
- Integer flag = salesOrderService.getOrderBySalesDealCodeNum(platformOrderIdValue.trim());
|
|
|
- if(flag > 0){
|
|
|
- order.setReturnStatus("error");
|
|
|
- order.setReturnMsg("交易号重复");
|
|
|
- }
|
|
|
- order.setPlatformOrderId(platformOrderIdValue.trim());
|
|
|
+ Integer flag = salesOrderService.getOrderBySalesDealCodeNum(platformOrderIdValue.trim());
|
|
|
+ if (flag > 0) {
|
|
|
+ order.setReturnStatus("error");
|
|
|
+ order.setReturnMsg("交易号重复");
|
|
|
+ }
|
|
|
+ order.setPlatformOrderId(platformOrderIdValue.trim());
|
|
|
// }
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
order.setReturnStatus("error");
|
|
|
order.setReturnMsg("订单交易号不正确");
|
|
|
order.setPlatformOrderId("1");
|
|
@@ -537,15 +535,15 @@ public class ExcelUtil {
|
|
|
order.setOrderProductBarCode(OrderProductBarCodeValue);
|
|
|
String orderNum = getValue(temp.getCell(numColumnIndex)).trim();
|
|
|
String orderRemark = getValue(temp.getCell(remarkColumnIndex));
|
|
|
- if(orderNum != null && !"".equals(orderNum)){
|
|
|
- orderNum = orderNum.replaceAll("\\r|\\r|\\n","");
|
|
|
+ if (orderNum != null && !"".equals(orderNum)) {
|
|
|
+ orderNum = orderNum.replaceAll("\\r|\\r|\\n", "");
|
|
|
}
|
|
|
- if(orderNum == null || "".equals(orderNum) || Integer.valueOf(orderNum) == 0){
|
|
|
+ if (orderNum == null || "".equals(orderNum) || Integer.valueOf(orderNum) == 0) {
|
|
|
order.setReturnStatus("error");
|
|
|
order.setReturnMsg("数量不正确");
|
|
|
// 读取购买数量
|
|
|
order.setOrderNum(0);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
// 读取购买数量
|
|
|
order.setOrderNum(Integer.valueOf(orderNum));
|
|
|
orderNumByInt = Integer.valueOf(orderNum);
|
|
@@ -553,35 +551,35 @@ public class ExcelUtil {
|
|
|
order.setOrderRemark(orderRemark);
|
|
|
|
|
|
String colorDiscount = "0";
|
|
|
- if(selfOperated == 1){
|
|
|
+ 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)) {
|
|
|
+ colorDiscount = colorDiscount.replaceAll("\\r|\\r|\\n", "");
|
|
|
}
|
|
|
- if(colorDiscount == null || "".equals(colorDiscount)){
|
|
|
+ if (colorDiscount == null || "".equals(colorDiscount)) {
|
|
|
order.setReturnStatus("error");
|
|
|
order.setReturnMsg("价格不正确");
|
|
|
// 读取购买数量
|
|
|
order.setOrderProductDiscount(0);
|
|
|
order.setOrderProductPrice(0);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
// 读取购买数量
|
|
|
Double colorDiscountDou = Double.valueOf(colorDiscount);
|
|
|
- colorDiscountDou = colorDiscountDou*100/orderNumByInt;
|
|
|
+ colorDiscountDou = colorDiscountDou * 100 / orderNumByInt;
|
|
|
order.setOrderProductDiscount(colorDiscountDou.intValue());
|
|
|
order.setOrderProductPrice(colorDiscountDou.intValue());
|
|
|
Double orderTotal = Double.valueOf(colorDiscount);
|
|
|
- orderTotal = orderTotal*100;
|
|
|
+ orderTotal = orderTotal * 100;
|
|
|
order.setOrderTotal(orderTotal.intValue());
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
order.setOrderProductDiscount(0);
|
|
|
order.setOrderProductPrice(0);
|
|
|
order.setOrderTotal(0);
|
|
|
}
|
|
|
|
|
|
- try{
|
|
|
- if (infoColumnIndex.length == 1){
|
|
|
+ try {
|
|
|
+ if (infoColumnIndex.length == 1) {
|
|
|
// 如果infoColumnIndex = 1, 则表示需要截取(可能是-、“ ”)
|
|
|
Cell cell = temp.getCell(infoColumnIndex[0]);
|
|
|
String addrInfo = getValue(cell);
|
|
@@ -618,7 +616,7 @@ public class ExcelUtil {
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
order.setReturnStatus("error");
|
|
|
order.setReturnMsg("地址错误");
|
|
|
order.setPlatformOrderId("1");
|
|
@@ -632,22 +630,22 @@ public class ExcelUtil {
|
|
|
order.setOrderProductName(price.get(order.getOrderProductBarCode()).getColorName());
|
|
|
order.setOrderId(OrderNoUtil.createOrderCode(Math.abs(new Random().nextInt(1000))));
|
|
|
|
|
|
- if(isOtherStore == 2){
|
|
|
+ if (isOtherStore == 2) {
|
|
|
// 读取店铺
|
|
|
String storeValue = getValue(temp.getCell(orderStoreInfoStColumnIndex)).trim();
|
|
|
- for (int k=0;k<storeArray.length;k++){
|
|
|
- String[] stores = storeArray[k].split("_");
|
|
|
- if(stores[0].trim().equals(storeValue.trim())){
|
|
|
- //店铺
|
|
|
- order.setStoreId(Integer.valueOf(stores[1]));
|
|
|
- }
|
|
|
+ for (int k = 0; k < storeArray.length; k++) {
|
|
|
+ String[] stores = storeArray[k].split("_");
|
|
|
+ if (stores[0].trim().equals(storeValue.trim())) {
|
|
|
+ //店铺
|
|
|
+ order.setStoreId(Integer.valueOf(stores[1]));
|
|
|
+ }
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//店铺
|
|
|
order.setStoreId(Integer.valueOf(storeArray[0]));
|
|
|
}
|
|
|
order.setOid(oid);
|
|
|
- try{
|
|
|
+ try {
|
|
|
if (postType.equals("ems")) {
|
|
|
if (order.getOrderProvince().contains("广东")) {
|
|
|
order.setOrderPostType("ems");
|
|
@@ -657,7 +655,7 @@ public class ExcelUtil {
|
|
|
} else {
|
|
|
order.setOrderPostType(postType);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
order.setOrderPostType("ems");
|
|
|
e.printStackTrace();
|
|
|
logger.info("匹配快递公司失败");
|
|
@@ -666,7 +664,7 @@ public class ExcelUtil {
|
|
|
orderEfasts.add(order);
|
|
|
} catch (Exception e) {
|
|
|
row.getCell(0).setCellStyle(cellStyle);
|
|
|
- errorNum ++;
|
|
|
+ errorNum++;
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
// 迭代
|
|
@@ -714,8 +712,8 @@ public class ExcelUtil {
|
|
|
Iterator<Cell> cells = row.cellIterator();
|
|
|
while (cells.hasNext()) {
|
|
|
Cell cell = cells.next();
|
|
|
- cellNum = cell.getColumnIndex();
|
|
|
- break;
|
|
|
+ cellNum = cell.getColumnIndex();
|
|
|
+ break;
|
|
|
}
|
|
|
if (cellNum == -1) return null;
|
|
|
|
|
@@ -741,11 +739,12 @@ public class ExcelUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *获取值
|
|
|
+ * 获取值
|
|
|
+ *
|
|
|
* @param cell
|
|
|
* @return
|
|
|
*/
|
|
|
- private static Object getExcelCell(Cell cell){
|
|
|
+ private static Object getExcelCell(Cell cell) {
|
|
|
Object obj;
|
|
|
if (null != cell) {
|
|
|
switch (cell.getCellType()) {
|
|
@@ -854,7 +853,7 @@ public class ExcelUtil {
|
|
|
return new String[]{addrs[0].trim(), addrs[1].trim(), addrs[2].trim(), address};
|
|
|
}
|
|
|
} else if (addrs != null && addrs.length > 4) {
|
|
|
- String start = addrs[0].trim() + splitCharTemp + addrs[1].trim() + splitCharTemp + addrs[2].trim() + splitCharTemp;
|
|
|
+ String start = addrs[0].trim() + splitCharTemp + addrs[1].trim() + splitCharTemp + addrs[2].trim() + splitCharTemp;
|
|
|
String addressInfo = addrInfo.substring(start.length(), addrInfo.length());
|
|
|
return new String[]{addrs[0].trim(), addrs[1].trim(), addrs[2].trim(), addressInfo};
|
|
|
}
|
|
@@ -943,6 +942,7 @@ public class ExcelUtil {
|
|
|
|
|
|
/**
|
|
|
* excel 强制获取text文本
|
|
|
+ *
|
|
|
* @param cell
|
|
|
* @return
|
|
|
*/
|
|
@@ -951,4 +951,81 @@ public class ExcelUtil {
|
|
|
return cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
|
+ //获取俩个日期内所有月份
|
|
|
+ public static List<String> month(Date startDate, Date endDate) {
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ try {
|
|
|
+ /*Date startDate = new SimpleDateFormat("yyyy-MM").parse(y1);
|
|
|
+ Date endDate = new SimpleDateFormat("yyyy-MM").parse(y2);*/
|
|
|
+
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ if (startDate == null) {
|
|
|
+ startDate = new SimpleDateFormat("yyyy-MM").parse("2018-02");
|
|
|
+ }
|
|
|
+ calendar.setTime(startDate);
|
|
|
+ // 获取开始年份和开始月份
|
|
|
+ int startYear = calendar.get(Calendar.YEAR);
|
|
|
+ int startMonth = calendar.get(Calendar.MONTH);
|
|
|
+ // 获取结束年份和结束月份
|
|
|
+ if (endDate == null) {
|
|
|
+ calendar.setTime(new Date());
|
|
|
+ } else {
|
|
|
+ calendar.setTime(endDate);
|
|
|
+ }
|
|
|
+ int endYear = calendar.get(Calendar.YEAR);
|
|
|
+ int endMonth = calendar.get(Calendar.MONTH);
|
|
|
+ //
|
|
|
+
|
|
|
+ for (int i = startYear; i <= endYear; i++) {
|
|
|
+ String date = "";
|
|
|
+ if (startYear == endYear) {
|
|
|
+ for (int j = startMonth; j <= endMonth; j++) {
|
|
|
+ if (j < 9) {
|
|
|
+ date = i + "-0" + (j + 1);
|
|
|
+ } else {
|
|
|
+ date = i + "-" + (j + 1);
|
|
|
+ }
|
|
|
+ list.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (i == startYear) {
|
|
|
+ for (int j = startMonth; j < 12; j++) {
|
|
|
+ if (j < 9) {
|
|
|
+ date = i + "-0" + (j + 1);
|
|
|
+ } else {
|
|
|
+ date = i + "-" + (j + 1);
|
|
|
+ }
|
|
|
+ list.add(date);
|
|
|
+ }
|
|
|
+ } else if (i == endYear) {
|
|
|
+ for (int j = 0; j <= endMonth; j++) {
|
|
|
+ if (j < 9) {
|
|
|
+ date = i + "-0" + (j + 1);
|
|
|
+ } else {
|
|
|
+ date = i + "-" + (j + 1);
|
|
|
+ }
|
|
|
+ list.add(date);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (int j = 0; j < 12; j++) {
|
|
|
+ if (j < 9) {
|
|
|
+ date = i + "-0" + (j + 1);
|
|
|
+ } else {
|
|
|
+ date = i + "-" + (j + 1);
|
|
|
+ }
|
|
|
+ list.add(date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|