feat(OA调用接口):新增

This commit is contained in:
liaohechuan 2024-11-29 15:26:12 +08:00
parent 98edf427fa
commit 9de540acf4
5 changed files with 181 additions and 0 deletions

View File

@ -20,6 +20,8 @@ public class Msg {
public static final String SAP = "SAP";
public static final String OA = "OA";
public static final String DEFAULT_TO_SYSTEM = IEP;
public static final String ERP_INT = "erp_int";

View File

@ -20,4 +20,7 @@ public interface RemoteInvokeService {
@PostMapping("/requestErpPort")
JSONObject requestErpPort(@RequestBody JSONObject jsonObject);
@PostMapping("/requestOAPort")
JSONObject requestOAPort(@RequestBody JSONObject jsonObject);
}

View File

@ -9,6 +9,7 @@ import com.foreverwin.iep.integration.component.Invoke;
import com.foreverwin.iep.integration.constant.Msg;
import com.foreverwin.iep.integration.domain.InvokeRequest;
import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.iep.integration.handler.def.oa.OAUtil;
import com.foreverwin.iep.integration.handler.def.sap.SapUtil;
import com.foreverwin.iep.integration.service.IntInDataService;
import com.foreverwin.iep.integration.utils.JS;
@ -190,4 +191,49 @@ public class InvokeController {
return response;
}
@ApiOperation(value = "请求OA接口用", notes = "请求OA接口用")
@SysLog("请求OA接口用" )
@PostMapping("/requestOAPort")
@Inner(value = false)
public JSONObject requestOAPort(@RequestBody JSONObject jsonObject) {
SecurityUtils.setUserName(Msg.USER);
String nowTime = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss");
JSONObject jsonBody = new JSONObject();
jsonBody.put("SITE", jsonObject.getString("SITE"));
jsonBody.put("REQ_ID", StrUtil.uuid());
jsonBody.put("KEY_VALUE", jsonObject.getString("KEY_VALUE"));
jsonBody.put("SEND_TIME", nowTime);
jsonBody.put("SENDER", Msg.IEP);
jsonBody.put("START", nowTime);
jsonBody.put("MESSAGE_ID", jsonObject.getString("MESSAGE_ID"));
jsonBody.put("RECEIVER", Msg.OA);
jsonBody.put("RETRY", false);
// messageContent内容
JSONObject messageContentJson = OAUtil.appendHead(jsonObject.getJSONObject("jsonBody"));
jsonBody.put("MESSAGE_CONTENT", messageContentJson);
String requestText = jsonBody.toJSONString();
InvokeRequest request = JSONObject.parseObject(requestText, InvokeRequest.class);
request.setMessageContent(requestText);
request.setSrcRequestBody(requestText);
InvokeResponse invokeResponse = invoke.execute(null, request);
JSONObject response = new JSONObject();
response.put("REQ_ID", invokeResponse.getTransSid());
response.put("RESULT", invokeResponse.getResult());
response.put("MESSAGE", invokeResponse.getMessageContent());
JSONObject objectResponse = invokeResponse.getObjectResponse();
if (ObjectUtil.isNotNull(objectResponse)) {
for (String key : objectResponse.keySet()) {
response.put(key, objectResponse.getString(key));
}
}
return response;
}
}

View File

@ -0,0 +1,51 @@
package com.foreverwin.iep.integration.handler.def.oa;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.integration.constant.Msg;
import com.foreverwin.iep.integration.domain.InvokeRequest;
import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.iep.integration.service.HandlerService;
import com.foreverwin.iep.integration.utils.JS;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* 来料检验调用接口
*/
@AllArgsConstructor
@Service("OA_INCOMING_INSPECTION")
public class OAIncomingInspection implements HandlerService {
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
JSONObject messageContentjsonObject = JS.parseObject(invokeRequest.getMessageContent());
String jsonInputString = messageContentjsonObject.get(Msg.MESSAGE_CONTENT).toString(); // JSON 格式的请求数据
try {
// 统一调用 OA 接口
InvokeResponse invokeResponse = OAUtil.sendOA(jsonInputString);
if(!"E".equals(invokeResponse.getResult())){
// 请求处理成功
JSONArray jsonArray = JS.parseArray(invokeResponse.getMessageContent());
invokeResponse = new InvokeResponse();
invokeResponse.setTransSid(invokeRequest.getTransSid());
invokeResponse.setResult(Msg.S);
invokeResponse.setMessageContent(Msg.SUCCESS);
JSONObject jsonObject = jsonArray.getJSONObject(0);
if (!jsonObject.getBoolean("status")) {
invokeResponse.setResult(Msg.E);
invokeResponse.setMessageContent(jsonObject.getString("msg"));
}
}
return invokeResponse;
} catch (Exception e) {
return getDefaultInvoke().fail(invokeRequest.getTransSid(), e.getMessage());
}
}
@Override
public String validation(InvokeRequest invokeRequest) {
return null;
}
}

View File

@ -0,0 +1,79 @@
package com.foreverwin.iep.integration.handler.def.oa;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.iep.integration.utils.SSLUtil;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class OAUtil {
private static final String oaUrl = "/api/naliv/wf/createOrupdateWf";
private static final String WbpUrl = "https://agw.esb.nit.pub/oa/pip";
public static String appendHead(String jsonStr) {
JSONObject allJson = new JSONObject();
allJson.put("API_METHOD", "POST");
JSONObject json = JSONObject.parseObject(jsonStr);
allJson.put("API_DATA", json);
allJson.put("API_PATH", oaUrl);
return allJson.toJSONString();
}
public static JSONObject appendHead(JSONObject jsonObj) {
JSONObject allJson = new JSONObject();
allJson.put("API_METHOD", "POST");
allJson.put("API_DATA", jsonObj);
allJson.put("API_PATH", oaUrl);
return allJson;
}
public static InvokeResponse sendOA(String requestBody) {
InvokeResponse invokeResponse = new InvokeResponse();
invokeResponse.setResult("S");
try {
// 禁用 SSL 验证
SSLUtil.disableCertificateValidation();
// 创建 URL 对象
URL url = new URL(WbpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json"); // 设置内容类型
// 发送请求
try (OutputStream os = connection.getOutputStream()) {
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// 获取最终响应码
int finalResponseCode = connection.getResponseCode();
if (finalResponseCode == HttpURLConnection.HTTP_OK) {
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String inputLine;
StringBuilder responseBuild = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
responseBuild.append(inputLine);
}
invokeResponse.setMessageContent(String.valueOf(responseBuild));
return invokeResponse;
}
} else {
invokeResponse.setResult("E");
invokeResponse.setMessageContent(String.valueOf(finalResponseCode));
return invokeResponse;
}
} catch (Exception e) {
invokeResponse.setResult("E");
invokeResponse.setMessageContent(e.getMessage());
return invokeResponse;
}
}
}