From 72ccd32e36fbc848740165b01b9a75ba014adf2c Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期二, 28 四月 2026 17:05:39 +0800
Subject: [PATCH] 添加 蓝牙打印机获取 打印模板 API 新增 锦隆 物料条码 80×60 100×60 ZPL指令 打印模板

---
 WebAPI/Controllers/WebAPIController.cs |  245 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 235 insertions(+), 10 deletions(-)

diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index 6a78309..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
 {
@@ -392,7 +393,7 @@
                     objJsonResult.Message = "鐧诲綍寮傚父锛乀oken 鐢熸垚寮傚父锛屾棤娉曡幏鍙栧叕鍙镐俊鎭紒";
                 }
 
-                string tokenStr = Utility.JWTHelper.GenerateToken(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
+                string tokenStr = Utility.JWTHelper.GenerateToken(ds.Tables[0].Rows[0]["Czybm"].ToString(), ds.Tables[0].Rows[0]["Czymc"].ToString());
 
 
                 objjson.code = "0";
@@ -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; ;
             }
@@ -20473,7 +20474,7 @@
             {
                 objjson.code = "0";
                 objjson.count = 0;
-                objjson.Message = "鑾峰彇澶辫触" + ex.ToString();
+                objjson.Message = "鑾峰彇澶辫触" + ex.Message.ToString();
                 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");
@@ -22852,6 +22864,7 @@
         /// <returns></returns>
         [Route("Web/GetModuleName")]
         [HttpGet]
+        [AllowAnonymous]
         public object GetModuleName(string HModuleType)
         {
             try
@@ -23455,6 +23468,7 @@
         #region 鐢ㄤ簬杩炴帴鐨勫仴搴峰害妫�楠岋紝鍙鑳借闂�氳繖涓帴鍙o紝鍒欒〃鏄庤繛鎺ュ彲鐢�
         [Route("Health")]
         [HttpGet]
+        [AllowAnonymous]
         public IHttpActionResult CheckHealth()
         {
             // 杩斿洖 200 鐘舵�佺爜 纭鍋ュ悍鐘舵��
@@ -23991,5 +24005,216 @@
             }
         }
         #endregion
+
+        #region  APP鐧诲綍鏉冮檺楠岃瘉鎺ュ彛
+        /// <summary>
+        /// APP鐧诲綍鏉冮檺楠岃瘉鎺ュ彛
+        /// </summary>
+        [Route("Auth/CheckAppLoginAuth")]
+        [HttpPost]
+        public object CheckAppLoginAuth()
+        {
+            try
+            {
+                // 鑾峰彇璇锋眰鍙傛暟
+                string orgID = HttpContext.Current.Request.Form["orgID"] ?? "";
+                string orgName = HttpContext.Current.Request.Form["orgName"] ?? "";
+                string serverUrl = HttpContext.Current.Request.Form["serverUrl"] ?? "";
+                string phoneType = HttpContext.Current.Request.Form["phoneType"] ?? "";
+                string userAccount = HttpContext.Current.Request.Form["userAccount"] ?? "";
+                string other = HttpContext.Current.Request.Form["other"] ?? "";
+                // 鍙傛暟楠岃瘉
+                if (string.IsNullOrEmpty(userAccount))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "璐﹀彿涓嶈兘涓虹┖!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (string.IsNullOrEmpty(orgID))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "缁勭粐ID涓嶈兘涓虹┖!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                // 鍙傛暟瀹夊叏澶勭悊锛堥槻姝㈡敞鍏ワ級
+                orgID = orgID.Replace("'", "''");
+                orgName = orgName.Replace("'", "''");
+                serverUrl = serverUrl.Replace("'", "''");
+                phoneType = phoneType.Replace("'", "''");
+                userAccount = userAccount.Replace("'", "''");
+
+                // 鎵ц鍥哄畾瀛樺偍杩囩▼
+                string sql = $"EXEC SP_CheckAppLoginAuth '{orgID}', '{orgName}', '{serverUrl}', '{phoneType}','{userAccount}','{other}'";
+                ds = oCN.RunProcReturn(sql, "SP_CheckAppLoginAuth");
+
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    int result = Convert.ToInt32(ds.Tables[0].Rows[0]["Result"]);
+                    string message = ds.Tables[0].Rows[0]["Message"].ToString();
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = message;
+                    objJsonResult.data = ds.Tables[0];
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "楠岃瘉鎺ュ彛杩斿洖寮傚父!";
+                    objJsonResult.data = null;
+                }
+
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                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