This commit is contained in:
syngna_qiao 2024-11-29 16:28:52 +08:00
commit 4af3f4906f
9 changed files with 265 additions and 2 deletions

View File

@ -22,6 +22,8 @@ public class Msg {
public static final String AGV = "AGV";
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;
@ -224,4 +225,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

@ -71,9 +71,11 @@ public class ShopOrderStatisticTransController {
InvokeResponse invokeResponse = new InvokeResponse();
String site = TenantContextHolder.getTenantId();
List<ZShoporderStatisticsTransaction> newList = new ArrayList<>();
String bat = SapUtil.noPrefixGenerateReqId();
for (ZShoporderStatisticsTransaction soStatisticsTrans : shoporderStatisticsTransactionList) {
soStatisticsTrans.setSid(UUID.randomUUID().toString());
soStatisticsTrans.setSite(site);
soStatisticsTrans.setSyncTransBatch(bat);
soStatisticsTrans.setCreator(SecurityUtils.getUserName());
soStatisticsTrans.setDateCreate(LocalDateTime.now());
soStatisticsTrans.setConfirmedDate(LocalDateTime.now());
@ -345,11 +347,13 @@ public class ShopOrderStatisticTransController {
String result = outJson.getString("MSGTY");
String message = outJson.getString("MSGTX");
String msgno = outJson.getString("MSGNO"); // 系统消息编号
String mblnr = outJson.getString("MBLNR"); // 物料凭证编号
for (ZLotMaterialConsumptionTransaction targetObj : srcList) {
targetObj.setSyncStatus(result);
targetObj.setSyncMsgText(message);
targetObj.setSyncMsgNo(msgno);
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
targetObj.setSyncVoucherNo(mblnr);
targetObj.setCreator(SecurityUtils.getUserName());
targetObj.setDateCreate(LocalDateTime.now());
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);

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;
}
}
}

View File

@ -0,0 +1,69 @@
package com.foreverwin.iep.integration.handler.def.sap;
import cn.hutool.core.util.ObjectUtil;
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("SAP_INCOMING_INSPECTION")
public class SapIncomingInspection implements HandlerService {
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
JSONObject messageContentjsonObject = JS.parseObject(invokeRequest.getMessageContent());
String jsonInputString = messageContentjsonObject.get(Msg.MESSAGE_CONTENT).toString(); // JSON 格式的请求数据
try {
// 统一调用 SAP 接口
InvokeResponse invokeResponse = SapUtil.sendSap(jsonInputString);
if(!"E".equals(invokeResponse.getResult())){
// 请求处理成功
JSONObject jsonObject = JS.parseObject(invokeResponse.getMessageContent());
invokeResponse = new InvokeResponse();
invokeResponse.setTransSid(invokeRequest.getTransSid());
invokeResponse.setResult(Msg.S);
invokeResponse.setMessageContent(Msg.SUCCESS);
JSONObject responseContextJson = jsonObject.getJSONObject("RESPONSE_CONTEXT");
if ("200".equals(responseContextJson.getString("RFC_CODE"))) {
JSONObject responseBodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
if (ObjectUtil.isNotEmpty(responseBodyJson)) {
JSONObject esReturnJson = responseBodyJson.getJSONObject("ES_RETURN");
if (esReturnJson != null) {
String msgty = esReturnJson.getString("MSGTY");
if (Msg.E.equals(msgty)) {
invokeResponse.setResult(Msg.E);
}
invokeResponse.setMessageContent(esReturnJson.getString("MSGTX"));
} else {
invokeResponse.setResult(Msg.E);
invokeResponse.setMessageContent("ERP接口调用返回ES_RETURN无数据!");
}
} else {
invokeResponse.setResult(Msg.E);
invokeResponse.setMessageContent("ERP接口调用返回RESPONSE_BODY无数据!");
}
} else {
invokeResponse.setResult(Msg.E);
invokeResponse.setMessageContent(responseContextJson.getString("RFC_REASON"));
}
}
return invokeResponse;
} catch (Exception e) {
return getDefaultInvoke().fail(invokeRequest.getTransSid(), e.getMessage());
}
}
@Override
public String validation(InvokeRequest invokeRequest) {
return null;
}
}

View File

@ -120,4 +120,14 @@ public class SapUtil {
// 组合成业务流水号
return "REQ_" + timestamp + String.format("%03d", randomNumber);
}
public static String noPrefixGenerateReqId() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
// 生成时间戳部分
String timestamp = dateFormat.format(new Date());
// 生成随机数部分
int randomNumber = ThreadLocalRandom.current().nextInt(1000);
// 组合成业务流水号
return timestamp + String.format("%03d", randomNumber);
}
}

View File

@ -59,9 +59,8 @@ public class ShopOrderStatisticTransService implements HandlerService {
if (shoporderStatisticsTransaction != null) {
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
shoporderStatisticsTransaction.setSyncTransBatch(outJson.getString("RUECK"));
shoporderStatisticsTransaction.setSyncTicketLine(outJson.getString("RMZHL"));
shoporderStatisticsTransaction.setSyncTicketNo(outJson.getString("VORNR"));
shoporderStatisticsTransaction.setSyncTicketNo(outJson.getString("RUECK"));
String result = outJson.getString("MSGTY");
invokeResponse.setResult(result);
shoporderStatisticsTransaction.setSyncStatus(result);