From 7a8ce5a3760aa10a8109f9d34f13d19652975404 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期日, 29 十二月 2024 20:06:56 +0800
Subject: [PATCH] 1、erp报工接口改造,ip改为配置
---
hangzhoumesParent/common/servicebase/src/main/java/com/mes/damage/service/impl/DamageServiceImpl.java | 85 +++---------------------------------------
1 files changed, 6 insertions(+), 79 deletions(-)
diff --git a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/damage/service/impl/DamageServiceImpl.java b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/damage/service/impl/DamageServiceImpl.java
index a4bc42f..85d0136 100644
--- a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/damage/service/impl/DamageServiceImpl.java
+++ b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/damage/service/impl/DamageServiceImpl.java
@@ -20,8 +20,8 @@
import com.mes.work_assignment.mapper.WorkAssignmentMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.io.BufferedReader;
@@ -54,8 +54,8 @@
@Resource
WorkAssignmentMapper workAssignmentMapper;
- @Resource
- RestTemplate restTemplate;
+ @Value("${mes.glassGap}")
+ private String erpUrl;
/**
@@ -170,7 +170,7 @@
}
@Override
- public void autoSubmitReport(String glassId, int deviceId, String workingProcedure, String remark,int type) {
+ public void autoSubmitReport(String glassId, int deviceId, String workingProcedure, String remark, int type) {
Damage damage = new Damage();
damage.setGlassId(glassId);
damage.setWorkingProcedure(workingProcedure);
@@ -180,6 +180,7 @@
damage.setStatus(0);
this.insertDamage(damage);
}
+
/**
* 娣诲姞鎶ュ伐淇℃伅
*/
@@ -307,7 +308,7 @@
log.info("鎶ュ伐鏁版嵁reportingWork锛歿}锛宺eportingWorkDetails锛歿}", reportingWork, reportingWorkDetails);
try {
// 鐩爣绯荤粺鐨凙PI URL
- String url = "http://192.168.2.100:8086/reportingWork/mesSaveReportingWorkWorn";
+ String url = erpUrl + "/reportingWork/mesReportingWork";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
@@ -369,80 +370,6 @@
return false;
}
}
-
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public Boolean sendToERPRest(ReportingWork reportingWork, List<ReportingWorkDetail> reportingWorkDetails) {
- log.info("鎶ュ伐鏁版嵁reportingWork锛歿}锛宺eportingWorkDetails锛歿}", reportingWork, reportingWorkDetails);
- try {
- // 鐩爣绯荤粺鐨凙PI URL
- String url = "http://192.168.2.100:8086/reportingWork/mesSaveReportingWorkWorn";
- URL obj = new URL(url);
- HttpURLConnection con = (HttpURLConnection) obj.openConnection();
-
- // 璁剧疆璇锋眰鏂规硶鍜岃姹傚ご
- con.setRequestMethod("POST");
- con.setRequestProperty("Content-Type", "application/json; utf-8");
- con.setRequestProperty("Accept", "application/json");
- con.setDoOutput(true);
-
- // 鍒涘缓 JSON 瀵硅薄
- JSONObject result = new JSONObject();
-
- ObjectMapper objectMapper = new ObjectMapper();
-
- // 灏� ReportingWork 杞崲涓� JSONObject
- JSONObject reportingWorkJson = new JSONObject(objectMapper.writeValueAsString(reportingWork));
- reportingWorkJson.put("reportingWorkTime", reportingWork.getReportingWorkTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
- // 灏� ReportingWorkDetail 鍒楄〃杞崲涓� JSONArray
- JSONArray detailsJsonArray = new JSONArray(objectMapper.writeValueAsString(reportingWorkDetails));
-
- // 灏� JSON 瀵硅薄鍜屾暟缁勬坊鍔犲埌缁撴灉瀵硅薄涓�
- result.put("title", reportingWorkJson);
- result.put("detail", detailsJsonArray);
- result.put("type", 0);
- result.put("userId", "admin");
- result.put("userName", "admin");
- result.put("qualityInsStatus", 0);
-
- // 灏� result 瀵硅薄杞崲涓哄瓧绗︿覆
- String jsonInputString = result.toString();
- System.out.println("jsonInputString : " + result);
- // 鍙戦�佽姹�
- try (OutputStream os = con.getOutputStream()) {
- byte[] input = jsonInputString.getBytes("utf-8");
- os.write(input, 0, input.length);
- }
-
- // 鑾峰彇鍝嶅簲鐮�
- int responseCode = con.getResponseCode();
- System.out.println("Response Code : " + responseCode);
-
- // 鑾峰彇鍝嶅簲鍐呭
- try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) {
- StringBuilder response = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- response.append(inputLine);
- }
- // 瑙f瀽鍝嶅簲鍐呭
- JSONObject jsonResponse = new JSONObject(response.toString());
-
- // 鎻愬彇 code 鍜� message
- int code = jsonResponse.getInt("code");
- String message = jsonResponse.getStr("data");
- log.info("鎶ュ伐澶辫触锛歿},{}", code, message);
- if (code == 200 && message.equals("true")) {
- return true;
- } else {
- return false;
- }
- }
-
} catch (Exception e) {
e.printStackTrace();
return false;
--
Gitblit v1.8.0