关闭

activiti 使用

580人阅读 评论(1) 收藏 举报

activiti使用:最近公司要做一个项目,使用工作流,但是也没有人会,只好自己去研究研究。本人菜鸟一个使用的方法有可能狠低级勿喷啊。欢迎指正!研究时间只有4天==!



activiti的配置文件:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

		<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
		<property name="jdbcDriver" value="oracle.jdbc.driver.OracleDriver"></property>
		<property name="jdbcUrl" value="jjdbc:oracle:thin:@123.56.41.65:1521:orcl"></property>
		<property name="jdbcUsername" value="ilmp"></property>
		<property name="jdbcPassword" value="ilmp"></property>
		<property name="databaseSchemaUpdate" value="true"></property>
	</bean>

	<!-- 流程引擎 -->
	<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
		<property name="processEngineConfiguration" ref="processEngineConfiguration" />
	</bean>
	

	<!-- 由流程引擎对象,提供的方法,创建项目中使用的Activiti工作流的Service -->
	<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
	<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
	<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
	<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
	<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
	<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
	<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
	
</beans>
工作流的话也就涉及到待办,已办,新建任务什么的了。


查询待办的代码:

/**
	 * 查询待办分页数据
	 * @param page 分页对象
	 * @param taskManager
	 * @return
	 */
	public Page<Map<String, Object>> findMissionPage(String taskId, String taskName) {

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Page<Map<String, Object>> result = new Page<Map<String, Object>>();

		// 创建查询对象
		NativeTaskQuery taskQuery = taskService.createNativeTaskQuery();
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT * FROM " + managementService.getTableName(Task.class)+" H WHERE H.CREATE_TIME_ IS NOT NULL AND H.PROC_INST_ID_ IS NOT NULL AND H.ASSIGNEE_ = #{userCode}");
		taskQuery.parameter("userCode", UserUtils.getUser().getUserCode());
		
		if(StringUtils.isNotBlank(taskId)){
			sb.append(" and H.PROC_INST_ID_ LIKE #{taskId}");
			taskQuery.parameter("taskId", "%"+taskId+"%");
		}
		
		// 设置排序 字段,根据任务创建时间降序
		sb.append(" ORDER BY H.CREATE_TIME_ DESC");
		
		// 执行sql
		taskQuery.sql(sb.toString());

		// 获取查询列表
		List<Task> taskLst = taskQuery.list();
		
		WorkflowService workflowService = new WorkflowService();
		Map<String, String> processNames = workflowService.findDeploymentList();
		Map<String, String> resourceMap = ResourceUtils.getResource("jkyprocessflow").getMap();
		
		for (Task task : taskLst) {
			
			TaskRes taskRes = new TaskRes();
			taskRes.setProcessInstanceId(task.getProcessInstanceId());
			TaskRes taskResInfo = taskResDao.get(taskRes);
			
			String pid = workflowService.findDeploymentid(task.getProcessDefinitionId()).getDeploymentId();
			if(StringUtils.isNotBlank(taskName)){
				if(!(processNames.get(pid)).contains(taskName)){
					continue;
				}
			}
			Map<String,Object> map = new HashMap<String,Object>();
			String processInstanceId = task.getProcessInstanceId();
			map.put("id", task.getId());
			map.put("processName", processNames.get(pid));
			map.put("name", task.getName());
			map.put("createTime", task.getCreateTime());
			map.put("assignee", UserUtils.get(task.getAssignee()).getUserName());
			map.put("processInstanceId", processInstanceId);
			map.put("executionId", task.getExecutionId());
			map.put("resCode", taskResInfo==null ? "" : taskResInfo.getResCode());
			map.put("serviceCode", taskResInfo==null ? "" : taskResInfo.getBusinessCode());
			map.put("processDefinitionId", task.getProcessDefinitionId());
			map.put("instanceStatus", (workflowService.processIsEnd(processInstanceId)) == true ? "运行中":"完成");
			
			// 维护流程
			if(resourceMap.get("maintenanceProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/maService/commit");
				}else{
					map.put("formUri", "/instru/maService/form");
				}
			}
			// 维修流程
			else if(resourceMap.get("repairProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/maintain/commit");
				}else{
					map.put("formUri", "/instru/maintain/maform");
				}
			}
			// 划拨流程
			else if(resourceMap.get("assginProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/assign/commit");
				}else{
					map.put("formUri", "/instru/assign/form");
				}
			}
			// 项目申报流程
			else if(resourceMap.get("projectApplicationProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/book/commit");
				}else{
					map.put("formUri", "/instru/book/form");
				}
			}
			// 查重评议流程
			else if(resourceMap.get("reviewProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/review/commit");
				}else if("提交申诉理由".equals(task.getName())){
					map.put("formUri", "/instru/review/commit");
				}else{
					map.put("formUri", "/instru/review/form");
				}
			}
			// 报废流程
			else if(resourceMap.get("discardeProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/scrap/commit");
				}else{
					map.put("formUri", "/instru/scrap/form");
				}
			}
			// 计量计划流程
			else if(resourceMap.get("metplanProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/metplan/commit");
				}else{
					map.put("formUri", "/instru/metplan/form");
				}
			}
			// 海关监管流程
			else if(resourceMap.get("customsMagerProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/gac/commit");
				}else{
					map.put("formUri", "/instru/gac/form");
				}
			}
			// 资源信息流程
			else if(resourceMap.get("resourceInfoProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/infoResource/commit");
				}else{
					map.put("formUri", "/instru/infoResource/form");
				}
			}
			// 合同编辑流程
			else if(resourceMap.get("contractEditorProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/cont/commit");
				}else{
					map.put("formUri", "/instru/cont/form");
				}
			}
			// 购置计划流程
			else if(resourceMap.get("purchasePlanProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/purPlan/commit");
				}else{
					map.put("formUri", "/instru/purPlan/form");
				}
			}
			 // 计量流程
			else if(resourceMap.get("measureProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/metrec/commit");
				}else{
					map.put("formUri", "/instru/metrec/form");
				}
			}
			// 单位基本信息
			else if(resourceMap.get("baseInfoProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/instruBasic/commit");
				}else{
					map.put("formUri", "/instru/instruBasic/form");
				}
			}
			// 管理制度
			else if(resourceMap.get("manageProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/instruInsti/commit");
				}else{
					map.put("formUri", "/instru/instruInsti/form");
				}
			}
			list.add(map);
			}
		result.setPageSize(30);
		result.setList(list);
		result.setCount(list.size());
		result.setPageNo(1);

		return result;
	}
	


查询已办数据:


/**
	 * 查询办结分页数据
	 * @param page 分页对象
	 * @param taskManager
	 * @return
	 */
	public Page<Map<String, Object>> findFinishedPage(TaskManager taskManager,String taskId, String taskName,String status) {
		
		
		// 创建历史流程实例 查询对象
		HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery();
		NativeHistoricTaskInstanceQuery nativeHistoricTaskInstanceQuery = historyService.createNativeHistoricTaskInstanceQuery();
		
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT * FROM " + managementService.getTableName(HistoricTaskInstance.class)+" H WHERE H.END_TIME_ IS NOT NULL AND H.PROC_INST_ID_ IS NOT NULL AND H.ASSIGNEE_ = #{userCode}");
		nativeHistoricTaskInstanceQuery.parameter("userCode", UserUtils.getUser().getUserCode());
		if(StringUtils.isNotBlank(taskId)){
			sb.append(" AND H.PROC_INST_ID_ LIKE #{taskId}");
			nativeHistoricTaskInstanceQuery.parameter("taskId", "%"+taskId+"%");
		}
		if(StringUtils.isNotBlank(status)&&status.equals("complete")){
			historicProcessInstanceQuery.finished();
		}
		sb.append(" ORDER BY H.PROC_INST_ID_ DESC");

		nativeHistoricTaskInstanceQuery.sql(sb.toString());
		Page<TaskManager> page = taskManager.getPage();
		nativeHistoricTaskInstanceQuery.listPage(page.getPageNo(), 30);
		
		List<HistoricTaskInstance> htiList = removeDuplicate(nativeHistoricTaskInstanceQuery.list());
		
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Page<Map<String, Object>> result = new Page<Map<String, Object>>();
		
		historicProcessInstanceQuery.orderByProcessInstanceEndTime().desc();

		List<HistoricProcessInstance> retList = new ArrayList<HistoricProcessInstance>();
		for (HistoricTaskInstance hi : htiList) {
			
			historicProcessInstanceQuery.processInstanceId(hi.getProcessInstanceId());
			
			// 添加排序,按结束时间降序
			historicProcessInstanceQuery.orderByProcessInstanceEndTime().desc();

			// 数据列表
			List<HistoricProcessInstance> historyList = historicProcessInstanceQuery
					.list();
			
			retList.addAll(historyList);
		}
		
		
		WorkflowService workflowService = new WorkflowService();

		Map<String, String> processNames = workflowService.findDeploymentList();
		Map<String, String> resourceMap = ResourceUtils.getResource("jkyprocessflow").getMap();

		for (HistoricProcessInstance history : retList) {
			String pid = workflowService.findDeploymentid(history.getProcessDefinitionId()).getDeploymentId();
			if(StringUtils.isNotBlank(taskName)){
				if(!(processNames.get(pid)).contains(taskName)){
					continue;
				}
			}
			TaskRes taskRes = new TaskRes();
			taskRes.setProcessInstanceId(history.getId());
			TaskRes taskResInfo = taskResDao.get(taskRes);
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("processName", processNames.get(pid));
			map.put("id", history.getId());
			map.put("processInstanceId", taskResInfo == null ? "":taskResInfo.getProcessInstanceId());
			map.put("name", history.getName());
			map.put("createTime", history.getStartTime());
			map.put("endTime", history.getEndTime());
			map.put("serviceCode", taskResInfo == null ? "" : taskResInfo.getBusinessCode());
			map.put("userName", UserUtils.get(history.getStartUserId()).getUserName());
			// 维护流程
			if(resourceMap.get("maintenanceProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/maService/formRead");
			}
			// 维修流程
			else if(resourceMap.get("repairProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/maintain/formRead");
			}
			// 划拨流程
			else if(resourceMap.get("assginProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/assign/view");
			}
			// 报废流程
			else if(resourceMap.get("discardeProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/scrap/formRead");
			}
			// 项目申报流程
			else if(resourceMap.get("projectApplicationProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/book/view");
			}
			// 计量计划流程
			else if(resourceMap.get("metplanProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/metplan/formRead");
			}
			// 查重评议流程
			else if(resourceMap.get("reviewProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/review/view");
			}
			// 海关监管流程
			else if(resourceMap.get("customsMagerProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/gac/formRead");
			}
			// 资源信息流程
			else if(resourceMap.get("resourceInfoProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/infoResource/formRead");
			}
			// 合同编辑流程
			else if(resourceMap.get("contractEditorProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/cont/view");
			}
			// 购置计划流程
			else if(resourceMap.get("purchasePlanProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/purPlan/view");
			}
			 // 计量流程
			else if(resourceMap.get("measureProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/metrec/formRead");
			}
			//单位基本信息流程
			else if(resourceMap.get("baseInfoProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/instruBasic/formRead");
			}
			//管理制度流程
			else if(resourceMap.get("manageProcessDefinitionPid").equals(pid)){
				map.put("formUri", "/instru/instruInsti/formRead");
			}
			list.add(map);
			}
		
		result.setPageSize(10);
		result.setList(list);
		result.setCount(list.size());
		result.setPageNo(1);
		return result;
	}

查询待办任务历程:

public List<Map<String,Object>> findTaskDetailInfo(String taskId, String jobId) {
		WorkflowService workflowService = new WorkflowService();
		List<HistoricActivityInstance> taskLst = workflowService
				.getProcessById(jobId);

		List<Comment> taskCommont = workflowService.getProcessCommont(taskId);
		Map<String, String[]> commap = new HashMap<String, String[]>();

		for (Comment comment : taskCommont) {
			String[] str = new String[2];
			str[0] = comment.getUserId();
			str[1] = comment.getFullMessage();
			commap.put(comment.getTaskId(), str);
		}
		List<Map<String, Object>> objLst = new ArrayList<Map<String, Object>>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		for (HistoricActivityInstance task : taskLst) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("processInstanceId", task.getProcessInstanceId());
			map.put("activityName", task.getActivityName());
			String start = sdf.format(task.getStartTime());
			map.put("startTime", start);
			String end = sdf.format(task.getEndTime());
			map.put("endTime", end);
			if (commap.size() > 0 && commap.get(task.getTaskId()) != null
					&& commap.get(task.getTaskId())[0] != null) {
				map.put("userName", UserUtils.get(commap.get(task.getTaskId())[0])
						.getUserName());
			} else if (task.getAssignee() != null
					&& UserUtils.get(task.getAssignee()).getUserName() != null) {
				map.put("userName", UserUtils.get(task.getAssignee()).getUserName());
			}

			if (commap.size() > 0 && commap.get(task.getTaskId()) != null) {
				map.put("commitMsg", commap.get(task.getTaskId())[1]);
			} else {
				map.put("commitMsg", "");
			}
			map.put("taskTime", formatDuring(task.getEndTime().getTime()- task.getStartTime().getTime()));

			objLst.add(map);
		}

		return objLst;
	}

查询已办历程数据:

/**
	 * 查询已办
	 * @param taskId
	 * @return
	 */
	public List<Map<String,Object>>  findTaskDetailFinished(String taskId,String jobId) {
		WorkflowService workflowService = new WorkflowService();
		List<HistoricActivityInstance> taskLst = workflowService
				.getProcessById(jobId);

		List<Comment> taskCommont = workflowService.getHistoryProcessCommont(taskId);
		Map<String, String[]> commap = new HashMap<String, String[]>();

		for (Comment comment : taskCommont) {
			String[] str = new String[2];
			str[0] = comment.getUserId();
			str[1] = comment.getFullMessage();
			commap.put(comment.getTaskId(), str);
		}
		List<Map<String, Object>> objLst = new ArrayList<Map<String, Object>>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		for (HistoricActivityInstance task : taskLst) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("processInstanceId", task.getProcessInstanceId());
			map.put("activityName", task.getActivityName());
			String start = sdf.format(task.getStartTime());
			map.put("startTime", start);
			String end = sdf.format(task.getEndTime());
			map.put("endTime", end);
			if (commap.size() > 0 && commap.get(task.getTaskId()) != null
					&& commap.get(task.getTaskId())[0] != null) {
				map.put("userName", UserUtils.get(commap.get(task.getTaskId())[0])
						.getUserName());
			} else if (task.getAssignee() != null
					&& UserUtils.get(task.getAssignee()).getUserName() != null) {
				map.put("userName", UserUtils.get(task.getAssignee()).getUserName());
			}

			if (commap.size() > 0 && commap.get(task.getTaskId()) != null) {
				map.put("commitMsg", commap.get(task.getTaskId())[1]);
			} else {
				map.put("commitMsg", "");
			}
			map.put("taskTime", formatDuring(task.getEndTime().getTime()
					- task.getStartTime().getTime()));

			objLst.add(map);
		}

		return objLst;
	}

计算用时的私有方法:

private String formatDuring(long mss) {
        String days = mss / (1000 * 60 * 60 * 24) == 0 ? "":String.valueOf(mss / (1000 * 60 * 60 * 24))+"天";
        String hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) == 0 ? "":String.valueOf((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))+"小时";
        String minutes = (mss % (1000 * 60 * 60)) / (1000 * 60) == 0 ? "":String.valueOf((mss % (1000 * 60 * 60)) / (1000 * 60))+"分钟";
        String seconds = (mss % (1000 * 60)) / 1000 == 0 ? "":String.valueOf((mss % (1000 * 60)) / 1000)+"秒";
        return days + hours + minutes 
                + seconds;
    }

流程审核代码:

@Transactional(readOnly = false)
	public void save(Flow flow) {
		

		Map<String, Object> variables = new HashMap<String, Object>();
		String inputUser="";
		if(flow.getLinkman() != null){
			inputUser = flow.getLinkman().getUserCode();
		}
		
		String taskId = flow.getTaskId();
		
		// 完成任务后判断流程是否结束
		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

		TaskRes taskResTmp = new TaskRes();
		taskResTmp.setProcessInstanceId(task.getProcessInstanceId());
		TaskRes taskResinfo = taskResDao.get(taskResTmp);
		String userCode = "";
		
		
		String processInstanceId = task.getProcessInstanceId();
		if("0".equals(flow.getFlag())){
			String taskDefinitionKey = "";
			if("firstAudit".equals(task.getTaskDefinitionKey())){
				taskDefinitionKey = "createOrder";
			}else if("secondAudit".equals(task.getTaskDefinitionKey())){
				taskDefinitionKey = "firstAudit";
			}else if("thirdAudit".equals(task.getTaskDefinitionKey())){
				taskDefinitionKey = "secondAudit";
			}else if("fourAudit".equals(task.getTaskDefinitionKey())){
				taskDefinitionKey = "thirdAudit";
			}else if("fiveAudit".equals(task.getTaskDefinitionKey())){
				taskDefinitionKey = "fourAudit";
			}else if("sixAudit".equals(task.getTaskDefinitionKey())){
				taskDefinitionKey = "fiveAudit";
			}
			// 获取流程实例ID
			List<HistoricTaskInstance> htiList = historyService.createHistoricTaskInstanceQuery()// 历史任务表查询
					.processInstanceId(processInstanceId)// 使用流程实例ID查询
					.taskDefinitionKey(taskDefinitionKey)
					.list();
			List<HistoricIdentityLink> list = historyService  
		            .getHistoricIdentityLinksForProcessInstance(processInstanceId);  
			if(htiList.size() > 0 ){
				userCode = htiList.get(0).getAssignee();
			}else{
				userCode = list.get(0).getUserId();
			}
			
		}
		if (flow.getTaskId() != null&& !"0".equals(flow.getFlag())) {
			variables.put("inputUser", inputUser);
			taskResinfo.setUpdateBy(UserUtils.getUser());
		}else{
			variables.put("inputUser", userCode);
		}
		taskResDao.update(taskResinfo);
		
		String commit = flow.getRemark();

		if("1".equals(flow.getFlag())){
			commit = "[同意]"+commit;
		}else if("0".equals(flow.getFlag())){
			commit = "[驳回]"+commit;
		}
		TaskRes taskRes = new TaskRes();
		taskRes.setStatus(flow.getFlag());
		if (task != null) {
			// 说明assignee是该任务的办理人,有权限完成
			//根据 auditType判断是几级审核
			if(("firstAudit").equals(task.getTaskDefinitionKey())){
				variables.put("firstAudit", taskRes);
			}else if(("secondAudit").equals(task.getTaskDefinitionKey())){
				variables.put("secondAudit", taskRes);
			}else if(("thirdAudit").equals(task.getTaskDefinitionKey())){
				variables.put("thirdAudit", taskRes);
			}else if(("fourAudit").equals(task.getTaskDefinitionKey())){
				variables.put("fourAudit", taskRes);
			}else if(("fiveAudit").equals(task.getTaskDefinitionKey())){
				variables.put("fiveAudit", taskRes);
			}else if(("sixAudit").equals(task.getTaskDefinitionKey())){
				variables.put("sixAudit", taskRes);
			}
		}
		
		taskService.addComment(taskId,processInstanceId,commit);
		
		taskService.complete(taskId, variables);
		
	}


流程开始代码:

流程开始涉及到主动和被动

private void saveCommon(TaskManager taskManager, String processInstance_id){

		
		String uuid = IdGen.uuid();
		// 流程定义的key从配置文件获取
		String processDefinitionKey = "";
		// 业务标识
		String businessKey = uuid;
		// 设置任务发起人
		identityService.setAuthenticatedUserId(UserUtils.getUser().getUserCode());
		HashMap<String, Object> variables = new HashMap<String, Object>();

		Resource resource = new Resource();
		List<String> resCodeList = new ArrayList<String>();
		if("0".equals(taskManager.getTaskType())){
			Office office = new Office();
			office.setOfficeCode(taskManager.getOffice().getOfficeCode());
			resource.setOffice(office);
		}else if("3".equals(taskManager.getTaskType())){
			String[] tmpstr = taskManager.getResCode().split(",");
			for (String str : tmpstr) {
				resCodeList.add(str);
			}
			resource.setResCodeList(resCodeList);
		}else if("2".equals(taskManager.getTaskType())){
			resource.setBeginOriginalPrice(taskManager.getBeginOriginalPrice());
			resource.setEndOriginalPrice(taskManager.getEndOriginalPrice());
		}else if("1".equals(taskManager.getTaskType())){
			resource.setCategoryBigCode(taskManager.getCategoryBigCode());
			resource.setCategoryMiddleCode(taskManager.getCategoryMiddleCode());
			resource.setCategorySmallCode(taskManager.getCategorySmallCode());
			resource.setCategoryDiffCode(taskManager.getCategoryDiffCode());
		}
		
		if("4".equals(taskManager.getTaskType())){
			if("0".equals(taskManager.getFlag())){
				TaskRes taskRes = new TaskRes();
				taskRes.setStatus("0");
				variables.put("startAudit", taskRes);
			}
			variables.put("inputUser", taskManager.getLinkman().getUserCode());
			processDefinitionKey = ResourceUtils.getResource("jkyprocessflow").getMap().get(taskManager.getFlowName());
			ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey,variables);

			// 启动的流程实例id
			processInstance_id = processInstance.getProcessInstanceId();
			// 任务资源
			TaskRes taskRes = new TaskRes();
			taskRes.setTaskCode(uuid);
			taskRes.setTaskResCode(IdGen.uuid());
			taskRes.setCreateBy(UserUtils.getUser());
			taskRes.setCreateDate(new Date());
			taskRes.setUpdateBy(UserUtils.getUser());
			taskRes.setUpdateDate(new Date());
			taskRes.setProcessInstanceId(processInstance_id);
			taskRes.setTaskId(processInstance.getId());
			taskRes.setBusinessCode(taskManager.getBusinessCode());
			taskRes.setBusinessTable(taskManager.getBusinessTable());
			taskRes.setTriggerType(taskManager.getFlag());
			taskRes.setStatus("2");
			taskResDao.insert(taskRes);
		}else{
		List<Resource> resourceList = resourceDao.findList(resource);
		List<TaskRes> taskReslst = new ArrayList<TaskRes>();
			if(resourceList.size() > 0){
			for (Resource res : resourceList) {
				//设置流程发起人
				variables = new HashMap<String, Object>();
				if("1".equals(taskManager.getFlag())){
					processDefinitionKey = ResourceUtils.getResource("jkyprocessflow").getMap().get(taskManager.getFlowName());
					taskManager.setTaskClass(processDefinitionKey);
					TaskRes taskRes = new TaskRes();
					taskRes.setStatus("0");
					variables.put("startAudit", taskRes);
					variables.put("inputUser", taskManager.getLinkman().getUserCode());
				}else{
					processDefinitionKey = taskManager.getTaskClass();
				if(res.getLinkman() != null && res.getLinkman().getUserCode() != null){
					TaskRes taskRes = new TaskRes();
					taskRes.setStatus("1");
					variables.put("startAudit", taskRes);
					variables.put("inputUser", res.getLinkman().getUserCode());
				}else{
					variables.put("inputUser", "system");
				}}
				// 启动流程实例
				ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey,variables);
				
				// 启动的流程实例id
				processInstance_id = processInstance.getProcessInstanceId();
				// 任务资源
				TaskRes taskRes = new TaskRes();
				taskRes.setTaskCode(uuid);
				taskRes.setTaskResCode(IdGen.uuid());
				taskRes.setResCode(res.getResCode());
				taskRes.setCreateBy(UserUtils.getUser());
				taskRes.setCreateDate(new Date());
				taskRes.setUpdateBy(UserUtils.getUser());
				taskRes.setUpdateDate(new Date());
				taskRes.setProcessInstanceId(processInstance_id);
				taskRes.setTaskId(processInstance.getId());
				taskRes.setBusinessCode(taskManager.getBusinessCode());
				taskRes.setBusinessTable(taskManager.getBusinessTable());
				taskRes.setTriggerType(taskManager.getFlag());
				taskRes.setStatus("2");
				// TODO
				taskResDao.insert(taskRes);
				
				taskReslst.add(taskRes);
				}
			}
		}
		// 设置uuid
		taskManager.setId("");
		taskManager.setTaskCode(uuid);
		taskManager.setCreateBy(UserUtils.getUser());
		taskManager.setCreateDate(new Date());
		taskManager.setUpdateBy(UserUtils.getUser());
		taskManager.setUpdateDate(new Date());
		//保存任务指派信息
		super.save(taskManager);
	}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9613次
    • 积分:172
    • 等级:
    • 排名:千里之外
    • 原创:8篇
    • 转载:0篇
    • 译文:0篇
    • 评论:3条
    最新评论