| 
					
				 | 
			
			
				@ -2,7 +2,8 @@ package com.yihu.ehr.thread; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.config.ThreadConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.dbhelper.jdbc.DBHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.util.ZipUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.util.Zipper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.util.http.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.util.http.HttpsClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.ehr.util.log.LogUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.NameValuePair; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -10,10 +11,9 @@ import org.apache.http.message.BasicNameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.BufferedReader; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.ByteArrayOutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.File; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStreamReader; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -28,7 +28,9 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String resultString = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String versionName = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String versionCode = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String downloadPath = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String token; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private boolean isStart = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void run() { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -49,16 +51,19 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (!StringUtils.isEmpty(filePath)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            //关闭服務 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            closeService(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            //睡眠五秒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            Thread.sleep(5000L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            //解压 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (zipFile(filePath)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                //启动服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                startService(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                //上传结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                upLoagResult(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                //更新本地版本号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                updateVersion(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                //判断服务是否启动 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String message = "启动服務失败"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (isStart) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    message = "启动服務成功"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                //上传结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                upLoagResult(message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -82,11 +87,14 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private void updateVersion() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "update system_param set param_value='"+versionCode+"' where param_key='VERSION'";//UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(versionCode)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            versionCode = "1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "update system_param set param_value='" + versionCode + "' where param_key='VERSION'";//UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        db.execute(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private void upLoagResult() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private void upLoagResult(String isStart) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONObject jo = net.sf.json.JSONObject.fromObject(resultString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            Map<String, Object> params = new HashMap<String, Object>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -101,6 +109,7 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            formParams.add(new BasicNameValuePair("versionName", versionName)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            formParams.add(new BasicNameValuePair("versionCode", versionCode)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            formParams.add(new BasicNameValuePair("access_token", token)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            formParams.add(new BasicNameValuePair("message", isStart)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            formParams.add(new BasicNameValuePair("updateDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            formParams.add(new BasicNameValuePair("orgCode", orgCode)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            resultString = HttpsClientUtil.post(ThreadConfig.SERVICE_URL + ThreadConfig.UPDATE_THREAD_UPLOADRESULT, formParams, ThreadConfig.SERVICE_USERNAME, ThreadConfig.SERVICE_PASSWORD); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -120,19 +129,19 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (listSYSTEM != null && listSYSTEM.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemCode = listSYSTEM.get(0).getString("param_value"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String sql = "insert into system_param (id,param_key,param_value) values " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "('" + UUID.randomUUID() + "'," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " 'SYSTEM_CODE' ," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " '"+ThreadConfig.SYSTEM_CODE+"'" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " '" + ThreadConfig.SYSTEM_CODE + "'" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            ")"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    db.execute(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("初始化参数成功orgCode:" + orgCode + "---systemCode:" + systemCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.error("初始化参数失败:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        LogUtil.info("初始化参数成功orgCode:" + orgCode + "---systemCode:" + systemCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private void closeService() throws Exception { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -143,33 +152,48 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (system.contains("windows")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("关闭windows服务"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //windows 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String root = System.getProperty("catalina.home").replace('\\', '/'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] commandStop = {root + "\\bin\\shutdown.bat"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] envp = {"JAVA_HOME=" + root + "\\jdk1.8.0_45", "CATALINA_HOME=" + root}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                File workdir = new File(root + "\\bin"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("关闭服务目录:" + commandStop[0].toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Process process = Runtime.getRuntime().exec(commandStop, envp, workdir); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //取得命令结果的输出流 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                InputStream fis = process.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //用一个读输出流类去读 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                BufferedReader br = new BufferedReader(new InputStreamReader(fis)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String line = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //逐行读取输出到控制台 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                while ((line = br.readLine()) != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String batPathStop = UpdateThread.class.getResource("/").getPath() + "config/stop.bat"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Process psStop = Runtime.getRuntime().exec(batPathStop); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ByteArrayOutputStream baosStop = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                InputStream osStop = psStop.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                byte bStop[] = new byte[256]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                while (osStop.read(bStop) > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    baosStop.write(bStop); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                fis.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                br.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sStop = baosStop.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                osStop.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baosStop.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //判断是否服务是否关闭 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                while (true) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String batPath = UpdateThread.class.getResource("/").getPath() + "config/serviceAlive.bat"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Process ps = Runtime.getRuntime().exec(batPath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    InputStream os = ps.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    byte b[] = new byte[256]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    while (os.read(b) > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        baos.write(b); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String s = baos.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    os.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    baos.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (!Boolean.valueOf(s.trim())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        isStart = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    LogUtil.info("服务正在关闭"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Thread.sleep(1000L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("重启linux服务"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Runtime.getRuntime().exec("service " + ThreadConfig.TOMCAT_SERVICENAME + " restart"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Runtime.getRuntime().exec("service " + ThreadConfig.TOMCAT_SERVICENAME + " stop"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Thread.sleep(6000L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.info("关闭成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.error("关闭失败:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private void startService() throws Exception { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -179,28 +203,40 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (system.contains("windows")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("启动windows服务"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //windows 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String root = System.getProperty("catalina.home").replace('\\', '/'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] commandStart = {root + "\\bin\\startup.bat"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] envp = {"JAVA_HOME=" + root + "\\jdk1.8.0_45", "CATALINA_HOME=" + root}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                File workdir = new File(root + "\\bin"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("启动服务目录:" + commandStart[0].toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Process process = Runtime.getRuntime().exec(commandStart, envp, workdir); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //取得命令结果的输出流 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                InputStream fis = process.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //用一个读输出流类去读 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                BufferedReader br = new BufferedReader(new InputStreamReader(fis)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String line = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //逐行读取输出到控制台 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                while ((line = br.readLine()) != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String batPathStart = UpdateThread.class.getResource("/").getPath() + "config/start.bat"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Process psStart = Runtime.getRuntime().exec(batPathStart); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ByteArrayOutputStream baosStart = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                InputStream osStart = psStart.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                byte bStart[] = new byte[256]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                while (osStart.read(bStart) > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    baosStart.write(bStart); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                osStart.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baosStart.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                while (true) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    int i = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String batPath = UpdateThread.class.getResource("/").getPath() + "config/serviceAlive.bat"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Process ps = Runtime.getRuntime().exec(batPath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    InputStream os = ps.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    byte b[] = new byte[256]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    while (os.read(b) > 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        baos.write(b); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String s = baos.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    os.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    baos.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (Boolean.valueOf(s.trim())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        i++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (i > 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        LogUtil.info("第" + i + "次判断服务已经启动"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Thread.sleep(1000L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                fis.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                br.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("启动linux服务"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Runtime.getRuntime().exec("service " + ThreadConfig.TOMCAT_SERVICENAME + " restart"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Runtime.getRuntime().exec("service " + ThreadConfig.TOMCAT_SERVICENAME + " start"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.info("启动成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -212,8 +248,8 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String home = System.getProperty("catalina.home").replace('\\', '/'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String url = home.substring(0, home.lastIndexOf('/') + 1) + "tomcat8-esb-ds/webapps"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            boolean zipResult = ZipUtil.unZip(filePath, url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.info("解压" + zipResult + ",解压路径:" + url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Zipper.unzipFile(new File(filePath.trim()), url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.info("解压成功解压路径:" + url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.error("解压失败:" + e.getMessage()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -229,13 +265,13 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // params.put("orgCode", orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            path = getFilePath(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //  HttpClientUtil.downFile(path, params, ThreadConfig.getURL(ThreadConfig.UPDATE_THREAD_DOWNUPDATEWAR), "", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> params = new HashMap<String, Object>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("systemCode", systemCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("orgCode", orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("access_token", token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!HttpsClientUtil.downLoadFileByBase64(path, params, ThreadConfig.SERVICE_URL + ThreadConfig.UPDATE_THREAD_DOWNUPDATEWAR, ThreadConfig.SERVICE_USERNAME, ThreadConfig.SERVICE_PASSWORD)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("文件下载失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // Map<String, Object> params = new HashMap<String, Object>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // params.put("systemCode", systemCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //  params.put("orgCode", orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // params.put("access_token", token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.info("开始下载文件,文件下載地址在:" + ThreadConfig.SYSTEM_DOWNLOADPATH + downloadPath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // HttpClientUtil.downFile(path, new HashMap<String, Object>(), , "", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            HttpClientUtil.getFile(ThreadConfig.SYSTEM_DOWNLOADPATH + downloadPath, path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LogUtil.info("下载文件成功,文件保存目录:" + path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -256,7 +292,7 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<JSONObject> listSYSTEM = db.query("select * from system_param where param_key='VERSION'"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (listSYSTEM != null && listSYSTEM.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ThreadConfig.SOFT_VERSIONCODE = listSYSTEM.get(0).getString("param_value"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sql = "insert into system_param (id,param_key,param_value) values " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "('" + UUID.randomUUID() + "'," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        " 'VERSION' ," + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -264,7 +300,7 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ")"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                db.execute(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ThreadConfig.SOFT_VERSIONCODE="1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ThreadConfig.SOFT_VERSIONCODE = "1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // resultString = HttpClientUtil.doPost(ThreadConfig.SERVICE_URL + ThreadConfig.UPDATE_THREAD_GETUPDATEFLAG, params, ThreadConfig.SERVICE_USERNAME, ThreadConfig.SERVICE_PASSWORD); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> params = new HashMap<String, Object>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -277,8 +313,13 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //不需要更新返回空 需要更新返回版本号版本名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!StringUtils.isEmpty(resultString)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                net.sf.json.JSONObject jo = net.sf.json.JSONObject.fromObject(resultString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LogUtil.info("判断是否有需要更新的任务返回結果:" + resultString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                versionName = String.valueOf(jo.get("versionName")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                versionCode = String.valueOf(jo.get("versionCode")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                downloadPath = String.valueOf(jo.get("file")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isEmpty(versionName)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return false; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -309,13 +350,42 @@ public class UpdateThread implements Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return folderPath + fileName + ".war"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static void main(String[] args) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String cmd = "cmd /c start F:\\aaa.bat";// pass 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static boolean getProcess() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        boolean flag = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //tomcat8-esb-service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Process ps = Runtime.getRuntime().exec(cmd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ps.waitFor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception ioe) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Process p = Runtime.getRuntime().exec("cmd /c tasklist "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            InputStream os = p.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            byte b[] = new byte[256]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            while (os.read(b) > 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baos.write(b); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String s = baos.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (s.indexOf("smss.exe") >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                flag = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                flag = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (java.io.IOException ioe) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return flag; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static void main(String[] args) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        while (true) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String batPath = UpdateThread.class.getResource("/").getPath() + "config/serviceAlive.bat"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Process ps = Runtime.getRuntime().exec(batPath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            InputStream os = ps.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            byte b[] = new byte[256]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            while (os.read(b) > 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baos.write(b); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String s = baos.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            System.out.println(s); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            os.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baos.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (Boolean.valueOf(s.trim())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |