Browse Source

Merge branch 'master' of http://192.168.1.220:10080/esb/esb

hzp 9 years ago
parent
commit
dc16c1457f

+ 4 - 1
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/common/ApplicationStart.java

@ -90,10 +90,13 @@ public class ApplicationStart implements ServletContextListener {
            ThreadConfig.TOMCAT_SERVICENAME = prop.getProperty("tomcat.servicename");
            //ThreadConfig.SOFT_VERSIONCODE = prop.getProperty("soft.versionCode");
            ThreadConfig.SYSTEM_CODE= prop.getProperty("system.code");
            ThreadConfig.SYSTEM_CODE = prop.getProperty("system.code");
            ThreadConfig.TOKEN_INFO = prop.getProperty("token.info");
            ThreadConfig.TOKEN_USER_NAME = prop.getProperty("token.user_name");
            ThreadConfig.TOKEN_METHOD = prop.getProperty("token.getToken");
            ThreadConfig.SYSTEM_DOWNLOADPATH = prop.getProperty("system.downloadPath");
        } catch (Exception e) {
            e.printStackTrace();
        }

+ 2 - 1
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/config/ThreadConfig.java

@ -32,10 +32,11 @@ public class ThreadConfig {
    public static String TOKEN_INFO = "{\"fingerprint\": \"abc\"}";
    public static String TOKEN_METHOD = "authorizations/clients/";
    public static String TOMCAT_SERVICENAME = "tomcat8-esb-service";
    public static String TOMCAT_SERVICENAME = "tomcat8-esb-ds";
    public static String SOFT_VERSIONCODE = "1";
    public static String SYSTEM_CODE = "";
    public static String SYSTEM_DOWNLOADPATH="";
    private static Properties prop = new Properties();

+ 137 - 67
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/thread/UpdateThread.java

@ -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;
            }
        }
    }
}

+ 2 - 1
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/util/ZipUtil.java

@ -86,6 +86,7 @@ public class ZipUtil {
            }
            flag = true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
        return flag;
@ -129,7 +130,7 @@ public class ZipUtil {
            //ZipUtil.zip("F:/简历",
            //       "F:/sss.war");
            ZipUtil.unZip("F:/sss.war",
            ZipUtil.unZip("E:/Hos-Resource-Mini-Update.war",
                    "E:/");
        } catch (Exception e) {
            // TODO Auto-generated catch block

+ 177 - 0
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/util/Zipper.java

@ -0,0 +1,177 @@
package com.yihu.ehr.util;
import com.yihu.ehr.util.operator.StringUtil;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.FileHeader;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
 * 文件压缩辅助类
 *
 * @created Air 2015/5/26.
 */
public class Zipper {
    /**
     * 使用给定密码解压指定的ZIP压缩文件到指定目录
     * <p>
     * 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
     *
     * @param zip    指定的ZIP压缩文件
     * @param dest   解压目录
     * @param passwd ZIP文件的密码
     * @return 解压后文件数组
     * @throws ZipException 压缩文件有损坏或者解压缩失败抛出
     */
    public static File[] unzip(String zip, String dest, String passwd) throws ZipException {
        File zipFile = new File(zip);
        return unzip(zipFile, dest, passwd);
    }
    /**
     * 使用给定密码解压指定的ZIP压缩文件到当前目录
     *
     * @param zip    指定的ZIP压缩文件
     * @param passwd ZIP文件的密码
     * @return 解压后文件数组
     * @throws ZipException 压缩文件有损坏或者解压缩失败抛出
     */
    public static File[] unzip(String zip, String passwd) throws ZipException {
        File zipFile = new File(zip);
        File parentDir = zipFile.getParentFile();
        return unzip(zipFile, parentDir.getAbsolutePath(), passwd);
    }
    /**
     * 使用给定密码解压指定的ZIP压缩文件到指定目录
     * <p>
     * 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
     *
     * @param dest   解压目录
     * @param passwd ZIP文件的密码
     * @return 解压后文件数组
     * @throws ZipException 压缩文件有损坏或者解压缩失败抛出
     */
    public static File[] unzip(File zipFile, String dest, String passwd) throws ZipException {
        ZipFile zFile = new ZipFile(zipFile);
        zFile.setFileNameCharset("GBK");
        if (!zFile.isValidZipFile()) {
            throw new ZipException("压缩文件不合法,可能被损坏.");
        }
        File destDir = new File(dest);
        if (destDir.isDirectory() && !destDir.exists()) {
            destDir.mkdir();
        }
        if (zFile.isEncrypted()) {
            zFile.setPassword(passwd.toCharArray());
        }
        zFile.extractAll(dest);
        List<FileHeader> headerList = zFile.getFileHeaders();
        List<File> extractedFileList = new ArrayList<>();
        for (FileHeader fileHeader : headerList) {
            if (!fileHeader.isDirectory()) {
                extractedFileList.add(new File(destDir, fileHeader.getFileName()));
            }
        }
        File[] extractedFiles = new File[extractedFileList.size()];
        extractedFileList.toArray(extractedFiles);
        return extractedFiles;
    }
    /**
     * @param unzipFile   需要压缩的文件(文件夹)
     * @param zipFileName 压缩后的文件名
     * @return 成功-File 失败-null
     * @throws ZipException
     */
    public File zipFile(File unzipFile, String zipFileName) throws ZipException {
        return zipFile(unzipFile, zipFileName, null);
    }
    /**
     * @param unzipFile   需要压缩的文件(文件夹)
     * @param zipFileName 压缩后的文件名
     * @param pwd         压缩密码
     * @return 成功-File 失败-null
     * @throws ZipException 2015.09.15 airhead modify 压缩文件为文件夹时,压缩从子目录开始,忽略当前目录
     */
    public File zipFile(File unzipFile, String zipFileName, String pwd) throws ZipException {
        //文件不存在时不压缩
        if (!unzipFile.exists()) {
            return null;
        }
        ZipParameters parameters = new ZipParameters();
        parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
        if (!StringUtil.isEmpty(pwd)) {
            parameters.setEncryptFiles(true);
            parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
            parameters.setPassword(pwd.toCharArray());
        }
        File file = new File(zipFileName);
        if (!file.exists()) {
            file.getParentFile().mkdirs();
        }
        ZipFile zipFile = new ZipFile(zipFileName);
        if (unzipFile.isDirectory()) {
//            zipFile.addFolder(unzipFile, parameters);
            File[] files = unzipFile.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    zipFile.addFolder(files[i], parameters);
                } else {
                    zipFile.addFile(files[i], parameters);
                }
            }
        } else {
            zipFile.addFile(unzipFile, parameters);
        }
        return new File(zipFileName);
    }
    /**
     * @param zipFile        需要解压的文件名
     * @param unzipDirectory 解压文件路径
     * @return 成功-File 失败-null
     * @throws ZipException
     */
    public static File unzipFile(File zipFile, String unzipDirectory) throws ZipException {
        return unzipFile(zipFile, unzipDirectory, null);
    }
    /**
     * @param zipFile        需要解压的文件名
     * @param unzipDirectory 解压文件路径
     * @param pwd            解压密码
     * @return 成功-File 失败-null
     * @throws ZipException
     */
    public static File unzipFile(File zipFile, String unzipDirectory, String pwd) throws ZipException {
        ZipFile zFile = new ZipFile(zipFile);
        zFile.setFileNameCharset("GBK");
        if (!zFile.isValidZipFile()) {
            throw new ZipException("无效的压缩文件.");
        }
        if (zFile.isEncrypted()) {
            zFile.setPassword(pwd.toCharArray());
        }
        zFile.extractAll(unzipDirectory);
        return new File(unzipDirectory);
    }
    public static void main(String[] args) throws Exception {
        Zipper.unzipFile(new File("E:\\Hos-Resource-Mini-Update.war"), "E:/");
    }
}

+ 34 - 1
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/util/http/HttpClientUtil.java

@ -3,6 +3,7 @@ package com.yihu.ehr.util.http;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
@ -385,6 +386,37 @@ public class HttpClientUtil {
        return file;
    }
    public static void getFile(String url, String destFileName)
            throws Exception {
        // 生成一个httpclient对象
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        InputStream in = entity.getContent();
        File file = new File(destFileName);
        FileOutputStream fout = null;
        try {
            fout = new FileOutputStream(file);
            int l = -1;
            byte[] tmp = new byte[1024];
            while ((l = in.read(tmp)) != -1) {
                fout.write(tmp, 0, l);
                // 注意这里如果用OutputStream.write(buff)的话,图片会失真,大家可以试试
            }
            fout.flush();
        } finally {
            // 关闭低层流。
            if (in != null) {
                in.close();
            }
            if (fout != null) {
                fout.close();
            }
            httpclient.close();
        }
    }
    public static void main(String[] args) throws Exception {
        Map<String, Object> params = new HashMap<String, Object>();
@ -411,6 +443,7 @@ public class HttpClientUtil {
        //params.put("id", "aaaaaaaa1");
        // params.put("queryParams", "[]");
        params.put("systemCode", "test1");
        HttpClientUtil.downFile("E:/bbb.war", params, "http://localhost:10060/api/v1.0/esb/downUpdateWar", "", "");
        //  HttpClientUtil.downFile("E:/AADq8amUQ2161111.war", params, , "", "");
        HttpClientUtil.getFile("http://172.19.103.54/group1/M00/00/06/rBFuWVX6rQGADZfKAABQtFXK5o8933.war", "E:/AADq8amUQ2161231111.war");
    }
}

+ 24 - 12
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/util/http/HttpsClientUtil.java

@ -310,7 +310,7 @@ public class HttpsClientUtil {
            HttpPost httpPost = new HttpPost(url);
            //设置请求信息
            RequestConfig requestConfig = RequestConfig.custom().
                    setAuthenticationEnabled(true).build();
                    setAuthenticationEnabled(true).setConnectTimeout(8 * 1000 * 60).build();
            //设置参数
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            for (Map.Entry<String, Object> entry : params.entrySet()) {
@ -332,9 +332,10 @@ public class HttpsClientUtil {
                response = httpclient.execute(httpPost);
            }
            HttpEntity httpEntity = response.getEntity();
            String responString = EntityUtils.toString(httpEntity, "UTF-8");
            String responString = EntityUtils.toString(httpEntity);
            file = new File(filePath);
            file.getParentFile().mkdirs();
            System.out.println(responString.length());
            InputStream i = new ByteArrayInputStream(Base64.decode(responString));
            FileOutputStream fileout = new FileOutputStream(file);
            /**
@ -357,8 +358,7 @@ public class HttpsClientUtil {
        }
    }
    public static File downLoadFile(String filePath, Map<String, Object> params, String url, String username, String password) {
    public static boolean downLoadFile(String filePath, Map<String, Object> params, String url, String username, String password) {
        File file = null;
        CloseableHttpResponse response = null;
        List<BasicNameValuePair> jsonParams = new ArrayList<>();
@ -368,7 +368,7 @@ public class HttpsClientUtil {
            HttpPost httpPost = new HttpPost(url);
            //设置请求信息
            RequestConfig requestConfig = RequestConfig.custom().
                    setAuthenticationEnabled(true).build();
                    setAuthenticationEnabled(true).setConnectTimeout(8 * 1000 * 60).build();
            //设置参数
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            for (Map.Entry<String, Object> entry : params.entrySet()) {
@ -390,27 +390,30 @@ public class HttpsClientUtil {
                response = httpclient.execute(httpPost);
            }
            HttpEntity httpEntity = response.getEntity();
            InputStream is = httpEntity.getContent();
            String responString = EntityUtils.toString(httpEntity);
            file = new File(filePath);
            file.getParentFile().mkdirs();
            System.out.println(responString.length());
            InputStream i = new ByteArrayInputStream(responString.getBytes("UTF-8"));
            FileOutputStream fileout = new FileOutputStream(file);
            /**
             * 根据实际运行效果 设置缓冲区大小
             */
            byte[] buffer = new byte[1024];
            int ch = 0;
            while ((ch = is.read(buffer)) != -1) {
            while ((ch = i.read(buffer)) != -1) {
                fileout.write(buffer, 0, ch);
            }
            is.close();
            i.close();
            fileout.flush();
            fileout.close();
            return true;
        } catch (Exception e) {
            return null;
            e.printStackTrace();
            return false;
        } finally {
            close(httpclient, response);
        }
        return file;
    }
    /**
@ -492,10 +495,19 @@ public class HttpsClientUtil {
        // formParams.add(new BasicNameValuePair("orgCode", "123"));
        // formParams.add(new BasicNameValuePair("access_token", "3801916fbd19d6fdc2adf2752b491a5d"));
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("info", "{\"fingerprint\": \"abc\"}");
        params.put("access_token", "4cqetfocxyorlb5ug9umgatlpkjjn18n");
        params.put("systemCode", "MINIESB");
        params.put("orgCode", "FJWYSYY");
        //params.put("info", "{\"fingerprint\": \"abc\"}");
        //params.put("user_name", "admin");
        //POST /api/v1.0/simplified-esb/fillMiningPUT /api/v1.0/authorizations/users/{user_name}
        System.out.println(getToken());
        // System.out.println(getToken());
        // System.out.println(HttpsClientUtil.post("https://192.168.5.109:4431/api/v1.0/simplified-esb/fillMining", formParams, "admin", "123456"));
        //params.put("access_token", "7txx6wx8cmak3zpnpralh3d9626z9vfu");
        //   params.put("systemCode", "MINIESB");
        //  params.put("orgCode", "test1");
        // params.put("info", "{\"fingerprint\": \"abc\"}");
        // HttpsClientUtil.downLoadFileByBase64("E:/a.war", params, "https://172.19.103.45:8443/api/v1.0/simplified-esb/downUpdateWar", "", "");
        HttpsClientUtil.downLoadFile("E:/b.zip", params, "https://192.168.131.6:4432/api/v1.0/simplified-esb/downUpdateWar", "", "");
    }
}

+ 9 - 0
Hos-Resource-Mini-Update/src/main/resources/config/serviceAlive.bat

@ -0,0 +1,9 @@
@echo off
for /f "skip=3 tokens=4" %%i in ('sc query tomcat8-esb-ds') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    echo true
) else (
    echo false
)
exit

+ 2 - 0
Hos-Resource-Mini-Update/src/main/resources/config/start.bat

@ -0,0 +1,2 @@
net start tomcat8-esb-ds
exit

+ 2 - 0
Hos-Resource-Mini-Update/src/main/resources/config/stop.bat

@ -0,0 +1,2 @@
net stop tomcat8-esb-ds
exit

+ 5 - 3
Hos-Resource-Mini-Update/src/main/resources/config/threadConfig.properties

@ -1,6 +1,6 @@
soft.versionCode=1
## service address
service.url=https://ehr.yihu.com/api/v1.0/
service.url=https://172.19.103.73:443/api/v1.0/
service.clientId = kHAbVppx44
service.clientKey = Bd2h8rdYhep6NKOO
service.username=user
@ -15,7 +15,7 @@ updateThread.downUpdateWar=simplified-esb/downUpdateWar
updateThread.uploadResult=simplified-esb/uploadResult
##service name
tomcat.servicename=tomcat8-esb-service
tomcat.servicename=tomcat8-esb-ds
##token
token.info={"fingerprint": "abc"}
@ -24,4 +24,6 @@ token.getToken=authorizations/clients/
token.user_name=kHAbVppx44
system.code=MINIESB
system.code=MINIESB
system.downloadPath=http://172.19.103.54/

+ 6 - 3
Hos-Resource-Mini-helper/src/main/java/com.yihu.ehr/thread/LogThread.java

@ -3,6 +3,7 @@ package com.yihu.ehr.thread;
import com.yihu.ehr.config.ThreadConfig;
import com.yihu.ehr.dbhelper.jdbc.DBHelper;
import com.yihu.ehr.util.HttpsClientUtil;
import com.yihu.ehr.util.ZipUtil;
import com.yihu.ehr.util.log.LogUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
@ -22,7 +23,7 @@ public class LogThread implements Runnable {
    private String systemCode = "";
    private int sleepTime = 60 * 1000;
    private DBHelper db = new DBHelper();
    private String logFileName = "esb_mini.log";
    private String logFileName = "esb_mini.zip";
    private String token;
    @Override
@ -78,11 +79,11 @@ public class LogThread implements Runnable {
                            ")";
                    db.execute(sql);
                }
                LogUtil.info("初始化参数成功orgCode:" + orgCode + "---systemCode:" + systemCode);
            } catch (Exception e) {
                LogUtil.error("初始化参数失败:" + e.getMessage());
            }
        }
        LogUtil.info("初始化参数成功orgCode:" + orgCode + "---systemCode:" + systemCode);
    }
@ -116,7 +117,9 @@ public class LogThread implements Runnable {
    public String getLogFile() {
        String home = System.getProperty("catalina.home").replace('\\', '/');
        String filePath = home.substring(0, home.lastIndexOf('/') + 1) + "log/" + logFileName;
        String srcPath = home.substring(0, home.lastIndexOf('/') + 1) + File.separator + "log4j";
        String filePath = srcPath + File.separator + logFileName;
        ZipUtil.zip(srcPath, filePath);
        LogUtil.info("日志文件路径:" + filePath);
        File file = new File(filePath);
        if (file.exists()) {

+ 8 - 8
Hos-Resource-Mini-helper/src/main/java/com.yihu.ehr/thread/SQLThread.java

@ -26,7 +26,7 @@ public class SQLThread implements Runnable {
    private DBHelper db = new DBHelper();
    private DBHelper localdb = null;
    private String token;
    private boolean flag=true;
    private boolean flag = true;
    @Override
    public void run() {
@ -69,20 +69,20 @@ public class SQLThread 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);
    }
    /**
@ -127,9 +127,9 @@ public class SQLThread implements Runnable {
            List<NameValuePair> formParams = new ArrayList<NameValuePair>();
            formParams.add(new BasicNameValuePair("id", id));
            if(flag){
            if (flag) {
                formParams.add(new BasicNameValuePair("message", "执行失败"));
            }else{
            } else {
                formParams.add(new BasicNameValuePair("message", "执行成功"));
            }
            formParams.add(new BasicNameValuePair("result", resultObj));
@ -166,10 +166,10 @@ public class SQLThread implements Runnable {
        try {
            List<org.json.JSONObject> locallist = localdb.query(sql);
            LogUtil.info("执行语句得到数据数目:" + locallist.size());
            flag=true;
            flag = true;
            return locallist.toString();
        } catch (Exception e) {
            flag=false;
            flag = false;
            LogUtil.error("执行语句失败:" + e.getMessage());
            return "";
        }

+ 1 - 1
Hos-Resource-Mini-helper/target/maven-archiver/pom.properties

@ -1,5 +1,5 @@
#Generated by Maven
#Tue Mar 15 15:11:16 CST 2016
#Wed Mar 16 12:50:34 CST 2016
version=1.0-SNAPSHOT
groupId=ehr
artifactId=Hos-Resource-Mini-Helper