admin
2021-10-13 052e1d5c47c4e536fde79074d53b0481c7d4f9b6
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
69
70
71
72
73
74
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;
    }
 
}