Explorar o código

添加配置的功能。

YangZhiJie %!s(int64=8) %!d(string=hai) anos
pai
achega
49e2940435

+ 39 - 1
config/applicationContext.xml

@@ -11,7 +11,11 @@
 	<!-- 自动扫描 -->
 	<context:component-scan base-package="com.leanwo" />
 
-
+	<bean id="autoUpdateService" class="org.leanwo.management.util.AutoUpdateService">
+		<property name="updateSite" value="http://192.168.1.200/AutoUpdate"></property>
+	</bean>	
+	
+	
 	<bean id="applicationSettingCache" class="com.leanwo.management.model.ApplicationSettingCache">
 		<property name="settings">
 			<list>
@@ -31,6 +35,22 @@
 		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="autoUpdateFileNames">
+			<list>
+				<value>DingDingServer-0.0.1-SNAPSHOT</value>
+			</list>
+		</property>		
+		<property name="xmlConfigPath" >
+			<bean class="com.leanwo.management.model.XmlConfigPath">
+				<property name="xmlFileName" value="config/applicationContext_topnc.xml"></property>
+				<property name="nodeNames">
+					<list>
+						<value>dataSource1</value>
+						<value>dataSource2</value>
+					</list>
+				</property>
+			</bean>
+		</property>		
 	</bean>
 	
 	<bean id="applicationSetting2" class="com.leanwo.management.model.ApplicationSetting">
@@ -38,6 +58,22 @@
 		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="autoUpdateFileNames">
+			<list>
+				<value>DingDingServer-0.0.1-SNAPSHOT</value>
+			</list>
+		</property>
+		<property name="xmlConfigPath" >
+			<bean class="com.leanwo.management.model.XmlConfigPath">
+				<property name="xmlFileName" value="config/applicationContext.xml"></property>
+				<property name="nodeNames">
+					<list>
+						<value>dataSource1</value>
+						<value>dataSource2</value>
+					</list>
+				</property>
+			</bean>
+		</property>		
 	</bean>
 	
 	<bean id="applicationSetting3" class="com.leanwo.management.model.ApplicationSetting">
@@ -76,4 +112,6 @@
 	</bean>
 	
 	<bean id="springUtil" class="org.leanwo.management.util.SpringUtil" />
+	<bean id="xmlConfigPathService" class="org.leanwo.management.util.XmlConfigPathService"/>
+	
 </beans>

+ 68 - 0
src/main/java/com/leanwo/management/ServerManagmentJFrame.java

@@ -29,6 +29,7 @@ import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.Timer;
 
@@ -39,6 +40,7 @@ import org.apache.commons.exec.ExecuteWatchdog;
 import org.apache.commons.exec.PumpStreamHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.leanwo.management.util.AutoUpdateService;
 import org.leanwo.management.util.SpringUtil;
 
 import com.leanwo.management.model.ApplicationSetting;
@@ -85,6 +87,7 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 		this.setBounds((width - windowsWidth) / 2, (height - windowsHeight) / 2, windowsWidth, windowsHeight);
 		
 		statusLabels = new HashMap<ApplicationSetting, JLabel>();
+		
 		generateViewFromJson();
 		
 		this.setVisible(true); // 显示,如果不设置就什么都看不到
@@ -192,6 +195,28 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
         constrains.anchor = GridBagConstraints.NORTH;
         jPanel.add(label, constrains);
 
+		label = new JLabel("检查更新");
+        label.setBorder(BorderFactory.createEtchedBorder());
+		constrains = new GridBagConstraints();
+		constrains.insets = new Insets(0, 0, 0, 0);
+        constrains.fill = GridBagConstraints.BOTH;
+        constrains.gridx = 4;
+        constrains.gridy = 0;
+        constrains.weightx = 10;        
+        constrains.anchor = GridBagConstraints.NORTH;
+        jPanel.add(label, constrains);
+
+		label = new JLabel("修改配置");
+        label.setBorder(BorderFactory.createEtchedBorder());
+		constrains = new GridBagConstraints();
+		constrains.insets = new Insets(0, 0, 0, 0);
+        constrains.fill = GridBagConstraints.BOTH;
+        constrains.gridx = 5;
+        constrains.gridy = 0;
+        constrains.weightx = 10;
+        constrains.anchor = GridBagConstraints.NORTH;
+        jPanel.add(label, constrains);
+        
 		ApplicationSettingCache applicationSettingCache = (ApplicationSettingCache) SpringUtil.getSingleBean(ApplicationSettingCache.class);
 		List<ApplicationSetting> settings = applicationSettingCache.getSettings();
 		if (settings != null && settings.size() > 0) {
@@ -261,6 +286,49 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 						}
 					}
 				});
+		        
+
+				JButton checkUpdate = new JButton("检查更新");
+				constrains = new GridBagConstraints();
+				constrains.insets = new Insets(5, 5, 5, 5);
+		        constrains.fill = GridBagConstraints.BOTH;
+		        constrains.gridx = 4;
+		        constrains.gridy = rowIndex;
+		        constrains.weightx = 10;
+		        jPanel.add(checkUpdate, constrains);
+		        checkUpdate.addActionListener(new ActionListener() {
+					@Override
+					public void actionPerformed(ActionEvent e) {
+						AutoUpdateService autoUpdateService = (AutoUpdateService) SpringUtil.getSingleBean(AutoUpdateService.class);
+						if(autoUpdateService.canUpdate(setting)) {
+							Object[] options = {"确定","取消"};
+							int response = JOptionPane.showOptionDialog(null, "如果您确定要升级,请点击\'确定\'按钮,否则点击\'取消\'按钮", "确定是否升级", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
+							if(response==0)
+							{
+								autoUpdateService.autoUpdate(setting);
+							}
+						}else {
+							JOptionPane.showMessageDialog(null, "在服务器上未找到可更新的程序", "没有可更新的程序", JOptionPane.ERROR_MESSAGE);
+						}
+					}
+				});
+		        
+
+				JButton config = new JButton("配置");
+				constrains = new GridBagConstraints();
+				constrains.insets = new Insets(5, 5, 5, 5);
+		        constrains.fill = GridBagConstraints.BOTH;
+		        constrains.gridx = 5;
+		        constrains.gridy = rowIndex;
+		        constrains.weightx = 10;
+		        jPanel.add(config, constrains);
+		        config.addActionListener(new ActionListener() {
+					@Override
+					public void actionPerformed(ActionEvent e) {
+						ServerSettingJFrame serverSettingJFrame = new ServerSettingJFrame(setting);
+						serverSettingJFrame.setVisible(true);
+					}
+				});
 			}
 		}
 	}

+ 183 - 0
src/main/java/com/leanwo/management/ServerSettingJFrame.java

@@ -0,0 +1,183 @@
+package com.leanwo.management;
+
+import java.awt.AWTEvent;
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.SystemTray;
+import java.awt.TrayIcon;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.Timer;
+
+import org.leanwo.management.util.SpringUtil;
+import org.leanwo.management.util.XmlConfigPathService;
+
+import com.leanwo.management.model.ApplicationSetting;
+import com.leanwo.management.model.XmlConfigPath;
+
+/**
+ * 服务器配置
+ * @author YangZhiJie
+ *
+ */
+public class ServerSettingJFrame  extends JFrame{
+	private ApplicationSetting applicationSetting;
+	private XmlConfigPath xmlConfigPath;
+	private XmlConfigPathService xmlConfigPathService;
+	private JPanel jPanel = null;
+	private GridBagConstraints constrains = null;
+	private JLabel label = null;
+	private JTextField portTextField;
+	private JTextField tokenTextField;
+	private Map<String, JTextArea> textAreas = new HashMap<String, JTextArea>();
+	private JButton saveButton;
+	
+	private int index = 0;
+	
+	public ServerSettingJFrame(ApplicationSetting applicationSetting) {
+		this.setLayout(new BorderLayout());
+		this.setSize(800, 600);
+		this.setTitle("程序配置管理器");
+		this.xmlConfigPathService = (XmlConfigPathService) SpringUtil.getSingleBean(XmlConfigPathService.class);
+		this.applicationSetting = applicationSetting;
+		this.xmlConfigPathService.load(applicationSetting);
+		this.xmlConfigPath = applicationSetting.getXmlConfigPath();
+		this.jPanel = new JPanel(new GridBagLayout());
+		this.add(jPanel, BorderLayout.NORTH);
+		
+        if(this.xmlConfigPath != null) {
+    		label = new JLabel("端口号");
+    		constrains = new GridBagConstraints();
+    		constrains.insets = new Insets(0, 0, 0, 0);
+            constrains.fill = GridBagConstraints.BOTH;
+            constrains.gridx = 0;
+            constrains.gridy = index;
+            constrains.weightx = 100;        
+            constrains.anchor = GridBagConstraints.NORTH;
+            jPanel.add(label, constrains);
+            
+            index++;
+            portTextField = new JTextField();
+            if(xmlConfigPath.getPortNo() != null) {
+            	portTextField.setText(xmlConfigPath.getPortNo().toString());
+            }
+    		constrains = new GridBagConstraints();
+    		constrains.insets = new Insets(0, 0, 0, 0);
+            constrains.fill = GridBagConstraints.BOTH;
+            constrains.gridx = 0;
+            constrains.gridy = index;
+            constrains.weightx = 100;        
+            constrains.anchor = GridBagConstraints.NORTH;
+            jPanel.add(portTextField, constrains);
+            
+            
+            index++;    		
+    		label = new JLabel("Token");
+    		constrains = new GridBagConstraints();
+    		constrains.insets = new Insets(0, 0, 0, 0);
+            constrains.fill = GridBagConstraints.BOTH;
+            constrains.gridx = 0;
+            constrains.gridy = index;
+            constrains.weightx = 100;        
+            constrains.anchor = GridBagConstraints.NORTH;
+            jPanel.add(label, constrains);
+
+            index++;    	
+            tokenTextField = new JTextField();
+            tokenTextField.setText(xmlConfigPath.getToken());
+    		constrains = new GridBagConstraints();
+    		constrains.insets = new Insets(0, 0, 0, 0);
+            constrains.fill = GridBagConstraints.BOTH;
+            constrains.gridx = 0;
+            constrains.gridy = index;
+            constrains.weightx = 100;        
+            constrains.anchor = GridBagConstraints.NORTH;
+            jPanel.add(tokenTextField, constrains);
+            
+            
+            
+        	Map<String, String> contents = applicationSetting.getXmlConfigPath().getContents();
+        	for(String key : contents.keySet()) {
+        		index ++;
+        		label = new JLabel(key);
+        		constrains = new GridBagConstraints();
+        		constrains.insets = new Insets(0, 0, 0, 0);
+                constrains.fill = GridBagConstraints.BOTH;
+                constrains.gridx = 0;
+                constrains.gridy = index;
+                constrains.weightx = 100;        
+                constrains.anchor = GridBagConstraints.NORTH;
+                jPanel.add(label, constrains);
+                
+        		index ++;
+        		JTextArea textArea = new JTextArea();
+        		textArea.setText(contents.get(key));
+        		textArea.setRows(5);
+        		constrains = new GridBagConstraints();
+        		constrains.insets = new Insets(0, 0, 0, 0);
+                constrains.fill = GridBagConstraints.BOTH;
+                constrains.gridx = 0;
+                constrains.gridy = index;
+                constrains.weightx = 100;        
+                constrains.anchor = GridBagConstraints.NORTH;
+                jPanel.add(textArea, constrains);
+                textAreas.put(key, textArea);
+        	}
+
+    		index ++;
+        	saveButton = new JButton("保存");
+    		constrains = new GridBagConstraints();
+    		constrains.insets = new Insets(0, 0, 0, 0);
+            constrains.fill = GridBagConstraints.BOTH;
+            constrains.gridx = 0;
+            constrains.gridy = index;
+            constrains.weightx = 100;        
+            constrains.anchor = GridBagConstraints.NORTH;
+            jPanel.add(saveButton, constrains);
+            
+            saveButton.addActionListener(new ActionListener() {
+				@Override
+				public void actionPerformed(ActionEvent e) {
+					String portStr = portTextField.getText();
+					if(portStr != null) {
+						try {
+							xmlConfigPath.setPortNo(Integer.parseInt(portStr));
+						}catch(Exception ex) {
+							JOptionPane.showMessageDialog(null, "端口号必须为整数", "端口号必须为整数", JOptionPane.ERROR_MESSAGE);
+							return;
+						}
+					}
+					xmlConfigPath.setToken(tokenTextField.getText());
+					if(xmlConfigPath.getContents() != null) {
+						for(String key : textAreas.keySet()) {
+							xmlConfigPath.getContents().put(key, textAreas.get(key).getText());
+						}
+					}
+					xmlConfigPathService.save(applicationSetting);
+				}
+			});
+        }
+	}
+}

+ 53 - 0
src/main/java/com/leanwo/management/model/ApplicationSetting.java

@@ -1,5 +1,10 @@
+/*
+ * 
+ */
 package com.leanwo.management.model;
 
+import java.util.List;
+
 import org.apache.commons.exec.ExecuteWatchdog;
 
 /**
@@ -34,11 +39,23 @@ public class ApplicationSetting {
 	 */
 	private String stopBatFile;
 	
+	/**
+	 * 自动更新的文件名.
+	 */
+	private List<String> autoUpdateFileNames;
+
+	/**
+	 * XML文件配置.
+	 */
+	private XmlConfigPath xmlConfigPath;
+	
+	
 	/**
 	 * 
 	 */
 	private ExecuteWatchdog executeWatchdog;
 
+	
 	/**
 	 * Gets the 应用程序名称.
 	 *
@@ -146,4 +163,40 @@ public class ApplicationSetting {
 	public void setInstallPath(String installPath) {
 		this.installPath = installPath;
 	}
+
+	/**
+	 * Gets the 自动更新的文件名.
+	 *
+	 * @return the 自动更新的文件名
+	 */
+	public List<String> getAutoUpdateFileNames() {
+		return autoUpdateFileNames;
+	}
+
+	/**
+	 * Sets the 自动更新的文件名.
+	 *
+	 * @param autoUpdateFileNames the new 自动更新的文件名
+	 */
+	public void setAutoUpdateFileNames(List<String> autoUpdateFileNames) {
+		this.autoUpdateFileNames = autoUpdateFileNames;
+	}
+
+	/**
+	 * Gets the xML文件配置.
+	 *
+	 * @return the xML文件配置
+	 */
+	public XmlConfigPath getXmlConfigPath() {
+		return xmlConfigPath;
+	}
+
+	/**
+	 * Sets the xML文件配置.
+	 *
+	 * @param xmlConfigPath the new xML文件配置
+	 */
+	public void setXmlConfigPath(XmlConfigPath xmlConfigPath) {
+		this.xmlConfigPath = xmlConfigPath;
+	}
 }

+ 125 - 0
src/main/java/com/leanwo/management/model/XmlConfigPath.java

@@ -0,0 +1,125 @@
+package com.leanwo.management.model;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * XML配置路径.
+ */
+public class XmlConfigPath {
+	
+	/**
+	 * XML文件名.
+	 */
+	private String xmlFileName;
+	
+	/**
+	 * 端口号.
+	 */
+	private Integer portNo;
+	
+	/**
+	 * Token.
+	 */
+	private String token;
+	
+	/**
+	 * 节点名称.
+	 */
+	private List<String> nodeNames;
+	
+	/**
+	 * 节点数据.
+	 */
+	private Map<String, String> contents;
+
+	/**
+	 * Gets the xML文件名.
+	 *
+	 * @return the xML文件名
+	 */
+	public String getXmlFileName() {
+		return xmlFileName;
+	}
+
+	/**
+	 * Sets the xML文件名.
+	 *
+	 * @param xmlFileName the new xML文件名
+	 */
+	public void setXmlFileName(String xmlFileName) {
+		this.xmlFileName = xmlFileName;
+	}
+
+	/**
+	 * Gets the 端口号.
+	 *
+	 * @return the 端口号
+	 */
+	public Integer getPortNo() {
+		return portNo;
+	}
+
+	/**
+	 * Sets the 端口号.
+	 *
+	 * @param portNo the new 端口号
+	 */
+	public void setPortNo(Integer portNo) {
+		this.portNo = portNo;
+	}
+
+	/**
+	 * Gets the token.
+	 *
+	 * @return the token
+	 */
+	public String getToken() {
+		return token;
+	}
+
+	/**
+	 * Sets the token.
+	 *
+	 * @param token the new token
+	 */
+	public void setToken(String token) {
+		this.token = token;
+	}
+
+	/**
+	 * Gets the 节点数据.
+	 *
+	 * @return the 节点数据
+	 */
+	public Map<String, String> getContents() {
+		return contents;
+	}
+
+	/**
+	 * Sets the 节点数据.
+	 *
+	 * @param contents the new 节点数据
+	 */
+	public void setContents(Map<String, String> contents) {
+		this.contents = contents;
+	}
+
+	/**
+	 * Gets the 节点名称.
+	 *
+	 * @return the 节点名称
+	 */
+	public List<String> getNodeNames() {
+		return nodeNames;
+	}
+
+	/**
+	 * Sets the 节点名称.
+	 *
+	 * @param nodeNames the new 节点名称
+	 */
+	public void setNodeNames(List<String> nodeNames) {
+		this.nodeNames = nodeNames;
+	}
+}

+ 51 - 0
src/main/java/org/leanwo/management/util/AutoUpdateService.java

@@ -0,0 +1,51 @@
+package org.leanwo.management.util;
+
+import com.leanwo.management.model.ApplicationSetting;
+
+/**
+ * 自动更新服务.
+ *
+ * @author YangZhiJie
+ */
+public class AutoUpdateService {
+	
+	/**
+	 * 更新的网站.
+	 */
+	private String updateSite;
+	
+	/**
+	 * Gets the 更新的网站.
+	 *
+	 * @return the 更新的网站
+	 */
+	public String getUpdateSite() {
+		return updateSite;
+	}
+
+	/**
+	 * Sets the 更新的网站.
+	 *
+	 * @param updateSite the new 更新的网站
+	 */
+	public void setUpdateSite(String updateSite) {
+		this.updateSite = updateSite;
+	}
+
+	/**
+	 * 检查服务器上是否有可更新的程序
+	 * @return
+	 */
+	public boolean canUpdate(ApplicationSetting setting) {
+		
+		return false;
+	}
+
+	/**
+	 * 确定执行更新.
+	 */
+	public void autoUpdate(ApplicationSetting setting) {
+		
+	}
+	
+}

+ 36 - 0
src/main/java/org/leanwo/management/util/XmlConfigPathService.java

@@ -0,0 +1,36 @@
+package org.leanwo.management.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.stereotype.Service;
+
+import com.leanwo.management.model.ApplicationSetting;
+import com.leanwo.management.model.XmlConfigPath;
+
+public class XmlConfigPathService {
+	/**
+	 * 从文件中加载ApplicationSetting中的
+	 * portNo,token,contents等属性
+	 * @param setting
+	 */
+	public void load(ApplicationSetting setting) {
+		XmlConfigPath xmlConfigPath = setting.getXmlConfigPath();
+		if(xmlConfigPath != null) {
+			xmlConfigPath.setPortNo(100);
+			xmlConfigPath.setToken("123456");
+			Map<String, String> contentMap = new HashMap<String, String>();
+			contentMap.put("dataSource1", "1");
+			contentMap.put("dataSource2", "2");
+			xmlConfigPath.setContents(contentMap);
+		}
+	}
+	
+	/**
+	 * 将ApplicationSetting的属性portNo,token,contents保存到文件
+	 * @param setting
+	 */
+	public void save(ApplicationSetting setting) {
+		
+	}
+}