From 2d07ecf4a434a9d68d3ba82997916c5eade88d35 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期三, 06 五月 2026 17:12:02 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/WebAPIController.cs |  295 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 292 insertions(+), 3 deletions(-)

diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index 9e1452f..6c68f9e 100644
--- a/WebAPI/Controllers/WebAPIController.cs
+++ b/WebAPI/Controllers/WebAPIController.cs
@@ -20,6 +20,7 @@
 using WebAPI.Models;
 using WebAPI.Service;
 using SyntacticSugar.constant;
+using System.Text.RegularExpressions;
 
 namespace WebAPI.Controllers
 {
@@ -23568,7 +23569,7 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触, 鍗曟嵁鏃犺繑鍥炲��!";
+                    objjson.Message = "鏃犲緟涓婃ā鍗曟嵁!";
                     objjson.data = null;
                     return objjson;
                 }else
@@ -23623,7 +23624,7 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触, 鍗曟嵁鏃犺繑鍥炲��!";
+                    objjson.Message = "鏃犲緟寮�宸ュ崟鎹�!";
                     objjson.data = null;
                     return objjson;
                 }
@@ -23680,7 +23681,7 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触, 鍗曟嵁鏃犺繑鍥炲��!";
+                    objjson.Message = "鏃犲緟涓嬫ā鍗曟嵁!";
                     objjson.data = null;
                     return objjson;
                 }
@@ -24005,6 +24006,7 @@
         }
         #endregion
 
+        #region  APP鐧诲綍鏉冮檺楠岃瘉鎺ュ彛
         /// <summary>
         /// APP鐧诲綍鏉冮檺楠岃瘉鎺ュ彛
         /// </summary>
@@ -24080,5 +24082,292 @@
                 return objJsonResult;
             }
         }
+        #endregion
+
+        #region 钃濈墮鎵撳嵃鏈鸿幏鍙栨墦鍗版ā鏉�
+        public class PrintRequestDto
+        {
+            public string ptMode { get; set; }
+            public string templateName { get; set; }
+            public JArray msg { get; set; } // 浣犵殑鎵归噺鏁版嵁
+        }
+        /// <summary>
+        /// ptMode: 鎵撳嵃妯″紡锛屽嵆闇�瑕侀偅绉嶆墦鍗版寚浠わ紝CPCL,TSPL,ESC,ZPL 涓�夋嫨
+        /// templateName: 妯℃澘鍚嶏紝鏍规嵁妯℃澘鍘绘寚瀹氱洰褰曚笅鏍规嵁鍚庣紑鎵炬枃浠�
+        /// msg: 鎵撳嵃鍐呭
+        /// </summary>
+        /// <param name="ptMode"></param>
+        /// <param name="templateName"></param>
+        /// <param name="msg"></param>
+        /// <returns></returns>
+        [Route("WebAPI/getBLEPrintTemplate")]
+        [HttpPost]
+        public object getBLEPrintTemplate([FromBody] PrintRequestDto dto)
+        {
+            var ptMode = dto.ptMode;
+            var templateName = dto.templateName;
+            var msg = dto.msg;
+            if (string.IsNullOrWhiteSpace(ptMode))
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏈�夋嫨鎵撳嵃妯″紡锛屾棤娉曠敓鎴愭墦鍗版ā鏉�!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            if (string.IsNullOrWhiteSpace(templateName))
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏈�夋嫨鎵撳嵃妯℃澘锛屾棤娉曠敓鎴愭墦鍗版ā鏉�!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            string suffix = ".txt";
+            string folder = "ptTemplate";
+            // 鍖归厤 {{ 瀛楁鍚� }} 鎵�闇�姝e垯琛ㄨ揪寮� 鏀寔涓枃
+            var regex = new Regex(@"{{\s*([\u4e00-\u9fa5a-zA-Z0-9_\s]+?)\s*}}", RegexOptions.Compiled);
+
+            // 鍖归厤 鐭╁舰妗� 浣嶇疆 瀹介珮 鎵�闇�姝e垯琛ㄨ揪寮�
+            var RectRegex = new Regex(@"^\^FO(\d+),(\d+)\^GB(\d+),(\d+)", RegexOptions.Compiled);
+            // 鍖归厤 妯℃澘瀛楃涓� 鎵�鍦ㄨ 浣嶇疆 瀹介珮 鎵�闇�姝e垯琛ㄨ揪寮� 鏀寔涓枃
+            var fieldRegex = new Regex(@"\^FO(\d+),(\d+)\^A[A-Z]+,(\d+),(\d+).*\{\{\s*([\u4e00-\u9fa5a-zA-Z0-9_\s]+?)\s*}\}", RegexOptions.Compiled);
+
+            if (ptMode == "ZPL")
+            {
+                suffix = ".zpl";
+                folder = "ZPLTemplate";
+            }
+
+            try
+            {
+                // 璇诲彇妯℃澘鏂囦欢
+                string rootPath = System.Web.HttpContext.Current.Server.MapPath("~/");
+                string templateDir = Path.Combine(rootPath, folder);
+                string templateFile = Path.Combine(templateDir, templateName+suffix);
+
+                // 濡傛灉鐩綍涓嶅瓨鍦�
+                if (!Directory.Exists(templateDir))
+                {
+                    Directory.CreateDirectory(templateDir);
+                }
+
+                // 濡傛灉鏂囦欢涓嶅瓨鍦�
+                if (!File.Exists(templateFile))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.Message = $"妯℃澘鏂囦欢涓嶅瓨鍦細{templateFile}";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                // 璇诲彇妯℃澘锛圲TF8 鏀寔涓枃锛�
+                string templateContent = File.ReadAllText(templateFile, Encoding.UTF8);
+
+                // 閫愯璇诲彇妯℃澘鏂囦欢
+                var lines = templateContent.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
+                var sb = new StringBuilder();
+
+                foreach(JToken JOneKVP in msg)
+                {
+                    if(JOneKVP is JObject item)
+                    {
+                        //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 = lines[i];
+                            string preLine = "";
+                            string concatStr = "";
+                            if(i>0)
+                            {
+                                // 鑾峰彇褰撳墠琛岀殑涓婁竴琛岋紝鐢ㄤ簬鍒ゆ柇鏄惁鏄煩褰㈡
+                                preLine = lines[i - 1];
+                            }
+
+                            // 璺宠繃娉ㄩ噴琛� //
+                            if (currentLine.TrimStart().StartsWith("//"))
+                            {
+                                continue;
+                            }
+
+                            // 鍒ゆ柇鐭╁舰妗嗭紝濡傛灉鍓嶄竴琛屾槸鐭╁舰妗嗭紝鍒欓渶鍒ゆ柇璇ヨ瀛楃涓查暱搴︽槸鍚﹁秴闀�
+                            if(!getConcatStr(rectRegex: RectRegex, fieldRegex: fieldRegex,
+                                PreLine: preLine, CurrLine: currentLine, fieldObject: item, ref concatStr))
+                            {
+                                // 姝e垯琛ㄨ揪寮忓尮閰� {{ 瀛楁鍚� }} 鎵�鍦ㄨ鐨勫瓧娈碉紝濡傛灉鏈夛紝鍒欒繘琛屾浛鎹紝娌℃湁锛屽垯榛樿涓虹┖瀛楃涓�
+                                concatStr = 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(concatStr);
+                            sb.Append("\r\n"); // 鏍囧噯鎹㈣
+                        }
+                    }
+                }
+
+                
+                string result = sb.ToString().TrimEnd();
+                // 杩斿洖娓叉煋鍚庣殑鎵撳嵃鎸囦护
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = $"妯℃澘娓叉煋鎴愬姛";
+                objJsonResult.data = result;
+                return objJsonResult;
+            }
+            catch (Exception ex)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = $"妯℃澘娓叉煋澶辫触锛歿ex.Message}";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+        }
+
+        private bool getConcatStr(Regex rectRegex, Regex fieldRegex,
+            string PreLine, string CurrLine, JObject fieldObject, ref string concatStr)
+        {
+            var rectRegexResult = rectRegex.Match(PreLine);
+            var fieldRegexResult = fieldRegex.Match(CurrLine);
+            if (!rectRegexResult.Success)
+            {
+                return false;
+            }
+
+            if(!fieldRegexResult.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);
+
+            // 妯℃澘瀛楃涓� 浣嶇疆 瀛楃瀹介珮
+            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);
+            string fieldName = fieldRegexResult.Groups[5].Value;
+
+            string fieldValue = fieldObject[fieldName].ToString() ?? "";
+            if(string.IsNullOrWhiteSpace(fieldValue))
+            {
+                return false;
+            }
+
+            if(fieldValue.Length * fieldWidth > rectWidth)
+            {
+                // 瀛楃涓查暱搴﹀ぇ浜庣煩褰㈢殑鏈�澶ч暱搴� 鍒欐枃鏈渶瑕佷粠鐭╁舰鐨刌浣嶇疆寮�濮嬫覆鏌�
+                fieldLocationY = rectLocationY;
+                // 鑾峰彇鎹㈣鎵�闇�鐨勮鏁�
+                int lineCount = int.Parse(Math.Ceiling((float)fieldValue.Length / fieldWidth).ToString());
+                
+                // 璁$畻鎹㈣鍚庣殑鏈�澶ц鏁� * 瀛楃楂樺害 鏄惁澶т簬鐭╁舰鏈�澶ч珮搴�
+                if(lineCount * fieldHeight > rectHeight)
+                {
+                    fieldWidth = int.Parse(Math.Floor((float)fieldHeight / lineCount).ToString());
+                    fieldHeight = int.Parse(Math.Floor((float)fieldHeight / lineCount).ToString());
+                }
+
+                for(uint i=0;i<lineCount; i++)
+                {
+                    concatStr += fieldRegex.Replace(CurrLine, match =>
+                    {
+                        return "";
+                    });
+                }
+
+            }
+
+            return true;
+
+        }
+        #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