From 62c1c41aab86ad3bf8967149769f9c2a40ac4313 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期四, 07 五月 2026 16:08:19 +0800
Subject: [PATCH] 锦隆 打印机 自动判断是否超出打印区间 超出换行功能 制作完成

---
 WebAPI/Controllers/WebAPIController.cs |  227 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 210 insertions(+), 17 deletions(-)

diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index 5251999..0d2b7ca 100644
--- a/WebAPI/Controllers/WebAPIController.cs
+++ b/WebAPI/Controllers/WebAPIController.cs
@@ -23569,7 +23569,7 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触, 鍗曟嵁鏃犺繑鍥炲��!";
+                    objjson.Message = "鏃犲緟涓婃ā鍗曟嵁!";
                     objjson.data = null;
                     return objjson;
                 }else
@@ -23624,7 +23624,7 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触, 鍗曟嵁鏃犺繑鍥炲��!";
+                    objjson.Message = "鏃犲緟寮�宸ュ崟鎹�!";
                     objjson.data = null;
                     return objjson;
                 }
@@ -23681,7 +23681,7 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触, 鍗曟嵁鏃犺繑鍥炲��!";
+                    objjson.Message = "鏃犲緟涓嬫ā鍗曟嵁!";
                     objjson.data = null;
                     return objjson;
                 }
@@ -24127,7 +24127,12 @@
             string suffix = ".txt";
             string folder = "ptTemplate";
             // 鍖归厤 {{ 瀛楁鍚� }} 鎵�闇�姝e垯琛ㄨ揪寮� 鏀寔涓枃
-            var regex = new Regex(@"{{\s*([\u4e00-\u9fa5a-zA-Z0-9_\s]+?)\s*}}", RegexOptions.Compiled);
+            var regex = new Regex(@"{{\s*([\u4e00-\u9fa5a-zA-Z0-9_\s]+?)\s*}}", RegexOptions.Singleline);
+
+            // 鍖归厤 鐭╁舰妗� 浣嶇疆 瀹介珮 鎵�闇�姝e垯琛ㄨ揪寮�
+            var RectRegex = new Regex(@"^\^FO(\d+),(\d+)\^GB(\d+),(\d+)", RegexOptions.Singleline);
+            // 鍖归厤 妯℃澘瀛楃涓� 鎵�鍦ㄨ 浣嶇疆 瀹介珮 鎵�闇�姝e垯琛ㄨ揪寮� 鏀寔涓枃
+            var fieldRegex = new Regex(@"\^FO(\d+),(\d+)\^A[A-Z]+,(\d+),(\d+).*?\{\{\s*([\u4e00-\u9fa5a-zA-Z0-9_\s]+?)\s*\}\}", RegexOptions.Singleline);
 
             if (ptMode == "ZPL")
             {
@@ -24168,9 +24173,45 @@
                 {
                     if(JOneKVP is JObject item)
                     {
-                        foreach (var line in lines)
+                        //foreach (var line in lines)
+                        //{
+                            //string currentLine = line;
+
+                            //// 璺宠繃娉ㄩ噴琛� //
+                            //if (currentLine.TrimStart().StartsWith("//"))
+                            //{
+                                //continue;
+                            //}
+
+
+                            //// 姝e垯琛ㄨ揪寮忓尮閰� {{ 瀛楁鍚� }} 鎵�鍦ㄨ鐨勫瓧娈碉紝濡傛灉鏈夛紝鍒欒繘琛屾浛鎹紝娌℃湁锛屽垯榛樿涓虹┖瀛楃涓�
+                            //currentLine = regex.Replace(currentLine, match =>
+                            //{
+                                ////鍒ゆ柇涓婁竴琛屾槸鍚︿负鐭╁舰琛岋紝濡傛灉鏄煩褰㈣锛屽垯鏍规嵁鐭╁舰琛岀殑瀹介珮鍒ゆ柇瀛楃鏄惁闇�瑕佹崲琛�
+
+                                //string fieldName = match.Groups[1].Value.Trim();
+                                //if (msg != null && item.ContainsKey(fieldName))
+                                //{
+                                    //return item[fieldName]?.ToString() ?? "";
+                                //}
+                                //return "";
+                            //});
+                            //// 灏嗘墍鏈� \n 鐨勬崲琛岀 鏇挎崲涓� \r\n
+
+                            //sb.Append(currentLine);
+                            //sb.Append("\r\n"); // 鏍囧噯鎹㈣
+                        //}
+
+                        for(int i = 0; i<lines.Length; i++)
                         {
-                            string currentLine = line;
+                            string currentLine = lines[i];
+                            string preLine = "";
+                            string concatStr = "";
+                            if(i>0)
+                            {
+                                // 鑾峰彇褰撳墠琛岀殑涓婁竴琛岋紝鐢ㄤ簬鍒ゆ柇鏄惁鏄煩褰㈡
+                                preLine = lines[i - 1];
+                            }
 
                             // 璺宠繃娉ㄩ噴琛� //
                             if (currentLine.TrimStart().StartsWith("//"))
@@ -24178,19 +24219,32 @@
                                 continue;
                             }
 
-                            // 姝e垯琛ㄨ揪寮忓尮閰� {{ 瀛楁鍚� }} 鎵�鍦ㄨ鐨勫瓧娈碉紝濡傛灉鏈夛紝鍒欒繘琛屾浛鎹紝娌℃湁锛屽垯榛樿涓虹┖瀛楃涓�
-                            currentLine = regex.Replace(currentLine, match =>
+                            // 鍒ゆ柇鐭╁舰妗嗭紝濡傛灉鍓嶄竴琛屾槸鐭╁舰妗嗭紝鍒欓渶鍒ゆ柇璇ヨ瀛楃涓查暱搴︽槸鍚﹁秴闀�
+                            if(!getConcatStr(rectRegex: RectRegex, fieldRegex: fieldRegex,
+                                PreLine: preLine, CurrLine: currentLine, fieldObject: item,
+                                templateRegex: regex,
+                                ref concatStr))
                             {
-                                string fieldName = match.Groups[1].Value.Trim();
-                                if (msg != null && item.ContainsKey(fieldName))
+                                // 姝e垯琛ㄨ揪寮忓尮閰� {{ 瀛楁鍚� }} 鎵�鍦ㄨ鐨勫瓧娈碉紝濡傛灉鏈夛紝鍒欒繘琛屾浛鎹紝娌℃湁锛屽垯榛樿涓虹┖瀛楃涓�
+                                concatStr = regex.Replace(currentLine, match =>
                                 {
-                                    return item[fieldName]?.ToString() ?? "";
-                                }
-                                return "";
-                            });
-                            // 灏嗘墍鏈� \n 鐨勬崲琛岀 鏇挎崲涓� \r\n
+                                    string fieldName = match.Groups[1].Value.Trim();
+                                    if (msg != null && item.ContainsKey(fieldName))
+                                    {
+                                        return item[fieldName]?.ToString() ?? "";
+                                    }
+                                    return "";
+                                });
+                            }
 
-                            sb.Append(currentLine);
+                            if(string.IsNullOrWhiteSpace(concatStr))
+                            {
+                                concatStr = currentLine;
+                            }
+
+                            
+                            // 灏嗘墍鏈� \n 鐨勬崲琛岀 鏇挎崲涓� \r\n
+                            sb.Append(concatStr);
                             sb.Append("\r\n"); // 鏍囧噯鎹㈣
                         }
                     }
@@ -24209,12 +24263,151 @@
             {
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
-                objJsonResult.Message = $"妯℃澘娓叉煋澶辫触锛歿ex.Message}";
+                objJsonResult.Message = $"妯℃澘娓叉煋澶辫触锛歿ex}";
                 objJsonResult.data = null;
                 return objJsonResult;
             }
 
         }
+
+        private bool getConcatStr(Regex rectRegex, Regex fieldRegex,
+            string PreLine, string CurrLine, JObject fieldObject, Regex templateRegex, ref string concatStr)
+        {
+            var rectRegexResult = rectRegex.Match(PreLine);
+            var fieldRegexResult = fieldRegex.Match(CurrLine);
+            var templateRegexResult = templateRegex.Match(CurrLine);
+            if (!rectRegexResult.Success)
+            {
+                return false;
+            }
+
+            if(!fieldRegexResult.Success)
+            {
+                return false;
+            }
+
+            if(!templateRegexResult.Success)
+            {
+                return false;
+            }
+            
+
+            // 鐭╁舰 浣嶇疆 瀹介珮
+            int rectLocationX = int.Parse(rectRegexResult.Groups[1].Value);
+            int rectLocationY = int.Parse(rectRegexResult.Groups[2].Value);
+            int rectWidth = int.Parse(rectRegexResult.Groups[3].Value);
+            int rectHeight = int.Parse(rectRegexResult.Groups[4].Value);
+
+            var fiEnum = fieldRegexResult.Groups;
+
+            // 妯℃澘瀛楃涓� 浣嶇疆 瀛楃瀹介珮
+            int fieldLocationX = int.Parse(fieldRegexResult.Groups[1].Value);
+            int fieldLocationY = int.Parse(fieldRegexResult.Groups[2].Value);
+            int fieldWidth = int.Parse(fieldRegexResult.Groups[3].Value);
+            int fieldHeight = int.Parse(fieldRegexResult.Groups[4].Value);
+            var fieldName = fieldRegexResult.Groups[5].Value;
+            
+            
+            JToken fieldValueToken = "";
+            fieldObject.TryGetValue(fieldName, out fieldValueToken);
+
+            if (string.IsNullOrWhiteSpace(fieldValueToken?.ToString()))
+            {
+                return false;
+            }
+            string fieldValue = fieldValueToken.ToString();
+            if (fieldValue.Length * fieldWidth > rectWidth)
+            {
+                // 瀛楃涓查暱搴﹀ぇ浜庣煩褰㈢殑鏈�澶ч暱搴� 鍒欐枃鏈渶瑕佷粠鐭╁舰鐨刌浣嶇疆寮�濮嬫覆鏌�
+                fieldLocationY = rectLocationY;
+                // 鑾峰彇鎹㈣鎵�闇�鐨勮鏁�
+                int lineCount = int.Parse(Math.Ceiling((float)fieldValue.Length / fieldWidth).ToString());
+                
+                // 璁$畻鎹㈣鍚庣殑鏈�澶ц鏁� * 瀛楃楂樺害 鏄惁澶т簬鐭╁舰鏈�澶ч珮搴�
+                if(lineCount * fieldHeight > rectHeight)
+                {
+                    
+                    fieldHeight = int.Parse(Math.Floor((float)rectHeight / lineCount).ToString());
+                    fieldWidth = fieldHeight;
+                }
+
+                // 璁$畻姣忚搴旇鏀惧灏戝瓧绗︼紙姝g‘绠楁硶锛�
+                int maxCharsPerLine = (int)Math.Ceiling((double)fieldValue.Length / lineCount);
+
+                for (int i = 0; i < lineCount; i++)
+                {
+                    // 璧峰浣嶇疆
+                    int start = i * maxCharsPerLine;
+
+                    // 鍓╀綑澶氬皯瀛楃锛堟牳蹇冿細淇濊瘉涓嶈秺鐣岋級
+                    int remaining = fieldValue.Length - start;
+
+                    if (remaining <= 0)
+                        break;
+
+                    // 鏈鍙栧嚑涓瓧绗︼紙缁濆瀹夊叏锛�
+                    int take = Math.Min(maxCharsPerLine, remaining);
+
+                    // 鎴彇褰撳墠琛屾枃鏈�
+                    string lineText = fieldValue.Substring(start, take);
+
+                    // 璁$畻鏂拌鍧愭爣
+                    int newY = fieldLocationY + i * fieldHeight;
+
+                    // 鏇挎崲鎷兼帴
+                    concatStr += fieldRegex.Replace(CurrLine, m =>
+                        $"^FO{fieldLocationX},{newY}^AJN,{fieldWidth},{fieldHeight}^CI28^FD{lineText}^FS"
+                    );
+                }
+                return true;
+            }
+
+            return false;
+
+        }
         #endregion
+        [HttpGet]
+        [Route("Web/getSysParameter")]
+        public object getSysParameter(string HClientID)
+        {
+            var HValue = oSystemParameter.GetSingleSystemParameter("uni-app_savelogin", ref DBUtility.ClsPub.sExeReturnInfo);
+            if (HValue == "3" && HClientID != null)
+            {
+                DataSet ds = oCN.RunProcReturn("select * from Gy_UserClientIdRelation where HClientID= '" + HClientID + "'", "Gy_UserClientIdRelation");
+                if (ds != null && ds.Tables.Count > 0)
+                {
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "鏍规嵁璁惧鑷姩鐧诲綍";
+                    objJsonResult.data = HValue;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "绯荤粺鍙傛暟涓嶅瓨鍦紝璇疯仈绯荤鐞�";
+                    objJsonResult.data = 0;
+                    return objJsonResult;
+                }
+
+            }
+            else if (HValue == "2" || HValue == "1")
+            {
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "淇濆瓨鎴愬姛";
+                objJsonResult.data = HValue;
+                return objJsonResult;
+            }
+            else
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "绯荤粺鍙傛暟涓嶅瓨鍦紝璇疯仈绯荤鐞�";
+                objJsonResult.data = 0;
+                return objJsonResult;
+            }
+        }
     }
 }

--
Gitblit v1.9.1