Skip to content

Commit

Permalink
Merge pull request #46 from rememberber/develop
Browse files Browse the repository at this point in the history
支持通过excel导入目标用户和数据
  • Loading branch information
rememberber authored Mar 19, 2018
2 parents 0d00274 + cb1f957 commit 6c9a04b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<fastjson.version>1.2.46</fastjson.version>
<sun-mail.version>1.5.6</sun-mail.version>
<aliyun-java-sdk-core.version>3.5.0</aliyun-java-sdk-core.version>
<poi.version>3.17</poi.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -86,6 +87,12 @@
<version>${aliyun-java-sdk-core.version}</version>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>

<dependency>
<groupId>com.apple</groupId>
<artifactId>AppleJavaExtensions</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConstantsUI {
* 软件名称,版本
*/
public final static String APP_NAME = "WePush";
public final static String APP_VERSION = "v_1.10.0_180316";
public final static String APP_VERSION = "v_2.0.0_180319";

/**
* 主窗口图标
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="文件路径(*.txt,*.csv)"/>
<text value="文件路径(*.txt,*.csv,*.xlsx"/>
</properties>
</component>
<component id="cb5ac" class="javax.swing.JTextField" binding="memberFilePathField">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.xiaoleilu.hutool.io.file.FileReader;
import com.xiaoleilu.hutool.log.Log;
import com.xiaoleilu.hutool.log.LogFactory;
import com.xiaoleilu.hutool.poi.excel.ExcelReader;
import com.xiaoleilu.hutool.poi.excel.ExcelUtil;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
Expand Down Expand Up @@ -53,7 +55,8 @@ public static void addListeners() {

try {
MainWindow.mainWindow.getMemberTabImportProgressBar().setIndeterminate(true);
if (file.getName().endsWith(".csv")) {
String fileNameLowerCase = file.getName().toLowerCase();
if (fileNameLowerCase.endsWith(".csv")) {
// 可以解决中文乱码问题
DataInputStream in = new DataInputStream(new FileInputStream(file));
reader = new CSVReader(new InputStreamReader(in, "utf-8"));
Expand All @@ -64,7 +67,22 @@ public static void addListeners() {
currentImported++;
MainWindow.mainWindow.getMemberTabCountLabel().setText(String.valueOf(currentImported));
}
} else {
} else if (fileNameLowerCase.endsWith(".xlsx") || fileNameLowerCase.endsWith(".xls")) {
ExcelReader excelReader = ExcelUtil.getReader(file);
List<List<Object>> readAll = excelReader.read(1, Integer.MAX_VALUE);
PushData.allUser = Collections.synchronizedList(new ArrayList<>());
for (List<Object> objects : readAll) {
if (objects != null && objects.size() > 0) {
String[] nextLine = new String[objects.size()];
for (int i = 0; i < objects.size(); i++) {
nextLine[i] = objects.get(i).toString();
}
PushData.allUser.add(nextLine);
currentImported++;
MainWindow.mainWindow.getMemberTabCountLabel().setText(String.valueOf(currentImported));
}
}
} else if (fileNameLowerCase.endsWith(".txt")) {
fileReader = new FileReader(file);
PushData.allUser = Collections.synchronizedList(new ArrayList<>());
BufferedReader br = fileReader.getReader();
Expand All @@ -74,6 +92,10 @@ public static void addListeners() {
currentImported++;
MainWindow.mainWindow.getMemberTabCountLabel().setText(String.valueOf(currentImported));
}
} else {
JOptionPane.showMessageDialog(MainWindow.mainWindow.getMemberPanel(), "不支持该格式的文件!", "文件格式不支持",
JOptionPane.ERROR_MESSAGE);
return;
}
MainWindow.mainWindow.getMemberTabImportProgressBar().setMaximum(100);
MainWindow.mainWindow.getMemberTabImportProgressBar().setValue(100);
Expand Down Expand Up @@ -281,7 +303,7 @@ public static void addListeners() {
fileChooser = new JFileChooser();
}

FileFilter filter = new FileNameExtensionFilter("*.txt,*.csv", "txt", "csv", "TXT", "CSV");
FileFilter filter = new FileNameExtensionFilter("*.txt,*.csv,*.xlsx,*.xls", "txt", "csv", "TXT", "CSV", "xlsx", "xls");
fileChooser.setFileFilter(filter);

int approve = fileChooser.showOpenDialog(MainWindow.mainWindow.getSettingPanel());
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/version_summary.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"currentVersion": "v_1.10.0_180316",
"currentVersion": "v_2.0.0_180319",
"versionIndex": {
"v_1.1.0_170701": "0",
"v_1.2.0_170831": "1",
Expand All @@ -10,7 +10,8 @@
"v_1.7.0_180226": "6",
"v_1.8.0_180226": "7",
"v_1.9.0_180228": "8",
"v_1.10.0_180316": "9"
"v_1.10.0_180316": "9",
"v_2.0.0_180319": "10"
},
"versionDetailList": [
{
Expand Down Expand Up @@ -62,6 +63,11 @@
"version": "v_1.10.0_180316",
"title": "新增对阿里云短信的支持",
"log": "1.新增对阿里云短信的支持~\n2.其他细节优化\n"
},
{
"version": "v_2.0.0_180319",
"title": "新增支持通过excel导入目标用户和数据",
"log": "1.新增支持通过excel导入目标用户和数据~\n2.其他细节优化\n"
}
]
}

0 comments on commit 6c9a04b

Please sign in to comment.