144 lines
5.6 KiB
Java
144 lines
5.6 KiB
Java
package com.tenwa.flow.action.comm;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT;
|
|
import jbo.com.tenwa.entity.comm.flow.FLOW_WORK_FLAG;
|
|
import jbo.sys.FLOW_OBJECT;
|
|
import jbo.sys.FLOW_TASK;
|
|
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
import com.amarsoft.are.jbo.BizObjectManager;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
|
|
|
|
public class BaseFlowStartAction extends FlowBussionAction {
|
|
private String error_message = "failed@发起流程出错";
|
|
|
|
public String getError_message() {
|
|
return error_message;
|
|
}
|
|
public void setError_message(String error_message) {
|
|
this.error_message = error_message;
|
|
}
|
|
@Override
|
|
public String initFLow(JBOTransaction tx) throws Exception {
|
|
try {
|
|
//初始化当前用户信息
|
|
String flowunid="";
|
|
//生成业务流程数据并返回流程的编号
|
|
Map<String,String>deleteCondition=new HashMap<String,String>();
|
|
BizObject flowBussiness=this.initFLowBusinonObject(tx);
|
|
this.customOperation(tx,flowBussiness);
|
|
flowunid=flowBussiness.getAttribute("flow_unid").toString();
|
|
if(this.getFlowMutexConfig().size()>0){
|
|
String checkResult=this.flowMutexCheck(tx);
|
|
if(checkResult.length()>0)
|
|
{ deleteCondition.put("flow_unid",flowunid);
|
|
DataOperatorUtil.deleteJBOByCondtion(FLOW_BUSSINESS_OBJECT.CLASS_NAME, deleteCondition, tx);
|
|
return "failed@"+checkResult;
|
|
}
|
|
this.flowMutexInfoInit(tx);
|
|
}
|
|
|
|
this.updateFLowBusinonObject(tx);
|
|
this.executeFlowStartScript(tx, flowBussiness);
|
|
return this.startFlow(tx,flowunid);
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
tx.rollback();
|
|
return error_message;
|
|
}
|
|
}
|
|
/**
|
|
* 发起流程之前自定义操作
|
|
* @param tx
|
|
* @param flowBussiness
|
|
* @throws Exception
|
|
*/
|
|
public void customOperation(JBOTransaction tx,BizObject flowBussiness)throws Exception{
|
|
|
|
}
|
|
|
|
/**
|
|
*流程互斥检查
|
|
* @param tx
|
|
* @throws Exception
|
|
*/
|
|
public String flowMutexCheck(JBOTransaction tx)throws Exception{
|
|
BizObjectManager bom=JBOFactory.getBizObjectManager(FLOW_WORK_FLAG.CLASS_NAME);
|
|
tx.join(bom);
|
|
String mutextKeyValue="";
|
|
String mutextKey="";
|
|
String res="";
|
|
String sql="SELECT O.flow_unid,O.flow_name FROM O WHERE O.mutex_key=:mutex_key AND O.flow_name=:flownameb AND EXISTS (SELECT fc.flow_nameb FROM jbo.com.tenwa.entity.comm.flow.FLOW_MUTEX_CONFIG fc WHERE fc.flow_nameA=:flowname)";
|
|
for(int i=0;i<this.getFlowMutexConfig().size();i++){
|
|
if(this.getFlowMutexConfig().get(i).getAttribute("mutex_key")==null||this.getFlowMutexConfig().get(i).getAttribute("mutex_key").getString().length()==0){
|
|
mutextKey="FlowKey";
|
|
}else{
|
|
mutextKey=this.getFlowMutexConfig().get(i).getAttribute("mutex_key").getString();
|
|
}
|
|
Map<String,String>searchCondtion=new HashMap<String,String>();
|
|
mutextKeyValue=this.FlowParam.get(mutextKey);
|
|
List<BizObject>mutexList=bom.createQuery(sql).setParameter("mutex_key",mutextKeyValue).setParameter("flownameb",this.getFlowMutexConfig().get(i).getAttribute("flow_nameb").getString()).setParameter("flowname",this.getFlowNo()).getResultList(false);
|
|
if(mutexList.size()>0){
|
|
for(int j=0;j<mutexList.size();j++){
|
|
searchCondtion.put("objectno", mutexList.get(j).getAttribute("flow_unid").getString());
|
|
BizObject flowobject=DataOperatorUtil.getSingleJBO(FLOW_OBJECT.CLASS_NAME, searchCondtion, tx);
|
|
List<BizObject> flowTask = JBOFactory.getBizObjectManager(FLOW_TASK.CLASS_NAME).createQuery("objectno=:objectno and (endtime is null or endtime='') ").setParameter("objectno", mutexList.get(j).getAttribute("flow_unid").getString()).getResultList(false);
|
|
String OperatorUser ="";
|
|
if(flowTask.size()>0){
|
|
for(int k=0;k<flowTask.size();k++){
|
|
if(OperatorUser.length()>0){OperatorUser+=",";}
|
|
OperatorUser=OperatorUser+flowTask.get(k).getAttribute("username").getString();
|
|
}
|
|
}
|
|
if(res!=""){
|
|
res+=",";
|
|
}
|
|
res+=flowobject.getAttribute("flowname").getString()+"[当前处理人:"+OperatorUser+"]";
|
|
}
|
|
}
|
|
}
|
|
if(res.length()>0){res="当前流程和下面流程互斥不同时执行【"+res+"】";}
|
|
return res;
|
|
}
|
|
/**
|
|
* 保存互斥信息
|
|
* @param tx
|
|
* @throws Exception
|
|
*/
|
|
public void flowMutexInfoInit(JBOTransaction tx) throws Exception{
|
|
BizObjectManager bom=JBOFactory.getBizObjectManager(FLOW_WORK_FLAG.CLASS_NAME);
|
|
tx.join(bom);
|
|
String mutextKey="";
|
|
String mutextKeyValue="";
|
|
for(int i=0;i<this.getFlowMutexConfig().size();i++){
|
|
if(this.getFlowMutexConfig().get(i).getAttribute("mutex_key")==null||this.getFlowMutexConfig().get(i).getAttribute("mutex_key").getString().length()==0){
|
|
mutextKey="FlowKey";
|
|
}else{
|
|
mutextKey=this.getFlowMutexConfig().get(i).getAttribute("mutex_key").getString();
|
|
}
|
|
if(this.FlowParam.containsKey(mutextKey)){
|
|
mutextKeyValue =this.FlowParam.get(mutextKey);
|
|
}else{
|
|
throw new Exception("没有配置流程互斥字没有取到值");
|
|
}
|
|
BizObject old = bom.createQuery("flow_unid=:flowunid and flow_name=:flowname and mutex_key=:mutexkey ").setParameter("flowunid",this.FlowParam.get("FlowUnid")).setParameter("flowname",this.getFlowNo()).setParameter("mutexkey",mutextKeyValue).getSingleResult(false);
|
|
if(old==null){
|
|
BizObject bo=bom.newObject();
|
|
bo.setAttributeValue("flow_unid",this.FlowParam.get("FlowUnid"));
|
|
bo.setAttributeValue("flow_name",this.getFlowNo());
|
|
bo.setAttributeValue("mutex_key",mutextKeyValue);
|
|
this.initTabeUserInfo(bo);
|
|
bom.saveObject(bo);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|