|
@@ -1,6 +1,7 @@
|
|
|
package com.steerinfo.ems.emsgmpcjh.service.impl;
|
|
|
|
|
|
import com.steerinfo.ems.Utils.ExcelToolUtils;
|
|
|
+import com.steerinfo.ems.Utils.MarketSlmException;
|
|
|
import com.steerinfo.ems.emsgmpcjh.mapper.EmsGmPcJhMapper;
|
|
|
import com.steerinfo.ems.emsgmpcjh.model.EmsGmPcJh;
|
|
|
import com.steerinfo.ems.emsgmpcjh.service.IEmsGmPcJhService;
|
|
@@ -19,6 +20,7 @@ import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* EmsGmPcJh服务实现:
|
|
@@ -93,7 +95,6 @@ public class EmsGmPcJhServiceImpl extends BaseServiceImpl<EmsGmPcJh, String> imp
|
|
|
rs.setMessage("导入失败");
|
|
|
rs.setCode("500");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -124,8 +125,8 @@ public class EmsGmPcJhServiceImpl extends BaseServiceImpl<EmsGmPcJh, String> imp
|
|
|
List<String[]> list = ExcelToolUtils.parseExcel(is, fileName, 0);
|
|
|
|
|
|
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
String name = fileName.substring(2, 4);
|
|
|
-
|
|
|
for (int i = 1; i < list.size(); i++) {
|
|
|
String[] arr = list.get(i);
|
|
|
String[] arr1 = list.get(0);
|
|
@@ -144,8 +145,12 @@ public class EmsGmPcJhServiceImpl extends BaseServiceImpl<EmsGmPcJh, String> imp
|
|
|
//AT2006 = "G-G2-";
|
|
|
//AT2004 = "G-L1-";
|
|
|
//AT2007 = "G-X1-";
|
|
|
- if(arr[0].length()>8){
|
|
|
- throw new Exception("排产日期(编号)有误");
|
|
|
+ //Pattern pattern = Pattern.compile("^-?[0-9]+"); //这个也行
|
|
|
+ //Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");//这个也行
|
|
|
+ //正整数
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
+ if(arr[0].length()>8 || !pattern.matcher(arr[0]).matches()){
|
|
|
+ throw new MarketSlmException(500,"排产日期(编号)有误!");
|
|
|
}
|
|
|
StringBuffer s=new StringBuffer(arr[0]).insert(4,"-").insert(7,"-");
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
@@ -186,31 +191,37 @@ public class EmsGmPcJhServiceImpl extends BaseServiceImpl<EmsGmPcJh, String> imp
|
|
|
spp.setUnitid("008");
|
|
|
for(int j =1;j<arr1.length;j++) {
|
|
|
switch (arr1[j].trim()) {
|
|
|
- case "规格":
|
|
|
+ case "规格" :
|
|
|
spp.setSpecifications(arr[j].replace("*", "x"));
|
|
|
break;
|
|
|
- case "钢种":
|
|
|
+ case "钢种" :
|
|
|
spp.setGrades(arr[j]);
|
|
|
break;
|
|
|
- case "长度":
|
|
|
+ case "长度" :
|
|
|
spp.setLengths(new BigDecimal(arr[j]));
|
|
|
break;
|
|
|
- case "运输方式":
|
|
|
+ case "运输方式" :
|
|
|
spp.setTransportType(arr[j]);
|
|
|
break;
|
|
|
- case "用途":
|
|
|
+ case "用途" :
|
|
|
spp.setPurpose(arr[j]);
|
|
|
- case "订单量":
|
|
|
+ break;
|
|
|
+ case "订单量" :
|
|
|
+ if(!pattern.matcher(arr[j]).matches()){
|
|
|
+ throw new MarketSlmException(500,"订单量有误,请仔细检查");
|
|
|
+ }
|
|
|
spp.setKxfWeight(new BigDecimal(arr[j]));
|
|
|
spp.setPlanWeight(new BigDecimal(arr[j]));
|
|
|
break;
|
|
|
- case "交货日期":
|
|
|
+ case "交货日期" :
|
|
|
+ spp.setDeliveryDate(simpleDateFormat.parse(arr[j]));
|
|
|
break;
|
|
|
- case "备注":
|
|
|
+ case "备注" :
|
|
|
spp.setMemo(arr[j]);
|
|
|
break;
|
|
|
+ case "分厂" : continue;
|
|
|
default:
|
|
|
- throw new Exception("请选择模板文件");
|
|
|
+ throw new MarketSlmException(500,"模板文件存在模板外的列,请仔细检查!!");
|
|
|
}
|
|
|
}
|
|
|
//spp.setSteelCode(steel);
|
|
@@ -357,6 +368,9 @@ public class EmsGmPcJhServiceImpl extends BaseServiceImpl<EmsGmPcJh, String> imp
|
|
|
//}
|
|
|
lists.add(spp);
|
|
|
}
|
|
|
+ } catch (Exception e){
|
|
|
+ throw new MarketSlmException (500,"导入失败,请检查文档中是否有错误数据。");
|
|
|
+ }
|
|
|
return lists;
|
|
|
}
|
|
|
}
|