Browse Source

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

zhenglingfeng 8 years ago
parent
commit
f128670b7f
23 changed files with 802 additions and 52 deletions
  1. 137 0
      hos-broker/src/main/java/com/yihu/hos/common/compiler/CamelCompiler.java
  2. 21 0
      hos-broker/src/main/java/com/yihu/hos/controllers/ESBCamelController.java
  3. 18 1
      hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java
  4. 137 0
      hos-camel/src/main/java/compiler/JavaCompilerUtil.java
  5. 25 0
      hos-camel/src/main/java/crawler/route/QuartzRoute.java
  6. 31 0
      hos-core/src/main/java/com/yihu/hos/core/file/FileUtil.java
  7. 3 0
      src/main/java/com/yihu/hos/common/constants/Constants.java
  8. 9 1
      src/main/java/com/yihu/hos/datacollect/model/RsJobConfig.java
  9. 18 0
      src/main/java/com/yihu/hos/datacollect/service/DatacollectManager.java
  10. 40 12
      src/main/java/com/yihu/hos/system/controller/FlowController.java
  11. 2 1
      src/main/java/com/yihu/hos/system/dao/FlowClassDao.java
  12. 9 0
      src/main/java/com/yihu/hos/system/dao/FlowDao.java
  13. 46 0
      src/main/java/com/yihu/hos/system/dao/FlowTempDao.java
  14. 4 0
      src/main/java/com/yihu/hos/system/dao/intf/IFlowDao.java
  15. 17 0
      src/main/java/com/yihu/hos/system/dao/intf/IFlowTempDao.java
  16. 9 0
      src/main/java/com/yihu/hos/system/model/SystemServiceFlow.java
  17. 93 0
      src/main/java/com/yihu/hos/system/model/SystemServiceFlowTemp.java
  18. 86 24
      src/main/java/com/yihu/hos/system/service/FlowManager.java
  19. 8 0
      src/main/java/com/yihu/hos/system/service/intf/IFlowManage.java
  20. 5 0
      src/main/resources/resource/RsJobConfig.hbm.xml
  21. 48 0
      src/main/resources/resource/SystemServiceFlowTemp.hbm.xml
  22. 1 1
      src/main/webapp/WEB-INF/ehr/jsp/system/flow/editorFlow.jsp
  23. 35 12
      src/main/webapp/WEB-INF/ehr/jsp/system/flow/editorFlowJs.jsp

+ 137 - 0
hos-broker/src/main/java/com/yihu/hos/common/compiler/CamelCompiler.java

@ -0,0 +1,137 @@
package com.yihu.hos.common.compiler;
import com.yihu.hos.core.file.FileUtil;
import javax.tools.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
 *  java编译工具类
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/11/17.
 */
public class CamelCompiler {
    private static String packagePathTemplate = System.getProperty("user.dir")//获取到项目的根路径
            + "/hos-broker/src/main/java/";
    private static String classPathTemplate = System.getProperty("user.dir")//获取到项目的根路径
            + "/hos-broker/src/main/java/%s/%s.java";
    /**
     * 编译java文件
     * @param packageName     java包路径
     * @param oldClassName   旧java文件名
     * @param newClassName   新java文件名
     * @param newCron         新cron表达式
     * @throws IOException
     */
    public static void compiler(String packageName,String oldClassName,String newClassName,String newCron) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        File file = genNewJava(packageName, oldClassName,newClassName, newCron);
        if (file!=null){
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
            // options命令行选项
            Iterable<String> options = Arrays.asList("-d",classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
            JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
            // 编译源程序
            boolean success = task.call();
            if (!success){
                List diagnostics1 = diagnostics.getDiagnostics();
                for (int i=0;i<diagnostics1.size();i++){
                    System.out.println(diagnostics1.get(i).toString());
                }
            }
            fileManager.close();
            System.out.println((success) ? "编译成功" : "编译失败");
        }
    }
    /**
     *  修改cron表达式,生成新java文件
     * @param packageName   包名
     * @param oldClassName  旧类名
     * @param newClassName  新类名
     * @param newContent    新cron表达式
     */
    public static File genNewJava(String packageName, String oldClassName,String newClassName, String newContent) {
        try {
            String oldPath = String.format(classPathTemplate, packageName, oldClassName);
            String newPath = String.format(classPathTemplate, packageName, newClassName);
            String text = FileUtil.readFileText(new File(oldPath));
            if (text.contains("?cron=")){
                String oldStr = text.substring(text.indexOf("?cron=")+6);
                String cron = oldStr.substring(0,oldStr.indexOf("\""));
                text = text.replace(cron,newContent);
            }
            if (text.contains(oldClassName)){
                text = text.replace(oldClassName,newClassName);
            }
            File f = new File(newPath);
            FileWriter fw = new FileWriter(f);
            fw.write(text);
            fw.flush();
            fw.close();//这里只是产生一个JAVA文件,简单的IO操作
            return f;
        }
        catch (Exception e) {
            System.out.println("修改操作出错");
            e.printStackTrace();
        }
        return null;
    }
    public static void compiler2(String packageName,String className) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        Iterable compilationUnits = fileManager.getJavaFileObjects(String.format(classPathTemplate, packageName, className));
        // options命令行选项
        // 指定的路径一定要存在,javac不会自己创建文件夹
        Iterable<String> options = Arrays.asList(  "-d", classPath);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
        // 编译源程序
        boolean success = task.call();
        if (!success){
            List diagnostics1 = diagnostics.getDiagnostics();
            for (int i=0;i<diagnostics1.size();i++){
                System.out.println(diagnostics1.get(i).toString());
            }
        }
        fileManager.close();
        System.out.println((success) ? "编译成功" : "编译失败");
    }
    public static void main(String[] args) {
        try {
            compiler("/crawler/route", "QuartzRoute","QuartzRoute001","xx000xx");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

+ 21 - 0
hos-broker/src/main/java/com/yihu/hos/controllers/ESBCamelController.java

@ -118,4 +118,25 @@ public class ESBCamelController {
            @RequestParam(value = "serviceFlow") String serviceFlow) {
        return esbCamelService.onRouteDefineStop(serviceFlow);
    }
    @RequestMapping(value = "/genCamelFile", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation(value = "生成新的camel文件", produces = "application/json", notes = "生成新的camel文件")
    public Result genCamelFile(
            @ApiParam(name = "routeId", value = "routeId", required = true)
            @RequestParam(value = "routeId") String routeId,
            @ApiParam(name = "pageName", value = "包名", required = true)
            @RequestParam(value = "pageName") String pageName,
            @ApiParam(name = "oldClassName", value = "旧类名", required = true)
            @RequestParam(value = "oldClassName") String oldClassName,
            @ApiParam(name = "newClassName", value = "新类名", required = true)
            @RequestParam(value = "newClassName") String newClassName,
            @ApiParam(name = "newCron", value = "新cron表达式", required = true)
            @RequestParam(value = "routeId") String newCron) {
        return esbCamelService.genNewClassfile(routeId, pageName, oldClassName, newClassName, newCron);
    }
}

+ 18 - 1
hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java

@ -1,6 +1,7 @@
package com.yihu.hos.services;
import com.yihu.hos.common.classLoader.DynamicClassLoader;
import com.yihu.hos.common.compiler.CamelCompiler;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.core.constants.CoreConstant;
import com.yihu.hos.core.datatype.ClassFileUtil;
@ -14,6 +15,7 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Map;
@ -231,4 +233,19 @@ public class ESBCamelService {
        // 完成
        logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 删除过程结束");
    }
}
    /* **************************       修改任务cron生成新的camel文件 add by hzy   *********************************** */
    public Result genNewClassfile(String routeId, String packageName, String oldClassName, String newClassName,String newCron) {
        try {
            CamelCompiler.compiler(packageName,oldClassName,newClassName,newCron);
            return Result.success("生成新文件成功!");
        } catch (IOException e) {
            e.printStackTrace();
            return Result.error("生成新文件失败!");
        }
    }
    }

+ 137 - 0
hos-camel/src/main/java/compiler/JavaCompilerUtil.java

@ -0,0 +1,137 @@
package compiler;
import com.yihu.hos.core.file.FileUtil;
import javax.tools.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
 *  java编译工具类
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/11/17.
 */
public class JavaCompilerUtil {
    private static String packagePathTemplate = System.getProperty("user.dir")//获取到项目的根路径
            + "/hos-camel/src/main/java/";
    private static String classPathTemplate = System.getProperty("user.dir")//获取到项目的根路径
            + "/hos-camel/src/main/java/%s/%s.java";
    /**
     * 编译java文件
     * @param packageName     java包路径
     * @param oldClassName   旧java文件名
     * @param newClassName   新java文件名
     * @param newCron         新cron表达式
     * @throws IOException
     */
    public static void compiler(String packageName,String oldClassName,String newClassName,String newCron) throws IOException {
        String classPath = JavaCompilerUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        File file = genNewJava(packageName, oldClassName,newClassName, newCron);
        if (file!=null){
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
            // options命令行选项
            Iterable<String> options = Arrays.asList("-d",classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
            JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
            // 编译源程序
            boolean success = task.call();
            if (!success){
                List diagnostics1 = diagnostics.getDiagnostics();
                for (int i=0;i<diagnostics1.size();i++){
                    System.out.println(diagnostics1.get(i).toString());
                }
            }
            fileManager.close();
            System.out.println((success) ? "编译成功" : "编译失败");
        }
    }
    /**
     *  修改cron表达式,生成新java文件
     * @param packageName   包名
     * @param oldClassName  旧类名
     * @param newClassName  新类名
     * @param newContent    新cron表达式
     */
    public static File genNewJava(String packageName, String oldClassName,String newClassName, String newContent) {
        try {
            String oldPath = String.format(classPathTemplate, packageName, oldClassName);
            String newPath = String.format(classPathTemplate, packageName, newClassName);
            String text = FileUtil.readFileText(new File(oldPath));
            if (text.contains("?cron=")){
                String oldStr = text.substring(text.indexOf("?cron=")+6);
                String cron = oldStr.substring(0,oldStr.indexOf("\""));
                text = text.replace(cron,newContent);
            }
            if (text.contains(oldClassName)){
                text = text.replace(oldClassName,newClassName);
            }
            File f = new File(newPath);
            FileWriter fw = new FileWriter(f);
            fw.write(text);
            fw.flush();
            fw.close();//这里只是产生一个JAVA文件,简单的IO操作
            return f;
        }
        catch (Exception e) {
            System.out.println("修改操作出错");
            e.printStackTrace();
        }
        return null;
    }
    public static void compiler2(String packageName,String className) throws IOException {
        String classPath = JavaCompilerUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        Iterable compilationUnits = fileManager.getJavaFileObjects(String.format(classPathTemplate, packageName, className));
        // options命令行选项
        // 指定的路径一定要存在,javac不会自己创建文件夹
        Iterable<String> options = Arrays.asList(  "-d", classPath);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
        // 编译源程序
        boolean success = task.call();
        if (!success){
            List diagnostics1 = diagnostics.getDiagnostics();
            for (int i=0;i<diagnostics1.size();i++){
                System.out.println(diagnostics1.get(i).toString());
            }
        }
        fileManager.close();
        System.out.println((success) ? "编译成功" : "编译失败");
    }
    public static void main(String[] args) {
        try {
            compiler("/crawler/route", "QuartzRoute","QuartzRoute001","xx000xx");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

+ 25 - 0
hos-camel/src/main/java/crawler/route/QuartzRoute.java

@ -0,0 +1,25 @@
package crawler.route;
import crawler.processor.Processor0;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/11/17.
 */
public class QuartzRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("quartz://myGroupName/myTimerName?cron=0/5+*+*+*+*+?")
                .process(new Processor0() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("I'm running every 5 sec...Change by XXXX===========");
                    }
                });
    }
}

+ 31 - 0
hos-core/src/main/java/com/yihu/hos/core/file/FileUtil.java

@ -284,4 +284,35 @@ public class FileUtil {
        return buffer;
    }
    /**
     * 读取文本文件内容
     * @param file  文件路径
     * @return
     */
    public static String readFileText(File file) {
        StringBuilder stringBuilder = new StringBuilder();
        InputStream in = null;
        BufferedReader br = null;
        try {
            in = new FileInputStream(file);
            br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            String line = null;
            while ((line = br.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e1) {
                }
            }
        }
        return stringBuilder.toString();
    }
}

+ 3 - 0
src/main/java/com/yihu/hos/common/constants/Constants.java

@ -9,6 +9,9 @@ public class Constants {
    //流程-队列名称
    public static String FLOW_QUEUE_NAME = "configuration.service.flow";
    //流程-模板类型
    public static String JAVA = "java";
    public static String CLASS = "class";
    //流程-路由类型
    public static String FLOW_TYPE_ROUTE = "route";

+ 9 - 1
src/main/java/com/yihu/hos/datacollect/model/RsJobConfig.java

@ -23,13 +23,21 @@ public class RsJobConfig implements java.io.Serializable {
	private Date repeatStartTime;
	private Date repeatEndTime;
	private Integer delayTime;
	private Integer flowId;
	// Constructors
	/** default constructor */
	public RsJobConfig() {
	}
	public Integer getFlowId() {
		return flowId;
	}
	public void setFlowId(Integer flowId) {
		this.flowId = flowId;
	}
	public String getJobContent() {
		return jobContent;
	}

+ 18 - 0
src/main/java/com/yihu/hos/datacollect/service/DatacollectManager.java

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.hos.common.Services;
import com.yihu.hos.core.http.HttpClientKit;
import com.yihu.hos.datacollect.dao.intf.IDatacollectDao;
import com.yihu.hos.datacollect.model.*;
import com.yihu.hos.datacollect.service.intf.IDatacollectManager;
@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -528,4 +530,20 @@ public class DatacollectManager implements IDatacollectManager {
            return;
        }
    }
    /**
     * TODO 调用broker接口生成camel相关文件
     * @param jobId
     * @param newCron
     * @throws Exception
     */
    private void genCamelFile(String jobId, String newCron) throws Exception {
        String url = "http://192.168.131.11:8080/esb/genCamelFile";
        Map<String,String> params = new HashMap<>();
        String result = HttpClientKit.post(url, params).getBody();
    }
}

+ 40 - 12
src/main/java/com/yihu/hos/system/controller/FlowController.java

@ -1,13 +1,14 @@
package com.yihu.hos.system.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.common.constants.Constants;
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.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.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
@ -84,19 +85,25 @@ public class FlowController extends BaseController {
            ObjectMapper objectMapper = new ObjectMapper();
            SystemServiceFlow flow = null;
            List<SystemServiceFlowClass> flowClassList = null;
            List<SystemServiceFlowTemp> flowTempList = null;
            if (id != null && id.length() > 0) {
                flow = flowManage.getFlowById(Integer.parseInt(id));
                flowClassList = flowManage.getFlowClassByFlowId(flow.getId());
                flowTempList = flowManage.getFlowTempByFlowId(flow.getId());
                if (Constants.CLASS.equals(flow.getFileType())){
                    model.addAttribute("flowClass", objectMapper.writeValueAsString(flowClassList));
                }else if (Constants.JAVA.equals(flow.getFileType())){
                    model.addAttribute("flowClass", objectMapper.writeValueAsString(flowTempList));
                }
            }  else {
                flow = new SystemServiceFlow();
                flowClassList = new ArrayList<>();
            }
            if (flowClassList == null){
                flowClassList = new ArrayList<>();
                flowTempList = new ArrayList<>();
            }
            flow.setFlowClassArray(flowClassList);
            flow.setFlowTempArray(flowTempList);
            model.addAttribute("model", flow);
            model.addAttribute("flowClass", objectMapper.writeValueAsString(flowClassList));
            model.addAttribute("contentPage", "/system/flow/editorFlow");
        } catch (Exception e) {
            e.printStackTrace();
@ -112,15 +119,23 @@ public class FlowController extends BaseController {
     */
    @RequestMapping("addFlow")
    @ResponseBody
    public Result addFlow(HttpServletRequest request) {
    public Result addFlow(HttpServletRequest request,String flowClass) {
        try {
            SystemServiceFlow obj = new SystemServiceFlow();
            BeanUtils.populate(obj, request.getParameterMap());
            ObjectMapper objectMapper = new ObjectMapper();
            SystemServiceFlow flow = objectMapper.readValue(flowClass,SystemServiceFlow.class);
            List<SystemServiceFlowClass> flowClass = new ArrayList<>();
            BeanUtils.populate(flowClass, request.getParameterMap());
            obj.setFlowClassArray(flowClass);
            return flowManage.addFlow(obj);
//            SystemServiceFlow obj = new SystemServiceFlow();
//            BeanUtils.populate(obj, request.getParameterMap());
//
//            List<SystemServiceFlowClass> flowClass = new ArrayList<>();
//            BeanUtils.populate(flowClass, request.getParameterMap());
//            obj.setFlowClassArray(flowClass);
//
//            List<SystemServiceFlowTemp> flowTemps = new ArrayList<>();
//            BeanUtils.populate(flowTemps, request.getParameterMap());
//            obj.setFlowTempArray(flowTemps);
            return flowManage.addFlow(flow);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
@ -190,5 +205,18 @@ public class FlowController extends BaseController {
    }
    @RequestMapping(value = "/flowList", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Result flowList(String type) {
        try {
            Result result = flowManage.getFlowList(type);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
}

+ 2 - 1
src/main/java/com/yihu/hos/system/dao/FlowClassDao.java

@ -7,6 +7,7 @@ import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
/**
@ -26,7 +27,7 @@ public class FlowClassDao extends SQLGeneralDAO implements IFlowClassDao {
        if (flowClasses != null && flowClasses.size() > 0) {
            return flowClasses;
        }
        return null;
        return new ArrayList<>();
    }
    @Override

+ 9 - 0
src/main/java/com/yihu/hos/system/dao/FlowDao.java

@ -1,11 +1,13 @@
package com.yihu.hos.system.dao;
import com.yihu.hos.system.dao.intf.IFlowDao;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
/**
@ -30,5 +32,12 @@ public class FlowDao  extends SQLGeneralDAO implements IFlowDao {
        return super.getDataGridResult(sb.toString(), Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
    }
    @Override
    public List<SystemServiceFlow> getFlowList(String type) throws Exception {
        String sql = "select * from system_service_flow where valid = 1 and file_type= '"+type+"' order by create_date";
        List<SystemServiceFlow> list = super.queryListBySql(sql,SystemServiceFlow.class);
        return list;
    }
}

+ 46 - 0
src/main/java/com/yihu/hos/system/dao/FlowTempDao.java

@ -0,0 +1,46 @@
package com.yihu.hos.system.dao;
import com.yihu.hos.system.dao.intf.IFlowTempDao;
import com.yihu.hos.system.model.SystemServiceFlowTemp;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/8/19.
 */
@Repository("flowTempDao")
public class FlowTempDao extends SQLGeneralDAO implements IFlowTempDao {
    public static final String BEAN_ID = "flowTempDao";
    @Override
    public List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer flowId) throws Exception {
        List<SystemServiceFlowTemp> flowTemps = (List<SystemServiceFlowTemp>) super.hibernateTemplate.find("from SystemServiceFlowTemp s where s.flowId=? ", flowId);
        if (flowTemps != null && flowTemps.size() > 0) {
            return flowTemps;
        }
        return new ArrayList<>();
    }
    @Override
    public boolean deleteFlowTempByFlowId(Integer flowId) {
        try {
            Session session = getCurrentSession();
            String sql = "delete from system_service_flow_template where flow_id = :flowId";
            Query query = session.createSQLQuery(sql);
            query.setInteger("flowId", flowId);
            query.executeUpdate();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}

+ 4 - 0
src/main/java/com/yihu/hos/system/dao/intf/IFlowDao.java

@ -1,8 +1,10 @@
package com.yihu.hos.system.dao.intf;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.web.framework.dao.XSQLGeneralDAO;
import com.yihu.hos.web.framework.model.Result;
import java.util.List;
import java.util.Map;
/**
@ -13,4 +15,6 @@ import java.util.Map;
public interface IFlowDao extends XSQLGeneralDAO {
    Result getFlowList(Map<String, Object> params) throws Exception;
    List<SystemServiceFlow> getFlowList(String type) throws Exception;
}

+ 17 - 0
src/main/java/com/yihu/hos/system/dao/intf/IFlowTempDao.java

@ -0,0 +1,17 @@
package com.yihu.hos.system.dao.intf;
import com.yihu.hos.system.model.SystemServiceFlowTemp;
import com.yihu.hos.web.framework.dao.XSQLGeneralDAO;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/8/19.
 */
public interface IFlowTempDao extends XSQLGeneralDAO {
    List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer flowId) throws Exception;
    boolean deleteFlowTempByFlowId(Integer flowId);
}

+ 9 - 0
src/main/java/com/yihu/hos/system/model/SystemServiceFlow.java

@ -22,6 +22,15 @@ public class SystemServiceFlow implements java.io.Serializable {
    private String flowClassList;
    private List<SystemServiceFlowClass> flowClassArray;
    private List<SystemServiceFlowTemp> flowTempArray;
    public List<SystemServiceFlowTemp> getFlowTempArray() {
        return flowTempArray;
    }
    public void setFlowTempArray(List<SystemServiceFlowTemp> flowTempArray) {
        this.flowTempArray = flowTempArray;
    }
    public String getFileType() {
        return fileType;

+ 93 - 0
src/main/java/com/yihu/hos/system/model/SystemServiceFlowTemp.java

@ -0,0 +1,93 @@
package com.yihu.hos.system.model;
/**
 *  系统服务流程模板文件类
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/8/19.
 */
public class SystemServiceFlowTemp implements java.io.Serializable {
    private Integer id;
    private String name;
    private Integer valid;
    private String className;
    private String packageName;
    private String classPath;
    private String type;
    private Integer flowId;
    private String isUpdate;
    public String getClassName() {
        return className;
    }
    public void setClassName(String className) {
        this.className = className;
    }
    public String getClassPath() {
        return classPath;
    }
    public void setClassPath(String classPath) {
        this.classPath = classPath;
    }
    public String getIsUpdate() {
        return isUpdate;
    }
    public void setIsUpdate(String isUpdate) {
        this.isUpdate = isUpdate;
    }
    public Integer getFlowId() {
        return flowId;
    }
    public void setFlowId(Integer flowId) {
        this.flowId = flowId;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getValid() {
        return valid;
    }
    public void setValid(Integer valid) {
        this.valid = valid;
    }
    public String getPackageName() {
        return packageName;
    }
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

+ 86 - 24
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -4,11 +4,16 @@ import com.yihu.hos.common.constants.Constants;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.services.ServiceFlowEventService;
import com.yihu.hos.system.dao.FlowClassDao;
import com.yihu.hos.system.dao.FlowTempDao;
import com.yihu.hos.system.dao.intf.IFlowClassDao;
import com.yihu.hos.system.dao.intf.IFlowDao;
import com.yihu.hos.system.dao.intf.IFlowTempDao;
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.system.service.intf.IFlowManage;
import com.yihu.hos.web.framework.model.DictItem;
import com.yihu.hos.web.framework.model.DictionaryResult;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -17,6 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -39,6 +45,8 @@ public class FlowManager implements IFlowManage {
    @Resource(name = FlowClassDao.BEAN_ID)
    private IFlowClassDao flowClassDao;
    @Resource(name = FlowTempDao.BEAN_ID)
    private IFlowTempDao flowTempDao;
    @Autowired
    ServiceFlowEventService serviceFlowEventService;
@ -56,12 +64,21 @@ public class FlowManager implements IFlowManage {
    public Result addFlow(SystemServiceFlow obj) throws Exception {
        obj.setCreateDate(new Date());
        flowDao.saveEntity(obj);
        List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
        for (SystemServiceFlowClass flowClass:flowClassList){
            flowClass.setFlowId(obj.getId());
            flowDao.saveEntity(flowClass);
            //发送消息到MQ对列
            sendUpdateMessage(obj.getCode(), flowClass, Constants.FLOW_OP_ADD);
        if (Constants.CLASS.equals(obj.getFileType())){
            List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
            for (SystemServiceFlowClass flowClass:flowClassList){
                flowClass.setFlowId(obj.getId());
                flowDao.saveEntity(flowClass);
                //发送消息到MQ对列
                sendUpdateMessage(obj.getCode(), flowClass, Constants.FLOW_OP_ADD);
            }
        }else if (Constants.JAVA.equals(obj.getFileType())){
            List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
            for (SystemServiceFlowTemp flowTemp:flowTempList){
                flowTemp.setFlowId(obj.getId());
                flowDao.saveEntity(flowTemp);
            }
        }
        return Result.success("保存成功");
@ -77,30 +94,45 @@ public class FlowManager implements IFlowManage {
        flow.setValid(obj.getValid());
        flow.setFileType(obj.getFileType());
        List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
        List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
        for (SystemServiceFlowClass flowClass:flowClassList){
            if (flowClass.getId()!=null) {
                classIds.remove(flowClass.getId());
                flowClassDao.updateEntity(flowClass);
                sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
            }else {
                flowClassDao.saveEntity(flowClass);
                sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
        if (Constants.JAVA.equals(flow.getFileType())){
            List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
            boolean succ = flowTempDao.deleteFlowTempByFlowId(obj.getId());
            if (succ){
                for (SystemServiceFlowTemp flowTemp:flowTempList){
                    flowTempDao.saveEntity(flowTemp);
                }
            }
        }else if (Constants.CLASS.equals(flow.getFileType())){
            List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
            List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
            for (SystemServiceFlowClass flowClass:flowClassList){
                if (flowClass.getId()!=null) {
                    classIds.remove(flowClass.getId());
                    flowClassDao.updateEntity(flowClass);
                    sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
                }else {
                    flowClassDao.saveEntity(flowClass);
                    sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
                }
            }
            //删除判断
            if (classIds !=null && classIds.size()>0){
                for (Integer id:classIds){
                    SystemServiceFlowClass flowClass = getFlowClassById(id);
                    flowClassDao.deleteEntity(flowClass);
                    sendDeleteMessage(flow.getCode(), flowClass);
                }
            }
        }
        flowDao.updateEntity(flow);
        //删除判断
        if (classIds !=null && classIds.size()>0){
            for (Integer id:classIds){
                SystemServiceFlowClass flowClass = getFlowClassById(id);
                flowClassDao.deleteEntity(flowClass);
                sendDeleteMessage(flow.getCode(), flowClass);
            }
        }
        return Result.success("更新成功");
    }
@ -114,6 +146,7 @@ public class FlowManager implements IFlowManage {
            //发送消息到MQ对列
            sendDeleteMessage(flow.getCode(), flowClass);
        }
        boolean succ = flowTempDao.deleteFlowTempByFlowId(id);
        flowDao.deleteEntity(flow);
        return Result.success("删除成功");
@ -153,6 +186,10 @@ public class FlowManager implements IFlowManage {
        return succ;
    }
    @Override
    public List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception {
        return flowTempDao.getFlowTempByFlowId(id);
    }
    @Override
@ -214,4 +251,29 @@ public class FlowManager implements IFlowManage {
        }
    }
    /**
     * 获取流程列表
     * @param type 流程的文件类型
     * @return
     * @throws Exception
     */
    @Override
    public  DictionaryResult getFlowList(String type) throws Exception {
        List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
        DictionaryResult re = new DictionaryResult("FLOW_LIST");
        if(flowList!=null&&flowList.size()>0)
        {
            List<DictItem> dictList = new ArrayList<>();
            for(SystemServiceFlow item:flowList){
                DictItem dict = new DictItem();
                dict.setCode(item.getId().toString());
                dict.setValue(item.getName());
                dict.setExtend("");
                dictList.add(dict);
            }
            re.setDetailModelList(dictList);
        }
        return re;
    }
}

+ 8 - 0
src/main/java/com/yihu/hos/system/service/intf/IFlowManage.java

@ -3,6 +3,7 @@ package com.yihu.hos.system.service.intf;
import com.yihu.hos.services.IBaseManager;
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 java.util.List;
@ -15,6 +16,7 @@ import java.util.Map;
 */
public interface IFlowManage extends IBaseManager {
    Result getFlowList(Map<String, Object> params) throws Exception;
    Result getFlowList(String type) throws Exception;
    SystemServiceFlow getFlowById(Integer id) throws Exception;
@ -37,4 +39,10 @@ public interface IFlowManage extends IBaseManager {
    boolean deleteFlowClassByFlowId(Integer flowId) ;
    /* ==========================flowTemp================================*/
    List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception;
}

+ 5 - 0
src/main/resources/resource/RsJobConfig.hbm.xml

@ -71,5 +71,10 @@
                <comment>延迟时间</comment>
            </column>
        </property>
        <property name="flowId" type="java.lang.Integer">
            <column name="flow_id">
                <comment>流程ID</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>

+ 48 - 0
src/main/resources/resource/SystemServiceFlowTemp.hbm.xml

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.yihu.hos.system.model.SystemServiceFlowTemp" table="system_service_flow_template">
        <id name="id" column="id">
            <generator class="increment"/>
        </id>
        <property name="className" type="java.lang.String">
            <column name="class_name" length="50">
                <comment>类文件名</comment>
            </column>
        </property>
        <property name="packageName" type="java.lang.String">
            <column name="package_name" length="50" not-null="true">
                <comment>包名</comment>
            </column>
        </property>
        <property name="classPath" type="java.lang.String">
            <column name="class_path" length="255">
                <comment>类文件路径</comment>
            </column>
        </property>
        <property name="name" type="java.lang.String">
            <column name="name" length="255">
                <comment>模板名称</comment>
            </column>
        </property>
        <property name="type" type="java.lang.String">
            <column name="type" length="50">
                <comment>类型</comment>
            </column>
        </property>
        <property name="valid" type="java.lang.Integer">
            <column name="valid" length="11">
                <comment>有效性</comment>
            </column>
        </property>
        <property name="flowId" type="java.lang.Integer">
            <column name="flow_id" length="11">
                <comment>流程ID</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>

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

@ -101,7 +101,7 @@
            <label>类别:</label>
            <div class="m-form-control ">
                <div class="l-text">
                    <input type="text" id="fileType"  class="l-text-field required" name="fileType">
                    <input type="text" id="fileType"   class="l-text-field required" name="fileType">
                </div>
            </div>
        </div>

+ 35 - 12
src/main/webapp/WEB-INF/ehr/jsp/system/flow/editorFlowJs.jsp

@ -7,6 +7,7 @@
<script type="text/javascript">
    /* *************************** 模块初始化 ***************************** */
    var fileType;
    var editorFlow = {
        //form
        actionUrl:"${contextRoot}/flow/addFlow",
@ -24,6 +25,7 @@
            var modelString = "${model.id}";
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                $("#fileType").attr("disabled","disabled");
                var icon = $("#iconUrl").attr("data-id");
                if(icon!='' && icon!='undefine'){
                    if(icon!= "${model.chart}"){
@ -38,7 +40,7 @@
                var valid = "${model.valid}";
                liger.get("valid").selectValue(valid);
                var fileType = "${model.fileType}";
                fileType = "${model.fileType}";
                liger.get("fileType").selectValue(fileType);
               data={
                    id: "${model.id}",
@ -50,6 +52,7 @@
                   fileType:"${model.fileType}",
                   flowClassList: '${flowClass}',
                   flowClassArray:'${model.flowClassArray}',
                   flowTempArray:'${model.flowTempArray}',
                   createDate:'${model.createDate}'
                };
@ -83,14 +86,26 @@
            }
            liger.get("type"+index).selectValue(type);
            me.flowClassData[me.$mun]= {
                "packageName": $("#packageName"+index).val(),
                "className": $("#className"+index).val(),
                "classPath": $("#classPath"+index).val(),
                "flowId": $("#flowId").val(),//流程id
                "type":$("#type"+index).val(),
                "id":$("#classId"+index).val(),
                "isUpdate":$("#isUpdate"+index).val()
            if("class"==fileType){
                me.flowClassData[me.$mun]= {
                    "packageName": $("#packageName"+index).val(),
                    "className": $("#className"+index).val(),
                    "classPath": $("#classPath"+index).val(),
                    "flowId": $("#flowId").val(),//流程id
                    "type":$("#type"+index).val(),
                    "id":$("#classId"+index).val(),
                    "isUpdate":$("#isUpdate"+index).val()
                }
            }else if("java"==fileType){
                me.flowClassData[me.$mun]= {
                    "packageName": $("#packageName"+index).val(),
                    "className": $("#className"+index).val(),
                    "classPath": $("#classPath"+index).val(),
                    "flowId": $("#flowId").val(),//流程id
                    "type":$("#type"+index).val(),
                    "id":$("#classId"+index).val(),
                    "isUpdate":$("#isUpdate"+index).val()
                }
            }
            me.$mun+=1;
        },
@ -98,6 +113,7 @@
            var me = this;
            $(".m-form-bottom").on("click","#btnSave",function () {
                fileType =liger.get("fileType").selectedValue;
                if(!$("#div_info_form").ligerAutoForm("validate")){
                    return;
                }
@ -109,13 +125,20 @@
                var data = $("#div_info_form").ligerAutoForm("getData");
                delete data.file;
                data.flowClassArray=me.flowClassData;
                var dataStr = JSON.stringify(data);
                debugger
                var dataList;
                if("java"==fileType){
                    data.flowTempArray = me.flowClassData;
                    dataList={"flowClass":JSON.stringify(data)}
                }else if("class"==fileType){
                    data.flowClassArray=me.flowClassData;
                    dataList={"flowClass":JSON.stringify(data)}
                }
                $.ajax({ //ajax处理
                    type: "POST",
                    url : me.actionUrl,
                    dataType : "json",
                    data:{"flowClass":dataStr},
                    data:dataList,
                    cache:false,
                    success :function(data){
                        if(data.successFlg) {