Browse Source

流程管理模块。添加模板文件上传

demon 8 years ago
parent
commit
a01024c809

+ 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";

+ 27 - 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());

+ 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

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

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

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

@ -4,10 +4,13 @@ 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;
@ -42,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;
@ -59,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("保存成功");
@ -80,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("更新成功");
    }
@ -117,6 +146,7 @@ public class FlowManager implements IFlowManage {
            //发送消息到MQ对列
            sendDeleteMessage(flow.getCode(), flowClass);
        }
        boolean succ = flowTempDao.deleteFlowTempByFlowId(id);
        flowDao.deleteEntity(flow);
        return Result.success("删除成功");
@ -156,6 +186,10 @@ public class FlowManager implements IFlowManage {
        return succ;
    }
    @Override
    public List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception {
        return flowTempDao.getFlowTempByFlowId(id);
    }
    @Override

+ 7 - 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;
@ -38,4 +39,10 @@ public interface IFlowManage extends IBaseManager {
    boolean deleteFlowClassByFlowId(Integer flowId) ;
    /* ==========================flowTemp================================*/
    List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception;
}

+ 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) {