用户上传流程模板---》WorkFlow -----》流程模板部署到数据库----》deployProcess(byte[] processFile,byte[] processImg)----》流程得有公文,审批信息---》Document ,ApproveInfo ---》创建流程实例---》addProcessInstance(String wf_name,int documentId)---》公文绑定流程---》addDocForProcess(Document doc,WorkFlow wf)
- /**
- * 流程
- */
- public class WorkFlow {
- private int wf_id;
- private String wf_name;
- private byte[] processFile;
- private byte[] processImg;
- private int flag;
- }
- public void deployProcess(byte[] processFile,byte[] processImg) {
- //将文件部署到数据库中
- ProcessDefinition pd = ProcessDefinition.parseXmlInputStream(new ByteArrayInputStream(processFile));
- getContext().deployProcessDefinition(pd);
- //把数据存储在对应的tb_workFlow中
- //去到对应的WorkFlow (根据名称取出对象)
- WorkFlow wf = wsf.findByKey(WorkFlow.class, "from WorkFlow wf where wf.wf_name=?",new Object[]{pd.getName()});
- if(wf==null) {
- wf = new WorkFlow();
- wf.setProcessFile(processFile);
- wf.setProcessImg(processImg);
- wf.setWf_name(pd.getName());
- wf.setFlag(1);
- save(wf);
- return;
- }
- wf.setProcessFile(processFile);
- wf.setProcessImg(processImg);
- wf.setWf_name(pd.getName());
- update(wf);
- }
- /**
- * 公文
- */
- public class Document {
- /** 公文id**/
- private int dom_id;
- /** 标题**/
- private String doc_title;
- /** 描述**/
- private String doc_desc;
- /** 附件**/
- private byte[] content;
- /** 创建者**/
- private User creator;
- /** 创建时间**/
- private Date createTime;
- /** 对应流程 多对一多个公文对应一个流程**/
- private WorkFlow workFlow;
- /** 对应流程实例**/
- private long processInstanceId;
- /**状态 **/
- private String status;
- /** 附件名称 **/
- private String loadName;
- /** 是否显示**/
- private int flag;
- /** 状态 **/
- public final static String STATUS_NEW = "新建";
- public final static String STATUS_ING = "审核中";
- public final static String STATUS_END = "结束";
- }
- /**
- * 审批信息
- */
- public class ApproveInfo {
- /** id **/
- private int ao_id;
- /** 审批意见 **/
- private String comment;
- /** 时间 **/
- private Date approveTime;
- /** 审批公文 **/
- private Document document;
- /** 审批者 **/
- private User approver;
- }
- //得到流程实例的ID (得到流程的实例 且返回实例的ID 将公文的ID 通过变量设置在上下文中)
- public long addProcessInstance(String wf_name,int documentId) {
- JbpmContext context = getContext();
- //通过流程名称得到流程定义
- ProcessDefinition pd = context.getGraphSessi().findLatestProcessDefinition(wf_name);
- //通过流程定义取得流程实例
- ProcessInstance pe = new ProcessInstance(pd);
- //将公文的ID 通过变量设置在上下文中
- pe.getContextInstance().createVariable("document", documentId);
- //存储流程实例到数据库中
- context.save(pe);
- return pe.getId();
- }
- //公文绑定流程
- public void addDocForProcess(Document doc,WorkFlow wf) {
- doc.setWorkFlow(wf);
- save(doc);
- long processInstanceId = addProcessInstance(wf.getWf_name(),doc.getDom_id());
- doc.setProcessInstanceId(processInstanceId);
- update(doc);
- }