Skip to content

Commit

Permalink
Merge pull request #41 from rememberber/develop
Browse files Browse the repository at this point in the history
1.8.0新版发布增加Mac版App
  • Loading branch information
rememberber authored Feb 27, 2018
2 parents 1aaf00f + ddbeb7d commit 4518e6e
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fangxuele.tool.wechat.push.ui.Init;
import com.fangxuele.tool.wechat.push.ui.MainWindow;
import com.fangxuele.tool.wechat.push.util.SystemUtil;
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
import com.xiaoleilu.hutool.log.Log;
Expand Down Expand Up @@ -40,8 +41,8 @@ public static MsgHisManage getInstance() {

private MsgHisManage() {
try {
msgHisFile = new File("data/msg_his.csv");
File msgHisDir = new File("data/");
msgHisFile = new File(SystemUtil.configHome + "data" + File.separator + "msg_his.csv");
File msgHisDir = new File(SystemUtil.configHome + "data" + File.separator);
if (!msgHisFile.exists()) {
msgHisDir.mkdirs();
msgHisFile.createNewFile();
Expand Down Expand Up @@ -100,8 +101,8 @@ public Map<String, String[]> readMsgHis() {
public List<String[]> readTemplateData(String msgName) {
CSVReader reader = null;
List<String[]> list = new ArrayList<>();
File dir = new File("data/template_data/");
File file = new File("data/template_data/" + msgName + ".csv");
File dir = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator);
File file = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator + msgName + ".csv");
try {
if (!file.exists()) {
dir.mkdirs();
Expand Down Expand Up @@ -146,8 +147,9 @@ public void writeMsgHis(Map<String, String[]> map) throws IOException {
* @throws IOException
*/
public void writeTemplateData(String msgName) throws IOException {
File dir = new File("data/template_data/");
File file = new File("data/template_data/" + msgName + ".csv");
File dir = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator);
File file = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator
+ msgName + ".csv");
if (!file.exists()) {
dir.mkdirs();
file.createNewFile();
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/fangxuele/tool/wechat/push/logic/PushManage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fangxuele.tool.wechat.push.ui.Init;
import com.fangxuele.tool.wechat.push.ui.MainWindow;
import com.fangxuele.tool.wechat.push.util.SystemUtil;
import com.opencsv.CSVWriter;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
Expand Down Expand Up @@ -349,7 +350,7 @@ public static WxMpService getWxMpService() {
* 推送停止或结束后保存数据
*/
public static void savePushData() throws IOException {
File pushHisDir = new File("data/push_his");
File pushHisDir = new File(SystemUtil.configHome + "data" + File.separator + "push_his");
if (!pushHisDir.exists()) {
pushHisDir.mkdirs();
}
Expand All @@ -362,7 +363,9 @@ public static void savePushData() throws IOException {

// 保存已发送
if (PushData.sendSuccessList.size() > 0) {
File toSendFile = new File(new StringBuilder("data/push_his/").append(msgName).append("-发送成功-").append(nowTime).append(".csv").toString());
File toSendFile = new File(new StringBuilder(SystemUtil.configHome).append("data")
.append(File.separator).append("push_his").append(File.separator).append(msgName)
.append("-发送成功-").append(nowTime).append(".csv").toString());
if (!toSendFile.exists()) {
toSendFile.createNewFile();
}
Expand All @@ -382,7 +385,9 @@ public static void savePushData() throws IOException {
PushData.toSendList.remove(str);
}
if (PushData.toSendList.size() > 0) {
File unSendFile = new File(new StringBuilder("data/push_his/").append(msgName).append("-未发送-").append(nowTime).append(".csv").toString());
File unSendFile = new File(new StringBuilder(SystemUtil.configHome).append("data").append(File.separator)
.append("push_his").append(File.separator).append(msgName).append("-未发送-").append(nowTime)
.append(".csv").toString());
if (!unSendFile.exists()) {
unSendFile.createNewFile();
}
Expand All @@ -395,7 +400,8 @@ public static void savePushData() throws IOException {

// 保存发送失败
if (PushData.sendFailList.size() > 0) {
File failSendFile = new File(new StringBuilder("data/push_his/").append(msgName).append("-发送失败-").append(nowTime).append(".csv").toString());
File failSendFile = new File(new StringBuilder(SystemUtil.configHome).append("data").append(File.separator)
.append("push_his").append(File.separator).append(msgName).append("-发送失败-").append(nowTime).append(".csv").toString());
if (!failSendFile.exists()) {
failSendFile.createNewFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
/**
* UI相关的常量
*
* @author rememberber(https://github.com/rememberber)
* @author rememberber(https : / / github.com / rememberber)
*/
public class ConstantsUI {

/**
* 软件名称,版本
*/
public final static String APP_NAME = "WePush";
public final static String APP_VERSION = "v_1.7.0_180226";
public final static String APP_VERSION = "v_1.8.0_180226";

/**
* 主窗口图标
*/
public final static Image IMAGE_ICON = Toolkit.getDefaultToolkit()
.getImage(MainWindow.class.getResource("/icon/logo-md.png"));
.getImage(MainWindow.class.getResource("/icon/logo-lg.png"));

/**
* 软件版本检查url
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/fangxuele/tool/wechat/push/ui/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public static void initMemberTab() {

MainWindow.mainWindow.getMemberHisComboBox().removeAllItems();

File pushHisDir = new File("data/push_his");
File pushHisDir = new File(SystemUtil.configHome + "data" + File.separator + "push_his");
if (!pushHisDir.exists()) {
pushHisDir.mkdirs();
}
Expand Down Expand Up @@ -390,7 +390,7 @@ public static void initPushHisTab() {
renderer.setPreferredSize(new Dimension(0, 0));
MainWindow.mainWindow.getPushHisLeftTable().getTableHeader().setDefaultRenderer(renderer);

File pushHisDir = new File("data/push_his");
File pushHisDir = new File(SystemUtil.configHome + "data" + File.separator + "push_his");
if (!pushHisDir.exists()) {
pushHisDir.mkdirs();
}
Expand Down Expand Up @@ -494,7 +494,8 @@ public static void initAllTab() {
initMemberTab();
initPushTab();
initScheduleTab();
initPushHisTab();
// 初始化后置,切换tab时再触发
// initPushHisTab();
initSettingTab();

// 检查新版版
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.form
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
</component>
</children>
</grid>
<grid id="563e6" binding="memberTabDownPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="563e6" binding="memberTabDownPanel" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="50" bottom="10" right="0"/>
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -673,13 +673,21 @@
</component>
<component id="6592d" class="javax.swing.JButton" binding="importFromFileButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="icon/fromVCS.png"/>
<text value="导入openid/手机号"/>
</properties>
</component>
<component id="8c101" class="javax.swing.JButton" binding="memberImportExploreButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="浏览"/>
</properties>
</component>
</children>
</grid>
<grid id="74bf2" binding="memberTabCenterPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public class MainWindow {
private JButton memberImportTagButton;
private JComboBox memberImportTagComboBox;
private JButton memberImportTagFreshButton;
private JButton memberImportExploreButton;
public static JFrame frame;

public static MainWindow mainWindow;
Expand Down Expand Up @@ -1354,4 +1355,12 @@ public JButton getPushHisCopyButton() {
public void setPushHisCopyButton(JButton pushHisCopyButton) {
this.pushHisCopyButton = pushHisCopyButton;
}

public JButton getMemberImportExploreButton() {
return memberImportExploreButton;
}

public void setMemberImportExploreButton(JButton memberImportExploreButton) {
this.memberImportExploreButton = memberImportExploreButton;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ public void mouseEntered(MouseEvent e) {

});

// 检查更新
MainWindow.mainWindow.getCheckUpdateLabel().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
checkUpdate(false);
new Thread(new Runnable() {
@Override
public void run() {
checkUpdate(false);
}
}).start();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fangxuele.tool.wechat.push.ui.Init;
import com.fangxuele.tool.wechat.push.ui.MainWindow;
import com.fangxuele.tool.wechat.push.util.DbUtilMySQL;
import com.fangxuele.tool.wechat.push.util.SystemUtil;
import com.opencsv.CSVReader;
import com.xiaoleilu.hutool.io.file.FileReader;
import com.xiaoleilu.hutool.log.Log;
Expand All @@ -17,6 +18,8 @@
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
Expand Down Expand Up @@ -181,7 +184,8 @@ public static void addListeners() {

// 从历史导入按钮事件
MainWindow.mainWindow.getImportFromHisButton().addActionListener(e -> new Thread(() -> {
File file = new File("data/push_his/" + MainWindow.mainWindow.getMemberHisComboBox().getSelectedItem().toString());
File file = new File(SystemUtil.configHome + "data/push_his" + File.separator
+ MainWindow.mainWindow.getMemberHisComboBox().getSelectedItem().toString());
CSVReader reader = null;
FileReader fileReader = null;

Expand Down Expand Up @@ -265,6 +269,27 @@ public static void addListeners() {
}
}
}).start());

// 浏览按钮
MainWindow.mainWindow.getMemberImportExploreButton().addActionListener(e -> {
File beforeFile = new File(MainWindow.mainWindow.getMemberFilePathField().getText());
JFileChooser fileChooser;

if (beforeFile.exists()) {
fileChooser = new JFileChooser(beforeFile);
} else {
fileChooser = new JFileChooser();
}

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

int approve = fileChooser.showOpenDialog(MainWindow.mainWindow.getSettingPanel());
if (approve == JFileChooser.APPROVE_OPTION) {
MainWindow.mainWindow.getMemberFilePathField().setText(fileChooser.getSelectedFile().getAbsolutePath());
}

});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import com.fangxuele.tool.wechat.push.ui.Init;
import com.fangxuele.tool.wechat.push.ui.MainWindow;
import com.fangxuele.tool.wechat.push.util.SystemUtil;
import com.xiaoleilu.hutool.io.FileUtil;
import com.xiaoleilu.hutool.log.Log;
import com.xiaoleilu.hutool.log.LogFactory;
import com.xiaoleilu.hutool.util.ClipboardUtil;
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* 推送历史管理tab相关事件监听
Expand All @@ -37,8 +40,10 @@ public void run() {
MainWindow.mainWindow.getPushHisTextArea().setText("");

int selectedRow = MainWindow.mainWindow.getPushHisLeftTable().getSelectedRow();
String selectedFileName = MainWindow.mainWindow.getPushHisLeftTable().getValueAt(selectedRow, 1).toString();
File pushHisFile = new File("data/push_his/" + selectedFileName);
String selectedFileName = MainWindow.mainWindow.getPushHisLeftTable()
.getValueAt(selectedRow, 1).toString();
File pushHisFile = new File(SystemUtil.configHome + "data" + File.separator
+ "push_his" + File.separator + selectedFileName);

try {
BufferedReader br = new BufferedReader(new FileReader(pushHisFile));
Expand Down Expand Up @@ -97,7 +102,7 @@ public void run() {
boolean delete = (boolean) tableModel.getValueAt(i, 0);
if (delete) {
String fileName = (String) tableModel.getValueAt(i, 1);
File msgTemplateDataFile = new File("data/push_his/" + fileName);
File msgTemplateDataFile = new File(SystemUtil.configHome + "data" + File.separator + "push_his" + File.separator + fileName);
if (msgTemplateDataFile.exists()) {
msgTemplateDataFile.delete();
}
Expand Down Expand Up @@ -136,13 +141,57 @@ public void run() {
}).start());

// 推送历史管理-导出按钮
MainWindow.mainWindow.getPushHisExportButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 导出推送历史
JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "敬请期待!", "提示",
JOptionPane.INFORMATION_MESSAGE);
MainWindow.mainWindow.getPushHisExportButton().addActionListener(e -> {
List<String> toExportFilePathList = new ArrayList<>();
int selectedCount = 0;

try {
DefaultTableModel tableModel = (DefaultTableModel) MainWindow.mainWindow.getPushHisLeftTable()
.getModel();
int rowCount = tableModel.getRowCount();
for (int i = 0; i < rowCount; i++) {
boolean selected = (boolean) tableModel.getValueAt(i, 0);
if (selected) {
selectedCount++;
String fileName = (String) tableModel.getValueAt(i, 1);
File msgTemplateDataFile = new File(SystemUtil.configHome + "data" + File.separator + "push_his" + File.separator + fileName);
if (msgTemplateDataFile.exists()) {
toExportFilePathList.add(msgTemplateDataFile.getAbsolutePath());
}
}
}

if (selectedCount > 0) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int approve = fileChooser.showOpenDialog(MainWindow.mainWindow.getSettingPanel());
String exportPath = "";
if (approve == JFileChooser.APPROVE_OPTION) {
exportPath = fileChooser.getSelectedFile().getAbsolutePath();
}

for (String toExportFilePath : toExportFilePathList) {
FileUtil.copy(toExportFilePath, exportPath, true);
}
JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "导出成功!", "提示",
JOptionPane.INFORMATION_MESSAGE);
try {
Desktop desktop = Desktop.getDesktop();
desktop.open(new File(exportPath));
} catch (Exception e2) {
logger.error(e2);
}
} else {
JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "请至少选择一个!", "提示",
JOptionPane.INFORMATION_MESSAGE);
}

} catch (Exception e1) {
JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "导出失败!\n\n" + e1.getMessage(), "失败",
JOptionPane.ERROR_MESSAGE);
logger.error(e1);
}

});

}
Expand Down
Loading

0 comments on commit 4518e6e

Please sign in to comment.