浏览代码

流程外部表单更新

fenghaifu 2 年之前
父节点
当前提交
dd7be58be0

+ 141 - 0
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/util/HttpUtils.java

@@ -0,0 +1,141 @@
+package org.jeecg.common.util;
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author fenghaifu
+ * @version V1.0
+ * @Copyright: 上海萃颠信息科技有限公司. All rights reserved.
+ * @Title:HttpUtils
+ * @projectName
+ * @Description:后台发送http请求
+ * @date: 2020/2/11 23:02
+ * @updatehistory: 2020/2/11 23:02 新增
+ */
+public class HttpUtils {
+	// 发送post请求
+	public static String sendPost(String url, String param) {
+		PrintWriter out = null;
+		BufferedReader in = null;
+		String result = "";
+		try {
+			URL realUrl = new URL(url);
+			// 打开和URL之间的连接
+			URLConnection conn = realUrl.openConnection();
+			// 设置通用的请求属性
+			conn.setRequestProperty("accept", "*/*");
+			conn.setRequestProperty("connection", "Keep-Alive");
+			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+			// 发送POST请求必须设置如下两行
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			// 获取URLConnection对象对应的输出流
+			out = new PrintWriter(conn.getOutputStream());
+			// 发送请求参数
+			out.print(param);
+			// flush输出流的缓冲
+			out.flush();
+			// 定义BufferedReader输入流来读取URL的响应
+			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+			String line;
+			while ((line = in.readLine()) != null) {
+				result += line;
+			}
+		} catch (Exception e) {
+			System.out.println("[POST请求]向地址:" + url + " 发送数据:" + param + " 发生错误!");
+		} finally {// 使用finally块来关闭输出流、输入流
+			try {
+				if (out != null) {
+					out.close();
+				}
+				if (in != null) {
+					in.close();
+				}
+			} catch (IOException ex) {
+				System.out.println("关闭流异常");
+			}
+		}
+		return result;
+	}
+
+	//发送GET请求
+	public static String sendGet(String url) {
+		String result = "";
+		BufferedReader in = null;
+		try {
+
+			String urlName = url;
+			URL realUrl = new URL(urlName);
+			URLConnection conn = realUrl.openConnection();// 打开和URL之间的连接
+			conn.setRequestProperty("accept", "*/*");// 设置通用的请求属性
+			conn.setRequestProperty("connection", "Keep-Alive");
+			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
+			conn.setConnectTimeout(4000);
+			conn.connect();// 建立实际的连接
+			in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));// 定义BufferedReader输入流来读取URL的响应
+			String line;
+			while ((line = in.readLine()) != null) {
+				result += line;
+			}
+		} catch (Exception e) {
+			System.out.println("发送GET请求出现异常!" + e);
+			throw new RuntimeException("获取中台数据异常!" + e);
+		} finally {// 使用finally块来关闭输入流
+			try {
+				if (in != null) {
+					in.close();
+				}
+			} catch (IOException ex) {
+				System.out.println("关闭流异常");
+			}
+		}
+		return result;
+	}
+
+	// 发送JSONPOST
+	public static JSONObject sendJsonPost(String url, JSONObject param) {
+		HttpResponse httpResponse = null;
+		try {
+			// 设置请求头
+			Map<String, String > heads = new HashMap<>();
+			heads.put("Content-Type", "application/json;charset=UTF-8");
+			httpResponse =  HttpRequest.post(url) // url
+					.addHeaders(heads) // 请求头设置
+					.body(param.toJSONString()) // json参数
+					.timeout(10 * 1000) // 超时
+					.execute(); // 请求
+			System.out.println("url:"+url+",param:"+ JSON.toJSONString(param)+",获取返回服务器的状态码:----- " + httpResponse.getStatus() );
+			if(httpResponse.getStatus() == 200){
+				//成功后响应数据
+				String result = httpResponse.body();
+				JSONObject jsonResult = JSONObject.parseObject(result);
+				System.out.println("获取返回内容:----- " + jsonResult.toString());
+				return jsonResult;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally{
+			try {
+				//释放连接
+				if(httpResponse != null){
+					httpResponse.close();
+				}
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		return new JSONObject();
+	}
+}

+ 19 - 0
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActBusinessController.java

@@ -21,6 +21,8 @@ import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.api.ISysBaseAPI;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.HttpUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.activiti.entity.*;
 import org.jeecg.modules.activiti.mapper.TbTableInfoMapper;
@@ -504,6 +506,23 @@ public class ActBusinessController {
             act.setApplyTime(new Date());
             actBusinessService.updateById(act);
 
+            // 获取外部表单回调
+            QueryWrapper<TbTableInfoOuter> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("text", act.getTableName());
+            TbTableInfoOuter tableInfoOuter = tbTableInfoOuterService.getOne(queryWrapper);
+            if (tableInfoOuter != null && oConvertUtils.isNotEmpty(tableInfoOuter.getSeturl())){
+                QueryWrapper<TbTableInfoPractice> practiceQueryWrapper = new QueryWrapper<>();
+                practiceQueryWrapper.eq("id", act.getTableId());
+                TbTableInfoPractice tableInfoPractice = tbTableInfoPracticeService.getOne(practiceQueryWrapper);
+                if (tableInfoPractice != null) {
+                    JSONObject jsonObject = JSON.parseObject(tableInfoPractice.getContent());
+                    jsonObject.put("actionUser", sysUser.getRealname());
+                    jsonObject.put("actionTime", DateUtils.date2Str(DateUtils.datetimeFormat.get()));
+                    jsonObject.put("action", "提交");
+                    HttpUtils.sendJsonPost(tableInfoOuter.getSeturl(), jsonObject);
+                }
+            }
+
             result.success("操作成功");
         } catch (Exception e) {
             e.printStackTrace();

+ 87 - 6
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActTaskController.java

@@ -3,7 +3,9 @@ package org.jeecg.modules.activiti.web;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
@@ -29,8 +31,13 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.api.ISysBaseAPI;
 import org.jeecg.common.system.vo.ComboModel;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.HttpUtils;
+import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.activiti.entity.*;
 import org.jeecg.modules.activiti.service.IActReModelService;
+import org.jeecg.modules.activiti.service.ITbTableInfoOuterService;
+import org.jeecg.modules.activiti.service.ITbTableInfoPracticeService;
 import org.jeecg.modules.activiti.service.Impl.ActBusinessServiceImpl;
 import org.jeecg.modules.activiti.service.Impl.ActZprocessServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -74,6 +81,10 @@ public class ActTaskController {
     private IActReModelService iActReModelService;
     @Autowired
     ISysBaseAPI sysBaseAPI;
+    @Autowired
+    private ITbTableInfoOuterService tbTableInfoOuterService;
+    @Autowired
+    private ITbTableInfoPracticeService tbTableInfoPracticeService;
 
     public void show(String userId,String name,String categoryId, Integer priority, HttpServletRequest request,List<Task> taskList){
         TaskQuery query = taskService.createTaskQuery().taskCandidateOrAssigned(userId);
@@ -296,15 +307,38 @@ public class ActTaskController {
         }
         taskService.addComment(id, procInstId, comment);
         ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(procInstId).singleResult();
+
+        ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
+        // 异步发消息
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+
+        // ----------- 获取外部表单回调 start,by fhf -------------
+        QueryWrapper<TbTableInfoOuter> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("text", actBusiness.getTableName());
+        TbTableInfoOuter tableInfoOuter = tbTableInfoOuterService.getOne(queryWrapper);
+        if (tableInfoOuter != null && oConvertUtils.isNotEmpty(tableInfoOuter.getSeturl())){
+            QueryWrapper<TbTableInfoPractice> practiceQueryWrapper = new QueryWrapper<>();
+            practiceQueryWrapper.eq("id", actBusiness.getTableId());
+            TbTableInfoPractice tableInfoPractice = tbTableInfoPracticeService.getOne(practiceQueryWrapper);
+            if (tableInfoPractice != null) {
+                Task task = taskService.createTaskQuery().taskId(id).singleResult();
+                JSONObject jsonObject = JSON.parseObject(tableInfoPractice.getContent());
+                jsonObject.put("actionUser", sysUser.getRealname());
+                jsonObject.put("actionTime", DateUtils.date2Str(DateUtils.datetimeFormat.get()));
+                jsonObject.put("action", task.getName()+"驳回");
+                HttpUtils.sendJsonPost(tableInfoOuter.getSeturl(), jsonObject);
+            }
+        }
+        // ----------- 获取外部表单回调 end,by fhf -------------
+
         // 删除流程实例
         runtimeService.deleteProcessInstance(procInstId, "backed");
-        ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
+
         actBusiness.setStatus(ActivitiConstant.STATUS_FINISH);
         actBusiness.setResult(ActivitiConstant.RESULT_FAIL);
         actBusinessService.updateById(actBusiness);
 
-        // 异步发消息
-        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+
         //我的消息跳转地址
         Map<String,Object> map =new HashMap<>();
         map.put("isUrl","1");
@@ -316,6 +350,9 @@ public class ActTaskController {
         // 记录实际审批人员
         actBusinessService.insertHI_IDENTITYLINK(IdUtil.simpleUUID(),
                 ActivitiConstant.EXECUTOR_TYPE, sysUser.getUsername(), id, procInstId);
+
+
+
         return Result.ok("操作成功");
     }
     /*流程流转历史*/
@@ -405,7 +442,7 @@ public class ActTaskController {
         LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         List<Task> tasks = taskService.createTaskQuery().processInstanceId(procInstId).list();
 
-
+        ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
         // 判断下一个节点
         if(tasks!=null&&tasks.size()>0){
             //修改公司id
@@ -420,7 +457,7 @@ public class ActTaskController {
 //            listTaskIdY.add(task.getId());
             //修改已办公司id
             iActReModelService.updateTaskInstPkOrgByIds(loginUser.getOrgCode(),listTaskId);
-            ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
+
             for(Task t : tasks){
                 if(StrUtil.isBlank(assignees)){
                     // 如果下个节点未分配审批人为空 取消结束流程
@@ -469,7 +506,7 @@ public class ActTaskController {
                 }
             }
         } else {
-            ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
+            //ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
             actBusiness.setStatus(ActivitiConstant.STATUS_FINISH);
             actBusiness.setResult(ActivitiConstant.RESULT_PASS);
             actBusinessService.updateById(actBusiness);
@@ -492,6 +529,25 @@ public class ActTaskController {
         // 记录实际审批人员
         actBusinessService.insertHI_IDENTITYLINK(IdUtil.simpleUUID(),
                 ActivitiConstant.EXECUTOR_TYPE, loginUser.getUsername(), id, procInstId);
+
+        // --------------- 获取外部表单回调 start, by fhf ---------------
+        QueryWrapper<TbTableInfoOuter> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("text", actBusiness.getTableName());
+        TbTableInfoOuter tableInfoOuter = tbTableInfoOuterService.getOne(queryWrapper);
+        if (tableInfoOuter != null && oConvertUtils.isNotEmpty(tableInfoOuter.getSeturl())){
+            QueryWrapper<TbTableInfoPractice> practiceQueryWrapper = new QueryWrapper<>();
+            practiceQueryWrapper.eq("id", actBusiness.getTableId());
+            TbTableInfoPractice tableInfoPractice = tbTableInfoPracticeService.getOne(practiceQueryWrapper);
+            if (tableInfoPractice != null) {
+                JSONObject jsonObject = JSON.parseObject(tableInfoPractice.getContent());
+                jsonObject.put("actionUser", loginUser.getRealname());
+                jsonObject.put("actionTime", DateUtils.date2Str(DateUtils.datetimeFormat.get()));
+                jsonObject.put("action", task.getName());
+                HttpUtils.sendJsonPost(tableInfoOuter.getSeturl(), jsonObject);
+            }
+        }
+        // --------------- 获取外部表单回调 end, by fhf ---------------
+
         return Result.ok("操作成功");
     }
     @RequestMapping(value = "/delegate", method = RequestMethod.POST)
@@ -542,6 +598,28 @@ public class ActTaskController {
         taskService.addComment(id, procInstId, comment);
         // 取得流程定义
         ProcessDefinitionEntity definition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(procDefId);
+
+        // ----------------获取外部表单回调 start, by fhf ------------
+        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(procInstId).singleResult();
+        ActBusiness actBusiness = actBusinessService.getById(pi.getBusinessKey());
+        QueryWrapper<TbTableInfoOuter> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("text", actBusiness.getTableName());
+        TbTableInfoOuter tableInfoOuter = tbTableInfoOuterService.getOne(queryWrapper);
+        if (tableInfoOuter != null && oConvertUtils.isNotEmpty(tableInfoOuter.getSeturl())){
+            QueryWrapper<TbTableInfoPractice> practiceQueryWrapper = new QueryWrapper<>();
+            practiceQueryWrapper.eq("id", actBusiness.getTableId());
+            TbTableInfoPractice tableInfoPractice = tbTableInfoPracticeService.getOne(practiceQueryWrapper);
+            if (tableInfoPractice != null) {
+                Task task = taskService.createTaskQuery().taskId(id).singleResult();
+                JSONObject jsonObject = JSON.parseObject(tableInfoPractice.getContent());
+                jsonObject.put("actionUser", loginUser.getRealname());
+                jsonObject.put("actionTime", DateUtils.date2Str(DateUtils.datetimeFormat.get()));
+                jsonObject.put("action", task.getName()+"驳回");
+                HttpUtils.sendJsonPost(tableInfoOuter.getSeturl(), jsonObject);
+            }
+        }
+
+        // ----------------获取外部表单回调 end, by fhf ------------
         // 获取历史任务的Activity
         ActivityImpl hisActivity = definition.findActivity(backTaskKey);
         // 实现跳转
@@ -582,6 +660,9 @@ public class ActTaskController {
         // 记录实际审批人员
         actBusinessService.insertHI_IDENTITYLINK(IdUtil.simpleUUID(),
                 ActivitiConstant.EXECUTOR_TYPE, loginUser.getUsername(), id, procInstId);
+
+
+
         return Result.ok("操作成功");
     }