From d1f26741bddf6f512d62c0100d42c52be8d37e76 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 06 二月 2021 15:35:40 +0800 Subject: [PATCH] 工具类优化 --- utils/src/main/java/org/yeshi/utils/wx/WXRedPackUtil.java | 148 ++++++++++++++++++++++++------------------------ 1 files changed, 74 insertions(+), 74 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/wx/WXRedPackUtil.java b/utils/src/main/java/org/yeshi/utils/wx/WXRedPackUtil.java index bb9caea..2955414 100644 --- a/utils/src/main/java/org/yeshi/utils/wx/WXRedPackUtil.java +++ b/utils/src/main/java/org/yeshi/utils/wx/WXRedPackUtil.java @@ -1,74 +1,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; - } - -} +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; + } + +} -- Gitblit v1.8.0