请求端方法:
Controller:
@Override public ResultData saveData(long userId, TemplateManage templateManage) { //改变状态入湖中 cloudFlowUtil.updateLakeStatusIng(templateManage.getFormId()); ltCloudUtil.updateLakeStatusIng(templateManage.getDataSourceId()); TemplateManage templateManageNew = new TemplateManage(); templateManageNew.setId(SnowflakeIdGenerator.getId()); templateManageNew.setName(templateManage.getName()); templateManageNew.setDesign(templateManage.getDesign()); templateManageNew.setParentId(templateManage.getParentId()); templateManageNew.setParentCode(templateManage.getParentCode()); templateManageNew.setGroupId(templateManage.getGroupId()); templateManageNew.setDataSourceId(templateManage.getDataSourceId()); templateManageNew.setDataSourceType(templateManage.getDataSourceType()); templateManageNew.setCreateUserName(templateManage.getCreateUserName()); templateManageNew.setFormId(templateManage.getFormId()); templateManageNew.setIsDeleted("0"); templateManageNew.setSpStatus("1"); templateManageNew.setLakeType(templateManage.getLakeType()); templateManageNew.setCreateTime(LocalDateTime.now()); templateManageNew.setCreateUserId(userId); List<DfsFormAppro> dfsFormApproList = dfsFormApproMapper.selectList(null); Boolean flag = false; //1.找到DfsFormAppro里有没有表单id templateManage.getFormId() DfsTaskAppro listByFormId = dfsTaskApproService.getListByFormId(templateManage.getFormId()); //2.如果有就再次提交 if (listByFormId != null){ cloudFlowUtil.reExecute(listByFormId.getTaskCloudFlowOrderId()); }else { //3.如果没有就初次提交 DfsFormAppro dfsFormAppro = new DfsFormAppro(); // 首次提交 dfsFormAppro.setId(SnowflakeIdGenerator.getId()); dfsFormAppro.setTaskFormId(templateManage.getFormId()); String orderId = ""; JSONObject appro = new JSONObject(); if (templateManage.getLakeType().equalsIgnoreCase("1")) { // 直报提交到审批流 appro = cloudFlowUtil.startAndExecute("35aef0a551384210a7b2be4df7008269"); } else if (templateManage.getLakeType().equalsIgnoreCase("2")) { // 爬虫提交到审批流 appro = cloudFlowUtil.startAndExecute("39fe7a406bff4f1a8afb94a68754172d"); } else if (templateManage.getLakeType().equalsIgnoreCase("3")) { // 同步提交到审批流 appro = cloudFlowUtil.startAndExecute("ca1f66846f9b4697992418cd2072f102"); } else if (templateManage.getLakeType().equalsIgnoreCase("4")) { // 集成提交到审批流 appro = cloudFlowUtil.startAndExecute("91a789b3f6864c09a9d4350e50ee25a8"); } else if (templateManage.getLakeType().equalsIgnoreCase("5")) { // 提交到审批流 appro = cloudFlowUtil.startAndExecute("4083c7761cf24a60a2199657950d3576"); } if (appro.getInteger("code") == 20000) { JSONObject taskOrder = JSONObject.parseObject(appro.getString("data")); orderId = taskOrder.getString("id"); dfsFormAppro.setTaskCloudFlowOrderId(orderId); } dfsFormAppro.setTemplateManageId(templateManageNew.getId()); dfsFormAppro.setCreateTime(LocalDateTime.now()); dfsFormAppro.setCreateUser(userId); // 向数据库中保存数据 formApproService.save(dfsFormAppro); } templateManageMapper.insert(templateManageNew); return ResultData.success("ok"); }
调用的CloudFlowUtil:
package com.todod.utils; import cn.dev33.satoken.stp.StpUtil; import com.alibaba.fastjson.JSONObject; import com.todod.dto.FormFillFieldReq; import com.todod.entity.QueryEntry; import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @Component public class CloudFlowUtil { @Value("${remote.cloud.flow.url}") private String BASE_CLOW_FLOW_URL; @Autowired private RestTemplate restTemplate; @Value("${remote.fill.in.url}") private String BASE_FILL_IN_URL; /** * @Title: getUserList * @Description: 获取流程列表,用来针对不同的云平台的用户显示 * @author: wgb * @date 2023-07-26 * @return JSONObject **/ public JSONObject getFlowList(){ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "flow/getProcessList", headers, String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } /** * @Title: startAndExecute * @Description: 执行"执行任务接口"(传入审核流id) * @param: processId 任务绑定审核流id * @author: wgb * @date 2023-07-26 * @return JSONObject **/ public JSONObject startAndExecute(String processId){ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); Map<String,Object> map = new HashMap<String,Object>(); map.put("processId", processId); map.put("processName", null); map.put("args", null); ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/startAndExecute", new HttpEntity<>(map, headers), String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } /** * @Title: reExecute * @Description: 驳回或撤回后再次提交 * @param: orderId 审核流实例id * @author: wgb * @date 2023-07-26 * @return JSONObject **/ public JSONObject reExecute(String orderId) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); Map<String, Object> map = new HashMap<String, Object>(); ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/task/reExecute?orderId="+orderId, new HttpEntity<>(map, headers), String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } /** * @Title: getTodoList * @Description: 获取待审批列表 * @param query * @return */ public JSONObject getTodoList(QueryEntry query) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/task/todoList", new HttpEntity<>(query, headers), String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } /** * @Title: getDoneList * @Description: 获取已完成列表 * @param query * @return */ public JSONObject getDoneList(QueryEntry query) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/task/doneList", new HttpEntity<>(query, headers), String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } /** * @Title: getUserList * @Description: 获取获取审批完成后列表 * @param: orderIds 审批实例id列表字符串 * @author: wgb * @date 2023-07-26 * @return JSONObject **/ public JSONObject getOrdercompletionList(String orderIds){ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); // headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/ordercompletion/getOrderByIds?orderIds=" + orderIds, headers, String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } public JSONObject updateLakeStatus(Long formId) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity( BASE_FILL_IN_URL + "ltcloud/form/updateLakeStatus?id=" + formId, headers, String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } //入湖驳回 public JSONObject updateLakeStatusBack(Long formId) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity( BASE_FILL_IN_URL + "ltcloud/form/updateLakeStatusBack?id=" + formId, headers, String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } //入湖中 public JSONObject updateLakeStatusIng(Long formId) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue()); ResponseEntity<String> postForEntity = restTemplate.postForEntity( BASE_FILL_IN_URL + "ltcloud/form/updateLakeStatusIng?id=" + formId, headers, String.class); JSONObject reData = JSONObject.parseObject(postForEntity.getBody()); return reData; } }
在yaml文件中配置好对应的路径即可:remote.cloud.flow.url = http://localhost:8083/cloud_flow/
被调用方Controller:
/** * @title startAndExecute * @description 启动并执行第一个任务节点 * @param param * @param userId 当前用户id * @return */ public Order startAndExecute(WfOrderParam param, Long userId) { // Process process = this.getProcessByProcessId(param.getProcessId()); param.setArgs(param.getArgs()!=null?param.getArgs():new HashMap<String,Object>()); param.getArgs().put("reason", "提交"); // param.getArgs().put(TododConstants.INSTANCE_URL, process.getInstanceUrl()); // // 设置业务ID // param.getArgs().put(SnakerEngine.ID, UUID.randomUUID().toString().replaceAll("-","")); // // 创建流程实例用户名 // param.getArgs().put(TododConstants.ORDER_USER_NAME_KEY, ""); // // 创建流程实例姓名 // param.getArgs().put(TododConstants.ORDER_USER_REAL_NAME_KEY, ""); Order order = snakerEngineFacets.startInstanceById(param.getProcessId(), userId.toString(), param.getArgs()); // 获取流程实例的所有任务 List<Task> tasks = snakerEngineFacets.getEngine().query().getActiveTasks(new QueryFilter().setOrderId(order.getId())); List<Task> newTasks = new ArrayList<Task>(); if (tasks != null && tasks.size() > 0) { Task task = tasks.get(0); // 保存审批记录 ApproRecords records = new ApproRecords(); records.setId(task.getId()); records.setOrderId(order.getId()); records.setPerformType("0"); records.setOperator(userId.toString()); records.setRemark("提交"); records.setFinishTime(LocalDateTime.now()); recordsService.save(records); newTasks.addAll(snakerEngineFacets.getEngine().executeTask(task.getId(), userId.toString(), param.getArgs())); } return order; }