From b2deb1cc93b3d2c3fb9dc795e3589e1c62329a8f Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期一, 23 三月 2026 14:07:29 +0800
Subject: [PATCH] lsh#站点同步至MES
---
rsf-server/src/main/java/com/vincent/rsf/server/api/entity/constant/RcsConstant.java | 3 +
rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java | 4 +
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/SynchronizationToMESSchedules.java | 131 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/entity/constant/RcsConstant.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/entity/constant/RcsConstant.java
index 120064a..9501d6f 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/api/entity/constant/RcsConstant.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/entity/constant/RcsConstant.java
@@ -18,5 +18,8 @@
//寰呬笅鍙戜换鍔″彂閫佽嚦涓浆绔�
public static String MISSION_TRANSFER_STATION = "/rsf-open-api/mission/task/master/control";
+
+ //绔欑偣淇℃伅鍚屾鑷矼ES
+ public static String SITE_SYNCHRONIZATION_TO_MES = "/rsf-open-api/mes/syncStationInfo";
}
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/SynchronizationToMESSchedules.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/SynchronizationToMESSchedules.java
new file mode 100644
index 0000000..2bdda34
--- /dev/null
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/SynchronizationToMESSchedules.java
@@ -0,0 +1,131 @@
+package com.vincent.rsf.server.manager.schedules;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.vincent.rsf.framework.common.Cools;
+import com.vincent.rsf.framework.exception.CoolException;
+import com.vincent.rsf.server.api.config.RemotesInfoProperties;
+import com.vincent.rsf.server.api.entity.CommonResponse;
+import com.vincent.rsf.server.api.entity.constant.RcsConstant;
+import com.vincent.rsf.server.manager.entity.BasStation;
+import com.vincent.rsf.server.manager.service.impl.BasStationServiceImpl;
+import com.vincent.rsf.server.system.constant.GlobalConfigCode;
+import com.vincent.rsf.server.system.entity.Config;
+import com.vincent.rsf.server.system.service.ConfigService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @author Munch D. Luffy
+ * @date 2026/03/23
+ * 鑷姩鍚屾鑷矼ES
+ */
+@Slf4j
+@Component
+public class SynchronizationToMESSchedules {
+
+ @Autowired
+ private ConfigService configService;
+ @Autowired
+ private BasStationServiceImpl basStationService;
+ @Autowired
+ private RestTemplate restTemplate;
+ @Autowired
+ private RemotesInfoProperties.WmsOpenApi wmsOpenApi;
+
+ /**
+ * @author Munch D. Luffy
+ * @date 2026/01/15
+ * @description: 缂撳瓨鍖哄煙鑷姩鐢熸垚绉诲簱浠诲姟
+ * @version 1.0
+ */
+ @Scheduled(cron = "0 0/01 * * * ? ")
+ @Transactional(rollbackFor = Exception.class)
+ public void siteSynchronizationToMES() throws Exception {
+ Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_SITE_SYNCHRONIZATION_TO_MES));
+ if (Cools.isEmpty(config) || !Boolean.parseBoolean(config.getVal())) {
+ return;
+ }
+
+ String autoSiteSynchronizationToMesValue = configService.getVal(GlobalConfigCode.AUTO_SITE_SYNCHRONIZATION_TO_MES_VALUE, String.class);
+ if (Cools.isEmpty(autoSiteSynchronizationToMesValue)) {
+ return;
+ }
+ Integer autoValue = Integer.parseInt(autoSiteSynchronizationToMesValue);
+ if (autoValue < 0) {
+ List<BasStation> basStationList = basStationService.list();
+ syncStationsToMes(basStationList);
+ } else if (autoValue > 0) {
+ List<BasStation> basStationList = basStationService.list();
+ syncStationsToMes(basStationList);
+ autoValue = autoValue - 1;
+ configService.setVal(GlobalConfigCode.AUTO_SITE_SYNCHRONIZATION_TO_MES_VALUE, String.valueOf(autoValue));
+ } else {
+ configService.setVal(GlobalConfigCode.AUTO_SITE_SYNCHRONIZATION_TO_MES, false);
+ }
+ }
+
+ private void syncStationsToMes(List<BasStation> basStationList) {
+ if (Cools.isEmpty(basStationList)) {
+ log.info("绔欑偣鍚屾鑷矼ES璺宠繃锛氱珯鐐瑰垪琛ㄤ负绌�");
+ return;
+ }
+ if (Cools.isEmpty(wmsOpenApi) || Cools.isEmpty(wmsOpenApi.getHost()) || Cools.isEmpty(wmsOpenApi.getPort())) {
+ throw new CoolException("open-api閰嶇疆缂哄け锛屾棤娉曞悓姝ョ珯鐐逛俊鎭埌MES");
+ }
+
+ List<Map<String, Object>> params = new ArrayList<>();
+ for (BasStation basStation : basStationList) {
+ if (Cools.isEmpty(basStation) || Cools.isEmpty(basStation.getStationName())) {
+ continue;
+ }
+ Map<String, Object> item = new HashMap<>();
+ item.put("ConnPortCode", basStation.getStationName());
+ item.put("ConnPortName", Cools.isEmpty(basStation.getStationId()) ? basStation.getStationName() : basStation.getStationId());
+ item.put("WorkshopCode", "YZ");
+ item.put("WorkshopName", "閾跺骇杞﹂棿");
+ item.put("ProductionLineCode", "YZ");
+ item.put("ProductionLineName", "閾跺骇浠撳簱");
+ item.put("CreatedBy", "WMSSystem");
+ item.put("IsValid", Objects.equals(basStation.getStatus(), 1));
+ params.add(item);
+ }
+
+ if (params.isEmpty()) {
+ log.info("绔欑偣鍚屾鑷矼ES璺宠繃锛氭棤鍙悓姝ョ珯鐐规暟鎹�");
+ return;
+ }
+
+ String url = wmsOpenApi.getHost() + ":" + wmsOpenApi.getPort() + RcsConstant.SITE_SYNCHRONIZATION_TO_MES;
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("Content-Type", "application/json");
+ headers.add("api-version", "v2.0");
+ HttpEntity<List<Map<String, Object>>> httpEntity = new HttpEntity<>(params, headers);
+
+ log.info("绔欑偣鍚屾鑷矼ES寮�濮嬶紝璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁版潯鏁帮細{}", url, params.size());
+ ResponseEntity<CommonResponse> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, CommonResponse.class);
+ CommonResponse body = response.getBody();
+ log.info("绔欑偣鍚屾鑷矼ES杩斿洖缁撴灉锛歿}", JSONObject.toJSONString(body));
+
+ if (Cools.isEmpty(body)) {
+ throw new CoolException("绔欑偣鍚屾鑷矼ES澶辫触锛氳繑鍥炵粨鏋滀负绌�");
+ }
+ if (!Objects.equals(body.getCode(), 200)) {
+ throw new CoolException("绔欑偣鍚屾鑷矼ES澶辫触锛�" + body.getMsg());
+ }
+ }
+}
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java b/rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java
index 77af9af..9ba59a7 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java
@@ -30,6 +30,10 @@
/*鍒濆浠诲姟鑷姩瑙勫垝璺緞*/
public final static String AUTO_TEMPLATE_PLANNING_STEP_FLOW = "AUTO_TEMPLATE_PLANNING_STEP_FLOW";
+ /*绔欑偣鍚屾鑷矼ES*/
+ public final static String AUTO_SITE_SYNCHRONIZATION_TO_MES = "AUTO_SITE_SYNCHRONIZATION_TO_MES";
+ public final static String AUTO_SITE_SYNCHRONIZATION_TO_MES_VALUE = "AUTO_SITE_SYNCHRONIZATION_TO_MES_VALUE";
+
}
--
Gitblit v1.9.1