导入

来源:互联网 发布:国产更美网络剧 编辑:程序博客网 时间:2024/04/28 03:26
public String lead(File file, String fileFileName,String operatorCode) {      //导入
String str = "";
int x = 0;
int y = 0;
int z = 0;
try {
BlackList blackList = null;
// 在这里默认excel有表头数据,其实就是list第一行,所以i从1开始
if (fileFileName.contains("xls") || fileFileName.contains("xlsx")) {
List<List<Object>> list = ExcelReader.readExcel(file,fileFileName);
if (list != null && list.size() > 1) {
for (int i = 0; i < list.size(); i++) {
blackList = new BlackList();
if(list.get(i).size()==0){
continue;
}
else{
Pattern pattern = Pattern.compile("^1[3|4|5|7|8][0-9]\\d{8}$");
Matcher matcher = pattern.matcher(list.get(i).get(0).toString().trim());
if(!matcher.matches()){
x++;
continue;
}
else{
List p = findByMobile(list.get(i).get(0).toString().trim());
if(p.size()>0){
y++;
continue;
}else{
// 通过 (String)list.get(i).get(0),(String)list.get(i).get(1)这种方式获取相应的值
// 并新建对象,把数据持久化到数据库中
blackList.setMobile(list.get(i).get(0).toString().trim());
if(list.get(i).size()==1){
blackList.setDescription("");
}else{
if(list.get(i).get(1).toString().trim().length()>40){
blackList.setDescription(list.get(i).get(1).toString().trim().substring(0,40));
}else{
blackList.setDescription(list.get(i).get(1).toString().trim());
}
}
addBlackList(blackList,operatorCode);
List n = findBlackListByMobile2(list.get(i).get(0).toString().trim());
if(n.size()>0){
updateImei_Imsi(blackList.getMobile(), operatorCode);
}
z++;
}
}
}
}
}
}
if (fileFileName.contains("txt")) {
List<Object> list = readtxt(file);
if (list != null) {
for (int i = 0; i < list.size(); i++) {
// for (int j = 0; j < list.get(i).size(); j++) {
blackList = new BlackList();
Pattern pattern = Pattern.compile("^1[3|4|5|7|8][0-9]\\d{8}$");
Matcher matcher = pattern.matcher(list.get(i).toString().trim());
if(!matcher.matches()){
x++;
continue;
}
else{
List p = findByMobile(list.get(i).toString().trim());
if(p.size()>0){
y++;
continue;
}else{
blackList.setMobile(list.get(i).toString().trim());
blackList.setDescription("");
addBlackList(blackList,operatorCode);
List n = findBlackListByMobile2(list.get(i).toString().trim());
if(n.size()>0){
updateImei_Imsi(blackList.getMobile(), operatorCode);
}
z++;
}
}
}
}
}
// }
} catch (IOException e) {
e.printStackTrace();
}
str = "导入成功"+z+"条,有"+x+"条格式错误,共有"+y+"条重复.";
return str;
}
0 0
原创粉丝点击