zhenglingfeng 8 лет назад
Родитель
Сommit
9b23fed3d8
22 измененных файлов с 474 добавлено и 379 удалено
  1. 10 19
      hos-broker/src/main/java/com/yihu/hos/common/configuration/MongoConfiguration.java
  2. 29 9
      hos-broker/src/main/java/com/yihu/hos/common/listener/ApplicationStartListener.java
  3. 69 38
      hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java
  4. 49 0
      hos-core/src/main/java/com/yihu/hos/core/datatype/ClassFileUtil.java
  5. 1 0
      hos-core/src/main/java/com/yihu/hos/core/encrypt/DES.java
  6. 87 0
      hos-web-framework/src/main/java/com/yihu/hos/web/framework/util/GridFSUtil.java
  7. 0 24
      src/main/java/com/yihu/hos/config/FilePathConfig.java
  8. 56 0
      src/main/java/com/yihu/hos/config/MongoConfig.java
  9. 0 9
      src/main/java/com/yihu/hos/services/IBaseManager.java
  10. 0 4
      src/main/java/com/yihu/hos/services/ServiceFlowEventService.java
  11. 45 24
      src/main/java/com/yihu/hos/system/controller/AppController.java
  12. 43 36
      src/main/java/com/yihu/hos/system/controller/FlowController.java
  13. 31 11
      src/main/java/com/yihu/hos/system/service/AppManager.java
  14. 36 162
      src/main/java/com/yihu/hos/system/service/FlowManager.java
  15. 7 0
      src/main/java/com/yihu/hos/system/service/intf/IAppManager.java
  16. 5 2
      src/main/java/com/yihu/hos/system/service/intf/IFlowManage.java
  17. 1 36
      src/main/resources/application.yml
  18. 1 1
      src/main/webapp/WEB-INF/ehr/jsp/system/app/appJs.jsp
  19. 1 1
      src/main/webapp/WEB-INF/ehr/jsp/system/app/editorApp.jsp
  20. 1 1
      src/main/webapp/WEB-INF/ehr/jsp/system/app/editorAppJs.jsp
  21. 1 1
      src/main/webapp/WEB-INF/ehr/jsp/system/flow/editorFlow.jsp
  22. 1 1
      src/main/webapp/WEB-INF/ehr/jsp/system/flow/flowJs.jsp

+ 10 - 19
hos-broker/src/main/java/com/yihu/hos/common/configuration/MongoConfiguration.java

@ -1,24 +1,20 @@
package com.yihu.hos.common.configuration;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.MongoTemplate;
import static java.util.Collections.singletonList;
/**
 * @created Airhead 2016/7/27.
 */
@Configuration
public class MongoConfiguration extends AbstractMongoConfiguration {
//    @Value("${spring.data.mongodb.uri}")
//    private String uri;
@Configuration("MongoConfiguration")
public class MongoConfiguration {
    public static final String BEAN_ID = "MongoConfiguration";
    @Value("${spring.data.mongodb.host}")
    private String host;
@ -33,20 +29,15 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
    @Value("${spring.data.mongodb.database}")
    private String database;
    @Override
    public String getDatabaseName() {
        return database;
    }
    private static MongoClient mongo;
    @Override
    @Bean
    public Mongo mongo() throws Exception {
        return new MongoClient(singletonList(new ServerAddress(host, port)),
                singletonList(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())));
    }
    public MongoTemplate mongoTemplate() throws Exception {
        return new MongoTemplate(mongo(), getDatabaseName());
    public MongoClient mongoClient() throws Exception {
        if(mongo == null) {
            return new MongoClient(singletonList(new ServerAddress(host, port)),
                    singletonList(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())));
        }
        return mongo;
    }
}

+ 29 - 9
hos-broker/src/main/java/com/yihu/hos/common/listener/ApplicationStartListener.java

@ -1,14 +1,19 @@
package com.yihu.hos.common.listener;
import com.mongodb.client.MongoDatabase;
import com.yihu.hos.common.configuration.MongoConfiguration;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.common.dao.BrokerDao;
import com.yihu.hos.core.constants.CoreConstant;
import com.yihu.hos.core.datatype.ClassFileUtil;
import com.yihu.hos.core.datatype.CollectionUtil;
import com.yihu.hos.core.encrypt.DES;
import com.yihu.hos.core.encrypt.RSA;
import com.yihu.hos.models.SystemCamelContext;
import com.yihu.hos.models.SystemClassMapping;
import com.yihu.hos.models.SystemServiceFlow;
import com.yihu.hos.models.SystemServiceFlowClass;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.apache.camel.builder.RouteBuilder;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
@ -16,6 +21,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@ -42,6 +48,8 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
    private void camelRouteStart(ContextRefreshedEvent contextRefreshedEvent) throws Exception {
        //从数据库获取所有路由对应的class路径以便动态加载
        BrokerDao brokerDao = (BrokerDao) contextRefreshedEvent.getApplicationContext().getBean(BrokerDao.BEAN_ID);
        MongoConfiguration mongoConfig = (MongoConfiguration) contextRefreshedEvent.getApplicationContext().getBean(MongoConfiguration.BEAN_ID);
        MongoDatabase mongoDatabase = mongoConfig.mongoClient().getDatabase("upload");
        List<SystemServiceFlow> systemServiceFlowList = brokerDao.getSystemServiceFlowList();
        List<SystemServiceFlowClass> systemServiceFlowClassList = brokerDao.getSystemServiceFlowClassList();
        File systemClassPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
@ -79,12 +87,18 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
                    String packageName = processesClass.getPackageName();
                    String classPath = processesClass.getClassPath();
                    // 创建文件
                    Boolean flag = ClassFileUtil.createClassfile(systemClassPath.toURI().toURL(), packageName, className, classPath);
                    FileOutputStream out = ClassFileUtil.createClassfile(systemClassPath.toURI().toURL(), packageName, className);
                    if (out != null) {
                        String fileName = DES.decrypt(classPath, DES.COMMON_PASSWORD);
                    // 记录到工具类中,以便其它线程需要时进行取用
                    if (flag) {
                        SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.PROCESSOR + className, packageName + CoreConstant.DOT + className);
                        if (GridFSUtil.readFile(mongoDatabase, out, fileName)) {
                            SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.PROCESSOR + className, packageName + CoreConstant.DOT + className);
                        } else {
                            isCorrectClassMap.put(code, false);
                        }
                    } else {
                        isCorrectClassMap.put(code, flag);
                        isCorrectClassMap.put(code, false);
                    }
                }
            }
@ -95,12 +109,18 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
                    String packageName = routesClass.getPackageName();
                    String classPath = routesClass.getClassPath();
                    // 创建文件
                    Boolean flag =ClassFileUtil.createClassfile(systemClassPath.toURI().toURL(), packageName, className, classPath);
                    // 记录到工具类中,以便其它线程需要时进行取用
                    if (flag) {
                        SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.ROUTE + className, packageName + CoreConstant.DOT + className);
                    FileOutputStream out = ClassFileUtil.createClassfile(systemClassPath.toURI().toURL(), packageName, className);
                    if (out != null) {
                        String fileName = DES.decrypt(classPath, DES.COMMON_PASSWORD);
                        // 记录到工具类中,以便其它线程需要时进行取用
                        if (GridFSUtil.readFile(mongoDatabase, out, fileName)) {
                            SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.ROUTE + className, packageName + CoreConstant.DOT + className);
                        } else {
                            isCorrectClassMap.put(code, false);
                        }
                    } else {
                        isCorrectClassMap.put(code, flag);
                        isCorrectClassMap.put(code, false);
                    }
                    if (isCorrectClassMap.get(code)) {
                        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();

+ 69 - 38
hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java

@ -1,21 +1,27 @@
package com.yihu.hos.services;
import com.mongodb.client.MongoDatabase;
import com.yihu.hos.common.classLoader.DynamicClassLoader;
import com.yihu.hos.common.compiler.CamelCompiler;
import com.yihu.hos.common.compiler.ClassParams;
import com.yihu.hos.common.configuration.MongoConfiguration;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.core.constants.CoreConstant;
import com.yihu.hos.core.datatype.ClassFileUtil;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.core.encrypt.DES;
import com.yihu.hos.models.SystemCamelContext;
import com.yihu.hos.models.SystemClassMapping;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.apache.camel.builder.RouteBuilder;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Map;
@ -26,6 +32,9 @@ import java.util.Map;
@Service("ESBCamelService")
public class ESBCamelService {
    public static final String BEAN_ID = "ESBCamelService";
    @Autowired
    private MongoConfiguration mongoConfig;
    private String dbName = "upload";
    private static Logger logger = LogManager.getLogger(ESBCamelService.class);
    /**
     * 当外界组件通知一个新的processor处理器被定义时,该事件被触发。
@ -41,8 +50,14 @@ public class ESBCamelService {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            this.createClassfile(serviceFlow, packageName, className, path, BrokerConstant.PROCESSOR);
            return Result.success("新增处理器成功!");
            FileOutputStream out = this.createClassfile(serviceFlow, packageName, className, BrokerConstant.PROCESSOR);
            String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
            MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
            if (GridFSUtil.readFile(db, out, fileName)) {
                return Result.success("新增处理器成功!");
            } else {
                return Result.error("新增处理器失败!");
            }
        } catch (Exception e) {
            logger.error(e);
            return Result.error("新增处理器失败!");
@ -59,23 +74,27 @@ public class ESBCamelService {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            this.updateClassfile(serviceFlow, packageName, className, path, BrokerConstant.PROCESSOR);
            SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
            SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
            classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.PROCESSOR + className));
            if (routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
            FileOutputStream out = this.updateClassfile(serviceFlow, packageName, className, BrokerConstant.PROCESSOR);
            String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
            MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
            if (GridFSUtil.readFile(db, out, fileName)) {
                SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
                SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
                DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
                Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
                classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.PROCESSOR + className));
                if (routeBuilderClass != null) {
                    RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                    SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
                    return Result.success("修改处理器成功!");
                }
            }
            return Result.success("修改处理器成功!");
            return Result.error("修改处理器失败!");
        } catch (Exception e) {
            logger.error(e);
            return Result.error("修改路由失败!");
            return Result.error("修改处理器失败!");
        }
    }
@ -90,16 +109,21 @@ public class ESBCamelService {
                return Result.error("必要的入参数据不正确,请检查!");
            }
            // 第1、2两步处理过程,都是在这里完成
            this.createClassfile(serviceFlow, packageName, className, path, BrokerConstant.ROUTE);
            // 3、===============加载到CamelContext中
            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
            if(routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
            FileOutputStream out = this.createClassfile(serviceFlow, packageName, className, BrokerConstant.ROUTE);
            String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
            MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
            if (GridFSUtil.readFile(db, out, fileName)) {
                // 3、===============加载到CamelContext中
                ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
                Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
                if(routeBuilderClass != null) {
                    RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                    SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
                }
                return Result.success("新增路由成功!");
            } else {
                return Result.error("新增路由失败!");
            }
            return Result.success("新增路由成功!");
        } catch (Exception e) {
            logger.error(e);
            return Result.error("新增路由失败!");
@ -118,15 +142,20 @@ public class ESBCamelService {
            }
            SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
            SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
            this.updateClassfile(serviceFlow, packageName, className, path, BrokerConstant.ROUTE);
            // 3、===============加载到CamelContext中
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE+className));
            if (routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
            FileOutputStream out = this.updateClassfile(serviceFlow, packageName, className, BrokerConstant.ROUTE);
            String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
            MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
            if (GridFSUtil.readFile(db, out, fileName)) {
                // 3、===============加载到CamelContext中
                DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
                Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE+className));
                if (routeBuilderClass != null) {
                    RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                    SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
                    return Result.success("修改路由成功!");
                }
            }
            return Result.success("修改路由成功!");
            return Result.error("修改路由失败!");
        } catch (Exception e) {
            return Result.error("修改路由失败!");
        }
@ -189,31 +218,33 @@ public class ESBCamelService {
    private void createClassfile(String serviceFlow, String packageName, String className, String path, String type) throws MalformedURLException {
    private FileOutputStream createClassfile(String serviceFlow, String packageName, String className, String type) throws MalformedURLException {
        // 1、============
        File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
        // 记录到工具类中,以便其它线程需要时进行取用
        SystemClassMapping.getSystemClassNameMapping().put(serviceFlow + type + className, packageName + CoreConstant.DOT + className);
        // 2、============开始写入class文件
        ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className, path);
        FileOutputStream out = ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className);
        // 完成
        logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 生成过程结束");
        return out;
    }
    private void updateClassfile(String serviceFlow, String packageName, String className, String path, String type) {
    private FileOutputStream updateClassfile(String serviceFlow, String packageName, String className, String type) {
        // 1、============
        Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
        String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
        if(StringUtil.isEmpty(systemClassName)) {
            return;
            return null;
        }
        String packagePath = StringUtil.replaceStrAll(packageName, ".", "/");
        String classPath = this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath() + packagePath + "/" + className + ".class";
        // 2、============开始写入class文件
        ClassFileUtil.updateClassfile(classPath, path);
        FileOutputStream out = ClassFileUtil.updateClassfile(classPath);
        // 完成
        logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 修改过程结束");
        return out;
    }
    private void deleteClassfile(String serviceFlow, String packageName, String className, String type) {
@ -312,7 +343,7 @@ public class ESBCamelService {
    public Result genProcessorFile(String serviceFlow, String packageName, String className, String path) {
        try {
            String   filePath= CamelCompiler.copyProcess(serviceFlow,path,packageName,className);
            String filePath= CamelCompiler.copyProcess(serviceFlow, path, packageName, className);
            if (filePath !=null){
                return Result.success(filePath);
            }else {

+ 49 - 0
hos-core/src/main/java/com/yihu/hos/core/datatype/ClassFileUtil.java

@ -93,4 +93,53 @@ public class ClassFileUtil {
            return false;
        }
    }
    /**
     * 通过这个工具方法,可以进行class文件的创建
     *
     * @param systemFlowURL 本次进行系统创建的system业务系统存储class文件的根目录
     * @param packageName   class文件的包信息
     * @param className     class文件的类名信息
     */
    public static FileOutputStream createClassfile(URL systemFlowURL, String packageName, String className) {
        // 开始输出文件内容
        try {
            File systemFlowFile = new File(systemFlowURL.getPath());
            if (!systemFlowFile.exists()) {
                systemFlowFile.mkdirs();
            }
            packageName = StringUtil.replaceStrAll(packageName, ".", "/");
            File packageFile = new File(systemFlowURL.getPath() + "/" + packageName);
            if (!packageFile.exists()) {
                packageFile.mkdirs();
            }
            String classPath = packageFile + "/" + className + ".class";
            File file = new File(classPath);
            if (file.isFile() && file.exists()) {
                file.delete();
            }
            file.createNewFile();
            FileOutputStream out = new FileOutputStream(classPath);
            return out;
        } catch (Exception e) {
            return null;
        }
    }
    public static FileOutputStream updateClassfile(String classPath) {
        // 开始输出文件内容
        try {
            File file = new File(classPath);
            if (file.isFile() && file.exists()) {
                file.delete();
            } else {
                file.createNewFile();
            }
            FileOutputStream out = new FileOutputStream(classPath);
            return out;
        } catch (Exception e) {
            return null;
        }
    }
}

+ 1 - 0
hos-core/src/main/java/com/yihu/hos/core/encrypt/DES.java

@ -11,6 +11,7 @@ import javax.crypto.spec.DESKeySpec;
 * @created Air 2015/6/2.
 */
public class DES {
    public static String COMMON_PASSWORD = "12345678";
    public static String encrypt(String data, String passWord) throws Exception {
        DESKeySpec desKey = new DESKeySpec(passWord.getBytes());
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");

+ 87 - 0
hos-web-framework/src/main/java/com/yihu/hos/web/framework/util/GridFSUtil.java

@ -20,10 +20,12 @@ import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;
import org.json.JSONObject;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Blob;
import java.util.*;
@ -450,4 +452,89 @@ public class GridFSUtil {
        }
        return result;
    }
    /**
     *  上传文件至Mongodb by GridFS
     *  @param db    数据库
     * @param file  文件
     */
    public static String uploadFile(MongoDatabase db, CommonsMultipartFile file) {
        //创建一个容器
        GridFSBucket gridFS = GridFSBuckets.create(db);
        //自定义字段
        Document metaDocument= new Document();
        // Create some custom options
        GridFSUploadOptions gridFSUploadOptions = new GridFSUploadOptions()
                .chunkSizeBytes(defaultChunkSize).metadata(metaDocument);
        String fileName = UUID.randomUUID() + file.getFileItem().getName();
        GridFSUploadStream uploadStream = gridFS.openUploadStream(fileName, gridFSUploadOptions);
        try {
            byte[] data = file.getBytes();
            uploadStream.write(data);
            ObjectId id = uploadStream.getFileId();
            if (id != null) {
                return fileName;
            }
        } finally {
            if (uploadStream != null) {
                uploadStream.close();
            }
        }
        return "";
    }
    /**
     * 据文件名返回文件,只返回第一个
     * @param fileName
     * @return
     */
    public static Boolean readFile(MongoDatabase db, OutputStream os, String fileName){
        try {
            GridFSBucket gridFS = GridFSBuckets.create(db);
            gridFS.downloadToStreamByName(fileName, os);
            os.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 从 mongodb GridFS 下载文件
     * @param dbName    数据库名
     * @param savePath 文件保存路径
     * @param fileName        GridFS文件名
     * @return
     */
    public static String downFile(String dbName, String savePath, String fileName) {
        //穿件mongodb连接
//        MongodbHelper mongoOrigin = new MongodbHelper(dbName);
        //创建一个容器
        MongoDatabase db = MongodbFactory.getDB(dbName);
        GridFSBucket gridFS = GridFSBuckets.create(db);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        gridFS.downloadToStreamByName(fileName, out);
        try {
            boolean succ = FileUtil.writeFile(savePath, out.toByteArray(), "utf-8");
            if (succ) {
                return savePath;
            } else {
                return null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

+ 0 - 24
src/main/java/com/yihu/hos/config/FilePathConfig.java

@ -1,24 +0,0 @@
package com.yihu.hos.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
 * Created by zhenglingfeng on 2016/11/23.
 */
@Configuration
public class FilePathConfig {
    @Value("${upload.file.path}")
    private String filePath;
    @Value("${upload.server.path}")
    private String serverPath;
    public String getFilePath() {
        return filePath;
    }
    public String getServerPath() {
        return serverPath;
    }
}

+ 56 - 0
src/main/java/com/yihu/hos/config/MongoConfig.java

@ -0,0 +1,56 @@
package com.yihu.hos.config;
import com.mongodb.*;
import com.yihu.ehr.dbhelper.jdbc.DBConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.MongoTemplate;
import static java.util.Collections.singletonList;
/**
 * @created Airhead 2016/7/27.
 */
@Configuration
public class MongoConfig {
    @Value("${spring.data.mongodb.host}")
    private String host;
    @Value("${spring.data.mongodb.port}")
    private int port;
    @Value("${spring.data.mongodb.username}")
    private String username;
    @Value("${spring.data.mongodb.password}")
    private String password;
    @Value("${spring.data.mongodb.authenticationDatabase}")
    private String authenticationDatabase;
    private static MongoClient mongo;
    @Bean
    public MongoClient mongoClient() throws Exception {
        if(mongo == null) {
            return new MongoClient(singletonList(new ServerAddress(host, port)),
                    singletonList(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())));
        }
        return mongo;
    }
    public String getHost() {
        return host;
    }
    public int getPort() {
        return port;
    }
    public String getUsername() {
        return username;
    }
    public String getPassword() {
        return password;
    }
}

+ 0 - 9
src/main/java/com/yihu/hos/services/IBaseManager.java

@ -1,19 +1,10 @@
package com.yihu.hos.services;
import org.springframework.web.multipart.MultipartFile;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/8/25.
 */
public interface IBaseManager {
    /**
     *
     * @param file  文件
     * @param baseSavePath 文件保存目录
     * @return
     */
    String uploadFile(MultipartFile file,String baseSavePath);
}

+ 0 - 4
src/main/java/com/yihu/hos/services/ServiceFlowEventService.java

@ -79,10 +79,6 @@ public class ServiceFlowEventService {
        this.sendMsg("processorClassAdded", serviceFlow, packageName, className, path);
    }
    public void processorClassChanged(String serviceFlow, String packageName, String className, String path) {
        this.sendMsg("processorClassChanged", serviceFlow, packageName, className, path);
    }
    private void sendMsg(String event, String serviceFlow, String packageName, String className, String path) {
        ObjectNode objectNode = objectMapper.createObjectNode();
        objectNode.put("event", event);

+ 45 - 24
src/main/java/com/yihu/hos/system/controller/AppController.java

@ -1,30 +1,30 @@
package com.yihu.hos.system.controller;
import com.yihu.hos.config.FilePathConfig;
import com.yihu.hos.system.model.SystemApp;
import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.system.service.intf.IAppManager;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.controller.BaseController;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.rmi.server.UID;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
 * 应用管理
@ -34,9 +34,6 @@ import java.util.UUID;
public class AppController extends BaseController {
    @Resource(name = "appManager")
    private IAppManager appManager;
    @Autowired
    private FilePathConfig filePathConfig;
    /**
     *  应用管理管理界面
     *
@ -329,23 +326,47 @@ public class AppController extends BaseController {
    /**
     * 文件上传
     * @param file
     * @param session
     * @return
     */
    @RequestMapping(value = "/upload", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Object upload(@RequestParam MultipartFile file,HttpSession session,HttpServletRequest request
    ) {
        UUID uuid = UUID.randomUUID();
        String basePath = filePathConfig.getFilePath() + uuid + "/";
        String path = appManager.uploadFile(file, basePath);
        if (StringUtils.isEmpty(path)){
            return Result.error("上传失败");
        }else {
            return Result.success(filePathConfig.getServerPath() + uuid + "/" + path);
    public Object upload(@RequestParam MultipartFile file) {
        try {
            CommonsMultipartFile transferFile = (CommonsMultipartFile)file;
            return appManager.uploadFile(transferFile);
        } catch (Exception e) {
            return Result.error("上传失败!");
        }
    }
    /**
     * 图片查看
     * @return
     */
    @RequestMapping(value = "/read/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public Object read(HttpServletResponse response, @PathVariable("fileName")  String fileName) {
        // response.setContentType("image/*");
        FileInputStream fis = null;
        OutputStream os = null;
        try {
            os = response.getOutputStream();
            appManager.readFile(os, fileName);
            int count = 0;
            byte[] buffer = new byte[1024 * 8];
            while ((count = fis.read(buffer)) != -1) {
                os.write(buffer, 0, count);
                os.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            fis.close();
            os.close();
        } catch (IOException e) {
            return Result.error("上传失败!");
        }
        return Result.error("上传成功!");
    }
}

+ 43 - 36
src/main/java/com/yihu/hos/system/controller/FlowController.java

@ -2,9 +2,6 @@ package com.yihu.hos.system.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.common.constants.Constants;
import com.yihu.hos.config.FilePathConfig;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowClass;
import com.yihu.hos.system.model.SystemServiceFlowTemp;
@ -12,21 +9,26 @@ import com.yihu.hos.system.service.FlowManager;
import com.yihu.hos.system.service.intf.IFlowManage;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 *  流程管理
@ -41,10 +43,6 @@ public class FlowController extends BaseController {
    @Resource(name = FlowManager.BEAN_ID)
    private IFlowManage flowManage;
    @Value("${esb.camelFile}")
    private String camelFile;
    @Autowired
    private FilePathConfig filePathConfig;
    /**
     *  流程管理管理界面
     *
@ -191,42 +189,51 @@ public class FlowController extends BaseController {
    /**
     * 文件上传
     * @param file
     * @param request
     * @return
     */
    @RequestMapping(value = "/upload", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Object upload(@RequestParam MultipartFile file,HttpServletRequest request
    ) {
    public Object upload(@RequestParam MultipartFile file) {
        //TODO 文件地址设置
        UUID uuid = UUID.randomUUID();
        StringBuilder basePath = new StringBuilder(camelFile + uuid + "/");
        String path = flowManage.uploadFile(file, basePath.toString());
        if (StringUtils.isEmpty(path)){
        try {
            CommonsMultipartFile transferFile = (CommonsMultipartFile)file;
            return flowManage.uploadFile(transferFile);
        } catch (Exception e) {
            return Result.error("上传失败");
        }else {
            return Result.success(basePath.toString() + path);
        }
    }
    @RequestMapping(value = "/uploadImg", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    /**
     * 图片查看
     * @return
     */
    @RequestMapping(value = "/read/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public Object uploadImg(@RequestParam MultipartFile file,HttpServletRequest request
    ) {
        //TODO 文件地址设置
        UUID uuid = UUID.randomUUID();
        String basePath = filePathConfig.getFilePath() + uuid + "/";
        String path = flowManage.uploadFile(file, basePath);
        if (StringUtils.isEmpty(path)){
            return Result.error("上传失败");
        }else {
            return Result.success(filePathConfig.getServerPath() + uuid + "/" + path);
    public Object read(HttpServletResponse response, @PathVariable("fileName")  String fileName) {
        // response.setContentType("image/*");
        FileInputStream fis = null;
        OutputStream os = null;
        try {
            os = response.getOutputStream();
            flowManage.readFile(os, fileName);
            int count = 0;
            byte[] buffer = new byte[1024 * 8];
            while ((count = fis.read(buffer)) != -1) {
                os.write(buffer, 0, count);
                os.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            fis.close();
            os.close();
        } catch (IOException e) {
            return Result.error("上传失败!");
        }
        return Result.error("上传成功!");
    }
    @RequestMapping(value = "/flowTempList", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Result flowTempList(String type) {

+ 31 - 11
src/main/java/com/yihu/hos/system/service/AppManager.java

@ -1,18 +1,22 @@
package com.yihu.hos.system.service;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.config.MongoConfig;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.core.encrypt.DES;
import com.yihu.hos.system.dao.intf.IAppDao;
import com.yihu.hos.system.dao.intf.IAppServiceDao;
import com.yihu.hos.system.model.SystemApp;
import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.system.service.intf.IAppManager;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
/**
@ -27,6 +31,9 @@ public class AppManager implements IAppManager {
    @Resource(name = "appServiceDao")
    private IAppServiceDao appServiceDao;
    @Autowired
    private MongoConfig mongoConfig;
    @Override
    public Result getAppList(Map<String, Object> params) throws Exception {
        return appDao.getAppList(params);
@ -124,17 +131,30 @@ public class AppManager implements IAppManager {
    @Override
    public String uploadFile(MultipartFile file, String baseSavePath) {
        String fileName =  file.getOriginalFilename();
        boolean succ = false;
    public Result uploadFile(CommonsMultipartFile file) {
        String dbName = "upload";
        String newFileName;
        try {
            succ = FileUtil.writeFile(baseSavePath +"/"+ fileName, file.getBytes(), "utf-8");
            if (succ){
                return  fileName;
            newFileName = GridFSUtil.uploadFile(mongoConfig.mongoClient().getDatabase(dbName), file);
            if (!StringUtil.isEmpty(newFileName)) {
                return Result.success(DES.encrypt(newFileName, DES.COMMON_PASSWORD));
            }
        } catch (IOException e) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("上传失败");
    }
    @Override
    public Result readFile(OutputStream os, String fileName) {
        String dbName = "upload";
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            GridFSUtil.readFile(mongoConfig.mongoClient().getDatabase(dbName), os, fileName);
            return Result.success("获取成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
        return Result.error("获取失败");
    }
}

+ 36 - 162
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -2,9 +2,9 @@ package com.yihu.hos.system.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.common.constants.Constants;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.core.http.HTTPResponse;
import com.yihu.hos.core.http.HttpClientKit;
import com.yihu.hos.config.MongoConfig;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.core.encrypt.DES;
import com.yihu.hos.services.ServiceFlowEventService;
import com.yihu.hos.system.dao.FlowClassDao;
import com.yihu.hos.system.dao.FlowTempDao;
@ -18,16 +18,18 @@ import com.yihu.hos.system.service.intf.IFlowManage;
import com.yihu.hos.web.framework.model.ActionResult;
import com.yihu.hos.web.framework.model.DictItem;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 系统流程管理业务类
@ -41,9 +43,6 @@ public class FlowManager implements IFlowManage {
    public static final String BEAN_ID = "flowManager";
    @Value("${esb.genCamelUrl}")
    private String genCamelUrl;
    @Resource(name = "flowDao")
    private IFlowDao flowDao;
@ -54,7 +53,8 @@ public class FlowManager implements IFlowManage {
    private IFlowTempDao flowTempDao;
    @Autowired
    ServiceFlowEventService serviceFlowEventService;
    @Autowired
    private MongoConfig mongoConfig;
    @Override
    public Result getFlowList(Map<String, Object> params) throws Exception {
        return flowDao.getFlowList(params);
@ -236,20 +236,32 @@ public class FlowManager implements IFlowManage {
        return false;
    }
    @Override
    public String uploadFile(MultipartFile file, String baseSavePath) {
        String fileName =  file.getOriginalFilename();
        boolean succ = false;
    public Result uploadFile(CommonsMultipartFile file) {
        String dbName = "upload";
        String newFileName;
        try {
            succ = FileUtil.writeFile(baseSavePath + File.separator + fileName, file.getBytes(), "utf-8");
            if (succ){
                return  fileName;
            newFileName = GridFSUtil.uploadFile(mongoConfig.mongoClient().getDatabase(dbName), file);
            if (!StringUtil.isEmpty(newFileName)) {
                return Result.success(DES.encrypt(newFileName, DES.COMMON_PASSWORD));
            }
        } catch (IOException e) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
        return Result.error("上传失败");
    }
    @Override
    public Result readFile(OutputStream os, String fileName) {
        String dbName = "upload";
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            GridFSUtil.readFile(mongoConfig.mongoClient().getDatabase(dbName), os, fileName);
            return Result.success("获取成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("获取失败");
    }
    /**
@ -315,7 +327,7 @@ public class FlowManager implements IFlowManage {
        Long timestamp = System.currentTimeMillis();
        Integer newFlowId = sendAddProcessore(flowTempId, timestamp);
        if (newFlowId != null){
            newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
            newFlowId = sendAddRoute(flowTempId, newFlowId, newCron);
            if (newFlowId !=null){
                return newFlowId;
            }else {
@ -328,141 +340,6 @@ public class FlowManager implements IFlowManage {
        }
    }
    public Integer addRouteFile(Integer tempId,Integer flowId, String newCron ,Long timestamp) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
        SystemServiceFlow newFlow = getFlowById(flowId);
        //route模板文件记录是否存在。不存在就返回。
        if (!flowTempRouters.isEmpty()){
            Map<String,String> params = null;
            SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
            StringBuilder basePath = new StringBuilder();;
            if (flowTemp.getPackageName()!=null){
                String packagePath[] = flowTemp.getPackageName().split("\\.");
                for (int i=0;i<packagePath.length;i++){
                    basePath.append(packagePath[i]).append("/");
                }
            }
            //新增processor记录
                String newClassName = flowTemp.getClassName()+timestamp;
                String newRoutePath =null;
                params = new HashMap<>();
                params.put("routeId", newFlow.getCode());
                params.put("type",Constants.FLOW_TYPE_ROUTE);
                params.put("filePath", flowTemp.getClassPath());
                params.put("packageName", basePath.toString());
                params.put("oldClassName", flowTemp.getClassName());
                params.put("newClassName",newClassName);//原文件名加当前时间戳
                params.put("newCron",newCron);
                HTTPResponse response  = HttpClientKit.post(genCamelUrl, params);
                if (response.getStatusCode()==200 ){
                    Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                    boolean succ = (boolean) body.get("successFlg");
                    if (succ){
                        newRoutePath = body.get("message").toString();
                    }else {
                        return null;
                    }
                    System.out.println(response.getBody());
                    SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
                    newFlowClass.setPackageName(flowTemp.getPackageName());
                    newFlowClass.setClassName(newClassName);
                    newFlowClass.setClassPath(newRoutePath);
                    newFlowClass.setFlowId(newFlow.getId());
                    newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
                    flowClassDao.saveEntity(newFlowClass);
                    newFlowClass.setIsUpdate("1");
                    sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
                }else {
                    return null;
                }
            return newFlow.getId();
        }
        return null;
    }
    public Integer addProcessorFile(Integer flowId, String newCron,Long timestamp) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
        List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
        SystemServiceFlow oldFlow = getFlowById(flowId);
        //route模板文件记录是否存在。不存在就返回。
        if (!flowClassRouters.isEmpty()){
            Map<String,String> params = null;
            SystemServiceFlowTemp flowTemp =flowClassRouters.get(0);
            StringBuilder basePath = new StringBuilder();;
            if (flowTemp.getPackageName()!=null){
                String packagePath[] = flowTemp.getPackageName().split("\\.");
                for (int i=0;i<packagePath.length;i++){
                    basePath.append(packagePath[i]).append("/");
                }
            }
            //成功生成文件后,添加flow和flowclass记录
            //生成新流程
            SystemServiceFlow newFlow = new SystemServiceFlow();
            newFlow.setName(oldFlow.getName()+timestamp);
            newFlow.setCode(oldFlow.getCode()+timestamp);
            newFlow.setChart(oldFlow.getChart());
            newFlow.setValid(1);
            newFlow.setCreateDate(new Date());
            newFlow.setFileType(Constants.CLASS);
            flowDao.saveEntity(newFlow);
            //新增processor记录
            for (SystemServiceFlowTemp process:flowClassProces){
//                String newProcessName = process.getClassName()+timestamp;
                String newProcessPath = null;
                StringBuilder proPath =  new StringBuilder( );;
                if (process.getPackageName()!=null){
                    String packagePath[] = process.getPackageName().split("\\.");
                    for (int i=0;i<packagePath.length;i++){
                        proPath.append(packagePath[i]).append("/");
                    }
                }
                params = new HashMap<>();
                params.put("routeId", newFlow.getCode());
                params.put("type",Constants.FLOW_TYPE_PROCESSOR);
                params.put("filePath", process.getClassPath());
                params.put("packageName", proPath.toString());
                params.put("newClassName",process.getClassName());//原文件名加当前时间戳
                params.put("oldClassName", process.getClassName());
                params.put("newCron",newCron);
                HTTPResponse response = HttpClientKit.post(genCamelUrl, params);
                if (response.getStatusCode()==200 ){
                    Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                    boolean succ = (boolean) body.get("successFlg");
                    if (succ){
                        newProcessPath = body.get("message").toString();
                        System.out.println(response.getBody());
                        SystemServiceFlowClass processClass = new SystemServiceFlowClass();
                        processClass.setPackageName(process.getPackageName());
                        processClass.setClassName(process.getClassName());
                        processClass.setClassPath(newProcessPath);
                        processClass.setFlowId(newFlow.getId());
                        processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
                        flowClassDao.saveEntity(processClass);
                        processClass.setIsUpdate("1");
                        sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
                    }else {
                        return null;
                    }
                }else {
                    return null;
                }
            }
            return newFlow.getId();
        }
        return null;
    }
    /**
     * 修改camel相关文件
     * @param flowId 流程ID
@ -472,8 +349,6 @@ public class FlowManager implements IFlowManage {
     */
    @Override
    public Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception {
        Long timestamp = System.currentTimeMillis();
        ObjectMapper objectMapper = new ObjectMapper();
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowTempId, Constants.FLOW_TYPE_ROUTE);
        List<SystemServiceFlowClass> flowClassRouters = flowClassDao.getFlowClass(flowId, Constants.FLOW_TYPE_ROUTE);
//        SystemServiceFlow oldFlow = getFlowById(flowId);
@ -507,13 +382,12 @@ public class FlowManager implements IFlowManage {
    /* *********************       发送消息方式生成文件   ********************************/
    public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron, Long timestamp) throws Exception {
    public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron) throws Exception {
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
        SystemServiceFlow newFlow = getFlowById(flowId);
        //route模板文件记录是否存在。不存在就返回。
        if (!flowTempRouters.isEmpty()) {
            Map<String, String> params = null;
            SystemServiceFlowTemp flowTemp = flowTempRouters.get(0);
            StringBuilder basePath = new StringBuilder();
            ;
@ -564,7 +438,7 @@ public class FlowManager implements IFlowManage {
            //新增processor记录
            for (SystemServiceFlowTemp process : flowTempProces) {
                String newProcessPath = null;
                String newProcessPath;
                StringBuilder proPath = new StringBuilder();
                ;
                if (process.getPackageName() != null) {

+ 7 - 0
src/main/java/com/yihu/hos/system/service/intf/IAppManager.java

@ -4,7 +4,11 @@ import com.yihu.hos.services.IBaseManager;
import com.yihu.hos.system.model.SystemApp;
import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.File;
import java.io.OutputStream;
import java.util.Map;
/**
@ -34,4 +38,7 @@ public interface IAppManager extends IBaseManager{
    Result deleteAppService(String id) throws Exception;
    Result uploadFile(CommonsMultipartFile file) throws Exception;
    Result readFile(OutputStream os, String fileName) throws Exception;
}

+ 5 - 2
src/main/java/com/yihu/hos/system/service/intf/IFlowManage.java

@ -5,7 +5,10 @@ import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowClass;
import com.yihu.hos.system.model.SystemServiceFlowTemp;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
@ -69,6 +72,6 @@ public interface IFlowManage extends IBaseManager {
     * @throws Exception
     */
    Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception;
    Result uploadFile(CommonsMultipartFile file) throws Exception;
    Result readFile(OutputStream os, String fileName) throws Exception;
}

+ 1 - 36
src/main/resources/application.yml

@ -27,21 +27,11 @@ spring:
      username: esb
      password: esb
      authenticationDatabase: admin
      database: configuration
  activemq:
    broker-url: tcp://172.19.103.86:61616?wireFormat.maxInactivityDuration=0
    user: admin
    password: admin
    pooled: false
esb:
  genCamelUrl: http://192.168.131.11:8099/esb/genCamelFile
  camelFile: D:\
upload:
  file:
    path: D:\code\newHealth\new-esb\esb\src\main\webapp\
  server:
    path: http://localhost:8080/esb/
---
spring:
  profiles: test
@ -52,20 +42,11 @@ spring:
      username: esb
      password: esb
      authenticationDatabase: admin
      database: configuration
  activemq:
    broker-url: tcp://172.19.103.86:61616?wireFormat.maxInactivityDuration=0
    user: admin
    password: admin
    pooled: false
esb:
  genCamelUrl: http://192.168.131.11:8099/esb/genCamelFile
  camelFile: usr/local/esb/
upload:
  file:
    path: /usr/local/esb/file/webapps/ROOT/
  server:
    path: http://172.19.103.89:8081/
#  data:
#    mongodb:
#      host: 172.19.103.86
@ -85,22 +66,12 @@ spring:
      username: esb
      password: esb
      authenticationDatabase: admin
      database: configuration
  activemq:
    broker-url: tcp://172.19.103.86:61616?wireFormat.maxInactivityDuration=0
    user: admin
    password: admin
    pooled: false
upload:
  file:
    path: /usr/local/esb/file/webapps/ROOT/
  server:
    path: http://172.19.103.89:8081/
esb:
  genCamelUrl: http://127.0.0.1:8099/esb/genCamelFile
  camelFile: D:\camel-class\
---
spring:
  profiles: hzy
@ -111,14 +82,8 @@ spring:
      username: esb
      password: esb
      authenticationDatabase: admin
      database: configuration
  activemq:
    broker-url: tcp://172.19.103.86:61616?wireFormat.maxInactivityDuration=0
    user: admin
    password: admin
    pooled: false
upload:
  file:
    path: /usr/local/esb/file/webapps/ROOT/
  server:
    path: http://172.19.103.89:8081/
    pooled: false

+ 1 - 1
src/main/webapp/WEB-INF/ehr/jsp/system/app/appJs.jsp

@ -33,7 +33,7 @@
                    {display: '应用名称', id: 'id', name: 'name', width: '15%'},
                    {display: '英文名', name: 'code', width: '10%'},
                    {display: '图标', name: 'icon', width: '10%',height:'50',align: 'center', render: function (rowdata, rowindex, value) {
                        return ' <div style="vertical-align:middle;"><img  style="width: 50px; height: 50px;"  src="'+ rowdata.icon+'" /></div>';
                        return ' <div style="vertical-align:middle;"><img  style="width: 50px; height: 50px;"  src="${contextRoot}/app/read/'+ rowdata.icon+'" /></div>';
                    }},
                    {display: '开发者', name: 'developer', width: '10%'},
                    {display: '状态', name: 'status', width: '10%',align: 'center', render: function (rowdata, rowindex, value) {

+ 1 - 1
src/main/webapp/WEB-INF/ehr/jsp/system/app/editorApp.jsp

@ -27,7 +27,7 @@
        <label><span class="red">*&nbsp;</span>图标:</label>
        <div class="m-form-control">
            <c:if test="${model.icon!=''}">
                <img style="width: 60px;" src="${model.icon}" id="img_icon">
                <img style="width: 60px;" src="${contextRoot}/app/read/${model.icon}" id="img_icon">
            </c:if>
        </div>
    </div>

+ 1 - 1
src/main/webapp/WEB-INF/ehr/jsp/system/app/editorAppJs.jsp

@ -162,7 +162,7 @@
                                formsay.html("上传成功");
                                formObj.find("input[type=text]").attr("data-id", data.message)//设置已上传的文件的ID
                                formObj.find("input[type=text]").val(data.message)//设置已上传的文件的ID
                                $("#img_icon").attr("src", data.message)//设置已上传的文件的ID
                                $("#img_icon").attr("src", "${contextRoot}/app/read/"+data.message)//设置已上传的文件的ID
                                formObj.closest("div").find("span").html("重新上传<i></i>");
                            }else{
                                $.ligerDialog.error("上传格式有问题");

+ 1 - 1
src/main/webapp/WEB-INF/ehr/jsp/system/flow/editorFlow.jsp

@ -42,7 +42,7 @@
        <div class="m-form-group">
            <label><span class="red">*&nbsp;</span>流程图:</label>
            <div class="m-form-control">
                <form id="formIcon" action="${contextRoot}/flow/uploadImg" method="post" enctype="multipart/form-data">
                <form id="formIcon" action="${contextRoot}/flow/upload" method="post" enctype="multipart/form-data">
                    <input type="text" id="iconUrl" name="chart" class="l-textbox btnIconGrayUp" style="width: 144px;"  placeholder="点击选择图片" readonly="readonly" data-id="">
                    <div style="float: right;">
                        <div  class="l-button l-button-no formIcon" data-id="formIcon">

+ 1 - 1
src/main/webapp/WEB-INF/ehr/jsp/system/flow/flowJs.jsp

@ -45,7 +45,7 @@
                        display: '操作', name: 'operator', width: '40%', render: function (row) {
                        var html = '<div class="m-inline-buttons" style="width:350px;vertical-align:middle;">';
                        html += "<a class=\"m-btn\" style=\"padding-right:10px\" onclick=\"flow.showImage('"+row.chart+"')\">查看流程图</a>";
                        html += "<a class=\"m-btn\" style=\"padding-right:10px\" onclick=\"flow.showImage('${contextRoot}/app/read/"+row.chart+"')\">查看流程图</a>";
                        html += "<a class=\"m-btn-edit\" onclick=\"flow.editorDialog('"+row.id+"')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"flow.delete('"+row.id+"')\"></a>";
                        html += '</div>';