feat(integration): 新增 基膜打印相关接口实现
- 新增获取打印模板接口 GET_PRINT_TABLE- 实现从远程参数获取打印模板数据- 添加打印模板名称提取功能 - 新增启动打印接口 JM_START_PRINTING- 实现向远程服务发送打印指令 - 添加打印结果状态处理逻辑 - 在集成服务常量中注册新接口标识
This commit is contained in:
parent
087b5f1f04
commit
c20aaf0ec6
@ -26,4 +26,8 @@ public class IntegrationSrv {
|
||||
public static final String QUALITY_TRACEABILITY = "QUALITY_TRACEABILITY";
|
||||
|
||||
public static final String SAP_DELETE_DELIVERY = "SAP_DELETE_DELIVERY";
|
||||
|
||||
public static final String GET_PRINT_TABLE = "GET_PRINT_TABLE";
|
||||
|
||||
public static final String JM_START_PRINTING = "JM_START_PRINTING";
|
||||
}
|
||||
|
||||
@ -0,0 +1,98 @@
|
||||
package com.foreverwin.iep.integration.handler.def.JMPrinter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.Local;
|
||||
import com.foreverwin.mom.admin.api.feign.RemoteParamService;
|
||||
import com.foreverwin.mom.common.core.constant.SecurityConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yTang
|
||||
* <p>
|
||||
* 2025/9/19 16:08
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("GET_PRINT_TABLE")
|
||||
public class GetPrintTable implements HandlerService {
|
||||
|
||||
private final RemoteParamService remoteParamService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
String url = remoteParamService.getByKey("JM_PRINT_TABLE", SecurityConstants.FROM_IN).getData();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
invokeResponse.setResult("S");
|
||||
|
||||
if(StrUtil.isNotBlank(url)){
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
// 改成 GET
|
||||
HttpGet getRequest = new HttpGet(url);
|
||||
getRequest.setHeader("Accept", "application/json");
|
||||
|
||||
try (CloseableHttpResponse response = httpClient.execute(getRequest)) {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != 200) {
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), responseBody);
|
||||
}
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
System.out.println("获取打印模板响应日志:"+responseString);
|
||||
|
||||
// 如果仍然要提取原始请求里的 name
|
||||
List<String> labelNames = extractNames(responseString);
|
||||
if (!labelNames.isEmpty()){
|
||||
invokeResponse.setMessageContent(labelNames.toString());
|
||||
} else {
|
||||
invokeResponse.setResult("E");
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
public static List<String> extractNames(String jsonStr) throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root = mapper.readTree(jsonStr);
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
// 这里根据你提供的结构:data -> list -> 每个对象里有 name
|
||||
JsonNode listNode = root.path("data").path("list");
|
||||
if (listNode.isArray()) {
|
||||
for (JsonNode node : listNode) {
|
||||
JsonNode nameNode = node.get("name");
|
||||
if (nameNode != null && !nameNode.isNull()) {
|
||||
names.add(nameNode.asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String validation(InvokeRequest invokeRequest) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.foreverwin.iep.integration.handler.def.JMPrinter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.Local;
|
||||
import com.foreverwin.mom.admin.api.feign.RemoteParamService;
|
||||
import com.foreverwin.mom.common.core.constant.SecurityConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author yTang
|
||||
* <p>
|
||||
* 2025/9/22 15:52
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service("JM_START_PRINTING")
|
||||
public class JMStartPrinting implements HandlerService {
|
||||
|
||||
private final RemoteParamService remoteParamService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
String url = remoteParamService.getByKey("JM_START_PRINTING", SecurityConstants.FROM_IN).getData();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
invokeResponse.setResult("S");
|
||||
if(StrUtil.isNotBlank(url)){
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
HttpPost postRequest = new HttpPost(url);
|
||||
|
||||
postRequest.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
|
||||
String messageContent = invokeRequest.getMessageContent();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(objectMapper.readTree(messageContent)));
|
||||
stringEntity.setContentType("application/json");
|
||||
postRequest.setEntity(stringEntity);
|
||||
|
||||
try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != 200) {
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), responseBody);
|
||||
}
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
System.out.println("手动调用熟化间任务日志:"+responseString);
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
if(responseJson.get("success").asBoolean(true)) {
|
||||
invokeResponse.setMessageContent(responseJson.get("message").asText());
|
||||
} else {
|
||||
invokeResponse.setResult("E");
|
||||
}
|
||||
return invokeResponse;
|
||||
} catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String validation(InvokeRequest invokeRequest) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user