llj
6 天以前 2f33b2da0791ed73c41c16dc6d6768e6b8fe31aa
WebAPI/Controllers/WebAPIController.cs
@@ -20,6 +20,7 @@
using WebAPI.Models;
using WebAPI.Service;
using SyntacticSugar.constant;
using System.Text.RegularExpressions;
namespace WebAPI.Controllers
{
@@ -340,6 +341,7 @@
        /// <returns></returns>
        [Route("Web/GetUser")]
        [HttpGet]
        [AllowAnonymous]
        public object GetUser(string UserName, string PassWord, string HOrgName)
        {
            try
@@ -384,11 +386,23 @@
                    }
                }
                if (!oSystemParameter.ShowBill(ref DBUtility.ClsPub.sErrInfo))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "登录异常!Token 生成异常,无法获取公司信息!";
                }
                string tokenStr = Utility.JWTHelper.GenerateToken(ds.Tables[0].Rows[0]["Czybm"].ToString(), ds.Tables[0].Rows[0]["Czymc"].ToString());
                objjson.code = "0";
                objjson.count = 1;
                objjson.Message = "[0000-1-073]登录成功!";
                objjson.data = ds.Tables[0];
                return objjson;
                JObject jobjJsonResult = JObject.FromObject(objjson);
                jobjJsonResult["token"] = tokenStr;
                return jobjJsonResult;
            }
            catch (Exception e)
@@ -396,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; ;
            }
@@ -2619,6 +2633,7 @@
        /// <returns></returns>
        [Route("Web/GetDataBases")]
        [HttpGet]
        [AllowAnonymous]
        public object GetDataBases()
        {
            try
@@ -18965,6 +18980,7 @@
        /// <returns></returns>
        [Route("Web/GetOrganizations")]
        [HttpGet]
        [AllowAnonymous]
        public object GetOrganizations()
        {
            try
@@ -18997,6 +19013,7 @@
        /// <returns></returns>
        [Route("Web/BaseInfo")]
        [HttpGet]
        [AllowAnonymous]
        public object GetBaseInfo()
        {
            try
@@ -20457,7 +20474,7 @@
            {
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "获取失败" + ex.ToString();
                objjson.Message = "获取失败" + ex.Message.ToString();
                objjson.data = null;
                return objjson;
            }
@@ -20952,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;
                }
@@ -21153,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");
@@ -21765,6 +21793,8 @@
            public string HTranslationText_English { get; set; }
            public string HTranslationText_Spain { get; set; }
            public List<MenuLoad> childMenus { get; set; }
            public DateTime HMakeDate { get; set; }
            public string HMaker { get; set; }
        }
        [Route("Web/MenuList")]
@@ -21871,6 +21901,163 @@
        }
        #endregion
        #region 构建路由嵌套对象
        [Route("Web/MenuList_1")]
        [HttpGet]
        public object MenuList_1(string HMakeName, string HType)
        {
            try
            {
                string filePath = HttpContext.Current.Server.MapPath($"~/RouterDisplay/DisplayConfig.json");
                string directory = Path.GetDirectoryName(filePath);
                if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                DateTime lastWriteTime = File.GetLastWriteTime(filePath);
                lastWriteTime = new DateTime(lastWriteTime.Year, lastWriteTime.Month, lastWriteTime.Day, lastWriteTime.Hour, 0, 0);
                DataSet ds = oCN.RunProcReturn($"select top 1 HMakeDate from Gy_Menu_1_build ORDER BY HMakeDate desc  ", "Gy_Menu_1_build");
                DateTime dbTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["HMakeDate"]);
                dbTime = new DateTime(dbTime.Year, dbTime.Month, dbTime.Day, dbTime.Hour, 0, 0);
                if (dbTime> lastWriteTime)
                {
                    List<MenuLoad> mu = new List<MenuLoad>();                       //以父子级结构存放菜单清单信息
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();            //数据库操作工具
                    string sql = "select HItemID,HPartentID,HNumber,HName,HLevel,Hurl,HType,HPicNum,HShowMode,isnull(HTranslationText_English,HName) HTranslationText_English,isnull(HTranslationText_Spain,HName) HTranslationText_Spain  from Gy_MenuDefineSet where HMakeName = '" + HMakeName + "' and HType = '" + HType + "' order by HPosition";
                    ds = oCn.RunProcReturn(sql, "Gy_MenuDefineSet");        //查询当前用户的自定义菜单数据
                    if (ds.Tables[0] == null || ds.Tables[0].Rows.Count == 0) //判断当前用户是否有设置过自定义信息,若记录数为0,则没有设置过,加载所有的菜单信息
                    {
                        string sql1 = "select HItemID,HPartentID,HNumber,HName,HLevel,Hurl,HType,HPicNum,HShowMode,isnull(HTranslationText_English,HName) HTranslationText_English,isnull(HTranslationText_Spain,HName) HTranslationText_Spain from Gy_MenuDefineSet where HMakeName=" +
                            "(select   top 1 c.GroupName  from Gy_Czygl a left join System_UserGroupInfo b on a.Czybm = b.UserId  " +
                            "left join System_UserGroup c on b.GroupId = c.GroupID  where a.Czymc ='" + HMakeName + "' order by len(c.GroupName ))";
                        ds = oCn.RunProcReturn(sql1, "Gy_MenuDefineSet");        //查询用户绑定的角色 是否设置菜单信息 取角色名称最短的一个
                        if ((ds.Tables[0] == null || ds.Tables[0].Rows.Count == 0))
                        {
                            sql1 = "select HItemID,HPartentID,HNumber,HName,HLevel,Hurl,HType,HPicNum,HShowMode,isnull(HTranslationText_English,HName) HTranslationText_English,isnull(HTranslationText_Spain,HName) HTranslationText_Spain  from Gy_MenuDefineSet where HMakeName = 'admin' and HType = '" + HType + "' order by HPosition";
                            ds = oCn.RunProcReturn(sql1, "Gy_MenuDefineSet");   //查询admin 是否设置菜单信息
                            if ((ds.Tables[0] == null || ds.Tables[0].Rows.Count == 0))
                            {
                                sql = "Select HitemID,HNumber,HName,HPartentID,HLevel,Hurl,HShowMode,isnull(HTranslationText_English,HName) HTranslationText_English,isnull(HTranslationText_Spain,HName) HTranslationText_Spain,HPicNum from Gy_Menu_1_build where HType = '" + HType + "' Order by HPosition,len(HitemID),HitemID  ";
                                ds = oCn.RunProcReturn(sql, "Gy_Menu_1_build");
                            }
                        }
                    }
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)       //将菜单的根节点保存到列表menu中
                    {
                        if (ds.Tables[0].Rows[i]["HPartentID"].ToString() == "0" || ds.Tables[0].Rows[i]["HitemID"].ToString() == ds.Tables[0].Rows[i]["HPartentID"].ToString())  //判断是否最外层根节点
                        {
                            MenuLoad tbj = new MenuLoad();
                            tbj.HitemID = ds.Tables[0].Rows[i]["HitemID"].ToString();
                            tbj.HNumber = ds.Tables[0].Rows[i]["HNumber"].ToString();
                            tbj.HName = ds.Tables[0].Rows[i]["HName"].ToString();
                            tbj.HPartentID = ds.Tables[0].Rows[i]["HPartentID"].ToString();
                            tbj.HLevel = int.Parse(ds.Tables[0].Rows[i]["HLevel"].ToString());
                            tbj.Hurl = ds.Tables[0].Rows[i]["Hurl"].ToString();
                            tbj.HShowMode = ds.Tables[0].Rows[i]["HShowMode"].ToString();
                            tbj.HTranslationText_English = ds.Tables[0].Rows[i]["HTranslationText_English"].ToString();
                            tbj.HTranslationText_Spain = ds.Tables[0].Rows[i]["HTranslationText_Spain"].ToString();
                            if (ds.Tables[0].Rows[i]["HPicNum"] != null)
                            {
                                tbj.HPicNum = ds.Tables[0].Rows[i]["HPicNum"].ToString();
                            }
                            mu.Add(tbj);
                        }
                    }
                    diguiLoad(ds.Tables[0], mu);                //使用递归,将需要加载的数据以父子级的结构存放在mu中
                    objJsonResult.code = "1";//信号参数
                    objJsonResult.count = 1;
                    objJsonResult.Message = "查询成功!";
                    objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(mu);
                    return objJsonResult;
                }
                else
                {
                    string josncontext = File.ReadAllText(filePath);
                    objJsonResult.code = "2";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "查询成功!";
                    objJsonResult.data = josncontext;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询失败!";
                objJsonResult.data = e.ToString();
                return objJsonResult;
            }
        }
        public class RequestDto
        {
            public string content { get; set; }
        }
        [Route("Web/buildRouteObj")]
        [HttpPost]
        public object buildRouteObj([FromBody] RequestDto request)
        {
            string filePath = HttpContext.Current.Server.MapPath($"~/RouterDisplay/DisplayConfig.json");
            try
            {
                string jsonContent = request.content;
                if (string.IsNullOrEmpty(jsonContent))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "JSON 内容不能为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(filePath))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "文件路径不能为空。!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string directory = Path.GetDirectoryName(filePath);
                if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                string contentToWrite = jsonContent;
                File.WriteAllText(filePath, contentToWrite);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "文件保存成功,路径为"+filePath;
                objJsonResult.data = null;
                LogService.Write($"路径为{filePath}");
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write("Exception!" + e.ToString());
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region [菜单目录自定义]
@@ -22677,6 +22864,7 @@
        /// <returns></returns>
        [Route("Web/GetModuleName")]
        [HttpGet]
        [AllowAnonymous]
        public object GetModuleName(string HModuleType)
        {
            try
@@ -23280,6 +23468,7 @@
        #region 用于连接的健康度检验,只要能访问通这个接口,则表明连接可用
        [Route("Health")]
        [HttpGet]
        [AllowAnonymous]
        public IHttpActionResult CheckHealth()
        {
            // 返回 200 状态码 确认健康状态
@@ -23380,7 +23569,7 @@
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "获取失败, 单据无返回值!";
                    objjson.Message = "无待上模单据!";
                    objjson.data = null;
                    return objjson;
                }else
@@ -23435,7 +23624,7 @@
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "获取失败, 单据无返回值!";
                    objjson.Message = "无待开工单据!";
                    objjson.data = null;
                    return objjson;
                }
@@ -23492,7 +23681,7 @@
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "获取失败, 单据无返回值!";
                    objjson.Message = "无待下模单据!";
                    objjson.data = null;
                    return objjson;
                }
@@ -23746,11 +23935,15 @@
                foreach (var param in rawParams)
                {
                    bool isMatched = false;
                    // 遍历所有工艺分类,判断参数名是否包含该分类名称
                    // 遍历所有工艺分类,判断参数名是以该分类名称开头
                    foreach (string category in categoryNames)
                    {
                        if (param.TechParamName.Contains(category))
                        if (param.TechParamName.StartsWith(category))
                        {
                            if(param.TechParamName.Length != category.Length)
                            {
                                param.TechParamName = param.TechParamName.Substring(category.Length);
                            }
                            groupedParams[category].Add(param);
                            isMatched = true;
                            break; // 匹配到第一个分类后停止(避免重复匹配)
@@ -23812,5 +24005,562 @@
            }
        }
        #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";
            // 匹配 {{ 字段名 }} 所需正则表达式 支持中文
            var regex = new Regex(@"{{\s*([\u4e00-\u9fa5a-zA-Z0-9_\s]+?)\s*}}", RegexOptions.Singleline);
            // 匹配 矩形框 位置 宽高 所需正则表达式
            var RectRegex = new Regex(@"^\^FO(\d+),(\d+)\^GB(\d+),(\d+)", RegexOptions.Singleline);
            // 匹配 模板字符串 所在行 位置 宽高 所需正则表达式 支持中文
            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")
            {
                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;
                }
                // 读取模板(UTF8 支持中文)
                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;
                            //}
                            //// 正则表达式匹配 {{ 字段名 }} 所在行的字段,如果有,则进行替换,没有,则默认为空字符串
                            //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,
                                templateRegex: regex,
                                ref concatStr))
                            {
                                // 正则表达式匹配 {{ 字段名 }} 所在行的字段,如果有,则进行替换,没有,则默认为空字符串
                                concatStr = regex.Replace(currentLine, match =>
                                {
                                    string fieldName = match.Groups[1].Value.Trim();
                                    if (msg != null && item.ContainsKey(fieldName))
                                    {
                                        return item[fieldName]?.ToString() ?? "";
                                    }
                                    return "";
                                });
                            }
                            if(string.IsNullOrWhiteSpace(concatStr))
                            {
                                concatStr = currentLine;
                            }
                            // 将所有 \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}";
                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)
            {
                // 字符串长度大于矩形的最大长度 则文本需要从矩形的Y位置开始渲染
                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;
                }
                // 计算每行应该放多少字符(正确算法)
                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
        #region APP根据设备id进行自动登录
        [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;
            }
        }
        #endregion
        #region 根据表名获取sql语句
        [HttpGet]
        [Route("Web/getSQL")]
        public object getSQL(string TableName, string ModeName, string OpertionType, string Identityid)
        {
            if (OpertionType == "insert")
            {
                string sql = $"select * from {TableName}";
                DataSet ds = oCN.RunProcReturn(sql, TableName);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "系统参数不存在,请联系管理";
                    objJsonResult.data = 0;
                    return objJsonResult;
                }
                sql = $"exec h_p_sqlhelper '{TableName}'";
                ds = oCN.RunProcReturn(sql, "h_p_sqlhelper");
                if (ds == null || ds.Tables.Count < 2 || ds.Tables[1].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "系统参数不存在,请联系管理";
                    objJsonResult.data = 0;
                    return objJsonResult;
                }
                StringBuilder sb = new StringBuilder();
                string columnsStr = ds.Tables[0].Rows[0][0].ToString();
                sb.AppendLine($"string sqlRes = $\"INSERT INTO [{TableName}] ({columnsStr})");
                sb.AppendLine("                VALUES (");
                // 2. 拼接 VALUES 里面的参数
                int count = ds.Tables[1].Rows.Count;
                for (int i = 0; i < count; i++)
                {
                    string propName = ds.Tables[1].Rows[i][0].ToString();
                    string valueFormat = "";
                    if (propName == "HMakeDate")
                    {
                        valueFormat = "getdata()";
                    }
                    else if (propName == "HERPItemID")
                    {
                        valueFormat = "'{0}'";
                    }
                    else
                    {
                        valueFormat = $"'{{{ModeName}.{propName}}}'"; // 默认通用逻辑
                    }
                    sb.Append("                " + valueFormat);
                    if (i < count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.AppendLine();
                }
                sb.AppendLine("                ); \";");
                sb.Append(" oCN.RunProc(sqlRes);");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "成功";
                objJsonResult.data = sb;
                return objJsonResult;
            }
            else
            {
                string whereKey = Identityid;
                string sql = $"select * from {TableName}";
                DataSet ds = oCN.RunProcReturn(sql, TableName);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "系统参数不存在,请联系管理";
                    objJsonResult.data = 0;
                    return objJsonResult;
                }
                sql = $"exec h_p_sqlhelper '{TableName}'";
                ds = oCN.RunProcReturn(sql, "h_p_sqlhelper");
                if (ds == null || ds.Tables.Count < 2 || ds.Tables[1].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "系统参数不存在,请联系管理";
                    objJsonResult.data = 0;
                    return objJsonResult;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append($"string sqlRes =$\"Update {TableName} set ");
                int count = ds.Tables[1].Rows.Count;
                int setFieldCount = 0;
                for (int i = 0; i < count; i++)
                {
                    string propName = ds.Tables[1].Rows[i][0].ToString();
                    if (propName == whereKey)
                        continue;
                    if (setFieldCount > 0)
                    {
                        sb.Append(",");
                    }
                    string valueFormat = "";
                    if (propName == "HModifyTime" || propName == "HUpDateDate")
                    {
                        valueFormat = $"{propName}=getdate()";
                    }
                    else
                    {
                        valueFormat = $"{propName}='{{{ModeName}.{propName}}}'";
                    }
                    sb.Append("\r\n                " + valueFormat);
                    setFieldCount++;
                }
                sb.Append($" where {whereKey}='{{{ModeName}.{whereKey}}}'\"");
                sb.AppendLine();
                sb.Append("oCN.RunProc(sqlRes);");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "成功";
                objJsonResult.data = sb;
                return objJsonResult;
            }
        }
        #endregion
    }
}