From 66517edf1de22c8203daa256abffddae43bae704 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 16 十月 2026 17:58:28 +0800
Subject: [PATCH] feat(mes): 袋码绑定托盘免先录生产批次
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/framework/config/MesQrCodeConfig.java | 89 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 1 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/framework/config/MesQrCodeConfig.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/framework/config/MesQrCodeConfig.java
index d4da7f7..c025482 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/framework/config/MesQrCodeConfig.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/framework/config/MesQrCodeConfig.java
@@ -1,22 +1,109 @@
package cn.iocoder.yudao.module.mes.framework.config;
+import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.mes.framework.qrcode.MesProQrLabelBuilder;
+import cn.iocoder.yudao.module.mes.framework.qrcode.QrCodeImageUtils;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+
+import java.util.Arrays;
/**
- * MES 浜岀淮鐮佺浉鍏抽厤缃細鍚姩鏃跺皢 traceBaseUrl 娉ㄥ叆浜岀淮鐮佹爣绛炬瀯寤哄櫒锛岄伩鍏嶄镜鍏� Controller 璋冪敤鐐�
+ * MES 浜岀淮鐮佺浉鍏抽厤缃細鍚姩鏃舵牎楠屽苟鎶婇厤缃敞鍏ヤ簩缁寸爜鏍囩鏋勫缓鍣紝閬垮厤渚靛叆 Controller 璋冪敤鐐广��
+ * <p>
+ * 绉嶅瓙鏍囩灞炰簬鍙楀浗鏍囩害鏉熺殑鍚堣鐗╂枡锛屼竴鏃﹀嵃鍑哄嵆鏃犳硶鍙洖锛屽洜姝よ繖閲岄噰鍙栥�屽惎鍔ㄥ嵆鏍¢獙銆佷笉鍚堟硶鍗虫嫆缁濆惎鍔ㄣ��
+ * 鐨勭瓥鐣ワ紝鑰屼笉鏄瓑鍒板鍑烘椂鎵嶅け璐ユ垨闈欓粯闄嶇骇锛�
+ * <ul>
+ * <li>杩芥函缃戝潃蹇呴』涓哄叕浼楀彲璁块棶鍦板潃锛岀姝㈠唴缃� IP / 鏈満鍦板潃 / 鏈浛鎹㈢殑鍗犱綅绗︼紱</li>
+ * <li>鐢熶骇缁忚惀鑰呭悕绉板繀濉紙鏍囩鍥涜绱犱箣涓�锛岀己澶卞嵆涓轰笉鍚堣鏍囩锛夛紱</li>
+ * <li>褰撳墠鐜蹇呴』瀛樺湪鍙覆鏌撲腑鏂囩殑瀛椾綋锛堝惁鍒欐爣绛句腑鏂囦細鍙樻垚鏂规锛夈��</li>
+ * </ul>
+ * 杩芥函缃戝潃涓庣敓浜х粡钀ヨ�呭悕绉扮殑**杩愯鏃�**鍙栧�间紭鍏堟潵鑷瓧鍏� {@code mes_trace_config}锛�
+ * 鍙湪绠$悊鍚庡彴銆屽瓧鍏哥鐞嗐�嶄腑淇敼鑰屾棤闇�閲嶅惎锛涢厤缃枃浠剁殑鍊奸��灞呬负鍏滃簳榛樿鍊笺��
+ * <p>
+ * 浣嗗惎鍔ㄦ牎楠�**鍙拡瀵归厤缃枃浠�**锛屽師鍥犳湁浜岋細涓�鏄繖閬撻槻绾垮繀椤诲湪鏁版嵁搴撳彲鐢ㄤ箣鍓嶅氨鑳芥嫤浣忎笉鍚堣閰嶇疆锛�
+ * 浜屾槸 @PostConstruct 闃舵涓嶅簲璁块棶鏁版嵁搴撱�傚瓧鍏稿�肩殑鍚堣鏍¢獙鐢� {@link MesTraceConfigResolver}
+ * 鍦ㄨ鍙栨椂瀹屾垚锛堥潪娉曞垯璁� ERROR 骞跺洖閫�閰嶇疆鏂囦欢锛岃璇ョ被娉ㄩ噴锛夈��
*/
+@Slf4j
@Configuration(proxyBeanMethods = false)
public class MesQrCodeConfig {
+
+ /**
+ * 鏈湴鐜 profile 鍚嶏細璇� profile 涓嬫斁瀹芥牎楠岋紝渚夸簬鏈湴寮�鍙戣皟璇�
+ */
+ private static final String PROFILE_LOCAL = "local";
@Resource
private MesProperties mesProperties;
+ @Resource
+ private Environment environment;
+
+ @Resource
+ private MesTraceConfigResolver mesTraceConfigResolver;
+
@PostConstruct
public void init() {
+ // 1. 娉ㄥ叆閰嶇疆鏂囦欢鐨勫�硷紙瀛椾綋鏍¢獙鐙珛浜庝笟鍔¢厤缃紝鏈湴鐜鍚屾牱蹇呴』閫氳繃锛屽惁鍒欐爣绛句腑鏂囦笉鍙锛�
MesProQrLabelBuilder.setTraceBaseUrl(mesProperties.getTraceBaseUrl());
+ MesProQrLabelBuilder.setOperatorName(mesProperties.getOperatorName());
+ MesProQrLabelBuilder.setImporterName(mesProperties.getImporterName());
+ MesProQrLabelBuilder.setImported(mesProperties.isImported());
+ MesProQrLabelBuilder.setAllowPlainQrCode(mesProperties.isAllowPlainQrCode());
+ QrCodeImageUtils.assertCjkFontAvailable();
+
+ // 2. 鏍¢獙閰嶇疆鏂囦欢銆備笅闈㈢殑鏍¢獙涓庢棩蹇楅兘蹇呴』璇婚厤缃枃浠剁殑鍊硷紝鍥犳瀛楀吀鏉ユ簮涓嶈兘鍦ㄦ涔嬪墠瑁呴厤
+ if (isLocalProfile()) {
+ log.info("[init] 褰撳墠涓烘湰鍦扮幆澧冿紙{}锛夛紝璺宠繃鏍囩鍚堣閰嶇疆鐨勪弗鏍兼牎楠岋紱閰嶇疆鏂囦欢 traceBaseUrl={}",
+ PROFILE_LOCAL, mesProperties.getTraceBaseUrl());
+ } else {
+ validateTraceBaseUrl();
+ validateOperatorName();
+ log.info("[init] 浜岀淮鐮佹爣绛鹃厤缃牎楠岄�氳繃锛涢厤缃枃浠� traceBaseUrl={}锛岀敓浜х粡钀ヨ��={}",
+ mesProperties.getTraceBaseUrl(), MesProQrLabelBuilder.resolveOperatorName());
+ }
+
+ // 3. 鏈�鍚庤閰嶅瓧鍏告潵婧愶細姝ゅ悗 resolveTraceUrl()/resolveOperatorName() 浼樺厛璧板瓧鍏�
+ // 锛堝瓧鍏告湭閰嶇疆鍒欒嚜鍔ㄥ洖閫�閰嶇疆鏂囦欢锛夈�傛澶勫彧瑁呴厤鏂规硶寮曠敤銆佺粷涓嶈皟鐢ㄢ�斺��
+ // 瑙f瀽瀛楀吀闇�瑕佽闂暟鎹簱锛屼笉鑳藉湪 @PostConstruct 闃舵瑙﹀彂銆�
+ MesProQrLabelBuilder.setTraceConfigProvider(mesTraceConfigResolver::resolveSnapshot);
+ }
+
+ private boolean isLocalProfile() {
+ return Arrays.asList(environment.getActiveProfiles()).contains(PROFILE_LOCAL);
+ }
+
+ /**
+ * 鏍¢獙閰嶇疆鏂囦欢涓殑杩芥函缃戝潃锛氬繀椤讳负鍏紬鎵爜鍙闂殑鍦板潃
+ * <p>
+ * 涓庡瓧鍏稿�煎叡鐢� {@link MesTraceUrlValidator}锛屼繚璇佷袱涓潵婧愮殑鍑嗗叆闂ㄦ瀹屽叏涓�鑷达紝
+ * 涓嶄細鍑虹幇銆岄厤缃枃浠舵嫤寰椾綇銆佸瓧鍏哥粫寰楄繃銆嶇殑缂哄彛銆�
+ */
+ private void validateTraceBaseUrl() {
+ String url = StrUtil.trim(mesProperties.getTraceBaseUrl());
+ MesTraceUrlValidator.invalidReason(url).ifPresent(reason -> {
+ throw new IllegalStateException("mes.trace-base-url " + reason
+ + "锛堣椤规槸瀛楀吀 " + MesTraceConfigResolver.DICT_TYPE + " 鏈厤缃椂鐨勫厹搴曞�硷級");
+ });
+ }
+
+ /**
+ * 鏍¢獙鐢熶骇缁忚惀鑰呭悕绉帮細鏍囩鍥涜绱犱箣涓�锛岀己澶卞嵆涓轰笉鍚堣鏍囩
+ * <p>
+ * 姝ゅ浠呭憡璀︿笉闃绘柇鍚姩锛氱敓浜х粡钀ヨ�呭悕绉版寜涓讳綋鍖哄垎锛岄儴鍒嗙幆澧冨彲鑳藉皻鏈厤缃紝
+ * 寮哄埗鍚姩澶辫触浼氬奖鍝嶆棤鍏冲姛鑳姐�傜湡姝g殑鎷︽埅鐐瑰湪鏍囩鏋勫缓澶勶紙缂哄け鏃舵嫆缁濆鍑猴級锛�
+ * 鍥犳涓嶄細鍑虹幇"閰嶇疆缂哄け鍗村嵃鍑轰笉鍚堣鏍囩"鐨勬儏鍐点��
+ */
+ private void validateOperatorName() {
+ if (StrUtil.isBlank(MesProQrLabelBuilder.resolveOperatorName())) {
+ log.warn("[init] 鐢熶骇缁忚惀鑰呭悕绉版湭閰嶇疆锛堥厤缃枃浠� mes.operator-name 涓庡瓧鍏� {} 鍧囦负绌猴級銆�"
+ + "璇ュ瓧娈典负绉嶅瓙鏍囩鍥涜绱犱箣涓�锛岀己澶辨椂灏嗘棤娉曞鍑轰簩缁寸爜鏍囩锛岃灏藉揩琛ュ厖銆�",
+ MesTraceConfigResolver.DICT_TYPE);
+ }
}
}
--
Gitblit v1.9.3