|
@@ -149,10 +149,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()) {
|
|
@@ -189,15 +190,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;
|
|
|
}
|
|
|
}
|
|
@@ -235,7 +236,7 @@ public class ExcelUtil {
|
|
|
Cell cell = null;
|
|
|
cell = rows.getCell(1);
|
|
|
String bomName = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
bomName = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -243,7 +244,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(2);
|
|
|
cell = rows.getCell(1);
|
|
|
String produceName = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
produceName = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -251,7 +252,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(3);
|
|
|
cell = rows.getCell(1);
|
|
|
String bomVersion = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
bomVersion = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -259,7 +260,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(4);
|
|
|
cell = rows.getCell(1);
|
|
|
String machineVersionNo = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
machineVersionNo = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -267,7 +268,7 @@ public class ExcelUtil {
|
|
|
rows = sheet.getRow(5);
|
|
|
cell = rows.getCell(1);
|
|
|
String bomRemarks = "";
|
|
|
- if(cell != null){
|
|
|
+ if (cell != null) {
|
|
|
bomRemarks = cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
@@ -276,24 +277,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++;
|
|
@@ -305,20 +306,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内容
|
|
|
* 不去除重复
|
|
@@ -480,7 +478,7 @@ public class ExcelUtil {
|
|
|
while (rows.hasNext()) {
|
|
|
Row temp = rows.next();
|
|
|
try {
|
|
|
- if(errorNum > 5){
|
|
|
+ if (errorNum > 5) {
|
|
|
break;
|
|
|
}
|
|
|
EfastOrder order = new EfastOrder();
|
|
@@ -494,41 +492,41 @@ public class ExcelUtil {
|
|
|
String userTel = String.valueOf(getExcelCell(telCell));
|
|
|
|
|
|
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)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- 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");
|
|
@@ -546,23 +544,51 @@ 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);
|
|
|
}
|
|
|
order.setOrderRemark(orderRemark);
|
|
|
|
|
|
- try{
|
|
|
- if (infoColumnIndex.length == 1){
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (infoColumnIndex.length == 1) {
|
|
|
|
|
|
Cell cell = temp.getCell(infoColumnIndex[0]);
|
|
|
String addrInfo = getValue(cell);
|
|
@@ -599,7 +625,7 @@ public class ExcelUtil {
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
order.setReturnStatus("error");
|
|
|
order.setReturnMsg("地址错误");
|
|
|
order.setPlatformOrderId("1");
|
|
@@ -613,17 +639,17 @@ 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]));
|
|
|
}
|
|
@@ -714,7 +740,7 @@ public class ExcelUtil {
|
|
|
}
|
|
|
|
|
|
order.setOid(oid);
|
|
|
- try{
|
|
|
+ try {
|
|
|
if (postType.equals("ems")) {
|
|
|
if (order.getOrderProvince().contains("广东")) {
|
|
|
order.setOrderPostType("ems");
|
|
@@ -724,7 +750,7 @@ public class ExcelUtil {
|
|
|
} else {
|
|
|
order.setOrderPostType(postType);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
order.setOrderPostType("ems");
|
|
|
e.printStackTrace();
|
|
|
logger.info("匹配快递公司失败");
|
|
@@ -733,7 +759,7 @@ public class ExcelUtil {
|
|
|
orderEfasts.add(order);
|
|
|
} catch (Exception e) {
|
|
|
row.getCell(0).setCellStyle(cellStyle);
|
|
|
- errorNum ++;
|
|
|
+ errorNum++;
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
|
|
@@ -781,8 +807,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;
|
|
|
|
|
@@ -808,11 +834,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()) {
|
|
@@ -921,7 +948,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};
|
|
|
}
|
|
@@ -1010,6 +1037,7 @@ public class ExcelUtil {
|
|
|
|
|
|
|
|
|
* excel 强制获取text文本
|
|
|
+ *
|
|
|
* @param cell
|
|
|
* @return
|
|
|
*/
|
|
@@ -1018,4 +1046,81 @@ public class ExcelUtil {
|
|
|
return cell.getStringCellValue();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static List<String> month(Date startDate, Date endDate) {
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ try {
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|