From eabb757720375b74900027e23e50303b7e02ca36 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期二, 09 十二月 2025 17:04:23 +0800
Subject: [PATCH] 添加nacos配置中心,可动态更新mes导入工程接口;修改Excel表数据转json格式
---
mes-processes/mes-plcSend/src/main/resources/bootstrap.yml | 18 ++++++
mes-processes/mes-plcSend/src/main/java/com/mes/device/service/GlassInfoService.java | 7 ++
mes-processes/mes-plcSend/src/main/resources/application.yml | 4 -
mes-web/src/utils/constants.js | 2
mes-web/public/config.js | 4
mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/GlassInfoServiceImpl.java | 18 ++++-
mes-processes/mes-plcSend/pom.xml | 5 +
mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java | 28 +++++++--
mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue | 40 ++++++++----
9 files changed, 94 insertions(+), 32 deletions(-)
diff --git a/mes-processes/mes-plcSend/pom.xml b/mes-processes/mes-plcSend/pom.xml
index 2531051..5d6f460 100644
--- a/mes-processes/mes-plcSend/pom.xml
+++ b/mes-processes/mes-plcSend/pom.xml
@@ -27,6 +27,11 @@
<artifactId>serverBase</artifactId>
<version>1.0.0</version>
</dependency>
+ <dependency>
+ <groupId>com.alibaba.cloud</groupId>
+ <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
+ <version>2.1.4.RELEASE</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java
index cee3a46..f310f10 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java
@@ -3,11 +3,13 @@
import com.mes.device.service.GlassInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@@ -27,15 +29,13 @@
private final GlassInfoService glassInfoService;
private final RestTemplate restTemplate = new RestTemplate();
- @Value("${mes.engineering.import-url}")
- private String mesEngineeringImportUrl;
/**
* 瀵煎叆宸ョ▼
* 鍓嶇鍏ュ弬绀轰緥锛�
* {
* "excelRows": [
- * {"glassId":"GL001","width":"1000","height":"2000","thickness":"5","quantity":"2","orderNumber":"NG25082101","filmsId":"鐧界幓"}
+ * {"glassId":"GL001","width":"1000","height":"2000","thickness":"5","quantity":"2","flowCardId":"NG25082101","filmsId":"鐧界幓"}
* ]
* }
*/
@@ -54,12 +54,28 @@
Map<String, Object> payload = glassInfoService.buildEngineerImportPayload(excelRows);
log.info("鏋勫缓鐨� MES 瀵煎叆鏁版嵁: {}", payload);
+ String mesEngineeringImportUrl = glassInfoService.getMesEngineeringImportUrl();
+
try {
ResponseEntity<Map> mesResp = restTemplate.postForEntity(mesEngineeringImportUrl, payload, Map.class);
+ // 鐩存帴杩斿洖 MES 鐨勫搷搴旓紝璁╁墠绔牴鎹搷搴斾綋涓殑 code 瀛楁鍒ゆ柇鏄惁鎴愬姛
return ResponseEntity.status(mesResp.getStatusCode()).body(mesResp.getBody());
+ } catch (org.springframework.web.client.ResourceAccessException e) {
+ // 杩炴帴瓒呮椂鎴栨棤娉曡繛鎺�
+ log.error("杞彂 MES 瀵煎叆鎺ュ彛澶辫触锛堣繛鎺ラ棶棰橈級 url={}, error={}", mesEngineeringImportUrl, e.getMessage(), e);
+ Map<String, Object> errorResponse = new java.util.HashMap<>();
+ errorResponse.put("code", 500);
+ errorResponse.put("message", "鏃犳硶杩炴帴鍒� MES 鎺ュ彛锛岃妫�鏌ョ綉缁滆繛鎺ユ垨鑱旂郴绠$悊鍛�");
+ errorResponse.put("data", false);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
} catch (Exception e) {
+ // 鍏朵粬寮傚父
log.error("杞彂 MES 瀵煎叆鎺ュ彛澶辫触 url={}, error={}", mesEngineeringImportUrl, e.getMessage(), e);
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("杞彂 MES 澶辫触: " + e.getMessage());
+ Map<String, Object> errorResponse = new java.util.HashMap<>();
+ errorResponse.put("code", 500);
+ errorResponse.put("message", "杞彂 MES 澶辫触: " + e.getMessage());
+ errorResponse.put("data", false);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
}
}
}
diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/GlassInfoService.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/GlassInfoService.java
index 53a6f5c..497e6bd 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/GlassInfoService.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/GlassInfoService.java
@@ -76,6 +76,13 @@
*/
boolean updateGlassStatus(List<String> glassIds, String status);
+ /**
+ * 鑾峰彇 MES 宸ョ▼瀵煎叆 URL
+ *
+ * @return MES 宸ョ▼瀵煎叆 URL
+ */
+ String getMesEngineeringImportUrl();
+
/**
* 灏嗗墠绔笂浼犵殑 Excel 琛屾暟鎹浆鎹负 MES 瀵煎叆宸ョ▼鎵�闇�鐨� JSON 缁撴瀯
*
diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/GlassInfoServiceImpl.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/GlassInfoServiceImpl.java
index 5d8b503..9b1dd51 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/GlassInfoServiceImpl.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/GlassInfoServiceImpl.java
@@ -7,6 +7,8 @@
import com.mes.device.mapper.DeviceGlassInfoMapper;
import com.mes.device.service.GlassInfoService;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -27,6 +29,7 @@
* @since 2024-11-20
*/
@Slf4j
+@RefreshScope
@Service("deviceGlassInfoService")
public class GlassInfoServiceImpl extends ServiceImpl<DeviceGlassInfoMapper, GlassInfo> implements GlassInfoService {
@@ -212,6 +215,14 @@
}
}
+ @Value("${mes.engineering.import-url}")
+ private String mesEngineeringImportUrl;
+
+ @Override
+ public String getMesEngineeringImportUrl() {
+ return mesEngineeringImportUrl;
+ }
+
@Override
public Map<String, Object> buildEngineerImportPayload(List<Map<String, Object>> excelRows) {
Map<String, Object> result = new HashMap<>();
@@ -235,7 +246,6 @@
int qty = (int) parseDouble(row.getOrDefault("quantity", 1), 1);
if (qty <= 0) qty = 1;
String glassId = str(row.get("glassId"));
- Integer orderNumber = Integer.parseInt(str(row.get("orderNumber")));
String filmsId = strOrDefault(row.get("filmsId"), filmsIdDefaultFinal);
String flowCardId = str(row.get("flowCardId"));
String productName = str(row.get("productName"));
@@ -256,7 +266,6 @@
m.put("glassId", finalGlassId);
m.put("engineerId", engineerIdFinal);
m.put("flowCardId", finalFlowCardId);
- m.put("orderNumber", orderNumber);
m.put("productSortNumber", idx + 1);
m.put("hollowCombineDirection", "0");
m.put("width", width);
@@ -279,7 +288,7 @@
m.put("combine", 0);
m.put("markIcon", "");
m.put("filmRemove", 0);
- m.put("flowCardSequence", String.valueOf(idx + 1));
+ m.put("flowCardSequence", flowCardId + "/" + (idx + 1));
m.put("process", "");
m.put("rawAngle", 0);
m.put("graphNo", 0);
@@ -324,7 +333,7 @@
double height = parseDouble(row.get("height"), 0d);
double thickness = parseDouble(row.get("thickness"), thicknessDefaultFinal);
String filmsId = strOrDefault(row.get("filmsId"), filmsIdDefaultFinal);
- Integer orderNumber = Integer.parseInt(str(row.get("orderNumber")));
+
String productName = str(row.get("productName"));
String customerName = str(row.get("customerName"));
@@ -339,7 +348,6 @@
m.put("totalLayer", 0);
m.put("layer", 0);
m.put("glassTotal", 1);
- m.put("orderNumber", orderNumber);
m.put("productName", productName);
m.put("customerName", customerName);
flowCardMap.put(flowCardId, m);
diff --git a/mes-processes/mes-plcSend/src/main/resources/application.yml b/mes-processes/mes-plcSend/src/main/resources/application.yml
index 47da507..441232f 100644
--- a/mes-processes/mes-plcSend/src/main/resources/application.yml
+++ b/mes-processes/mes-plcSend/src/main/resources/application.yml
@@ -48,7 +48,3 @@
max-target: 100
min-glass-count: 1
max-glass-count: 50
-
-mes:
- width: 2800
- height: 5000
\ No newline at end of file
diff --git a/mes-processes/mes-plcSend/src/main/resources/bootstrap.yml b/mes-processes/mes-plcSend/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..9c30bc2
--- /dev/null
+++ b/mes-processes/mes-plcSend/src/main/resources/bootstrap.yml
@@ -0,0 +1,18 @@
+# bootstrap.yml 浼樺厛绾ч珮浜� application.yml锛屼粎閰嶇疆Nacos鏍稿績杩炴帴
+spring:
+ application:
+ name: plcSend # 蹇呴』鍜宎pplication.yml涓殑name瀹屽叏涓�鑷�
+ cloud:
+ nacos:
+ config:
+ server-addr: 127.0.0.1:8848 # 鏇挎崲涓轰綘鐨凬acos鏈嶅姟绔疘P+绔彛锛堣繍缁存彁渚涳級
+ file-extension: yml # 閰嶇疆鏂囦欢鏍煎紡锛堝拰鏈湴淇濇寔涓�鑷达級
+ group: DEFAULT_GROUP # 榛樿鍒嗙粍锛屾棤闇�淇敼锛堝彲鎸夌幆澧冩敼濡侱EV_GROUP锛�
+ profiles:
+ active: dev
+
+# 鍙�夛細鍏抽棴Nacos閰嶇疆缂撳瓨锛堝紑鍙戠幆澧冪敤锛岀敓浜ч粯璁ゅ嵆鍙級
+# nacos:
+# config:
+# refresh-enabled: true
+# cache-time: 5000 # 閰嶇疆鎷夊彇闂撮殧锛堟绉掞級
\ No newline at end of file
diff --git a/mes-web/public/config.js b/mes-web/public/config.js
index 8a36ade..c92c07b 100644
--- a/mes-web/public/config.js
+++ b/mes-web/public/config.js
@@ -1,5 +1,5 @@
-const ip = '127.0.0.1'
-// const ip = '10.153.19.6'
+// const ip = '127.0.0.1'
+const ip = '10.153.19.192'
// const ip = '10.100.0.183'
// const ip = '192.168.2.8'
window.ipConfig = {
diff --git a/mes-web/src/utils/constants.js b/mes-web/src/utils/constants.js
index d33355f..44df4e3 100644
--- a/mes-web/src/utils/constants.js
+++ b/mes-web/src/utils/constants.js
@@ -1,6 +1,6 @@
// export const WebSocketHost = "10.153.19.150";
// export const WebSocketHost = "172.17.2.7";
-export const WebSocketHost = "10.153.19.225";//hxl
+export const WebSocketHost = "10.153.19.166";//hxl
// export const WebSocketHost = "10.153.19.2";//zt
//export const WebSocketHost = "10.153.19.20";//wsx
// export const WebSocketHost = "127.0.0.1";
diff --git a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
index 8b669ce..3021519 100644
--- a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
+++ b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
@@ -323,7 +323,7 @@
return
}
- // 鍙戦�佹暟鎹埌 MES 鎺ュ彛
+ // 鍙戦�佹暟鎹�
submitGlassData(parsedData)
} catch (error) {
@@ -391,11 +391,6 @@
headerStr.includes('qty') || headerStr === '鏁伴噺') {
headerMap.quantity = index
}
- // 璁㈠崟鍙�
- else if (headerStr.includes('璁㈠崟') || headerStr.includes('order') ||
- headerStr.includes('orderno') || headerStr === '璁㈠崟鍙�') {
- headerMap.orderNumber = index
- }
// 鑶滅郴
else if (headerStr.includes('鑶滅郴') || headerStr.includes('films') ||
headerStr.includes('film') || headerStr === '鑶滅郴id') {
@@ -439,8 +434,6 @@
const height = row[headerMap.height] ? String(row[headerMap.height]).trim() : ''
const thickness = row[headerMap.thickness] ? String(row[headerMap.thickness]).trim() : ''
const quantity = row[headerMap.quantity] ? String(row[headerMap.quantity]).trim() : ''
- // 璁㈠崟搴忓彿锛堟帴鍙h姹傛暣鏁帮紝杩欓噷灏濊瘯瑙f瀽涓烘暣鏁帮紝涓嶅彲瑙f瀽鍒欑疆绌猴級
- const orderNumber = parseInt(row[headerMap.orderNumber]) || ''
const filmsId = row[headerMap.filmsId] ? String(row[headerMap.filmsId]).trim() : ''
const flowCardId = row[headerMap.flowCardId] ? String(row[headerMap.flowCardId]).trim() : ''
const productName = row[headerMap.productName] ? String(row[headerMap.productName]).trim() : ''
@@ -476,7 +469,6 @@
height: parseNumber(height),
thickness: parseNumber(thickness),
quantity: '1', // 姣忔潯璁板綍鏁伴噺涓�1
- orderNumber: orderNumber,
filmsId: filmsId,
flowCardId: flowCardId || finalGlassId,
productName: productName,
@@ -506,8 +498,15 @@
const response = await engineeringApi.importEngineer(requestData)
- if (response?.code === 200 || response?.code === 0 || response?.data) {
- ElMessage.success(`鎴愬姛瀵煎叆 ${glassDataList.length} 鏉$幓鐠冩暟鎹紝宸ョ▼鍙凤細${requestData.engineerId}`)
+ // 妫�鏌� MES 鎺ュ彛鏄惁璋冪敤鎴愬姛
+ // MES 鎺ュ彛鎴愬姛鏃惰繑鍥炴牸寮忥細{ code: 200/0, data: true/false, message: "..." }
+ if (response?.code === 200 || response?.code === 0) {
+ // MES 鎺ュ彛璋冪敤鎴愬姛
+ const engineerId = response?.data?.engineerId || response?.engineerId || ''
+ const successMsg = engineerId
+ ? `鎴愬姛瀵煎叆 ${glassDataList.length} 鏉$幓鐠冩暟鎹紝宸ョ▼鍙凤細${engineerId}`
+ : `鎴愬姛瀵煎叆 ${glassDataList.length} 鏉$幓鐠冩暟鎹甡
+ ElMessage.success(successMsg)
// 灏嗗鍏ョ殑鐜荤拑ID濉厖鍒拌緭鍏ユ锛屾柟渚跨敤鎴锋煡鐪嬪拰缂栬緫
const glassIds = glassDataList.map(item => item.glassId).filter(id => id)
@@ -515,13 +514,26 @@
glassIdsInput.value = glassIds.join('\n')
}
} else {
- throw new Error(response?.message || '瀵煎叆澶辫触')
+ // MES 鎺ュ彛杩斿洖澶辫触
+ throw new Error(response?.message || 'MES 鎺ュ彛杩斿洖澶辫触')
}
} catch (error) {
console.error('鎻愪氦鐜荤拑鏁版嵁澶辫触:', error)
- // 鏄剧ず閿欒淇℃伅
- const errorMsg = error?.response?.data?.message || error?.message || '鏈煡閿欒'
+ // 鍒ゆ柇閿欒绫诲瀷锛岀粰鍑烘洿鍙嬪ソ鐨勬彁绀�
+ let errorMsg = '鏈煡閿欒'
+
+ // 妫�鏌ユ槸鍚︽槸鍚庣杩斿洖鐨勯敊璇搷搴旓紙鍚庣杞彂 MES 澶辫触锛�
+ if (error?.response?.status === 500 && error?.response?.data) {
+ // 鍚庣杩斿洖鐨勭粺涓�閿欒鏍煎紡
+ errorMsg = error.response.data.message || error.response.data || '杞彂 MES 鎺ュ彛澶辫触'
+ } else if (error?.response?.data?.message) {
+ // MES 鎺ュ彛杩斿洖鐨勯敊璇�
+ errorMsg = error.response.data.message
+ } else if (error?.message) {
+ errorMsg = error.message
+ }
+
ElMessage.error('鎻愪氦鏁版嵁澶辫触: ' + errorMsg)
// 鍗充娇澶辫触锛屼篃灏濊瘯濉厖鐜荤拑ID鍒拌緭鍏ユ
--
Gitblit v1.8.0