package com.amarsoft.app.flow; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.TreeMap; import jbo.app.APP_BUSINESS_TEMPLATE; import jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT; import jbo.com.tenwa.entity.comm.flow.FLOW_READER; import jbo.com.tenwa.entity.comm.flow.FLOW_STEP_NODE; import jbo.com.tenwa.entity.comm.flow.FLOW_WORK_FLAG; import jbo.sys.FLOW_ENTRUSTED_USER; import jbo.sys.FLOW_MODEL; import jbo.sys.FLOW_TASK; import jbo.sys.FLOW_TASK_USER_HIS; import jbo.sys.USER_TASK_DATA; import jbo.sys.USER_TASK_INFO; import org.apache.commons.lang.StringUtils; import com.amarsoft.app.lc.util.DateAssistant; import com.amarsoft.are.ARE; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.BizObjectQuery; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.are.lang.StringX; import com.amarsoft.are.msg.Message; import com.amarsoft.are.msg.SMTPDispatcher; import com.amarsoft.are.util.StringFunction; import com.amarsoft.are.util.json.JSONDecoder; import com.amarsoft.are.util.json.JSONObject; import com.amarsoft.awe.util.ASResultSet; import com.amarsoft.awe.util.SqlObject; import com.amarsoft.awe.util.Transaction; import com.amarsoft.biz.workflow.FlowPhase; import com.amarsoft.biz.workflow.FlowService; import com.amarsoft.biz.workflow.FlowTask; import com.amarsoft.biz.workflow.TaskDataObject; import com.amarsoft.context.ASUser; import com.amarsoft.dict.als.manage.NameManager; //import com.base.util.DateUtil; import com.tenwa.reckon.util.DateUtil; import com.tenwa.app.manage.constant.PushMessageConstant; import com.tenwa.app.manage.util.PushMessageUtil; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.flow.service.FLowStepEndNotice; import com.tenwa.flow.service.FlowUserManageServie; import com.tenwa.flow.service.FlowUserManageServieImp; import com.tenwa.flow.task.BaseFlowTaskDataService; import com.tenwa.flow.task.CommFlowTaskDataService; import com.tenwa.flow.task.ProductFlowTaskDataService; import com.tenwa.flow.task.TenwaFlowTask; import com.tenwa.flow.util.FlowUtil; import com.tenwa.officetempalte.util.FileOperatorUtil; import com.tenwa.reckon.util.UUIDUtil; /** * * 流程相关操作处理类(本类逻辑可随业务实际情况进行调整) 用于runJavaMethodTrans调用, 进行初始化流程、取消流程、主动撤回、退回 等操作 */ public class FlowAction { private String objectType; private String objectNo; private String flowNo; private String applyType; private String phaseNo; private String userID; private String orgID; private String taskNo; private String phaseAction; private String phaseOpinion; private String returnPoint;// 任意退回时,要退回到的任务节点流水号 private String recommit; private String readUserIds;// 传阅人员 private String passReadid;// 传阅ID private String AssignmentId;// 指派人员ID private String AssignSumbitType;// 指派处理方式 private String nextNodeType; private FlowService flowService; // app config private String DATA_CODE; private String GROUP_CODE; private String DATA_NAME; private String ISLIST; private String ISSHOW; private String DATA_POSITION; private String ISCONVERT; private String DONO; private String SORTNO; private String[] uids; private String uid; public String getObjectType() { return objectType; } public void setObjectType(String objectType) { this.objectType = objectType; } public String getObjectNo() { return objectNo; } public void setObjectNo(String objectNo) { this.objectNo = objectNo; } public String getFlowNo() { return flowNo; } public void setFlowNo(String flowNo) { this.flowNo = flowNo; } public String getApplyType() { return applyType; } public void setApplyType(String applyType) { this.applyType = applyType; } public String getPhaseNo() { return phaseNo; } public void setPhaseNo(String phaseNo) { this.phaseNo = phaseNo; } public String getUserID() { return userID; } public void setUserID(String userID) { this.userID = userID; } public String getOrgID() { return orgID; } public void setOrgID(String orgID) { this.orgID = orgID; } public String getTaskNo() { return taskNo; } public void setTaskNo(String taskNo) { this.taskNo = taskNo; } public String getPhaseAction() { return phaseAction; } public void setPhaseAction(String phaseAction) { this.phaseAction = phaseAction; } public String getPhaseOpinion() { return phaseOpinion; } public void setPhaseOpinion(String phaseOpinion) { this.phaseOpinion = phaseOpinion; } public String getReturnPoint() { return returnPoint; } public void setReturnPoint(String returnPoint) { this.returnPoint = returnPoint; } public String getRecommit() { return recommit; } public void setRecommit(String recommit) { this.recommit = recommit; } public String getReadUserIds() { if (null == readUserIds) { readUserIds = ""; } return readUserIds; } public void setReadUserIds(String readUserIds) { this.readUserIds = readUserIds; } public String getPassReadid() { return passReadid; } public void setPassReadid(String passReadid) { this.passReadid = passReadid; } public FlowAction() { flowService = new FlowService(); } public String getAssignSumbitType() { return AssignSumbitType; } public void setAssignSumbitType(String assignSumbitType) { AssignSumbitType = assignSumbitType; } public String getAssignmentId() { return AssignmentId; } public void setAssignmentId(String assignmentId) { AssignmentId = assignmentId; } public FlowService getFlowService() { return flowService; } public void setFlowService(FlowService flowService) { this.flowService = flowService; } /** * 初始化流程 * * @return success-处理成功; error-处理失败 */ public String initFlow(JBOTransaction tx) throws Exception { flowService.initFlow(applyType, objectNo, userID, tx); return "success"; } /** * 取消流程 * * @return success-处理成功; error-处理失败 */ public String delete(JBOTransaction tx) throws Exception { try { Map condtion = new HashMap(); condtion.put("flow_unid", objectNo); BaseFlowTaskDataService deleteTaskService = null; if (this.objectType.equals("ProductDefaultObject")) { deleteTaskService = new ProductFlowTaskDataService(tx, objectNo, this.flowNo, "", this.getFlowStartActionParm( tx, objectNo)); } else { deleteTaskService = new CommFlowTaskDataService(tx, objectNo, this.flowNo, "", this.getFlowStartActionParm(tx, objectNo)); } deleteTaskService.initDeleteNodes(); deleteTaskService.exectueFlowDelete(); DataOperatorUtil.deleteJBOByCondtion(FLOW_WORK_FLAG.CLASS_NAME, condtion, tx); DataOperatorUtil.deleteJBOByCondtion( FLOW_BUSSINESS_OBJECT.CLASS_NAME, condtion, tx); condtion.clear(); condtion.put("flowunid", objectNo); DataOperatorUtil.deleteJBOByCondtion(FLOW_STEP_NODE.CLASS_NAME, condtion, tx); flowService.delete(objectNo, objectType, tx); return "success@删除成"; } catch (Exception e) { tx.rollback(); e.printStackTrace(); return "fail@删除失败"; } } public Map getFlowStartActionParm(JBOTransaction tx, String ObjectNo) throws Exception { BizObjectManager tableEquip = JBOFactory .getBizObjectManager(FLOW_BUSSINESS_OBJECT.CLASS_NAME); tx.join(tableEquip); BizObjectQuery bqDest = tableEquip.createQuery("flow_unid=:flowunid"); bqDest.setParameter("flowunid", ObjectNo); BizObject flowBussinessObject = bqDest.getSingleResult(true);// 目标JBO,需要做更新操作 Map mapParam = new HashMap(); if (flowBussinessObject != null) { mapParam.put("ProjectId", flowBussinessObject.getAttribute("Proj_id").getString()); mapParam.put("ContractId", flowBussinessObject.getAttribute("Contract_id").getString()); mapParam.put("FlowUnid", flowBussinessObject.getAttribute("Flow_unid").getString()); mapParam.put("FlowKey", flowBussinessObject .getAttribute("Flow_key").getString()); String fixedParam = flowBussinessObject.getAttribute( "FixedFlowParam").getString(); if (fixedParam.length() > 0 && (!fixedParam.equals("[]"))) { JSONObject jsonFixedFlowParam = JSONDecoder.decode(fixedParam); mapParam.putAll(FileOperatorUtil .getJsonObjectToMap(jsonFixedFlowParam)); } } return mapParam; } /** * 新增加xuyunlong 流程中的数据归档 * * @param tx * @throws Exception */ public void PhaseInfoArchive(String sFlowNo, String sPhaseNo, String sObjectType, String sObjectNo, String sTaskNo, String suerId, String sorgId, JBOTransaction tx) throws Exception { Map condtion = new HashMap(); condtion.put("flow_unid", sObjectNo); BaseFlowTaskDataService dataTaskService = null; if (sObjectType.equals("ProductDefaultObject")) { dataTaskService = new ProductFlowTaskDataService(tx, sObjectNo, sFlowNo, sTaskNo, this.getFlowStartActionParm(tx, sObjectNo)); } else { dataTaskService = new CommFlowTaskDataService(tx, sObjectNo, sFlowNo, sTaskNo, this.getFlowStartActionParm(tx, sObjectNo)); } dataTaskService.initPhaseNodes(); dataTaskService.phaseFlowStepData(); } /** * 根据objectType,objectNo从FLOW_TASK中查找最新的phaseNo,用于申请页面提交时检查申请记录是否已提交 * * @return curPhaseNo--流程最新的phaseNo */ public String getCurPhaseNo(JBOTransaction tx) throws Exception { String curPhaseNo = ""; String endTime=""; BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "select phaseNo,endtime from O where SERIALNO=:SERIALNO") .setParameter("SERIALNO", this.getTaskNo()).getSingleResult(false); if (bo != null){ curPhaseNo = bo.getAttribute("phaseNo").getString(); if(bo.getAttribute("endtime")!=null){ endTime=bo.getAttribute("endtime").getString(); } } if(endTime.length()>0){curPhaseNo = "";} return curPhaseNo; } /** * 是否已提交 */ public String isCommited(JBOTransaction tx) throws Exception { String sRet = "no"; BizObject bo = JBOFactory.getBizObjectManager(FLOW_TASK.CLASS_NAME) .createQuery("select EndTime from O where SerialNo=:taskNo") .setParameter("taskNo", taskNo).getSingleResult(false); if (bo != null) { if (!StringX.isEmpty(bo.getAttribute("EndTime").getString())) sRet = "yes"; } tx.commit(); return sRet; } /** * 根据taskNo检查是否已经签署意见 * * @return yes-有意见; no-无意见; */ public String isSignOpinion(JBOTransaction tx) throws Exception { String sRet = "no"; BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_OPINION", tx) .createQuery("select serialNo from O where serialNo=:taskNo") .setParameter("taskNo", taskNo).getSingleResult(false); BizObject bo1 = JBOFactory.getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery("select phaseno from O where serialNo=:taskNo") .setParameter("taskNo", taskNo).getSingleResult(false); String phaseno = bo1.getAttribute("phaseno").getString(); if (bo != null || "0010".equals(phaseno)) { sRet = "yes"; } return sRet; } /** * 撤回流程 * * @return success-处理成功; error-处理失败 */ public String takeBack(JBOTransaction tx) throws Exception { String taskSerialNo = "";// 根据objectType,objectNo,flowNo,userID查最新已提交的任务 BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "select serialNo,RelativeSerialNo from O " + " where objectType=:objectType and objectNo=:objectNo and flowNo=:flowNo and userID=:userID and endTime is not null order by beginTime desc") .setParameter("objectType", objectType) .setParameter("objectNo", objectNo) .setParameter("flowNo", flowNo).setParameter("userID", userID) .getSingleResult(false); if (bo != null) { taskSerialNo = bo.getAttribute("serialNo").getString(); } else {// 不存在已提交的任务 return "success"; } // 下阶段任务已签署意见 List list = JBOFactory .getBizObjectManager("jbo.sys.FLOW_OPINION", tx) .createQuery( "select O.serialNo from O,jbo.sys.FLOW_TASK FT where O.serialNo=FT.serialNo and FT.RelativeSerialNo =:RelativeSerialNo ") .setParameter("RelativeSerialNo", taskSerialNo) .getResultList(false); if (list != null && list.size() > 0) { ARE.getLog().info("下阶段任务已签署意见,不能收回"); return "下阶段任务已签署意见,不能收回"; } String rv = flowService.takeBack(taskSerialNo, tx);// 0为成功 1为失败 if ("0".equals(rv)) return "success"; else return rv; } /** * 退回前一步 * * @return success-处理成功; error-处理失败 */ public String backStep(JBOTransaction tx) throws Exception { BizObjectManager ftManager = JBOFactory.getBizObjectManager( "jbo.sys.FLOW_TASK", tx); // 根据任务编号,查出流程的编号,阶段编号,对象类型,对象编号:新增加xuyunlong:退回归档 BizObject ft = ftManager .createQuery( "select O.flowno,O.phaseno,O.objecttype,O.objectno,O.userid,O.orgid from O where serialNo=:serialNo ") .setParameter("serialNo", taskNo).getSingleResult(false); // 将数据保存到历史记录里 PhaseInfoArchive(ft.getAttribute("flowno").getString(), ft .getAttribute("phaseno").getString(), ft.getAttribute("objecttype").getString(), ft.getAttribute("objectno").getString(), taskNo, ft .getAttribute("userid").getString(), ft.getAttribute("orgid").getString(), tx); String rv = flowService.backStep(taskNo, tx); if ("0".equals(rv)) return "success"; else return "error"; } /** * 退回到指定流程节点 * * @param ReturnPoint * 指定退回点 * @throws Exception * */ public String returnTask(JBOTransaction tx) throws Exception { // 将数据保存到历史记录里 BizObjectManager ftManager = JBOFactory.getBizObjectManager( "jbo.sys.FLOW_TASK", tx); // 根据任务编号,查出流程的编号,阶段编号,对象类型,对象编号:新增加xuyunlong:退回归档 BizObject ft = ftManager .createQuery( "select O.flowno,O.phaseno,O.objecttype,O.objectno,O.userid,O.orgid from O where serialNo=:serialNo ") .setParameter("serialNo", taskNo).getSingleResult(false); //处理任务池 BizObjectManager utdbom = JBOFactory.getBizObjectManager(USER_TASK_DATA.CLASS_NAME, tx); BizObjectManager utibom = JBOFactory.getBizObjectManager(USER_TASK_INFO.CLASS_NAME, tx); BizObject utdbo = utdbom.createQuery("taskno = '" + taskNo + "' and userid = '" + ft.getAttribute("userid").toString() + "' and (status = 'approve_status01' or status = 'approve_status03')").getSingleResult(true); if(utdbo != null) { int taskNumber = utibom.createQuery("userid = '" + utdbo.getAttribute("userid") + "' and roleid = '" + utdbo.getAttribute("roleid") + "'").getSingleResult(false).getAttribute("task_number").getInt(); ARE.getLog().info("***********任务池日志***:为"+ taskNo + "的" + utdbo.getAttribute("userid") + "用户关闭一个任务,当前未处理待办数为" + taskNumber); String status = utdbo.getAttribute("status").toString(); if("approve_status01".equals(status)) { utibom.createQuery("update O set task_number = task_number - 1 where userid = '" + utdbo.getAttribute("userid") + "' and roleid = '" + utdbo.getAttribute("roleid") + "'").executeUpdate(); } utdbo.setAttributeValue("status", "approve_status02"); utdbo.setAttributeValue("endtime", StringFunction.getTodayNow()); utdbom.saveObject(utdbo); } PhaseInfoArchive(ft.getAttribute("flowno").getString(), ft .getAttribute("phaseno").getString(), ft.getAttribute("objecttype").getString(), ft.getAttribute("objectno").getString(), taskNo, ft .getAttribute("userid").getString(), ft.getAttribute("orgid").getString(), tx); flowService.returnTask(taskNo, returnPoint, ("Y".equalsIgnoreCase(recommit) ? taskNo : ""), tx); //流程或步骤结束之后的通知 new FLowStepEndNotice().StepEndNotice(tx, ft.getAttribute("objectno").getString(),this.taskNo,"back"); return "退回成功"; } /** * 退回补充资料 * * @param ReturnPoint * 指定退回点 * @throws Exception * */ public String returnSupply(JBOTransaction tx) throws Exception { String sql = "select min(SerialNo) as v.minSerialNo from O where ObjectType =:ObjectType and ObjectNo =:ObjectNo "; BizObject bo = JBOFactory.getBizObjectManager("jbo.sys.FLOW_TASK") .createQuery(sql).setParameter("ObjectType", objectType) .setParameter("ObjectNo", objectNo).getSingleResult(false); if (bo != null) { flowService.returnSupply(taskNo, bo.getAttribute("minSerialNo") .getString(), tx); } return "success"; } /** * 从任务池获取任务 * * @return taskSerialNo-获取到的任务流水号; ""-无任务; "error"-处理失败 */ public String fetchTask(JBOTransaction tx) throws Exception { String sRet = flowService.fetchTask(userID, flowNo, phaseNo, tx); return sRet; } /** * 把任务退回到任务池 * * @return success-处理成功; error-处理失败 */ public String returnTaskToPool(JBOTransaction tx) throws Exception { flowService.returnTaskToPool(objectNo, objectType, phaseNo, flowNo, tx); return "success"; } /** * 更改任务处理人 */ public String changeOperator(JBOTransaction tx) throws Exception { BizObject userBO = JBOFactory .getBizObjectManager("jbo.sys.USER_INFO") .createQuery( "select O.userName,OI.OrgID,OI.OrgName " + "from O,jbo.sys.ORG_INFO OI where O.userID=:userID and O.belongOrg=OI.orgID") .setParameter("userID", AssignmentId).getSingleResult(false); if (userBO != null) { this.initFlowTaskUserHis(tx); //重新指派处理人的同时,修改任务池数据 FlowTask tf = new FlowTask(taskNo, tx); userID = tf.UserID; JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK") .createQuery( "update O set userID=:userID,userName=:userName,orgID=:orgID,orgName=:orgName where serialNo=:serialNo") .setParameter("serialNo", taskNo) .setParameter("userID", AssignmentId) .setParameter("userName", userBO.getAttribute("userName").getString()) .setParameter("orgID", userBO.getAttribute("orgID").getString()) .setParameter("orgName", userBO.getAttribute("orgName").getString()) .executeUpdate(); String role = tf.PhaseOpinion4; String curRole = role; Transaction tran = Transaction.createTransaction(tx); ASUser user = ASUser.getUser(AssignmentId, tran); if(!"".equals(role)) { String now = StringFunction.getTodayNow().replaceAll(":", "△"); SqlObject sql = null; if(user.getRoleTable().contains(role)) { sql = new SqlObject(("insert into user_task_data " + "select sys_guid() ,'" + AssignmentId + "', roleid, flowno, flowunid, project_id, contract_id, '" + now + "', endtime," + " 'approve_status03', taskno" + " from user_task_data where userid = '" + userID + "' and taskno = '" + taskNo + "' and (status = 'approve_status01' or status = 'approve_status03')")); sql.setDebugSql(sql.getDebugSql().replaceAll("△", ":")); sql.setOriginalSql(sql.getOriginalSql().replaceAll("△", ":")); sql.setRunSql(sql.getRunSql().replaceAll("△", ":")); tran.executeSQL(sql); sql = new SqlObject("update user_task_info set task_number = nvl(task_number, 0) + 1 " + " where userid = '" + AssignmentId + "' and roleid = '" + curRole + "'"); tran.executeSQL(sql); } else { role = user.getRoleTable().get(0); } sql = new SqlObject("update user_task_data set endtime = '" + now + "',status = 'approve_status04'" + " where userid = '" + userID + "' and taskno = '" + taskNo + "' and (status = 'approve_status01' or status = 'approve_status03')"); sql.setDebugSql(sql.getDebugSql().replaceAll("△", ":")); sql.setOriginalSql(sql.getOriginalSql().replaceAll("△", ":")); sql.setRunSql(sql.getRunSql().replaceAll("△", ":")); tran.executeSQL(sql); sql = new SqlObject("update user_task_info set task_number = nvl(task_number, 0) - 1 " + " where userid = '" + userID + "' and roleid = '" + curRole + "'"); tran.executeSQL(sql); } } return ""; } /** * 处理人调整历史 * * @param tx * @throws Exception */ public void initFlowTaskUserHis(JBOTransaction tx) throws Exception { BizObject userBO = JBOFactory .getBizObjectManager("jbo.sys.USER_INFO") .createQuery( "select O.userName,OI.OrgID,OI.OrgName " + "from O,jbo.sys.ORG_INFO OI where O.userID=:userID and O.belongOrg=OI.orgID") .setParameter("userID", this.userID).getSingleResult(false); BizObject task = JBOFactory.getBizObjectManager(FLOW_TASK.CLASS_NAME) .createQuery("select * from o where O.serialNo=:taskNo") .setParameter("taskNo", this.taskNo).getSingleResult(false); BizObjectManager flowUser = JBOFactory .getBizObjectManager(FLOW_TASK_USER_HIS.CLASS_NAME); tx.join(flowUser); BizObject bo = flowUser.newObject(); bo.setAttributeValue("TaskNo", this.taskNo); bo.setAttributeValue("SourceUser", task.getAttribute("USERID") .getString()); bo.setAttributeValue("newUser", AssignmentId); bo.setAttributeValue("inputuser", this.userID); bo.setAttributeValue("INPUTORGID", userBO.getAttribute("orgID") .getString()); bo.setAttributeValue("inputtime", DateAssistant.getTodayNow()); flowUser.saveObject(bo); } /** * 根据flow_object相关数据获取未完成的flow_task流水号 * * @return taskSerialNo */ public String getUnfinishedTaskNo(JBOTransaction tx) throws Exception { String taskSerialNo = ""; BizObject bo = null; if (phaseNo.equals("1000") || phaseNo.equals("8000")) { bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "select RELATIVESERIALNO from O where ObjectNo =:ObjectNo and PhaseNo =:PhaseNo ") .setParameter("ObjectNo", objectNo) .setParameter("PhaseNo", phaseNo) .getSingleResult(false); if (bo != null) taskSerialNo = bo.getAttribute("RELATIVESERIALNO").getString(); } else { bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "select SerialNo from O where ObjectType =:ObjectType and ObjectNo =:ObjectNo and FlowNo =:FlowNo and PhaseNo =:PhaseNo " + " and (PhaseAction is null or PhaseAction='') and (UserID =:UserID or AgentUserID=:agentuserid or UserID in (SELECT fu.sourceUser FROM " + FLOW_ENTRUSTED_USER.CLASS_NAME + " fu WHERE fu.NewUser=:newuser) ) and (EndTime is null or EndTime ='') order by serialNo desc ") .setParameter("ObjectType", objectType) .setParameter("ObjectNo", objectNo) .setParameter("FlowNo", flowNo) .setParameter("PhaseNo", phaseNo) .setParameter("UserID", userID) .setParameter("agentuserid", userID) .setParameter("newuser", userID).getSingleResult(false); if (bo != null) taskSerialNo = bo.getAttribute("SerialNo").getString(); } return taskSerialNo; } /** * 根据flowNo,phaseNo判断是否是任务池节点 * * @return yes-是; no-否; error-查询出错 */ public String isPoolSubmit(JBOTransaction tx) throws Exception { String sRet = "no"; String NodeType = flowService.getNodeProperty(flowNo, phaseNo, tx); if (!StringX.isEmpty(NodeType) && NodeType.toUpperCase().contains("POOL")) { sRet = "yes"; } return sRet; } /** * 根据flowNo,phaseNo判断是否是贷审会分发节点 * * @return yes-是; no-否; error-查询出错 */ public String isMeeting(JBOTransaction tx) throws Exception { String sRet = "no"; String NodeType = flowService.getNodeProperty(flowNo, phaseNo, tx); if (!StringX.isEmpty(NodeType) && NodeType.toUpperCase().contains("MEETING")) { sRet = "yes"; } if (sRet.equals("no")) { if (isMultiUsers(tx).equals("Y")) { sRet = "yes"; } } return sRet; } /** * 根据taskNo,phaseOpinion获得下一阶段个数、下一阶段号、下一阶段名称 * * @return 得下一阶段个数、下一阶段号、下一阶段名称 */ public String getNextPhaseNumAndInfo(Transaction Sqlca) throws Exception { String sRet = "", sPhaseNos = "", sPhaseNames = ""; FlowTask ft = new FlowTask(taskNo, Sqlca); FlowPhase[] fps = ft.getNextFlowPhase("", phaseOpinion); sRet = "" + fps.length; for (int i = 0; i < fps.length; i++) { sPhaseNos += fps[i].PhaseNo; sPhaseNames += fps[i].PhaseName; if (i < fps.length - 1) { sPhaseNos += "|"; sPhaseNames += "|"; } } sRet = sRet + "@" + sPhaseNos + "@" + sPhaseNames; return sRet; } /** * 获取下一阶段属性 * * @param tx * @return */ public String getNextPhaseAttr(JBOTransaction tx) throws Exception { return flowService.getNextPhaseAttr(tx, taskNo, phaseOpinion); } /** * 获取下一阶段信息 * * @param trans * @return */ public String getNextPhaseInfo(JBOTransaction trans) throws Exception { String returnMessage = flowService.getNextPhaseInfo(trans, taskNo, phaseAction, phaseOpinion); return returnMessage; } /** * 根据当前任务编号取得传阅人员 * * @param trans * @return * @throws Exception */ public String getPassActionList(JBOTransaction trans) throws Exception { BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", trans) .createQuery( "select flowmodel.ATTRIBUTE10,O.userid,O.objectno from O ,jbo.sys.FLOW_MODEL flowmodel where O.FLOWNO=flowmodel.flowno and O.PHASENO=flowmodel.phaseno and O.serialno=:taskno") .setParameter("taskno", this.taskNo).getSingleResult(false); String passReader = bo.getAttribute("ATTRIBUTE10").getString(); String userid = bo.getAttribute("userid").getString(); this.objectNo = bo.getAttribute("objectno").getString(); if (passReader == null || passReader.length() == 0) { return ""; } else { FlowUserManageServie fUserManager = new FlowUserManageServieImp( trans, new ASUser(userid)); Map model = new HashMap(); model.put("flowunid", this.objectNo); model.put("objectno", this.objectNo); model.put("taskno", this.taskNo); Map mapPassReader = fUserManager .getFlowOperatorUser(model, passReader); fUserManager.closeTransaction(); String returnReader = ""; for (String key : mapPassReader.keySet()) { if (returnReader.length() > 0) { returnReader += "@"; } returnReader = returnReader + key + " " + mapPassReader.get(key); } return returnReader; } } /** * 获取人员列表 * * @param trans * @return */ public String getActionList(JBOTransaction trans) throws Exception { String returnMessage = ""; String actionStr = "", aUserID = "", aRoleID = ""; String aUserName = "", aRoleName = ""; String[] actionList = flowService.getActionList(trans, taskNo, phaseOpinion); if (actionList != null) { for (int i = 0; i < actionList.length; i++) { String[] tempArr = actionList[i].split(" "); if (tempArr.length > 1) { if (actionStr.contains(tempArr[0])) { continue; } aUserID = tempArr[0]; aUserName = NameManager .getUserName(aUserID.contains("|") ? aUserID .split("\\|")[1] : aUserID); actionStr += "@" + aUserID + " " + aUserName; if (tempArr.length > 2) { aRoleID = tempArr[2]; aRoleName = NameManager.getRoleName(aRoleID); actionStr += " " + aRoleID + " " + aRoleName; } } else { aUserID = actionList[i]; aUserName = NameManager .getUserName(aUserID.contains("|") ? aUserID .split("\\|")[1] : aUserID); actionStr += "@" + aUserID + " " + aUserName; } } if (actionStr.contains("@")) { actionStr = actionStr.substring(1); } returnMessage = actionStr; } return returnMessage; } public String getFlowTaskPassReader(Transaction Sqlca) throws Exception { return null; } /** * 根据taskNo,phaseOpinion得到提交人列表 * * @param Sqlca * @return {phaseno:actions,phaseno2:actions2} */ public String genPhaseAction(Transaction Sqlca) throws Exception { StringBuffer sRet = new StringBuffer("{"); FlowTask ft = new FlowTask(taskNo, Sqlca); FlowPhase[] fps = ft.getNextFlowPhase("", phaseOpinion); String[] strs = ft.getActionList(phaseOpinion); if (fps.length > 1) {// 并行 for (int fp_i = 0; fp_i < fps.length; fp_i++) { String str = "\"" + fps[fp_i].PhaseNo + "\":["; for (int s_i = 0; s_i < strs.length; s_i++) { if (strs[s_i].startsWith(fps[fp_i].PhaseNo)) { str = str + "\"" + strs[s_i] + "\","; } } if (str.endsWith(",")) { str = str.substring(0, str.length() - 1); } str = str + "]"; if (fp_i > 0) { sRet.append(","); } sRet.append(str); } } else if (fps.length == 1) {// 非并行 String str = "\"" + fps[0].PhaseNo + "\":["; for (int i = 0; i < strs.length; i++) { str = str + "\"" + strs[i] + "\","; } if (str.endsWith(",")) { str = str.substring(0, str.length() - 1); } str = str + "]"; sRet.append(str); } sRet.append("}"); ARE.getLog().trace(sRet.toString()); return sRet.toString(); } /** * 检查如果是退回直接提交步骤,就不弹出用户选择框 * @throws Exception */ public String checkBackType(JBOTransaction tx) throws Exception { FlowTask ft = new FlowTask(taskNo, tx); if(ft.AssignedTaskNo.length() > 0) { FlowTask ftB = new FlowTask(ft.AssignedTaskNo, tx); this.nextNodeType = "TASK"; this.phaseOpinion = ftB.PhaseNo; this.phaseAction = ftB.UserID + " " + ftB.UserName; return this.submit(tx); } else { return "false"; } } /** * 根据taskNo得到flowTask对象,根据phaseAction, phaseOpinion提交 * * @return */ public String submit(JBOTransaction tx) throws Exception { String str = "success", attribute7, endTime = StringFunction.getTodayNow(); int attribute8; BizObjectManager ftManager = JBOFactory.getBizObjectManager("jbo.sys.FLOW_TASK", tx); BizObject ft = ftManager.createQuery( "select O.relativeSerialNo,O.endTime,FM.attribute7,FM.attribute8 from O,jbo.sys.FLOW_MODEL FM where O.flowNo=FM.flowNo and O.phaseNo=FM.phaseNo and serialNo=:serialNo ") .setParameter("serialNo", taskNo).getSingleResult(false); if (ft == null) {return "此流程任务已经不存在,请刷新列表!"; } else if (!StringX.isEmpty(ft.getAttribute("endTime"))) { return "此流程任务已自动提交!"; } //处理任务池 BizObjectManager utdbom = JBOFactory.getBizObjectManager(USER_TASK_DATA.CLASS_NAME, tx); BizObjectManager utibom = JBOFactory.getBizObjectManager(USER_TASK_INFO.CLASS_NAME, tx); BizObject utdbo = utdbom.createQuery("taskno = '" + taskNo + "' and userid = '" + userID + "' and (status = 'approve_status01' or status = 'approve_status03')").getSingleResult(true); if(utdbo != null) { int taskNumber = utibom.createQuery("userid = '" + utdbo.getAttribute("userid") + "' and roleid = '" + utdbo.getAttribute("roleid") + "'").getSingleResult(false).getAttribute("task_number").getInt(); ARE.getLog().info("***********任务池日志***:为"+ taskNo + "的" + utdbo.getAttribute("userid") + "用户关闭一个任务,当前未处理待办数为" + taskNumber); String status = utdbo.getAttribute("status").toString(); if("approve_status01".equals(status)) { utibom.createQuery("update O set task_number = task_number - 1 where userid = '" + utdbo.getAttribute("userid") + "' and roleid = '" + utdbo.getAttribute("roleid") + "'").executeUpdate(); } utdbo.setAttributeValue("status", "approve_status02"); utdbo.setAttributeValue("endtime", StringFunction.getTodayNow()); utdbom.saveObject(utdbo); } // 更新beginTime锁这些记录 ftManager .createQuery( "update O set beginTime=beginTime where relativeSerialNo=:relativeSerialNo and phaseNo<>'5000' ") .setParameter("relativeSerialNo", ft.getAttribute("relativeSerialNo").getString()) .executeUpdate(); // 查相同relativeserialno且不是5000传阅阶段的记录 BizObject allTaskNumBo = ftManager .createQuery(" select count(1) as v.allTaskNum from O where relativeSerialNo=:relativeSerialNo and phaseNo<>'5000' ") .setParameter("relativeSerialNo",ft.getAttribute("relativeSerialNo").getString()).getSingleResult(false); int allTaskNum = allTaskNumBo.getAttribute("allTaskNum").getInt(); //多人处理 if (allTaskNum > 1) { attribute7 = ft.getAttribute("attribute7").getString();// 01,单人处理,02,多人全部,03,多人任一,04,N人处理 attribute8 = ft.getAttribute("attribute8").getInt();// N人处理时设置的人数 if ("04".equals(attribute7)&& (ft.getAttribute("attribute8").isNull()|| attribute8 >= allTaskNum || attribute8 < 1)) { // 如果N人处理时没设置人数,则当做 // 02,多人全部 attribute7 = "02"; } // 已提交的任务数 BizObject commitedTaskNumBo = ftManager .createQuery( " select count(1) as v.commited from O where relativeSerialNo=:relativeSerialNo and phaseNo<>'5000' and endTime is not null and length(endTime)>0 ") .setParameter("relativeSerialNo", ft.getAttribute("relativeSerialNo").getString()) .getSingleResult(false); int commited = commitedTaskNumBo.getAttribute("commited").getInt(); if ("02".equals(attribute7) && commited + 1 < allTaskNum /* * 多人全部,已提交人数 * +1<总人数 */ || "04".equals(attribute7) && commited + 1 < attribute8 /* * N人处理, * 已提交人数 * + * 1 * < * N */) { // 仅结束当前任务 ftManager .createQuery( "update O set endTime=:endTime,phaseAction=:phaseAction where serialNo=:serialNo") .setParameter("serialNo", taskNo) .setParameter("phaseAction", "未达到人数") .setParameter("endTime", endTime).executeUpdate(); return str; } } if (!StringX.isSpace(phaseAction)) phaseAction = phaseAction.replace("@", ","); // 根据任务编号,查出流程的编号,阶段编号,对象类型,对象编号:新增加xuyunlong 归档每一步归档 ft = ftManager .createQuery( "select O.flowno,O.phaseno,O.FLOWSTATE,O.ASSIGNEDTASKNO,O.objecttype,O.objectno,O.userid,O.orgid from O where serialNo=:serialNo ") .setParameter("serialNo", taskNo).getSingleResult(false); // 将数据保存到历史记录里 PhaseInfoArchive(ft.getAttribute("flowno").getString(), ft .getAttribute("phaseno").getString(), ft.getAttribute("objecttype").getString(), ft.getAttribute("objectno").getString(), taskNo, ft .getAttribute("userid").getString(), ft.getAttribute("orgid").getString(), tx); if (this.phaseOpinion.equals("1000") || this.phaseOpinion.equals("8000")) { // 删除流程互斥 FlowUtil.deleteWorkFlowConflict(ft.getAttribute("objectno") .getString(), tx); Map condtion = new HashMap(); condtion.put("FlowUnid", ft.getAttribute("objectno").getString()); DataOperatorUtil.deleteJBOByCondtion(FLOW_STEP_NODE.CLASS_NAME, condtion, tx); } if(this.nextNodeType.indexOf("JOIN")>=0){ if(this.getIsStepLastUser(tx).equals("No")){ ftManager .createQuery( "update O set endTime=:endTime,phaseAction=:phaseAction,taskstate=1 where serialNo=:serialNo") .setParameter("serialNo", taskNo) .setParameter("phaseAction", "另外一个分支没有结束") .setParameter("endTime", endTime).executeUpdate(); }else{ flowService.commitAction(taskNo, phaseAction, phaseOpinion, "", tx); Transaction Sqlca =null; Sqlca = Transaction.createTransaction(tx); ASResultSet rs = null; String sql="update flow_task set userid=replace(userid,'*','') where objectno=:objectno and userid like '*%' "; SqlObject asql = new SqlObject(sql); asql.setParameter("objectno",ft.getAttribute("objectno").getString()); Sqlca.executeSQL(asql); Sqlca.disConnect(); } }else{ flowService.commitAction(taskNo, phaseAction, phaseOpinion, "", tx); if(ft.getAttribute("FLOWSTATE").getString().equals("ANYBACK")){ //退回之后再提交 if(ft.getAttribute("ASSIGNEDTASKNO")!=null){ if(ft.getAttribute("ASSIGNEDTASKNO").getString().length()>0){//如果退回再提交给原处理人要更新状态 ftManager.createQuery("update o set FLOWSTATE='NORMAL' WHERE objectno=:objectno and endtime is null") .setParameter("objectno", ft.getAttribute("objectno").getString()).executeUpdate(); } } } } // 更新代理人 BizObject taskUser = ftManager.createQuery("select O.userId from O where O.SERIALNO=:taskNo").setParameter("taskNo", this.taskNo).getSingleResult(false); if (!taskUser.getAttribute("userId").getString().equals(this.userID)) { this.doFinishAssignTask(tx); } // 更新其他任务的endTime ftManager .createQuery( "update O set endTime=:endTime, phaseAction=:phaseAction where ( endTime is null or endTime='' ) and relativeSerialNo=:relativeSerialNo and phaseNo<>'5000' ") .setParameter("relativeSerialNo", ft.getAttribute("relativeSerialNo").getString()) .setParameter("endTime", endTime) .setParameter("phaseAction", "AutoFinish").executeUpdate(); // 生成传阅的代办 this.startPassedByUser(tx); savePushMsg(tx); //流程或步骤结束之后的通知 new FLowStepEndNotice().StepEndNotice(tx, ft.getAttribute("objectno").getString(),this.taskNo,"next"); return str; } /** * 结束贷审会任务,设置flowState为voted * * @return */ public String endMeetingTask(JBOTransaction tx) throws Exception { BizObjectManager ftManager = JBOFactory.getBizObjectManager( "jbo.sys.FLOW_TASK", tx); // 根据任务编号,查出流程的编号,阶段编号,对象类型,对象编号:新增加xuyunlong BizObject ft = ftManager .createQuery( "select O.flowno,O.phaseno,O.objecttype,O.objectno,O.userid,O.orgid from O where serialNo=:serialNo ") .setParameter("serialNo", taskNo).getSingleResult(false); // 将数据保存到历史记录里 PhaseInfoArchive(ft.getAttribute("flowno").getString(), ft .getAttribute("phaseno").getString(), ft.getAttribute("objecttype").getString(), ft.getAttribute("objectno").getString(), taskNo, ft .getAttribute("userid").getString(), ft.getAttribute("orgid").getString(), tx); flowService.endMeetingTask(taskNo, tx); return "success"; } /** * 根据秘书汇总阶段的taskNo得到已投票的委员个数 * * @return */ public String getVotedNum(JBOTransaction tx) throws Exception { String sNum = ""; sNum = flowService.getVotedNum(taskNo, tx); return sNum; } // 根据秘书汇总阶段的flowstate得到没有投票的委员个数 public String getMeetingNum(JBOTransaction tx) throws Exception { int Num; // String // sql="Select flowstate From O Where objectNo=:objectNo and flowstate='MEETING'"; Map searchCondtion = new HashMap(); searchCondtion.put("objectNo", objectNo); searchCondtion.put("flowstate", "MEETING"); List meeting = new ArrayList(); meeting = DataOperatorUtil.getSetJBO(FLOW_TASK.CLASS_NAME, searchCondtion, tx); Num = meeting.size(); return Num + ""; } // 获取当前分支的分支数目 public String getForkNum(JBOTransaction tx) throws Exception { String PostScript = ""; String Num = ""; String sql = "Select PostScript From O Where FlowNo=:FlowNo and PhaseNo=:PhaseNo"; BizObject bo = JBOFactory.getBizObjectManager("jbo.sys.FLOW_MODEL") .createQuery(sql).setParameter("FlowNo", flowNo) .setParameter("PhaseNo", phaseNo).getSingleResult(false); if (bo != null) { PostScript = bo.getAttribute("PostScript").getString(); } Num = String.valueOf(PostScript.split(";").length); return Num; } // 判断当前节点的下个提交节点是否为聚合节点: 1-是 0-不是 public String isJoinNode(JBOTransaction tx) throws Exception { String isJoin = "0"; isJoin = flowService.isJoinNode(taskNo, phaseAction, phaseOpinion, tx); return isJoin; } // 获取其他分支的提交人 public String getJoinUser(JBOTransaction tx) throws Exception { String UserID = ""; FlowTask ftBusiness = new FlowTask(taskNo, tx); FlowPhase[] sFlowPhase = ftBusiness.getNextFlowPhase(phaseAction, phaseOpinion); if (sFlowPhase.length == 1) { String nextPhaseNo = sFlowPhase[0].PhaseNo; String NodeType = sFlowPhase[0].NodeType; if ("join".equalsIgnoreCase(NodeType)) { BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "Select UserID From O Where ObjectNo=:ObjectNo and ObjectType=:ObjectType and PhaseNo=:PhaseNo and (EndTime is null or EndTime = '')") .setParameter("ObjectNo", ftBusiness.ObjectNo) .setParameter("ObjectType", ftBusiness.ObjectType) .setParameter("PhaseNo", nextPhaseNo) .getSingleResult(false); if (bo != null) { UserID = bo.getAttribute("UserID").getString(); if (UserID.startsWith("*")) { UserID = UserID.substring(1); } } } } return UserID; } /** * 根据objectType, objectNo,flowNo 得到List(StringBuffer)。内容依次为流程节点nodes, * 节点描述信息nodeText, 节点连接线conn, 实际路径realPath的StringBuffer对象。 * * @return */ public List getFlowImgBufs() throws JBOException { StringBuffer nodesBuf = new StringBuffer(), nodeTextBuf = new StringBuffer(), connBuf = new StringBuffer(), realPathBuf = new StringBuffer(); // flow_model数据 List prePhases, modelList = JBOFactory .getBizObjectManager("jbo.sys.FLOW_MODEL") .createQuery( "select * from O where flowNo=:flowNo order by phaseNo ") .setParameter("flowNo", this.flowNo).getResultList(false); // TODO // 这里是根据phaseNo包含在postScript来判断的,如果postScript中使用类方法来取nextPhaseNo,下面的判断方法会出问题,需要再修改 BizObjectQuery beginEndPointQuery = JBOFactory .getBizObjectManager("jbo.sys.FLOW_MODEL") .createQuery( "select O.phaseNo from O where flowNo=:flowNo and postScript is not null and " + "(postScript like :phaseNo1 or postScript like :phaseNo2 or postScript like :phaseNo3 or postScript like :phaseNo4) ") .setParameter("flowNo", this.flowNo); for (BizObject bo : modelList) { String _phaseNo = bo.getAttribute("phaseNo").getString(); String _phaseName = bo.getAttribute("phaseName").getString(); String _nodeType = bo.getAttribute("nodeType").getString(); if (StringX.isEmpty(_nodeType)) _nodeType = "TASK"; int _x = bo.getAttribute("XCOORDINATE").getInt(); int _y = bo.getAttribute("YCOORDINATE").getInt(); int laneX = 0;// 获取泳道X坐标(如果有) String swimLane = bo.getAttribute("swimLane").getString(); if (!StringX.isEmpty(swimLane)) { List laneList = JBOFactory .getBizObjectManager("jbo.sys.FLOW_SWIMLANE") .createQuery( "Select * From O " + " Where LaneNo = :LaneNo") .setParameter("LaneNo", swimLane).getResultList(false); for (BizObject lane : laneList) { String laneConstraint = lane.getAttribute("laneConstraint") .getString().split(",")[0]; laneX = Integer.valueOf(laneConstraint); } } // 生成节点 if (nodesBuf.length() > 0) nodesBuf.append(","); nodesBuf.append("'" + _phaseNo + "':r.rect(" + (_x + laneX) + "," + _y + ",33,30,10).data('nodeType','" + _nodeType + "').attr({title:''})"); // 生成节点描述 if (nodeTextBuf.length() > 0) nodeTextBuf.append(","); nodeTextBuf.append(" r.text(" + (_x + laneX) + "+16, " + _y + "+42,'" + _phaseNo + "
" + _phaseName + "')"); // 生成连接线 prePhases = beginEndPointQuery .setParameter("phaseNo1", "%'" + _phaseNo + "'%") .setParameter("phaseNo2", "%\"" + _phaseNo + "\"%") .setParameter("phaseNo3", "%;" + _phaseNo + "%") .setParameter("phaseNo4", "%" + _phaseNo + ";%") .getResultList(false); for (BizObject prePhaseBo : prePhases) { String prePhaseNo = prePhaseBo.getAttribute("phaseNo") .getString(); connBuf.append("connections['" + prePhaseNo + "-" + _phaseNo + "']=r.connection(nodes['" + prePhaseNo + "'], nodes['" + _phaseNo + "'], connAttr );"); } } // flow_task数据 List ftBoList = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK") .createQuery( "select O.userName,O.beginTime,O.endTime, O.serialNo,O.relativeSerialNo,O.phaseNo, " + "FM.nodeType from O,jbo.sys.FLOW_MODEL FM where O.flowNo=:flowNo and O.objectType=:objectType and O.objectNo=:objectNo " + " and O.flowNo=FM.flowNo and O.phaseNo=FM.phaseNo and O.userID not like '*%' order by O.serialNo ") .setParameter("flowNo", this.flowNo) .setParameter("objectType", this.objectType) .setParameter("objectNo", this.objectNo).getResultList(false); TreeMap ftMap = new TreeMap(); for (int i = 0, size = ftBoList.size(); i < size; i++) { BizObject ftBo = ftBoList.get(i); String userName = ftBo.getAttribute("userName").getString(), beginTime = ftBo .getAttribute("beginTime").getString(), endTime = ftBo .getAttribute("endTime").getString(), relativeSerialNo = ftBo .getAttribute("relativeSerialNo").getString(), tempPhaseNo = ftBo .getAttribute("phaseNo").getString(), nodeType = ftBo .getAttribute("nodeType").getString(); realPathBuf.append("nodes['" + tempPhaseNo + "'].attr({'title': nodes['" + tempPhaseNo + "'].attr()['title'] +'
处理人:" + userName + ",开始时间:" + beginTime + ",结束时间:" + endTime + "'});"); ftMap.put(ftBo.getAttribute("serialNo").getString(), tempPhaseNo + "@@" + (relativeSerialNo == null ? "" : relativeSerialNo)); if (i == size - 1) this.phaseNo = tempPhaseNo; } ArrayList realPathList = new ArrayList(); for (String k : ftMap.keySet()) { String phaseNoAndRelaSN = ftMap.get(k); String[] arr = phaseNoAndRelaSN.split("@@"); if (arr.length > 1) { realPathList.add(ftMap.get(arr[1]).split("@@")[0] + "-" + arr[0]); } } // 生成实际路径 for (int i = 0, len = realPathList.size(); i < len; i++) { String[] phaseNos = realPathList.get(i).split("-"); realPathBuf.append("realPaths['" + realPathList.get(i) + "-" + i + "']=r.connection(nodes['" + phaseNos[0] + "'], nodes['" + phaseNos[1] + "'], realPathAttr );"); } ArrayList retList = new ArrayList(); // 按 nodes, nodeText, conn, realPath 顺序依次加入list retList.add(nodesBuf); retList.add(nodeTextBuf); retList.add(connBuf); retList.add(realPathBuf); return retList; } /** * 根据当前任务流水号taskNo和传阅人员phaseAction, 生成多条传阅任务,传阅阶段的默认阶段号为5000 */ public String passRound(JBOTransaction tx) throws Exception { String sRet = "success"; FlowTask ft = new FlowTask(taskNo, tx); ft.PhaseAction = this.phaseAction.replace("@", ","); ft.RelativeFlowObject.changePhase(new FlowPhase(ft.FlowNo, "5000", tx), ft, new TaskDataObject()); JBOFactory .getBizObjectManager("jbo.sys.FLOW_OBJECT", tx) .createQuery( "update O set phaseType=:phaseType, phaseNo=:phaseNo, " + " phaseName=:phaseName where objectType=:objectType and objectNo=:objectNo ") .setParameter("phaseType", ft.PhaseType) .setParameter("phaseNo", ft.PhaseNo) .setParameter("phaseName", ft.PhaseName) .setParameter("objectType", ft.ObjectType) .setParameter("objectNo", ft.ObjectNo).executeUpdate(); return sRet; } /** * 根据flowNo,phaseNo 查flow_model表ATTRIBUTE7,判断流程提交页面上的提交人是否多选 * (01,单人处理,02,多人全部,03,多人任一,04,N人处理) */ public String isMultiUsers(JBOTransaction tx) throws Exception { String sRet = "N"; BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_MODEL", tx) .createQuery( "select ATTRIBUTE7 from O where flowNo=:flowNo and phaseNo=:phaseNo ") .setParameter("flowNo", flowNo) .setParameter("phaseNo", phaseNo).getSingleResult(false); if (bo != null) { String ATTRIBUTE7 = bo.getAttribute("ATTRIBUTE7").getString(); if (!StringX.isEmpty(ATTRIBUTE7) && !"01".equals(ATTRIBUTE7)) { sRet = "Y"; } } return sRet; } /** * 工作指派 * * @param ReturnPoint * 选择指派人员,修改当前任务执行人员、机构 * @throws Exception * */ public String taskAssign(JBOTransaction tx) throws Exception { // 选择指派人 String tUserID = phaseAction.split(" ")[0]; BizObject userBO = JBOFactory .getBizObjectManager("jbo.sys.USER_INFO") .createQuery( "select O.userName,OI.OrgID,OI.OrgName " + "from O,jbo.sys.ORG_INFO OI where O.userID=:userID and O.belongOrg=OI.orgID") .setParameter("userID", tUserID).getSingleResult(false); if (userBO != null) { JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK") .createQuery( "update O set userID=:userID,userName=:userName,orgID=:orgID,orgName=:orgName where serialNo=:serialNo") .setParameter("serialNo", taskNo) .setParameter("userID", tUserID) .setParameter("userName", userBO.getAttribute("userName").getString()) .setParameter("orgID", userBO.getAttribute("orgID").getString()) .setParameter("orgName", userBO.getAttribute("orgName").getString()) .executeUpdate(); } return ""; } /** * 根据objectType,objectNo从FLOW_TASK中查找最新的phaseNo,用于申请页面提交时检查申请记录是否已提交 * * @return curPhaseNo--流程最新的phaseNo */ public String getPhaseDescribe(JBOTransaction tx) throws Exception { String sPhaseDescribe = ""; BizObject bo = JBOFactory .getBizObjectManager("jbo.sys.FLOW_MODEL", tx) .createQuery( "Select phaseDescribe From O Where FlowNo=:FlowNo and phaseNo=:phaseNo") .setParameter("flowNo", flowNo) .setParameter("phaseNo", phaseNo).getSingleResult(false); if (bo != null) sPhaseDescribe = bo.getAttribute("phaseDescribe").getString(); return sPhaseDescribe; } // 发送邮件 public void dispatcher(JBOTransaction tx) throws Exception { SMTPDispatcher mail = new SMTPDispatcher(); Properties p = new Properties(); p.setProperty("mail.smtp.host", "mail.amarsoft.com"); p.setProperty("mail.mime.charset", "GBK"); // 邮箱登录用户名密码 p.setProperty("mail.user", "user"); p.setProperty("mail.password", "password"); mail.init(p); Message m = new Message(); m.setMimeType("text/plain"); // 发件人邮箱 m.setSender("test@amarsoft.com"); m.setSubject("SMTP Dispatcher Test"); m.setBody("此消息通过SMTPDispatcher直接发送!" + "阶段名称=" + phaseOpinion + ",提交人=" + phaseAction); // 收件人邮箱 m.addRecipient("test@amarsoft.com"); mail.dispatchMessage(m); } public void startPassedByUser(JBOTransaction tx) throws Exception { if (this.getReadUserIds().length() > 0) { String[] userids = this.getReadUserIds().split("@"); for (int i = 0; i < userids.length; i++) { BizObjectManager readerInfo = JBOFactory .getBizObjectManager(FLOW_READER.CLASS_NAME); tx.join(readerInfo); BizObject Object = readerInfo.newObject(); Object.setAttributeValue("taskno", this.getTaskNo()); Object.setAttributeValue("flowunid", this.getObjectNo()); Object.setAttributeValue("reader", userids[i]); Object.setAttributeValue("InputUserID", this.getUserID()); Object.setAttributeValue("InputOrgID", this.getOrgID()); Object.setAttributeValue("inputtime", DateAssistant.getTodayNow()); Object.setAttributeValue("isRead", "0"); readerInfo.saveObject(Object); } } } public void endPassedByID(JBOTransaction tx) throws Exception { BizObjectManager readerInfo = JBOFactory .getBizObjectManager(FLOW_READER.CLASS_NAME); tx.join(readerInfo); BizObjectQuery bqDest = readerInfo.createQuery("id=:id"); bqDest.setParameter("id", this.passReadid); BizObject Object = null; Object = bqDest.getSingleResult(true);// 目标JBO,需要做更新操作 Object.setAttributeValue("isRead", "1"); Object.setAttributeValue("UpdateUserID", this.userID); Object.setAttributeValue("UpdateOrgID", this.getOrgID()); Object.setAttributeValue("UpdateTime", DateAssistant.getTodayNow()); readerInfo.saveObject(Object); } public String getIsOpitionsRequire(JBOTransaction tx) throws Exception { BizObject bo = null; BizObjectManager bm = null; BizObjectQuery bq = null; bm = JBOFactory.getFactory().getManager(FLOW_MODEL.CLASS_NAME); bq = bm.createQuery("FlowNo=:FlowNo and PhaseNo=:PhaseNo") .setParameter("FlowNo", this.getFlowNo()) .setParameter("PhaseNo", this.getPhaseNo()); bo = bq.getSingleResult(false); String isRequireOpition = bo.getAttribute("OPINIONSREQUIRED") .getString(); if (isRequireOpition == null || isRequireOpition == "") { isRequireOpition = "Y"; } return isRequireOpition; } public String getIsStepLastUser(JBOTransaction tx) throws Exception { if(this.nextNodeType.indexOf("JOIN")>=0){ TenwaFlowTask ft = new TenwaFlowTask(taskNo, tx);//使用jboTrans String cnumber=ft.getForkLastNumber(); if(cnumber.equals("1")){ return "Yes"; }else{ return "No"; } }else{ BizObject bo = null; BizObjectManager bm = null; BizObjectQuery bq = null; bm = JBOFactory.getFactory().getManager(FLOW_MODEL.CLASS_NAME); bq = bm.createQuery("FlowNo=:FlowNo and PhaseNo=:PhaseNo") .setParameter("FlowNo", this.getFlowNo()) .setParameter("PhaseNo", this.getPhaseNo()); bo = bq.getSingleResult(false); String operatorType = bo.getAttribute("ATTRIBUTE7").getString(); String operatorNunber = bo.getAttribute("ATTRIBUTE8").getString(); BizObjectManager ftManager = JBOFactory.getBizObjectManager( "jbo.sys.FLOW_TASK", tx); BizObject ft = ftManager .createQuery( "select O.relativeSerialNo,O.endTime,FM.attribute7,FM.attribute8 from O,jbo.sys.FLOW_MODEL FM where O.flowNo=FM.flowNo and O.phaseNo=FM.phaseNo and serialNo=:serialNo ") .setParameter("serialNo", this.getTaskNo()) .getSingleResult(false); BizObject allTaskNumBo = ftManager .createQuery( " select count(1) as v.allTaskNum from O where relativeSerialNo=:relativeSerialNo and phaseNo<>'5000' ") .setParameter("relativeSerialNo", ft.getAttribute("relativeSerialNo").getString()) .getSingleResult(false); int allTaskNum = allTaskNumBo.getAttribute("allTaskNum").getInt(); // 已提交的任务数 BizObject commitedTaskNumBo = ftManager .createQuery( " select count(1) as v.commited from O where relativeSerialNo=:relativeSerialNo and phaseNo<>'5000' and endTime is not null and length(endTime)>0 ") .setParameter("relativeSerialNo", ft.getAttribute("relativeSerialNo").getString()) .getSingleResult(false); int commited = commitedTaskNumBo.getAttribute("commited").getInt(); if (operatorType.endsWith("02")) { if ((commited + 1) == allTaskNum) { return "Yes"; } else { return "No"; } } if (operatorType.endsWith("04")) { int configNumber = 1; if (null == operatorNunber || operatorNunber.length() == 0) { operatorNunber = "1"; } configNumber = Integer.valueOf("operatorNunber"); if ((commited + 1) == configNumber) { return "Yes"; } else { return "No"; } } return "Yes"; } } public String getBackStepTaskInfo(JBOTransaction tx) throws Exception { String sql = ""; List bos = JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "SELECT O.serialno,O.phasename,O.userid,O.username FROM O WHERE O.objectno=:objectno AND O.phaseno=:phaseno ORDER BY endtime DESC") .setParameter("phaseno", this.getPhaseNo()) .setParameter("objectno", this.getObjectNo()) .getResultList(false); if (bos.size() > 0) { return "{\"taskNo\":\"" + bos.get(0).getAttribute("serialno") + "\",\"phaseName\":\"" + bos.get(0).getAttribute("phasename").getString() + "\",\"userId\":\"" + bos.get(0).getAttribute("userid").getString() + "\",\"userName\":\"" + bos.get(0).getAttribute("username").getString() + "\"}"; } else { return "{}"; } } public String MulityTaskAssignment(JBOTransaction tx) throws Exception { // 选择指派人 String tUserID = this.getAssignmentId(); BizObject userBO = JBOFactory .getBizObjectManager("jbo.sys.USER_INFO") .createQuery( "select O.userName,OI.OrgID,OI.OrgName " + "from O,jbo.sys.ORG_INFO OI where O.userID=:userID and O.belongOrg=OI.orgID") .setParameter("userID", tUserID).getSingleResult(false); if (userBO != null) { String[] taskNos = this.getTaskNo().split("@"); for (int i = 0; i < taskNos.length; i++) { JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK") .createQuery( "update O set AGENTUSERID=:userID,AGENTUSERNAME=:userName,AGENTORGID=:orgID,AGENTORGNAME=:orgName,ASSIGNSUBMITTYPE=:ASSIGNSUBMITTYPE,ASSIGNFINISH=0 where serialNo=:serialNo") .setParameter("serialNo", taskNos[i]) .setParameter("userID", tUserID) .setParameter("userName", userBO.getAttribute("userName").getString()) .setParameter("orgID", userBO.getAttribute("orgID").getString()) .setParameter("orgName", userBO.getAttribute("orgName").getString()) .setParameter("ASSIGNSUBMITTYPE", this.getAssignSumbitType()).executeUpdate(); } } return ""; } // 删除委托人员 public String deleteMulityTaskAssignment(JBOTransaction tx) throws Exception { String[] taskNos = this.getTaskNo().split("@"); for (int i = 0; i < taskNos.length; i++) { JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK") .createQuery( "update O set AGENTUSERID=:userID,AGENTUSERNAME=:userName,AGENTORGID=:orgID,AGENTORGNAME=:orgName,ASSIGNSUBMITTYPE='',ASSIGNFINISH='' where serialNo=:serialNo") .setParameter("serialNo", taskNos[i]) .setParameter("userID", "").setParameter("userName", "") .setParameter("orgID", "").setParameter("orgName", "") .executeUpdate(); } return ""; } public String doFinishAssignTask(JBOTransaction tx) throws Exception { BizObject userBO = JBOFactory .getBizObjectManager("jbo.sys.USER_INFO") .createQuery( "select O.userName,OI.OrgID,OI.OrgName " + "from O,jbo.sys.ORG_INFO OI where O.userID=:userID and O.belongOrg=OI.orgID") .setParameter("userID", this.userID).getSingleResult(false); try { JBOFactory .getBizObjectManager("jbo.sys.FLOW_TASK", tx) .createQuery( "update O set AGENTUSERID=:userID,AGENTUSERNAME=:userName,AGENTORGID=:orgID,AGENTORGNAME=:orgName,ASSIGNFINISH='1' where serialNo=:serialNo") .setParameter("serialNo", this.taskNo) .setParameter("userID", this.userID) .setParameter("userName", userBO.getAttribute("userName").getString()) .setParameter("orgID", userBO.getAttribute("orgID").getString()) .setParameter("orgName", userBO.getAttribute("orgName").getString()) .executeUpdate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return "error"; } return "SUCCESS"; } public String getDATA_CODE() { return DATA_CODE; } public String getGROUP_CODE() { return GROUP_CODE; } public void setDATA_CODE(String dATA_CODE) { DATA_CODE = dATA_CODE; } public void setGROUP_CODE(String gROUP_CODE) { GROUP_CODE = gROUP_CODE; } public void removeAppGroupTemp(JBOTransaction tx) throws Exception { Map condtion = new HashMap(); condtion.put("DATA_CODE", this.DATA_CODE); condtion.put("GROUP_CODE", this.GROUP_CODE); DataOperatorUtil.deleteJBOByCondtion(APP_BUSINESS_TEMPLATE.CLASS_NAME, condtion, tx); } public String getDATA_NAME() { return DATA_NAME; } public String getISLIST() { return ISLIST; } public String getISSHOW() { return ISSHOW; } public String getDATA_POSITION() { return DATA_POSITION; } public String getISCONVERT() { return ISCONVERT; } public String getDONO() { return DONO; } public String getSORTNO() { return SORTNO; } public void setDATA_NAME(String dATA_NAME) { DATA_NAME = dATA_NAME; } public void setISLIST(String iSLIST) { ISLIST = iSLIST; } public void setISSHOW(String iSSHOW) { ISSHOW = iSSHOW; } public void setDATA_POSITION(String dATA_POSITION) { DATA_POSITION = dATA_POSITION; } public void setISCONVERT(String iSCONVERT) { ISCONVERT = iSCONVERT; } public void setDONO(String dONO) { DONO = dONO; } public void setSORTNO(String sORTNO) { SORTNO = sORTNO; } // 删除分组的同时把数据配置也删除 public void removeAppGroupChild(JBOTransaction tx) throws Exception { Map condtion = new HashMap(); condtion.put("GROUP_CODE", this.GROUP_CODE); DataOperatorUtil.deleteJBOByCondtion(APP_BUSINESS_TEMPLATE.CLASS_NAME, condtion, tx); } public void modifyAppGroupTemp(JBOTransaction tx) throws Exception { // DataOperatorUtil.deleteJBOByCondtion(APP_BUSINESS_TEMPLATE.CLASS_NAME, // condtion, tx); JBOFactory .getBizObjectManager("jbo.app.APP_BUSINESS_TEMPLATE") .createQuery( "update O set " + "ISLIST=:ISLIST,ISSHOW=:ISSHOW,DATA_POSITION=:DATA_POSITION,ISCONVERT=:ISCONVERT " + "where GROUP_CODE=:GROUP_CODE AND DATA_CODE=:DATA_CODE") .setParameter("ISLIST", this.ISLIST) .setParameter("ISSHOW", this.ISSHOW) .setParameter("DATA_POSITION", this.DATA_POSITION) .setParameter("ISCONVERT", this.ISCONVERT) .setParameter("GROUP_CODE", this.GROUP_CODE) .setParameter("DATA_CODE", this.DATA_CODE).executeUpdate(); } class PushThread extends Thread { public void run() { pushMsg(); } } private void savePushMsg(JBOTransaction tx) { PushMessageConstant pc = null; try { pc = new PushMessageConstant(); } catch (Exception e1) { return; } String IS_PUSH = pc.getIS_PUSH(); if (IS_PUSH.equalsIgnoreCase("false")) { return; } String title = ""; String messageContent = ""; BizObjectManager ftManager = null; try { ftManager = JBOFactory.getBizObjectManager("jbo.sys.FLOW_TASK", tx); } catch (JBOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { BizObject ft = ftManager .createQuery( "select BO.proj_name, O.flowname " + "FROM O,jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT BO " + "WHERE serialNo=:serialNo AND O.objectno=BO.flow_unid") .setParameter("serialNo", this.taskNo) .getSingleResult(false); String projName = ft.getAttribute("proj_name") == null ? "" : ft .getAttribute("proj_name").toString(); String flowName = ft.getAttribute("flowname") == null ? "" : ft .getAttribute("flowname").toString(); title = flowName; messageContent = projName; } catch (JBOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (phaseAction.indexOf("|") > -1) { return; } else { String[] phaseArr = phaseAction.split("@"); this.uids = phaseArr; for (String uid : phaseArr) { if (StringUtils.isBlank(uid)) { continue; } savePush(uid, title, messageContent); } } PushThread t = new PushThread(); t.start(); } private void savePush(String userid, String title, String messageContent) { String date = DateUtil.getSystemTimeByFormat(new Date(), "yyyy/MM/dd HH:mm:ss.SSS"); String pushId = UUIDUtil.getUUID(); try { BizObjectManager bm = JBOFactory .getBizObjectManager("jbo.app.APP_PUSH_MESSAGE"); BizObject bo = bm.newObject(); bo.setAttributeValue("ID", pushId); bo.setAttributeValue("USERID", userid); bo.setAttributeValue("TITLE", title); bo.setAttributeValue("MESSAGE_CONTENT", messageContent); bo.setAttributeValue("RECORD_TS", date); bo.setAttributeValue("PUSH_TYPE", "0"); bm.saveObject(bo); } catch (JBOException e) { return; } } private void pushMsg() { String messagePayload = ""; messagePayload = "This is a message!"; PushMessageUtil pmu = new PushMessageUtil(); try { pmu.sends(messagePayload, this.uids); } catch (Exception e) { e.printStackTrace(); } } public String getUid() { return uid; } public void setUid(String uid) { this.uid = uid; } public String removeAppFlow(JBOTransaction tx) throws Exception { String flow_no = ""; BizObjectManager bomAppFlowShow = JBOFactory .getBizObjectManager("jbo.app.APP_FLOW_SHOW"); BizObject bo1 = bomAppFlowShow.createQuery( "select flow_no from O where ID ='" + this.uid + "' ") .getSingleResult(false); if (bo1 != null) { flow_no = bo1.getAttribute("flow_no").toString(); // BizObjectManager bomRoleFlow = JBOFactory // .getBizObjectManager("jbo.app.role_flow"); // @SuppressWarnings("unchecked") // List bo2 = bomRoleFlow.createQuery( // "select ri.rolename, o.flowname, o.roleid from role_flow O LEFT JOIN role_info ri ON o.roleid = ri.roleid where o.flowname<>'' " // + "and o.flowname is not null").getResultList(false); String sql = "select ri.rolename, o.flowname, o.roleid from role_flow O " + "LEFT JOIN role_info ri ON o.roleid = ri.roleid " + "where o.flowname<>'' " + "and o.flowname is not null"; Transaction sqlca = Transaction.createTransaction("als"); ASResultSet rs = null; List> list = new ArrayList>(); try { SqlObject sqlObject = new SqlObject(sql); rs = sqlca.getResultSet(sqlObject); while (rs.next()) { Map map = new HashMap(); map.put("rolename", rs.getString("rolename")); map.put("flow", rs.getString("flowname")); map.put("roleid", rs.getString("roleid")); list.add(map); } } catch (SQLException e) { ARE.getLog().error(e); } catch (Exception e) { ARE.getLog().error(e); } finally { if (rs != null) { try { rs.getStatement().close(); rs = null; } catch (SQLException e) { ARE.getLog().error(e); } } } boolean flag = true; String roles = ""; if (list != null && list.size() > 0) { for (Map map : list) { String flows = map.get("flow") == null ? "" : map.get( "flow").toString(); String rolename = map.get("rolename") == null ? "" : map .get("rolename").toString(); String[] arr = flows.trim().split(","); for (String str : arr) { if (str.equals(flow_no)) { flag = false; roles += rolename + ","; } } } } if (!flag) { roles = roles.trim(); if (roles.endsWith(",")) { roles = roles.substring(0, roles.length() - 1); } return "该流程已被角色:(\r\n" + roles + "\r\n) 绑定,无法删除!\r\n\r\n"; } Map condtion = new HashMap(); condtion.put("id", this.uid); try { DataOperatorUtil.deleteJBOByCondtion("jbo.app.APP_FLOW_SHOW", condtion, tx); } catch (Exception e) { return "删除失败!"; } } else { return "数据不存在,无法删除!"; } return "删除成功!"; } public String getNextNodeType() { return nextNodeType; } public void setNextNodeType(String nextNodeType) { this.nextNodeType = nextNodeType; } }