package org.yeshi.utils.wx;
|
|
import java.io.BufferedReader;
|
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import org.yeshi.utils.entity.wx.RedPackRecord;
|
|
public class WXRedPackUtil {
|
|
public static List<RedPackRecord> readCsv(InputStream inStream) throws Exception {
|
List<RedPackRecord> list = new ArrayList<RedPackRecord>();
|
RedPackRecord record = null;
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "GBK"));
|
// 换成你的文件名
|
// BufferedReader reader=new BufferedReader(new InputStreamReader(new
|
// FileInputStream(path),"GBK"));
|
|
String line = null;
|
// 第一行信息,为标题信息,不用,如果需要,注释掉
|
reader.readLine();
|
|
while ((line = reader.readLine()) != null) {
|
// CSV格式文件为逗号分隔符文件,这里根据逗号切分
|
String item[] = line.split(",");
|
// 用户openid
|
String openId = getValue(item, 3);
|
if (openId == null || openId.trim().length() == 0)
|
break;
|
|
record = new RedPackRecord();
|
record.setOpenId(openId);
|
record.setSendTime(getCsvDate(getValue(item, 0))); // 发送时间
|
record.setDetailno(getValue(item, 10)); // 红包订单号
|
record.setBillno(getValue(item, 11)); // 商户订单号
|
|
String status = getValue(item, 6);
|
if (status != null && status.trim().length() > 0) {
|
record.setStatus(status);
|
if ("已领取".equals(status)) {
|
record.setRcvTime(getCsvDate(getValue(item, 7)));
|
} else if ("过期未领退款".equals(status)) {
|
record.setRcvTime(getCsvDate(getValue(item, 8)));
|
}
|
}
|
list.add(record);
|
}
|
return list;
|
}
|
|
public static String getValue(String[] item, int index) {
|
if (item != null && item.length > index) {
|
String value = item[index];
|
return value;
|
}
|
return null;
|
}
|
|
public static String getCsvDate(String item) throws Exception {
|
if (item == null || item.trim().length() == 0)
|
return null;
|
|
if (item.indexOf("/") > 0) {
|
item = item.replaceAll("/", "-");
|
} else if (item.indexOf("年") > 0) {
|
item = item.replaceAll("年", "-").replaceAll("月", "-").replaceAll("日", "");
|
}
|
return item;
|
}
|
|
}
|