Commit 32302264 by 罗绍泽

封装了部分activiti引擎代码

parent 952dcef5
......@@ -123,6 +123,8 @@
<property name="procinstanceDAO" ref="procinstanceDAO"></property>
<property name="formmodelsDAO" ref="formmodelsDAO"></property>
<property name="procdefinitionDAO" ref="procdefinitionDAO"></property>
<property name="historyService" ref="historyService"></property>
<property name="repositoryService" ref="repositoryService"></property>
<property name="formtableDAO" ref="formtableDAO"></property>
</bean>
</beans>
......@@ -234,8 +234,6 @@ function fillTable2(businessId,taskId){
delete info.BUSINESS_DATA[key];
}
info.BUSINESS_DATA['FIELD_OPETYPE']='update';
info.BUSINESS_DATA['FIELD_TABLE_ID_SYSTEM']=info.FORM_MODEL.TABLE_ID;
info.BUSINESS_DATA['FIELD_TASK_ID_SYSTEM']=taskId;
$("#inputForm").form('load',info.BUSINESS_DATA);
......@@ -541,58 +539,7 @@ function showProcinstanceImg(index) {
width : 1000,
height : 500,
title : '流程图',
href:'procinstanceView_procinstanceTabHistory?instanceId='+is_row[0].INSTANCE_ID,
onLoad:function(){
$('#historyTable').datagrid({
iconCls:$.getJwWindowPic(),
url:gaowj.WEB_APP_NAME+"/procinstanceData_procinstanceHistory",
queryParams : {
processInstanceId:$("#instanceIdHide").val()
},//查询参数
rownumbers : true,//显示索引号
singleSelect : false,//是否多选
fitColumns : false,//是否撑满
autoRowHeight : false,//设定高度
rowStyler :function(index,row){return rowstyler(index,row);},
pagination : true,//分页显示
pageSize : rows,//显示行数
pageList : listPageSize,//条数选择
striped : true, //是否隔行显示
remoteSort : false,//是否从服务器排序
frozenColumns : [[
{
field : 'ck',
checkbox : true
}
]],
columns : [ [ {
field : 'ACTIVITY_NAME',
title : '环节名称',
width : 200,
align : 'center',
}, {
field : 'ASSIGNEE',
title : '办理人',
width : 200,
align : 'center',
}, {
field : 'START_TIME',
title : '开始时间',
width : 250,
align : 'center',
}, {
field : 'END_TIME',
title : '结束时间',
width : 250,
align : 'center',
} ] ],
onLoadSuccess : function() {
if(is_opetipmenuwidth==null){
is_opetipmenuwidth = 60;
}
}
});
}
href:'procinstanceView_procinstanceTabHistory?instanceId='+is_row[0].INSTANCE_ID
});
}
......
$(function(){
$('#historyTable').datagrid({
iconCls:$.getJwWindowPic(),
url:gaowj.WEB_APP_NAME+"/procinstanceData_procinstanceHistory",
queryParams : {
processInstanceId:$("#instanceIdHide").val()
},//查询参数
rownumbers : true,//显示索引号
singleSelect : false,//是否多选
fitColumns : false,//是否撑满
autoRowHeight : false,//设定高度
rowStyler :function(index,row){return rowstyler(index,row);},
striped : true, //是否隔行显示
columns : [ [ {
field : 'ACTIVITY_NAME',
title : '环节名称',
width : 200,
align : 'center',
}, {
field : 'ASSIGNEE',
title : '办理人',
width : 200,
align : 'center',
}, {
field : 'START_TIME',
title : '开始时间',
width : 250,
align : 'center',
}, {
field : 'END_TIME',
title : '结束时间',
width : 250,
align : 'center',
} ] ],
onLoadSuccess : function() {
if(is_opetipmenuwidth==null){
is_opetipmenuwidth = 60;
}
}
});
});
\ No newline at end of file
......@@ -2,6 +2,5 @@
<form id="inputForm" method="post" style="width: 100%;">
<input type="hidden" name="FIELD_OPETYPE" id="OPETYPE" value="${is_row.OPETYPE}" />
<input type="hidden" name="FIELD_UUID" id="UUID" value="${is_row.UUID}" />
<input type="hidden" name="FIELD_TABLE_ID_SYSTEM" id="TABLE_ID_SYSTEM"/>
<div id="table_content"></div>
</form>
\ No newline at end of file
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<div style="overflow:auto;height:100%;">
<div style="overflow:auto;">
<img src="procinstanceData_showProcinstanceImg?instanceId=${instanceId}" />
<img id="loadingImg" style="width: 20px;height: 20px;" src="gaowj/ria/jquery/jquery-easyui-1.4.1/themes/black/images/loading.gif" />
<img style="display:none" onload='$("#loadingImg").hide();$(this).show();' src="procinstanceData_showProcinstanceImg?instanceId=${instanceId}" />
</div>
<input type="hidden" id="instanceIdHide" value="${instanceId}" />
<div id="historyTable"></div>
</div>
<script type="text/javascript" src="${ctx}/process/pages/procinstance/js/procinstanceTabHistory.js" charset="utf-8"></script>
......@@ -147,8 +147,6 @@ function fillTable(businessId,taskId){
delete info.BUSINESS_DATA[key];
}
info.BUSINESS_DATA['FIELD_OPETYPE']='update';
info.BUSINESS_DATA['FIELD_TABLE_ID_SYSTEM']=info.FORM_MODEL.TABLE_ID;
info.BUSINESS_DATA['FIELD_TASK_ID_SYSTEM']=taskId;
$("#inputForm").form('load',info.BUSINESS_DATA);
}
......@@ -438,6 +436,6 @@ function showProcinstanceImg(index) {
width : 1000,
height : 500,
title : '流程图',
content:'<div style="height:100%;overflow:auto;"><img src="procinstanceData_showProcinstanceImg?instanceId='+is_row[0].INSTANCE_ID+'" /></div>'
href:'procinstanceView_procinstanceTabHistory?instanceId='+is_row[0].INSTANCE_ID
});
}
\ No newline at end of file
......@@ -2,7 +2,5 @@
<form id="inputForm" method="post" style="width: 100%;">
<input type="hidden" name="FIELD_OPETYPE" id="OPETYPE" value="${is_row.OPETYPE}" />
<input type="hidden" name="FIELD_UUID" id="UUID" value="${is_row.UUID}" />
<input type="hidden" name="FIELD_TABLE_ID_SYSTEM" id="TABLE_ID_SYSTEM"/>
<input type="hidden" name="FIELD_TASK_ID_SYSTEM" id="TASK_ID_SYSTEM"/>
<div id="table_content"></div>
</form>
\ No newline at end of file
......@@ -6,6 +6,7 @@ import java.util.Map;
import org.springframework.stereotype.Service;
import com.gaowj.business.exception.ActivitiException;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.Page;
......@@ -17,7 +18,7 @@ public interface ProcinstanceBusiness {
* @param entity
* @throws BusinessException
*/
Map<String, Object> insert_proc_instance(Map<String, Object> entity) throws BusinessException;
Map<String, Object> insert_proc_instance(Map<String, Object> entity) throws ActivitiException,BusinessException;
/**
* 插入
......@@ -25,7 +26,7 @@ public interface ProcinstanceBusiness {
* @param entity
* @throws BusinessException
*/
Map<String, Object> insert_proc_instance_next(Map<String, Object> entity) throws BusinessException;
Map<String, Object> insert_proc_instance_next(Map<String, Object> entity) throws ActivitiException,BusinessException;
/**
* 更新
......@@ -33,7 +34,7 @@ public interface ProcinstanceBusiness {
* @param entity
* @throws BusinessException
*/
Map<String, Object> update_proc_instance(Map<String, Object> entity) throws BusinessException;
Map<String, Object> update_proc_instance(Map<String, Object> entity) throws ActivitiException,BusinessException;
/**
* 更新
......@@ -41,7 +42,7 @@ public interface ProcinstanceBusiness {
* @param entity
* @throws BusinessException
*/
Map<String, Object> update_proc_instance_next(Map<String, Object> entity) throws BusinessException;
Map<String, Object> update_proc_instance_next(Map<String, Object> entity) throws ActivitiException,BusinessException;
/**
* 删除记录
......
......@@ -4,6 +4,7 @@ import java.util.Map;
import org.springframework.stereotype.Service;
import com.gaowj.business.exception.ActivitiException;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.Page;
......@@ -19,9 +20,9 @@ public interface ProctaskBusiness {
Map<String, Object> data_info(String businessId) throws BusinessException;
Map<String, Object> update(Map<String, Object> entity) throws BusinessException;
Map<String, Object> update(Map<String, Object> entity) throws ActivitiException,BusinessException;
Map<String, Object> updateToNext(String taskId,Map<String, Object> entity) throws BusinessException;
Map<String, Object> updateToNext(Map<String, Object> entity) throws ActivitiException,BusinessException;
Map<String, Object> back(Map<String, Object> entity) throws BusinessException;
}
package com.gaowj.business.exception;
/**
* activiti异常类
*
* @author luosz
*
*/
public class ActivitiException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
public ActivitiException(String frdMessage) {
super("操作失败!"+frdMessage);
}
public ActivitiException(Throwable throwable) {
super(throwable);
}
public ActivitiException(Throwable throwable, String frdMessage) {
super(throwable);
}
}
......@@ -3,11 +3,9 @@ package com.gaowj.business.procinstance;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
......@@ -21,37 +19,37 @@ import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
import org.apache.ibatis.session.RowBounds;
import com.gaowj.business.ProcinstanceBusiness;
import com.gaowj.business.exception.ActivitiException;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.formtable.formtableDAO;
import com.gaowj.business.procdefinition.procdefinitionDAO;
import com.gaowj.business.system.SystemBackDAO;
import com.gaowj.business.util.Page;
import com.gaowj.business.util.SessionUtil;
import com.gaowj.business.utils.ActivitiTools;
import com.gaowj.business.utils.model.ActivitiResultEnum;
public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
private procinstanceDAO procinstanceDAO;
private procdefinitionDAO procdefinitionDAO;
private formtableDAO formtableDAO;
private RuntimeService runtimeService;
private TaskService taskService;
private HistoryService historyService;
private RepositoryService repositoryService;
private SystemBackDAO systemBackDAO;
public RuntimeService getRuntimeService() {
......@@ -69,7 +67,6 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
public void setProcdefinitionDAO(procdefinitionDAO procdefinitionDAO) {
this.procdefinitionDAO = procdefinitionDAO;
}
public formtableDAO getFormtableDAO() {
return formtableDAO;
......@@ -120,326 +117,146 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
}
@Override
public Map<String, Object> insert_proc_instance(Map<String, Object> entity) throws BusinessException {
//流程定义id
String procId=entity.get("PROCID").toString();
//实时的表单模板id
String formModelId=entity.get("FORM_MODEL_ID").toString();
//一定要删掉,防止下面保存业务数据时候没有这个字段
public Map<String, Object> insert_proc_instance(Map<String, Object> entity) throws ActivitiException,BusinessException {
// 流程定义id
String procId = entity.get("PROCID").toString();
// 实时的表单模板id
String formModelId = entity.get("FORM_MODEL_ID").toString();
// 删除除业务数据外的所有字段
entity.remove("PROCID");
entity.remove("FORM_MODEL_ID");
Map<String, Object> query=new HashMap<String, Object>();
query.put("UUID", procId);
Map<String, Object> procdeFinition=procdefinitionDAO.list_procde_finition(query).get(0);
//存储自定义表单的业务数据
String businessId=insert_custom_business(procdeFinition.get("TABLE_ID").toString(),entity);
//通过流程定义id启动流程,因为是直接保存,所以并不启动流程实例
//存储流程实例id和业务数据id的关联
insertProcInstance(procId,businessId,formModelId,null);
ActivitiResultEnum activitiResultEnum = ActivitiTools.initNotStart(procId, formModelId, entity);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
return entity;
}
@Override
public Map<String, Object> insert_proc_instance_next(Map<String, Object> entity) throws BusinessException {
//流程定义id
String procId=entity.get("PROCID").toString();
//实时的表单模板id
String formModelId=entity.get("FORM_MODEL_ID").toString();
//一定要删掉,防止下面保存业务数据时候没有这个字段
public Map<String, Object> insert_proc_instance_next(Map<String, Object> entity) throws ActivitiException,BusinessException {
// 流程定义id
String procId = entity.get("PROCID").toString();
// 实时的表单模板id
String formModelId = entity.get("FORM_MODEL_ID").toString();
// 删除除业务数据外的所有字段
entity.remove("PROCID");
entity.remove("FORM_MODEL_ID");
Map<String, Object> query=new HashMap<String, Object>();
query.put("UUID", procId);
Map<String, Object> procdeFinition=procdefinitionDAO.list_procde_finition(query).get(0);
//存储自定义表单的业务数据
String businessId=insert_custom_business(procdeFinition.get("TABLE_ID").toString(),entity);
//通过流程定义id启动流程
String deploymentKey=procdeFinition.get("DEPLOYMENT_KEY").toString();
ProcessInstance processInstance=runtimeService.startProcessInstanceByKey(deploymentKey);
//获取我的任务(如果点击下一步的时候,是第一次插入,这直接将我的任务完成掉)
String taskId=taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskCandidateUser(SessionUtil.getCode()).list().get(0).getId();
taskService.complete(taskId);
//存储流程实例id和业务数据id的关联
insertProcInstance(procId,businessId,formModelId,processInstance.getId());
return entity;
}
private void insertProcInstance(String procId,String businessId,String formModelId, String instanceId) {
Map<String, Object> entity = new HashMap<String, Object>();
entity.put("BUSINESS_ID", businessId);
entity.put("FORM_MODEL_ID", formModelId);
if (instanceId != null) {
entity.put("INSTANCE_ID", instanceId);
}
entity.put("PROC_DEFINITION_ID", procId);
entity.put("UUID", java.util.UUID.randomUUID().toString());
entity.put("CREATE_TIME", new Date());
entity.put("CREATE_ID", SessionUtil.getCode());
entity.put("UPDATE_ID", SessionUtil.getCode());
entity.put("UPDATE_TIME", new Date());
// 动态传值插入
List<String> infoListKey = new ArrayList<String>();
List<Object> infoList = new ArrayList<Object>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
for (String str : key) {
infoList.add(entity.get(str));
infoListKey.add(str);
}
entity.put("infoListKey", infoListKey);
entity.put("infoList", infoList);
ActivitiResultEnum activitiResultEnum = ActivitiTools.initStart(procId, formModelId, entity);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
procinstanceDAO.insert_proc_instance(entity);
}
private String insert_custom_business(String tableId,Map<String, Object> entity) {
entity.remove("PROCID");
if (entity.get("UUID") == null) {
entity.put("UUID", java.util.UUID.randomUUID().toString());
}
if (entity.get("CREATE_TIME") == null) {
entity.put("CREATE_TIME", new Date());
}
if (entity.get("CREATE_ID") == null) {
entity.put("CREATE_ID", SessionUtil.getCode());
}
if (entity.get("UPDATE_ID") == null) {
entity.put("UPDATE_ID", SessionUtil.getCode());
}
if (entity.get("UPDATE_TIME") == null) {
entity.put("UPDATE_TIME", new Date());
}
Map<String, Object> query=new HashMap<String, Object>();
query.put("UUID", tableId);
// 动态传值插入
List<String> infoListKey = new ArrayList<String>();
List<Object> infoList = new ArrayList<Object>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
for (String str : key) {
infoList.add(entity.get(str));
infoListKey.add(str);
}
entity.put("infoListKey", infoListKey);
entity.put("infoList", infoList);
}
//设置表名
String tableName=formtableDAO.list_form_table(query).get(0).get("TABLE_NAME").toString();
entity.put("tableName", tableName);
procdefinitionDAO.insert_custom_business(entity);
return entity.get("UUID").toString();
return entity;
}
@Override
public Map<String, Object> update_proc_instance(Map<String, Object> entity) throws BusinessException {
// 业务表主键id
String uuid = entity.get("UUID").toString();
Map<String, Object> query = new HashMap<String, Object>();
query.put("BUSINESS_ID", uuid);
//获取流程实例表对象
Map<String, Object> procInstance=procinstanceDAO.list_proc_instance_all(query).get(0);
if(procInstance.get("INSTANCE_ID")!=null&&!"".equals(procInstance.get("INSTANCE_ID"))){
//表示流程实例已启动,根据实例id,判断当前登陆人是否为该记录的当前任务人
long taskCount=taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).count();
if(taskCount==0){
//如果该人员对该流程实例的任务数量为0,表示该人员目前无权限对该记录进行修改操作
return new HashMap<String, Object>(){{
put("ERROR", "-1");
}};
}
public Map<String, Object> update_proc_instance(Map<String, Object> entity) throws ActivitiException,BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, false);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
//流程定义id
String procDefinitionId=procInstance.get("PROC_DEFINITION_ID").toString();
//查询表名
Map<String, Object> query2=new HashMap<String, Object>();
query2.put("UUID", procDefinitionId);
String tableName=procdefinitionDAO.list_procde_finition(query2).get(0).get("TABLE_NAME").toString();
//更新业务数据
update_custom_business(tableName,entity);
return entity;
}
@Override
public Map<String, Object> update_proc_instance_next(Map<String, Object> entity) throws BusinessException {
// 业务表主键id
String uuid = entity.get("UUID").toString();
Map<String, Object> query = new HashMap<String, Object>();
query.put("BUSINESS_ID", uuid);
//获取流程实例表对象
Map<String, Object> procInstance=procinstanceDAO.list_proc_instance_all(query).get(0);
//流程定义id
String procDefinitionId=procInstance.get("PROC_DEFINITION_ID").toString();
if(procInstance.get("INSTANCE_ID")!=null&&!"".equals(procInstance.get("INSTANCE_ID"))){
//表示流程实例已启动,根据实例id,判断当前登陆人是否为该记录的当前任务人
long taskCount=taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).count();
if(taskCount==0){
//如果该人员对该流程实例的任务数量为0,表示该人员目前无权限对该记录进行修改操作
return new HashMap<String, Object>(){{
put("ERROR", "-1");
}};
}else{
//如果是当前环节处理人,则完成当前任务
Task task=taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).list().get(0);
taskService.complete(task.getId());
}
}else{
//如果没有实例id,则通过流程定义id启动流程
Map<String,Object> query_proc_definition=new HashMap<String, Object>();
query_proc_definition.put("UUID", procDefinitionId);
String deploymentKey=procdefinitionDAO.list_procde_finition(query_proc_definition).get(0).get("DEPLOYMENT_KEY").toString();
ProcessInstance processInstance=runtimeService.startProcessInstanceByKey(deploymentKey);
//将实例id保存到实例表
Map<String,Object> procInstanceUpdate=new HashMap<String, Object>();
procInstanceUpdate.put("UUID", procInstance.get("UUID"));
procInstanceUpdate.put("INSTANCE_ID", processInstance.getId());
update_proc_instance_data(procInstanceUpdate);
public Map<String, Object> update_proc_instance_next(Map<String, Object> entity) throws ActivitiException,BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, true);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
//查询表名
Map<String, Object> query2=new HashMap<String, Object>();
query2.put("UUID", procDefinitionId);
String tableName=procdefinitionDAO.list_procde_finition(query2).get(0).get("TABLE_NAME").toString();
//更新业务数据
update_custom_business(tableName,entity);
return entity;
}
private void update_proc_instance_data(Map<String, Object> entity) {
Map<String, Object> entity2 = new HashMap<String, Object>();
entity2.put("UUID", entity.get("UUID"));
if (entity.keySet() != null) {
List<Map<String,Object>> info=new ArrayList<Map<String,Object>>();
entity2.put("info", info);
Set<String> key = entity.keySet();
for(String str:key){
if("UUID".equals(str)){
continue;
}
Map<String,Object> colum=new HashMap<String, Object>();
colum.put("key", str);
colum.put("value", entity.get(str));
info.add(colum);
}
}
procinstanceDAO.update_proc_instance(entity2);
}
private String update_custom_business(String tableName,Map<String, Object> entity) {
entity.remove("TABLE_ID_SYSTEM");
entity.put("UPDATE_ID", SessionUtil.getCode());
entity.put("UPDATE_TIME", new Date());
// 动态传值插入
List<Map<String,Object>> infoList = new ArrayList<Map<String,Object>>();
//List<String> infoListKey = new ArrayList<String>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
for (String str : key) {
//UUID不需要加进去
if("UUID".equals(str)){
continue;
}
Map<String,Object> kv=new HashMap<String, Object>();
kv.put("value",entity.get(str));
kv.put("key",str);
infoList.add(kv);
}
entity.put("infoList", infoList);
}
//设置表名
entity.put("tableName", tableName);
entity.put("uuid", entity.get("UUID"));
procdefinitionDAO.update_custom_business(entity);
return entity.get("UUID").toString();
}
@Override
public void delete_proc_instance(List<String> list) throws BusinessException {
//查询流程实例表
Map<String,Object> query=new HashMap<String, Object>();
// 查询流程实例表
Map<String, Object> query = new HashMap<String, Object>();
query.put("UUIDIN", list);
List<Map<String, Object>> listInstance=procinstanceDAO.list_proc_instance_all(query);
//获取业务主键id
List<Map<String,Object>> listBusiness=new ArrayList<Map<String,Object>>();
for(Map<String, Object> m:listInstance){
Map<String,Object> business=new HashMap<String, Object>();
List<Map<String, Object>> listInstance = procinstanceDAO.list_proc_instance_all(query);
// 获取业务主键id
List<Map<String, Object>> listBusiness = new ArrayList<Map<String, Object>>();
for (Map<String, Object> m : listInstance) {
Map<String, Object> business = new HashMap<String, Object>();
business.put("UUID", m.get("BUSINESS_ID"));
business.put("TABLE_NAME", m.get("TABLE_NAME"));
listBusiness.add(business);
}
//整理业务表id,以表名为key,listuuid为value
Map<String,List<String>> listBusinessUuidList=new HashMap<String,List<String>>();
for(Map<String,Object> m:listBusiness){
List<String> listUuid=null;
if(listBusinessUuidList.get(m.get("TABLE_NAME"))==null){
listUuid=new ArrayList<String>();
// 整理业务表id,以表名为key,listuuid为value
Map<String, List<String>> listBusinessUuidList = new HashMap<String, List<String>>();
for (Map<String, Object> m : listBusiness) {
List<String> listUuid = null;
if (listBusinessUuidList.get(m.get("TABLE_NAME")) == null) {
listUuid = new ArrayList<String>();
listBusinessUuidList.put((String) m.get("TABLE_NAME"), listUuid);
}else{
listUuid=listBusinessUuidList.get(m.get("TABLE_NAME"));
} else {
listUuid = listBusinessUuidList.get(m.get("TABLE_NAME"));
}
listUuid.add(m.get("UUID").toString());
}
//根据业务主键id和表名删除具体的业务数据
for(String tableName:listBusinessUuidList.keySet()){
Map<String,Object> deleteParams=new HashMap<String, Object>();
// 根据业务主键id和表名删除具体的业务数据
for (String tableName : listBusinessUuidList.keySet()) {
Map<String, Object> deleteParams = new HashMap<String, Object>();
deleteParams.put("TABLE_NAME", tableName);
deleteParams.put("list", listBusinessUuidList.get(tableName));
procinstanceDAO.delete_proc_instance_business(deleteParams);
}
//删除实例表
// 删除实例表
procinstanceDAO.delete_proc_instance(list);
}
@Override
public Page<Map<String, Object>> list_proc_instance(int pageNo, int pageSize, Map<String, Object> query) throws BusinessException {
/*List<Task> listTask=taskService.createTaskQuery().taskAssignee(SessionUtil.getCode()).list();
System.out.println(listTask.size());*/
//只查询当前登陆人的实例列表
/*
* List<Task>
* listTask=taskService.createTaskQuery().taskAssignee(SessionUtil.
* getCode()).list(); System.out.println(listTask.size());
*/
// 只查询当前登陆人的实例列表
query.put("CREATE_ID", SessionUtil.getCode());
String procdefinitionUuid = null;
String tableName=null;
boolean notExist=false;
String tableName = null;
boolean notExist = false;
if (query.get("PROCDEFINITION_UUID") != null && !"".equals(query.get("PROCDEFINITION_UUID"))) {
procdefinitionUuid = query.get("PROCDEFINITION_UUID").toString();
query.remove("PROCDEFINITION_UUID");
//通过流程定义id获取表名
Map<String, Object> query2=new HashMap<String, Object>();
// 通过流程定义id获取表名
Map<String, Object> query2 = new HashMap<String, Object>();
query2.put("UUID", procdefinitionUuid);
tableName=procdefinitionDAO.list_procde_finition(query2).get(0).get("TABLE_NAME").toString();
tableName = procdefinitionDAO.list_procde_finition(query2).get(0).get("TABLE_NAME").toString();
}
// 计算起始记录
int pageStart = (pageNo - 1) * pageSize;
// 获取列表
List<Map<String, Object>> items = null;
if(tableName!=null){
if (tableName != null) {
query.put("tableName", tableName);
query.put("PROC_DEFINITION_ID", procdefinitionUuid);
try {
items = procinstanceDAO.list_proc_instance(new RowBounds(pageStart, pageSize), query);
} catch (Exception e) {
if(e.getMessage().indexOf("doesn't exist")!=-1){
//如果有XX不存在字样,说明当前需要查询的表不存在,则直接设置为空list
items=new ArrayList<Map<String, Object>>();
notExist=true;
if (e.getMessage().indexOf("doesn't exist") != -1) {
// 如果有XX不存在字样,说明当前需要查询的表不存在,则直接设置为空list
items = new ArrayList<Map<String, Object>>();
notExist = true;
}
}
}else{
} else {
items = procinstanceDAO.list_proc_instance_all(new RowBounds(pageStart, pageSize), query);
}
// 获取列表个数
int count = 0;
if (!notExist) {
......@@ -456,46 +273,49 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
return page;
}
@Override
public List<Map<String, Object>> list_proc_instance_history(String processInstanceId) throws BusinessException{
public List<Map<String, Object>> list_proc_instance_history(String processInstanceId) throws BusinessException {
List<HistoricActivityInstance> listHistoricActivityInstance = historyService // 历史相关Service
.createHistoricActivityInstanceQuery() // 创建历史活动实例查询
.processInstanceId(processInstanceId) // 执行流程实例id
//.finished()
// .finished()
.orderByHistoricActivityInstanceStartTime().asc().list();
List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
List<String> listAssignee=new ArrayList<String>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
List<String> listAssignee = new ArrayList<String>();
for (HistoricActivityInstance hai : listHistoricActivityInstance) {
if(hai.getActivityName()==null){
if (!"userTask".equals(hai.getActivityType())) {
// 只显示userTask类型
continue;
}
if(hai.getAssignee()==null&&hai.getEndTime()!=null){
//如果没有办理人,但是有结束时间,任务该环节是开始环节,默认剔除
continue;
}
if(hai.getAssignee()!=null){
/*
* if(hai.getActivityName()==null){ continue; }
*/
/*
* if(hai.getAssignee()==null&&hai.getEndTime()!=null){
* //如果没有办理人,但是有结束时间,任务该环节是开始环节,默认剔除 continue; }
*/
if (hai.getAssignee() != null) {
listAssignee.add(hai.getAssignee());
}
Map<String,Object> entry=new HashMap<String, Object>();
Map<String, Object> entry = new HashMap<String, Object>();
entry.put("ACTIVITY_NAME", hai.getActivityName());
entry.put("ASSIGNEE", hai.getAssignee()==null?"":hai.getAssignee());
entry.put("ASSIGNEE", hai.getAssignee() == null ? "" : hai.getAssignee());
entry.put("START_TIME", hai.getStartTime());
entry.put("END_TIME", hai.getEndTime()==null?"":hai.getEndTime());
entry.put("END_TIME", hai.getEndTime() == null ? "" : hai.getEndTime());
list.add(entry);
}
Map<String,Object> query=new HashMap<String, Object>();
Map<String, Object> query = new HashMap<String, Object>();
query.put("CODE_IN", listAssignee);
List<Map<String, Object>> items = systemBackDAO.listLoginUserInfo(query);
outer:
for(Map<String, Object> m:list){
for(Map<String, Object> user:items){
if(m.get("ASSIGNEE")!=null&&!"".equals(m.get("ASSIGNEE"))){
if(m.get("ASSIGNEE").equals(user.get("CODE"))){
m.put("ASSIGNEE",user.get("EMNAME"));
outer: for (Map<String, Object> m : list) {
for (Map<String, Object> user : items) {
if (m.get("ASSIGNEE") != null && !"".equals(m.get("ASSIGNEE"))) {
if (m.get("ASSIGNEE").equals(user.get("CODE"))) {
m.put("ASSIGNEE", user.get("EMNAME"));
continue outer;
}
}
......@@ -512,7 +332,7 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
@Override
public int listCount_proc_instance(Map<String, Object> query) throws BusinessException {
if(query.get("tableName")==null){
if (query.get("tableName") == null) {
return procinstanceDAO.listCount_proc_instance_all(query);
}
return procinstanceDAO.listCount_proc_instance(query);
......@@ -551,7 +371,7 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
}
// 获取流程定义对象
ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult();
String xmlName = processDefinition.getResourceName();
// 获取流程资源
InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), xmlName);
......@@ -559,7 +379,7 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
BpmnXMLConverter converter = new BpmnXMLConverter();
// 读取xml文件
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader=null;
XMLStreamReader reader = null;
try {
reader = factory.createXMLStreamReader(inputStream);
} catch (XMLStreamException e1) {
......@@ -570,15 +390,12 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
BpmnModel bpmnModel = converter.convertToBpmnModel((XMLStreamReader) reader);
// BpmnModel bpmnModel =
// this.repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId());
//imageStream = new DefaultProcessDiagramGenerator().generateDiagram(bpmnModel, "png", executedActivityIdList);
imageStream = new DefaultProcessDiagramGenerator().generateDiagram(bpmnModel, "png", executedActivityIdList,
Collections.<String>emptyList(),
"宋体",
"宋体",
null, 1.0);
// imageStream = new
// DefaultProcessDiagramGenerator().generateDiagram(bpmnModel,
// "png", executedActivityIdList);
imageStream = new DefaultProcessDiagramGenerator().generateDiagram(bpmnModel, "png", executedActivityIdList, Collections.<String>emptyList(), "宋体", "宋体", null, 1.0);
}
return imageStream;
}
}
......@@ -54,7 +54,7 @@
update C_T_PROC_INSTANCE set
]]>
<trim prefix="" suffixOverrides=",">
<foreach collection="info" item="info">
<foreach collection="infoList" item="info">
${info.key} = #{info.value} ,
</foreach>
</trim>
......
......@@ -7,12 +7,23 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;
import org.activiti.engine.impl.pvm.process.TransitionImpl;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import com.gaowj.business.ProctaskBusiness;
import com.gaowj.business.exception.ActivitiException;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.formmodels.formmodelsDAO;
import com.gaowj.business.formtable.formtableDAO;
......@@ -20,6 +31,8 @@ import com.gaowj.business.procdefinition.procdefinitionDAO;
import com.gaowj.business.procinstance.procinstanceDAO;
import com.gaowj.business.util.Page;
import com.gaowj.business.util.SessionUtil;
import com.gaowj.business.utils.ActivitiTools;
import com.gaowj.business.utils.model.ActivitiResultEnum;
public class ProctaskBusinessImpl implements ProctaskBusiness {
......@@ -35,6 +48,10 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
private formtableDAO formtableDAO;
private HistoryService historyService;
private RepositoryService repositoryService;
public RuntimeService getRuntimeService() {
return runtimeService;
}
......@@ -83,6 +100,22 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
this.formtableDAO = formtableDAO;
}
public HistoryService getHistoryService() {
return historyService;
}
public void setHistoryService(HistoryService historyService) {
this.historyService = historyService;
}
public RepositoryService getRepositoryService() {
return repositoryService;
}
public void setRepositoryService(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
@Override
public Page<Map<String, Object>> list_proc_task(int pageNo, int pageSize, Map<String, Object> query) throws BusinessException {
Page<Map<String, Object>> page = new Page<Map<String, Object>>();
......@@ -104,7 +137,7 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
map.put("EXECUTION_ID", task.getExecutionId());
map.put("PROCESS_INSTANCE_ID", task.getProcessInstanceId());
map.put("TASK_ID", task.getId());
//listInstanceId.add(task.getExecutionId());
// listInstanceId.add(task.getExecutionId());
listInstanceId.add(task.getProcessInstanceId());
}
......@@ -140,7 +173,7 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
}
}
} else {
//如果activit中没有任务,则new一个空的list
// 如果activit中没有任务,则new一个空的list
listInstance = new ArrayList<Map<String, Object>>();
}
page.setItems(listInstance);
......@@ -198,33 +231,25 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
}
@Override
public Map<String, Object> update(Map<String, Object> entity) throws BusinessException {
// 存储自定义表单的业务数据
update_custom_business(entity.get("TABLE_ID_SYSTEM").toString(), entity);
public Map<String, Object> update(Map<String, Object> entity) throws ActivitiException, BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, false);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
return entity;
}
@Override
public Map<String, Object> updateToNext(String taskId, Map<String, Object> entity) throws BusinessException {
// 存储自定义表单的业务数据
update_custom_business(entity.get("TABLE_ID_SYSTEM").toString(), entity);
// 通过任务id获取流程id
String processInstanceId = taskService.createTaskQuery().taskId(taskId).singleResult().getProcessInstanceId();
// 完成当前任务
taskService.complete(taskId);
// 判断当前流程是否结束
long count = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).count();
if (count == 0) {
// 表示流程已结束,修改实例表的complete字段为1
Map<String, Object> query = new HashMap<String, Object>();
query.put("BUSINESS_ID", entity.get("UUID"));
// 先获取实例表的uuid
String procinstanceId = procinstanceDAO.list_proc_instance_all(query).get(0).get("UUID").toString();
Map<String, Object> procinstance = new HashMap<String, Object>();
procinstance.put("UUID", procinstanceId);
procinstance.put("COMPLETE", 1);
// 通过实例表的uuid对实例表的状态进行更新
update_proc_instance(procinstance);
public Map<String, Object> updateToNext(Map<String, Object> entity) throws ActivitiException, BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, true);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
return entity;
}
......@@ -235,10 +260,8 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
update_custom_business(entity.get("TABLE_ID_SYSTEM").toString(), entity);
// 通过任务id获取流程id
String taskId = entity.get("TASK_ID_SYSTEM").toString();
// String processInstanceId =
// taskService.createTaskQuery().taskId(taskId).singleResult().getProcessInstanceId();
// 完成当前任务
taskService.complete(taskId);
// 退回当前任务
taskRollBack(taskId);
return entity;
}
......@@ -317,4 +340,63 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
return entity.get("UUID").toString();
}
private void taskRollBack(String taskId) {
try {
Map<String, Object> variables;
// 取得当前任务
HistoricTaskInstance currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
// 取得流程实例
ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).singleResult();
if (instance == null) {
// 流程结束
}
variables = instance.getProcessVariables();
// 取得流程定义
ProcessDefinitionEntity definition = (ProcessDefinitionEntity) (repositoryService.getProcessDefinition(currTask.getProcessDefinitionId()));
if (definition == null) {
// log.error("流程定义未找到");
return;
}
// 取得上一步活动
ActivityImpl currActivity = ((ProcessDefinitionImpl) definition).findActivity(currTask.getTaskDefinitionKey());
List<PvmTransition> nextTransitionList = currActivity.getIncomingTransitions();
// 清除当前活动的出口
List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>();
List<PvmTransition> pvmTransitionList = currActivity.getOutgoingTransitions();
for (PvmTransition pvmTransition : pvmTransitionList) {
oriPvmTransitionList.add(pvmTransition);
}
pvmTransitionList.clear();
// 建立新出口
List<TransitionImpl> newTransitions = new ArrayList<TransitionImpl>();
for (PvmTransition nextTransition : nextTransitionList) {
PvmActivity nextActivity = nextTransition.getSource();
ActivityImpl nextActivityImpl = ((ProcessDefinitionImpl) definition).findActivity(nextActivity.getId());
TransitionImpl newTransition = currActivity.createOutgoingTransition();
newTransition.setDestination(nextActivityImpl);
newTransitions.add(newTransition);
}
// 完成任务
List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getId()).taskDefinitionKey(currTask.getTaskDefinitionKey()).list();
for (Task task : tasks) {
taskService.complete(task.getId(), variables);
historyService.deleteHistoricTaskInstance(task.getId());
}
// 恢复方向
for (TransitionImpl transitionImpl : newTransitions) {
currActivity.getOutgoingTransitions().remove(transitionImpl);
}
for (PvmTransition pvmTransition : oriPvmTransitionList) {
pvmTransitionList.add(pvmTransition);
}
return;
} catch (Exception e) {
return;
}
}
}
package com.gaowj.business.utils;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import com.gaowj.business.formtable.formtableDAO;
import com.gaowj.business.procdefinition.procdefinitionDAO;
import com.gaowj.business.procinstance.procinstanceDAO;
import com.gaowj.business.util.SessionUtil;
import com.gaowj.business.utils.model.ActivitiResultEnum;
/**
* activiti工具类
*
* @author luosz
*
*/
public class ActivitiTools {
private static HistoryService historyService;
private static TaskService taskService;
private static RuntimeService runtimeService;
private static procdefinitionDAO procdefinitionDAO;
private static formtableDAO formtableDAO;
private static procinstanceDAO procinstanceDAO;
static {
ApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();
historyService = (HistoryService) context.getBean("historyService");
taskService = (TaskService) context.getBean("taskService");
runtimeService = (RuntimeService) context.getBean("runtimeService");
procdefinitionDAO = (procdefinitionDAO) context.getBean("procdefinitionDAO");
formtableDAO = (formtableDAO) context.getBean("formtableDAO");
procinstanceDAO = (procinstanceDAO) context.getBean("procinstanceDAO");
}
/**
* 根据任务id,判断当前登录人是否有权限修改
*
* @param taskId
* @return true:表示有权限;false:表示无权限
*/
public static boolean checkPowerByTaskId(String taskId) {
long taskCount = taskService.createTaskQuery().taskId(taskId).taskCandidateUser(SessionUtil.getCode()).count();
return taskCount > 0;
}
/**
* 根据实例id,判断当前登录人是否有权限修改
*
* @param instanceId
* @return true:表示有权限;false:表示无权限
*/
public static boolean checkPowerByInstanceId(String instanceId) {
long taskCount = taskService.createTaskQuery().processInstanceId(instanceId).taskCandidateUser(SessionUtil.getCode()).count();
return taskCount > 0;
}
/**
* 初始化数据
*
* @param procDefId
* 流程定义id
* @param formModelId
* 实时的表单模板id
* @param entity
* 业务数据
* @param isStart
* 是否直接开启流程(true:开启,false:不开启)
* @return
*/
public static ActivitiResultEnum init(String procDefId, String formModelId, Map<String, Object> entity, boolean isStart) {
// 获取流程定义信息
Map<String, Object> procdeFinition = findProcdeFinitionByUuid(procDefId);
// 存储自定义表单的业务数据
String businessId = insertCustomBusiness(procdeFinition.get("TABLE_ID").toString(), entity).get("UUID").toString();
// 流程实例id
String processInstanceId = null;
// 启动流程
if (isStart) {
// 根据流程定义中的流程key值启动流程(使用key值,搜索引擎会自动查找最新部署的流程进行启动)
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(procdeFinition.get("DEPLOYMENT_KEY").toString());
processInstanceId = processInstance.getId();
// 获取我的任务(如果点击下一步的时候,是第一次插入,就直接将我的任务完成掉)
String taskId = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskCandidateUser(SessionUtil.getCode()).singleResult().getId();
taskService.complete(taskId);
}
// 存储流程实例id和业务数据id的关联
insertProcInstance(procDefId, businessId, formModelId, processInstanceId);
return ActivitiResultEnum.OK;
}
/**
* 初始化数据,但不启动流程
*
* @param procDefId
* 流程定义id
* @param formModelId
* 实时的表单模板id
* @param entity
* 业务数据
* @return
*/
public static ActivitiResultEnum initNotStart(String procDefId, String formModelId, Map<String, Object> entity) {
return init(procDefId, formModelId, entity, false);
}
/**
* 初始化数据,且启动流程
*
* @param procDefId
* 流程定义id
* @param formModelId
* 实时的表单模板id
* @param entity
* 业务数据
* @return
*/
public static ActivitiResultEnum initStart(String procDefId, String formModelId, Map<String, Object> entity) {
return init(procDefId, formModelId, entity, true);
}
/**
*
* @param entity
* @param isNext
* @return
*/
public static ActivitiResultEnum save(Map<String, Object> entity, boolean isNext) {
Map<String, Object> procInstance = findProcInstanceByBusinessId(entity.get("UUID").toString());
// 验证是否有权限修改
if (!checkPowerByInstance(procInstance)) {
return ActivitiResultEnum.NO_POWER;
}
// 更新业务数据
String procDefId = procInstance.get("PROC_DEFINITION_ID").toString();
String tableId = findProcdeFinitionByUuid(procDefId).get("TABLE_ID").toString();
updateCustomBusiness(tableId, entity);
if (isNext) {
if (procInstance.get("INSTANCE_ID") == null || "".equals(procInstance.get("INSTANCE_ID"))) {
// 如果未启动,则通过流程定义id启动流程
String deploymentKey = findProcdeFinitionByUuid(procInstance.get("PROC_DEFINITION_ID").toString()).get("DEPLOYMENT_KEY").toString();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(deploymentKey);
procInstance.put("INSTANCE_ID", processInstance.getId());
// 将实例id保存到实例表
Map<String, Object> procInstanceUpdate = new HashMap<String, Object>();
procInstanceUpdate.put("UUID", procInstance.get("UUID"));
procInstanceUpdate.put("INSTANCE_ID", processInstance.getId());
updateProcInstanceData(procInstanceUpdate);
}
// 完成当前登录人任务
Task task = taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).singleResult();
taskService.complete(task.getId());
}
return ActivitiResultEnum.OK;
}
private static void updateProcInstanceData(Map<String, Object> entity) {
procinstanceDAO.update_proc_instance(machiningUpdateEntity(entity, "UUID"));
}
/**
* 根据流程实例表对象,判断当前登陆人是否有权限对该业务数据进行修改
*
* @param procInstance
* 流程实例表对象
* @return true:有权限;false:无权限
*/
private static boolean checkPowerByInstance(Map<String, Object> procInstance) {
// 验证是否有权限进行修改
if (procInstance.get("INSTANCE_ID") != null && !"".equals(procInstance.get("INSTANCE_ID"))) {
// 如果流程实例已经启动
if (!checkPowerByInstanceId(procInstance.get("INSTANCE_ID").toString())) {
// 没有权限
return false;
}
} else {
// 流程实例未启动(只有表单新建人才可以进行操作)
if (!SessionUtil.getCode().equals(procInstance.get("CREATE_ID"))) {
// 没有权限
return false;
}
}
return true;
}
/**
* 根据业务主键id,获取流程实例表对象(一个业务id主键肯定只对应一条流程实例表对象,因为一个业务表只可能启动一个流程实例)
*
* @param businessId
* 业务表主键id
* @return 流程实例表对象
*/
private static Map<String, Object> findProcInstanceByBusinessId(String businessId) {
Map<String, Object> query = new HashMap<String, Object>();
query.put("BUSINESS_ID", businessId);
// 获取流程实例表对象
return procinstanceDAO.list_proc_instance_all(query).get(0);
}
/**
* 根据流程定义表的主键id,获取流程定义数据
*
* @param uuid
* 主键uuid
* @return 流程定义表对象
*/
private static Map<String, Object> findProcdeFinitionByUuid(String uuid) {
Map<String, Object> query = new HashMap<String, Object>();
query.put("UUID", uuid);
return procdefinitionDAO.list_procde_finition(query).get(0);
}
/**
* 根据表定义表的主键id,获取表定义信息
*
* @param uuid
* 表定义表主键id
* @return 表定义表对象
*/
private static Map<String, Object> findFormTableByUuid(String uuid) {
Map<String, Object> query = new HashMap<String, Object>();
query.put("UUID", uuid);
return formtableDAO.list_form_table(query).get(0);
}
/**
* 根据表定义表的主键id,获取表定义表中的表名
*
* @param uuid
* @return
*/
private static String getTbleNameByUuid(String uuid) {
return findFormTableByUuid(uuid).get("TABLE_NAME").toString();
}
/**
* 插入业务表和流程实例表的关联表
*
* @param procDefId
* 流程定义id
* @param businessId
* 业务数据id
* @param formModelId
* 实时表单id
* @param instanceId
* 流程实例id(如果未启动流程实例,可传入null)
* @return 业务表和流程实例表的关联表信息
*/
private static Map<String, Object> insertProcInstance(String procDefId, String businessId, String formModelId, String instanceId) {
// 定义关联表对象
Map<String, Object> entity = new HashMap<String, Object>();
entity.put("BUSINESS_ID", businessId);
entity.put("FORM_MODEL_ID", formModelId);
if (instanceId != null) {
entity.put("INSTANCE_ID", instanceId);
}
entity.put("PROC_DEFINITION_ID", procDefId);
entity.put("UUID", java.util.UUID.randomUUID().toString());
entity.put("CREATE_TIME", new Date());
entity.put("CREATE_ID", SessionUtil.getCode());
entity.put("UPDATE_ID", SessionUtil.getCode());
entity.put("UPDATE_TIME", new Date());
procinstanceDAO.insert_proc_instance(machiningInsertEntity(entity));
return entity;
}
/**
* 插入业务数据
*
* @param tableId
* 表id(具体的业务数据所在表id)
* @param entity
* 业务数据
* @return 业务数据
*/
private static Map<String, Object> insertCustomBusiness(String tableId, Map<String, Object> entity) {
if (entity.get("UUID") == null) {
entity.put("UUID", java.util.UUID.randomUUID().toString());
}
if (entity.get("CREATE_TIME") == null) {
entity.put("CREATE_TIME", new Date());
}
if (entity.get("CREATE_ID") == null) {
entity.put("CREATE_ID", SessionUtil.getCode());
}
if (entity.get("UPDATE_ID") == null) {
entity.put("UPDATE_ID", SessionUtil.getCode());
}
if (entity.get("UPDATE_TIME") == null) {
entity.put("UPDATE_TIME", new Date());
}
// 动态传值插入
List<String> infoListKey = new ArrayList<String>();
List<Object> infoList = new ArrayList<Object>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
for (String str : key) {
infoList.add(entity.get(str));
infoListKey.add(str);
}
entity.put("infoListKey", infoListKey);
entity.put("infoList", infoList);
}
entity.put("tableName", getTbleNameByUuid(tableId));
procdefinitionDAO.insert_custom_business(entity);
return entity;
}
/**
* 更新业务数据
*
* @param tableId
* 表id(具体的业务数据所在表id)
* @param entity
* 业务数据
* @return 业务数据
*/
private static String updateCustomBusiness(String tableId, Map<String, Object> entity) {
entity.put("UPDATE_ID", SessionUtil.getCode());
entity.put("UPDATE_TIME", new Date());
// 设置表名
entity.put("tableName", getTbleNameByUuid(tableId));
entity.put("uuid", entity.get("UUID"));
procdefinitionDAO.update_custom_business(machiningUpdateEntity(entity, "uuid", "tableName"));
return entity.get("UUID").toString();
}
/**
* 处理弱类型插入时,数据的转换(注意Map自身为引用对象,外面方法调用时,不一定需要接收返回值进行处理)
*
* @param entity
* 处理前数据
* @param ignoreFields
* 需要忽略的字段
* @return 处理后数据
*/
private static Map<String, Object> machiningInsertEntity(Map<String, Object> entity, String... ignoreFields) {
// 动态传值插入
List<String> infoListKey = new ArrayList<String>();
List<Object> infoList = new ArrayList<Object>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
outer: for (String str : key) {
if (ignoreFields != null && ignoreFields.length > 0) {
for (String ignoreField : ignoreFields) {
if (str.equals(ignoreField)) {
// 如果是需要忽略的字段,直接继续外层循环
continue outer;
}
}
}
infoList.add(entity.get(str));
infoListKey.add(str);
}
entity.put("infoListKey", infoListKey);
entity.put("infoList", infoList);
}
return entity;
}
/**
* 处理弱类型更新时,数据的转换(注意Map自身为引用对象,外面方法调用时,不一定需要接收返回值进行处理)
*
* @param entity
* 处理前数据
* @param ignoreFields
* 需要忽略的字段
* @return 处理后数据
*/
private static Map<String, Object> machiningUpdateEntity(Map<String, Object> entity, String... ignoreFields) {
// 动态传值插入
List<Map<String, Object>> infoList = new ArrayList<Map<String, Object>>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
outer: for (String str : key) {
// UUID不需要加进去
if (ignoreFields != null && ignoreFields.length > 0) {
for (String ignoreField : ignoreFields) {
if (str.equals(ignoreField)) {
// 如果是需要忽略的字段,直接继续外层循环
continue outer;
}
}
}
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("value", entity.get(str));
kv.put("key", str);
infoList.add(kv);
}
entity.put("infoList", infoList);
}
return entity;
}
}
package com.gaowj.business.utils.model;
/**
* activiti工具类方法调用的返回值
*
* @author luosz
*
*/
public class ActivitiResult {
/**
* 错误码
*/
private int code;
/**
* 提示语
*/
private String msg;
public ActivitiResult() {
super();
}
public ActivitiResult(int code, String msg) {
super();
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.gaowj.business.utils.model;
/**
* ActivitiResult类型枚举类
*
* @author luosz
*
*/
public enum ActivitiResultEnum {
/**
* 成功
*/
OK(0, "成功"),
/**
* 无权限
*/
NO_POWER(-1, "您不是当前环节操作人,无权限修改该内容!");
private ActivitiResult activitiResult;
private ActivitiResultEnum(int code, String msg) {
activitiResult = new ActivitiResult(code, msg);
}
public ActivitiResult getActivitiResult() {
return activitiResult;
}
public int getCode() {
return activitiResult.getCode();
}
public String getMsg() {
return activitiResult.getMsg();
}
}
......@@ -8,6 +8,7 @@ import com.gaowj.business.ProcinstanceBusiness;
import com.gaowj.business.SystemOpeBusiness;
import com.gaowj.business.action.BasicAction;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.exception.ActivitiException;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.QueryParamUtil;
import com.gaowj.business.util.RequestUtils;
......@@ -40,56 +41,60 @@ public class actAction extends BasicAction {
*/
public String insertInfo() throws BusinessException {
ProcinstanceBusiness business = BusinessManager.getBusiness(ProcinstanceBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//去除不要更新的字段
// 去除不要更新的字段
entity.remove("OPETYPE");
//新增
Map<String,Object> procinstance=business.insert_proc_instance(entity);
// 新增
Map<String, Object> procinstance = business.insert_proc_instance(entity);
// 操作日志
//sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
// sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance,
"增加流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance, "增加流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
//
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
}
public String insertInfoToNext() throws BusinessException {
ProcinstanceBusiness business = BusinessManager.getBusiness(ProcinstanceBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//去除不要更新的字段
// 去除不要更新的字段
entity.remove("OPETYPE");
//新增
Map<String,Object> procinstance=business.insert_proc_instance_next(entity);
// 新增
Map<String, Object> procinstance = business.insert_proc_instance_next(entity);
// 操作日志
//sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
// sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance,
"增加流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance, "增加流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
//
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
}
/**
* 更新
*
......@@ -98,34 +103,32 @@ public class actAction extends BasicAction {
*/
public String updateInfo() throws BusinessException {
ProcinstanceBusiness business = BusinessManager.getBusiness(ProcinstanceBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//去除不要更新的字段
// 去除不要更新的字段
entity.remove("OPETYPE");
//更新
Map<String,Object> procinstance=business.update_proc_instance(entity);
if("-1".equals(procinstance.get("ERROR"))){
jsonObject.putAll(Status.getStatusErrorMessage("你不属于当前流程环节处理人,无权限处理该业务。"));
return "json";
}
// 更新
Map<String, Object> procinstance = business.update_proc_instance(entity);
// 操作日志
//sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
// sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance,
"更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance, "更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
//
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
}
/**
* 更新
*
......@@ -134,48 +137,45 @@ public class actAction extends BasicAction {
*/
public String updateInfoToNext() throws BusinessException {
ProcinstanceBusiness business = BusinessManager.getBusiness(ProcinstanceBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//去除不要更新的字段
// 去除不要更新的字段
entity.remove("OPETYPE");
//更新
Map<String,Object> procinstance=business.update_proc_instance_next(entity);
if("-1".equals(procinstance.get("ERROR"))){
jsonObject.putAll(Status.getStatusErrorMessage("你不属于当前流程环节处理人,无权限处理该业务。"));
return "json";
}
// 更新
Map<String, Object> procinstance = business.update_proc_instance_next(entity);
// 操作日志
//sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
// sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance,
"更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
sysbusiness.insert_logBusiness("insertInfo", "" + procinstance, "更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
//
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
}
public String deleteInfo() throws BusinessException{
public String deleteInfo() throws BusinessException {
ProcinstanceBusiness business = BusinessManager.getBusiness(ProcinstanceBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
String deletekey = (String) entity.get("CODE");
List<String> ListKey = QueryParamUtil.StringToList(deletekey);
try {
business.delete_proc_instance(ListKey);
// 操作日志
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("deleteProcinstance", "" + ListKey,
"删除流程实例数据", deletekey, "多个流水号","procinstance");
sysbusiness.insert_logBusiness("deleteProcinstance", "" + ListKey, "删除流程实例数据", deletekey, "多个流水号", "procinstance");
//
jsonObject.putAll(Status.getStatusSuccessMessage("删除成功"));
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("删除失败"));
......
......@@ -2,11 +2,11 @@ package com.gaowj.proctask.action;
import java.util.Map;
import com.gaowj.business.ProcinstanceBusiness;
import com.gaowj.business.ProctaskBusiness;
import com.gaowj.business.SystemOpeBusiness;
import com.gaowj.business.action.BasicAction;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.exception.ActivitiException;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.QueryParamUtil;
import com.gaowj.business.util.RequestUtils;
......@@ -14,13 +14,13 @@ import com.gaowj.business.util.Status;
import net.sf.json.JSONObject;
public class actAction extends BasicAction{
public class actAction extends BasicAction {
/**
*
*/
private static final long serialVersionUID = -4062030374955033260L;
private JSONObject jsonObject = new JSONObject();
public JSONObject getJsonObject() {
......@@ -33,68 +33,69 @@ public class actAction extends BasicAction{
public String updateInfo() throws BusinessException {
ProctaskBusiness business = BusinessManager.getBusiness(ProctaskBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//去除不要更新的字段
// 去除不要更新的字段
entity.remove("OPETYPE");
entity.remove("TASK_ID_SYSTEM");
//新增
Map<String,Object> procinstance=business.update(entity);
// 新增
Map<String, Object> procinstance = business.update(entity);
// 操作日志
//sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
// sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("updateInfo", "" + procinstance,
"更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
sysbusiness.insert_logBusiness("updateInfo", "" + procinstance, "更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
//
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
}
public String updateInfoToNext() throws BusinessException {
ProctaskBusiness business = BusinessManager.getBusiness(ProctaskBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
String taskId=entity.get("TASK_ID_SYSTEM").toString();
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//去除不要更新的字段
// 去除不要更新的字段
entity.remove("OPETYPE");
entity.remove("TASK_ID_SYSTEM");
//新增
Map<String,Object> procinstance=business.updateToNext(taskId, entity);
// 新增
Map<String, Object> procinstance = business.updateToNext(entity);
// 操作日志
//sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
// sysbusiness.insert_logBusiness(具体方法,操作内容,操作描述,操作记录ID,操作记录中文描述,分类)
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("updateInfo", "" + procinstance,
"更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
sysbusiness.insert_logBusiness("updateInfo", "" + procinstance, "更新流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
//
//
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
}
public String back() throws BusinessException {
ProctaskBusiness business = BusinessManager.getBusiness(ProctaskBusiness.class);
Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request, RequestUtils.UPDATEDATAFIELDPREFIX);
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
//business.list_proc_task(pageNo, pageSize, query)
// business.list_proc_task(pageNo, pageSize, query)
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
}
return "json";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment