GoodsDataFileParser.java
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.taover.bazhuayun.analysis.script.goodscollect;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.taover.bazhuayun.analysis.util.ExcelUtil;
public class GoodsDataFileParser {
private String fileNameIgnorePreffix;
private StringBuffer logStrBuffer = new StringBuffer();
private Set<GoodsInfoRow> rowSet = new HashSet<GoodsInfoRow>();
private String[] goodsNamePatternArr;
private String[] goodsSkuNameParrternArr;
private GroupInfoExcelData groupInfoData;
public GoodsDataFileParser(String[] goodsNamePatternArr, String[] goodsSkuNameParrternArr, GroupInfoExcelData groupInfoData) {
this.goodsNamePatternArr = goodsNamePatternArr;
this.goodsSkuNameParrternArr = goodsSkuNameParrternArr;
this.groupInfoData = groupInfoData;
}
public void setFileNameIgnorePreffix(String preffix) {
this.fileNameIgnorePreffix = preffix;
}
public void parse(GroupInfoExcelData groupInfoData, File[] listFiles) throws Exception {
for(int i=0; i<listFiles.length; ++i) {
File item = listFiles[i];
//获取发件组/发件人
String fileName = item.getName().replaceFirst(this.fileNameIgnorePreffix, "");
GroupInfoExcelDataRow groupInfo = this.groupInfoData.findByFileName(fileName);
//读取Excel文件
List<List<Object>> data = ExcelUtil.readExcelSheet(item, false);
if(data.isEmpty()) {
continue;
}
//写入set
GoodsInfoExcelDataHeader header = new GoodsInfoExcelDataHeader(this.goodsNamePatternArr, this.goodsSkuNameParrternArr, data.get(0));
for(int j=1; j<data.size(); ++j) {
this.rowSet.add(new GoodsInfoRow(groupInfo, header, data.get(j)));
}
}
}
public List<GoodsInfoRow> getResult() {
List<GoodsInfoRow> data = new ArrayList<GoodsInfoRow>();
Iterator<GoodsInfoRow> rowIter = this.rowSet.iterator();
while(rowIter.hasNext()) {
data.add(rowIter.next());
}
Collections.sort(data);
return data;
}
public String getLogString() {
return logStrBuffer.toString();
}
}