From da84e4e72c9d9cc7e2bd40dc4bb7b3222ca3519a Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期二, 28 四月 2026 17:07:52 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/WebAPIController.cs |  163 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 155 insertions(+), 8 deletions(-)

diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index d615992..5251999 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
 {
@@ -409,7 +410,7 @@
 
                 objjson.code = "0";
                 objjson.count = 0;
-                objjson.Message = "[0000-1-074]鐧诲綍寮傚父锛�" + e.Message;
+                objjson.Message = "[0000-1-074]鐧诲綍寮傚父锛�" + e;
                 objjson.data = null;
                 return objjson; ;
             }
@@ -20968,7 +20969,18 @@
                 {
                     objjson.code = "0";
                     objjson.count = 0;
-                    objjson.Message = "鑾峰彇澶辫触,鏄庣粏鏌ユ棤鏁版嵁";
+                    if(Type == "DJ")
+                    {
+                        objjson.Message = "鑾峰彇澶辫触,妯″叿鏃犵粦瀹氱殑鐐规瑙勭▼";
+                    }
+                    else if (Type == "BY")
+                    {
+                        objjson.Message = "鑾峰彇澶辫触,妯″叿鏃犵粦瀹氱殑淇濆吇瑙勭▼";
+                    }
+                    else
+                    {
+                        objjson.Message = "鑾峰彇澶辫触,鏄庣粏鏌ユ棤鏁版嵁";
+                    }
                     objjson.data = null;
                     return objjson;
                 }
@@ -21169,12 +21181,12 @@
 
                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
-                ds = oCN.RunProcReturn("select ManagerFlag from gy_czygl where czymc='" + user.Trim() + "'", "gy_czygl");
-                if (!(bool)ds.Tables[0].Rows[0]["ManagerFlag"])  //鏄惁绠$悊鍛�
-                {
-                    //涓嶆槸绠$悊鍛�
-                    sWhere += " and 鍒跺崟浜� = '" + user + "'";
-                }
+                //ds = oCN.RunProcReturn("select ManagerFlag from gy_czygl where czymc='" + user.Trim() + "'", "gy_czygl");
+                //if (!(bool)ds.Tables[0].Rows[0]["ManagerFlag"])  //鏄惁绠$悊鍛�
+                //{
+                //    //涓嶆槸绠$悊鍛�
+                //    sWhere += " and 鍒跺崟浜� = '" + user + "'";
+                //}
 
 
                 string sql = string.Format(@"select * from " + HView + " where 1 = 1 " + sWhere + " order by 鏃ユ湡 desc, hmainid desc");
@@ -23994,6 +24006,7 @@
         }
         #endregion
 
+        #region  APP鐧诲綍鏉冮檺楠岃瘉鎺ュ彛
         /// <summary>
         /// APP鐧诲綍鏉冮檺楠岃瘉鎺ュ彛
         /// </summary>
@@ -24069,5 +24082,139 @@
                 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);
+
+            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"); // 鏍囧噯鎹㈣
+                        }
+                    }
+                }
+
+                
+                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;
+            }
+
+        }
+        #endregion
     }
 }

--
Gitblit v1.9.1