From 9277d7f05222a33ebd8aeb47fff0aa708a600830 Mon Sep 17 00:00:00 2001 From: fang <123456> Date: Mon, 18 Nov 2024 14:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=85=E5=8A=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/ToDoCenterConstant.java | 2 +- .../midservice/handler/CreateToDoHandler.java | 35 ++++++++------ .../midservice/handler/DealToDoHandler.java | 43 ++++++++++------- .../midservice/handler/deleteToDoHandler.java | 31 +++++++----- .../servicehandler/BacklogServiceHandle.java | 40 ++++++++++++++-- .../sys/midservice/utils/RequestClient.java | 47 ++++++++++++------- 6 files changed, 132 insertions(+), 66 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/constant/ToDoCenterConstant.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/constant/ToDoCenterConstant.java index 9691a68..6eda690 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/constant/ToDoCenterConstant.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/constant/ToDoCenterConstant.java @@ -12,5 +12,5 @@ public class ToDoCenterConstant { public static String URI_SEND_finish = "/bpm/task/api/finishByRecordIdAndUserId.dhtml"; - public static String URI_send_deleteP = "/oa/task/api/deletePendingByRecordIdAndUserId.dhtml"; + public static String URI_send_deleteP = "/bpm/task/api/deletePendingByRecordIdAndUserId.dhtml"; } diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/CreateToDoHandler.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/CreateToDoHandler.java index 774092d..de79ead 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/CreateToDoHandler.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/CreateToDoHandler.java @@ -28,30 +28,37 @@ public class CreateToDoHandler { } return _CreateToDoHandler; } - public boolean sendCreateToDo(BacklogMessage messageInfo) { + public boolean sendCreateToDo(String messageInfo,String title) { logger.info("###进入待办推送接口数据组装"); try { //body - JSONObject jsonObject2 = new JSONObject(); + /* JSONObject jsonObject2 = new JSONObject(); jsonObject2.put("params",messageInfo); - String jsonMessage = jsonObject2.toJSONString(); + String jsonMessage = jsonObject2.toJSONString();*/ //调用接口结果 - String result = RequestClient.getInstance().callService(ToDoCenterConstant.URI_send_addNew,jsonMessage); + String result = RequestClient.getInstance().callService(ToDoCenterConstant.URI_send_addNew,messageInfo); logger.info("###接口返回结果"+result); //接口调用结果 JSONObject jsonObject = JSONObject.parseObject(result); - if(Objects.equals("success",jsonObject.getString("status"))){ - //发送成功 - //调用保存操作 - RequestClient.getInstance().saveCreateToDo(messageInfo.getTitle(),ToDoCenterConstant.URI_send_addNew,true,result,jsonMessage); - return true; + if(jsonObject == null){ + RequestClient.getInstance().saveCreateToDo(title,ToDoCenterConstant.URI_send_addNew,false,result,messageInfo); + logger.info("###响应报文为空"); + return false; }else{ - //调用保存操作 - RequestClient.getInstance().saveCreateToDo(messageInfo.getTitle(),ToDoCenterConstant.URI_send_addNew,false,result,jsonMessage); - //发送失败 - logger.error("###接口调通失败"); - return false; + if(Objects.equals("success",jsonObject.getString("status"))){ + //发送成功 + //调用保存操作 + RequestClient.getInstance().saveCreateToDo(title,ToDoCenterConstant.URI_send_addNew,true,result,messageInfo); + return true; + }else{ + //调用保存操作 + RequestClient.getInstance().saveCreateToDo(title,ToDoCenterConstant.URI_send_addNew,false,result,messageInfo); + //发送失败 + logger.error("###接口调通失败"); + return false; + } } + } catch (Exception e) { logger.error("###调用接口失败:"+e.getMessage(),e); return false; diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/DealToDoHandler.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/DealToDoHandler.java index d418ef5..f75f979 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/DealToDoHandler.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/DealToDoHandler.java @@ -19,40 +19,49 @@ public class DealToDoHandler { private static DealToDoHandler _DealToDoHandler; - public static synchronized DealToDoHandler get_DealToDoHandler(){ - if(_DealToDoHandler == null){ - _DealToDoHandler = new DealToDoHandler(); + public static synchronized DealToDoHandler get_DealToDoHandler() { + if (_DealToDoHandler == null) { + _DealToDoHandler = new DealToDoHandler(); } return _DealToDoHandler; } - public boolean sendDealToDo(Long appRecordId,String userId) { + public boolean sendDealToDo(Long appRecordId, String userId) { try { //body - JSONObject jsonObject2 = new JSONObject(); - JSONObject jsonObject_1 = new JSONObject(); + // JSONObject jsonObject2 = new JSONObject(); + /* JSONObject jsonObject_1 = new JSONObject(); jsonObject_1.put("appRecordId", appRecordId); - jsonObject_1.put("userId",userId); - jsonObject2.put("params",jsonObject_1); - String jsonMessage = jsonObject2.toJSONString(); + jsonObject_1.put("userId",userId);*/ + String part = " {\"appRecordId\": " + appRecordId + ",\"userId\": " + userId + "}"; + /* jsonObject2.put("params",part); + String jsonMessage = jsonObject2.toJSONString();*/ //调用接口结果 - String result = RequestClient.getInstance().callService(ToDoCenterConstant.URI_SEND_finish,jsonMessage); + String result = RequestClient.getInstance().callService(ToDoCenterConstant.URI_SEND_finish, part); //保存发送消息日志 // writeMessageLog(MessageCenterConstant.URI_SEND_MESSAGE,messageInfo,result); //接口调用结果 JSONObject jsonObject = JSONObject.parseObject(result); - if(jsonObject.getBoolean("success")){ - //发送成功 - RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_SEND_finish,true,result,jsonMessage,"2"); - return true; - }else{ + if (jsonObject == null) { //发送失败 - RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_SEND_finish,false,result,jsonMessage,"2"); + RequestClient.getInstance().saveDeLToDo(appRecordId, userId, ToDoCenterConstant.URI_SEND_finish, false, result, part, "2"); + logger.info("###响应报文为空"); return false; + } else { + if (jsonObject.getBoolean("success")) { + //发送成功 + RequestClient.getInstance().saveDeLToDo(appRecordId, userId, ToDoCenterConstant.URI_SEND_finish, true, result, part, "2"); + return true; + } else { + //发送失败 + RequestClient.getInstance().saveDeLToDo(appRecordId, userId, ToDoCenterConstant.URI_SEND_finish, false, result, part, "2"); + return false; + } } } catch (Exception e) { - logger.error("调用接口失败:"+e.getMessage(),e); + logger.error("调用接口失败:" + e.getMessage(), e); return false; } } } + diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/deleteToDoHandler.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/deleteToDoHandler.java index 0f6ad85..92faab6 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/deleteToDoHandler.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/handler/deleteToDoHandler.java @@ -29,26 +29,31 @@ public class deleteToDoHandler { public boolean sendDeleteToDo(Long appRecordId,String userId) { try { //body - JSONObject jsonObject2 = new JSONObject(); - JSONObject jsonObject_1 = new JSONObject(); - jsonObject_1.put("appRecordId", appRecordId); - jsonObject_1.put("userId",userId); - jsonObject2.put("params",jsonObject_1); - String jsonMessage = jsonObject2.toJSONString(); +// JSONObject jsonObject2 = new JSONObject(); + String part = " {\"appRecordId\": "+appRecordId+",\"userId\": "+userId+"}"; +// jsonObject2.put("params",part); +// String jsonMessage = jsonObject2.toJSONString(); //调用接口结果 - String result = RequestClient.getInstance().callService(ToDoCenterConstant.URI_send_deleteP,jsonMessage); + String result = RequestClient.getInstance().callService(ToDoCenterConstant.URI_send_deleteP,part); //保存发送消息日志 // writeMessageLog(MessageCenterConstant.URI_SEND_MESSAGE,messageInfo,result); //接口调用结果 JSONObject jsonObject = JSONObject.parseObject(result); - if(jsonObject.getBoolean("success")){ - //发送成功 - RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_send_deleteP,true,result,jsonMessage,"5"); - return true; - }else{ - RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_send_deleteP,false,result,jsonMessage,"5"); + if(jsonObject== null){ + RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_send_deleteP,false,result,part,"5"); + logger.info("###响应报文为空"); return false; + }else{ + if(jsonObject.getBoolean("success")){ + //发送成功 + RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_send_deleteP,true,result,part,"5"); + return true; + }else{ + RequestClient.getInstance().saveDeLToDo(appRecordId,userId,ToDoCenterConstant.URI_send_deleteP,false,result,part,"5"); + return false; + } } + } catch (Exception e) { logger.error("###调用中台服务消息中心发送消息服务异常:"+e.getMessage(),e); return false; diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/servicehandler/BacklogServiceHandle.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/servicehandler/BacklogServiceHandle.java index 3e3751e..85ad673 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/servicehandler/BacklogServiceHandle.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/servicehandler/BacklogServiceHandle.java @@ -39,9 +39,37 @@ public class BacklogServiceHandle extends AbstractServiceHandler { new QFilter[]{new QFilter("id", "=", todoInfo.getTaskId())}); logger.info("####待办taskid:"+todoInfo.getTaskId()); for (DynamicObject query_one : query) { - - BacklogMessage backlogMessage = new BacklogMessage(); - //业务类型名称 + StringBuffer form = new StringBuffer(); + // BacklogMessage backlogMessage = new BacklogMessage(); + form.append("{"); + form.append("\"title\":"); + form.append("\""+todoInfo.getTitle()+"\","); + form.append("\"bName\":"); + form.append("\""+ctx.getEntityName()+"\","); + form.append("\"bussinessCode\":"); + form.append("\""+dynamicObject.getString("billno")+"\","); + form.append("\"urGency\":"); + form.append("\"0\","); + form.append("\"currentStepName\":"); + form.append("\""+dynamicObject.getString("name")+"\","); + form.append("\"sendUserName\":"); + form.append("\""+dynamicObject.getString("startname")+"\","); + form.append("\"receiveUsersysName\":"); + form.append("\""+query_one.getString("username")+"\","); + form.append("\"receiveUserId\":"); + form.append("\""+query_one.getString("username")+"\","); + form.append("\"handleUrl\":"); + form.append("\""+todoInfo.getUrl()+"\","); + form.append("\"appHandleUrl\":"); + form.append("\""+todoInfo.getUrl()+"\","); + form.append("\"appName\":"); + form.append("\""+ctx.getEntityName()+"\","); + form.append("\"pendingId\":"); + form.append("\""+todoInfo.getTaskId()+"\","); + form.append("\"pendingAttr\":"); + form.append("\"0\""); + form.append("}"); + /* //业务类型名称 backlogMessage.setbName("业务类型名称"); // 紧急程度 backlogMessage.setUrGency("0"); @@ -76,8 +104,9 @@ public class BacklogServiceHandle extends AbstractServiceHandler { //notifyMethod 通知方式 backlogMessage.setNotifyMethod(""); //业务自定义数据 - backlogMessage.setJsonData(""); - CreateToDoHandler.get_CreateToDoHandler().sendCreateToDo(backlogMessage); + backlogMessage.setJsonData("");*/ + logger.info("###待办拼接请求体:"+form); + CreateToDoHandler.get_CreateToDoHandler().sendCreateToDo(form.toString(),todoInfo.getTitle()); } logger.info("###结束待办_createToDo"); @@ -100,6 +129,7 @@ public class BacklogServiceHandle extends AbstractServiceHandler { } //撤销 public void deleteToDo(MessageContext ctx, ToDoInfo info){ + logger.info("###创建撤销_deleteToDo"); List userIds = info.getUserIds(); DynamicObjectCollection query = QueryServiceHelper.query("bos_user", "id,name,phone,username", new QFilter[]{new QFilter("id", "in", userIds)}); diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/utils/RequestClient.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/utils/RequestClient.java index 7e5c835..e2a223d 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/utils/RequestClient.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/midservice/utils/RequestClient.java @@ -1,16 +1,13 @@ package shkd.sys.sys.midservice.utils; import cn.hutool.crypto.SmUtil; -import com.alibaba.fastjson.JSON; +import cn.hutool.http.HttpRequest; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; -import kd.bos.util.HttpClientUtils; import kd.bos.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -52,30 +49,48 @@ public class RequestClient { * 封装中台请求头,执行POST请求 * * @param url 接口地址(不含http://ip:port的后半部分) - * @param body JSON格式字符串 + * @param body FORM格式字符串 * @return 响应结果报文 */ public String callService(String url, String body){ - Map headers = getHeaders(); + // Map headers = getHeaders(); StringBuffer urlStr = new StringBuffer(); urlStr.append(this.protocal).append("://").append(this.ip); if (!StringUtils.isEmpty(this.port)) { urlStr.append(":").append(this.port); } - logger.info("环境参数,protocal:"+this.protocal+",ip:"+this.ip+",this.port:"+this.port); + logger.info("###环境参数,protocal:"+this.protocal+",ip:"+this.ip+",this.port:"+this.port); urlStr.append(url); String responseText = null; + String timestamp = Long.toString(System.currentTimeMillis() / 1000); + byte[] securityKey = this.clientSecret.substring(10, 26).getBytes(); + String authenticationCode = SmUtil.sm4(securityKey).encryptHex(clientKey + clientSecret + timestamp); + logger.info("###请求头主要参数:authen(sign)"+authenticationCode+"###时间戳"+timestamp); + Map params=new HashMap<>(2); + params.put("params",body); + /* Map params=new HashMap<>(2); + params.put("params",body); + String timestamp = Long.toString(System.currentTimeMillis() / 1000); + byte[] securityKey = clientSecret.substring(10, 26).getBytes(); + String authenticationCode = SmUtil.sm4(securityKey).encryptHex(clientKey + clientSecret + timestamp); + */ try { //直接POST请求 - responseText = HttpClientUtils.postjson(urlStr.toString(), headers, body); - logger.info(String.format("###调用接口成功,请求URL:%s,请求Header:%s,请求Body:%s,响应报文:%s", urlStr, JSON.toJSONString(headers), body, responseText)); - } catch (IOException e) { - logger.error(String.format("###调用接口异常:%s,请求URL:%s,请求Header:%s,请求Body:%s", e.getMessage(), urlStr, JSON.toJSONString(headers), body), e); + responseText = HttpRequest.post(urlStr.toString()) + .header("authen", authenticationCode) + .header("clientKey", clientKey) + .header("timestamp", timestamp) + .header("origin_client", "HttpToken") + .form(params) + .execute().body(); + logger.info(String.format("###调用接口成功,请求URL:%s,请求Body:%s,响应报文:%s", urlStr, body, responseText)); + } catch (Exception e) { + logger.error(String.format("###调用接口异常:%s,请求URL:%s,请求Body:%s", e.getMessage(), urlStr, body), e); } return responseText; } - private Map getHeaders(){ + /* private Map getHeaders(){ logger.info("###进入拼接请求头方法"); Map header=new HashMap<>(); String timestamp = Long.toString(System.currentTimeMillis() / 1000); @@ -87,7 +102,7 @@ public class RequestClient { header.put("origin_client", "HttpToken"); logger.info("###authen(sign)"+authenticationCode+"###时间戳"+timestamp); return header; - } + }*/ /*** * 保存待办日志 * @param title 标题 @@ -111,10 +126,10 @@ public class RequestClient { dynamicObject.set("shkd_request",title); dynamicObject.set("shkd_request_tag",jsonMessage); dynamicObject.set("shkd_response",isTrue); - dynamicObject.set("shkd_response",result); + dynamicObject.set("shkd_response_tag",result); dynamicObject.set("shkd_status","0"); SaveServiceHelper.save(new DynamicObject[]{dynamicObject}); - logger.info("###保存日志表id"+dynamicObject.getPkValue()); + logger.info("###保存日志表后id"+dynamicObject.getPkValue()); logger.info("###结束调用待办保存日志方法"); } /*** @@ -140,7 +155,7 @@ public class RequestClient { dynamicObject.set("shkd_request","业务id:"+appRecordId+",接收人手机号:"+userId); dynamicObject.set("shkd_request_tag",jsonMessage); dynamicObject.set("shkd_response",isTrue); - dynamicObject.set("shkd_response",result); + dynamicObject.set("shkd_response_tag",result); dynamicObject.set("shkd_status",status); SaveServiceHelper.save(new DynamicObject[]{dynamicObject}); logger.info("###保存日志表id"+dynamicObject.getPkValue());