using MES.Service.DB; using MES.Service.Dto.webApi; using MES.Service.Modes; using SqlSugar; namespace MES.Service.service { public class SysUserService : Repository { public List> QueryPurview(string userNo) { // 获取用户权限列表 List purviewData = this.DoPurview(userNo); List> resultList = new List>(); if (purviewData.Count > 0) { string purviewString = purviewData[0]; string[] splitResult = purviewString.Split(new string[] { "[" }, StringSplitOptions.None); if (splitResult.Length > 2) { for (int i = 2; i < splitResult.Length; i++) { string trimmedStr = splitResult[i].Trim(); // 去掉空格 string[] itemArray = trimmedStr.Split(new char[] { '#' }); // 创建字典并添加键值对 Dictionary itemDict = new Dictionary(); itemDict["name"] = itemArray[0]; // 第一部分作为名称 if (itemArray.Length > 1) { itemDict["code"] = itemArray[1]; // 第二部分作为代码 } else { itemDict["code"] = ""; // 如果没有第二部分,设置为空字符串 } resultList.Add(itemDict); } } } // 添加退出选项 Dictionary exitDict = new Dictionary(); exitDict["name"] = "退出"; exitDict["code"] = "tuichu"; resultList.Add(exitDict); return resultList; } private List DoPurview(string userNo) { List resultList = new List(); try { // 定义输入参数 var inputParam1 = new SugarParameter("c_User_No", userNo.ToUpper()); var inputParam2 = new SugarParameter("c_MachType", "AN"); // 定义输出参数 var outParam = new SugarParameter("c_Result", null, true); // 使用SqlSugar执行存储过程 Db.Ado.ExecuteCommand("BEGIN Prc_rf_j1_user_login(:c_User_No, :c_MachType, :c_Result); END;", inputParam1, inputParam2, outParam); // 获取输出参数的值 string result = outParam.Value == DBNull.Value ? string.Empty : (string)outParam.Value; // 添加到结果列表 if (!string.IsNullOrEmpty(result)) { resultList.Add(result); } } catch (Exception ex) { // 记录异常 Console.WriteLine($"获取用户权限失败: {ex.Message}"); // 可以选择抛出异常或返回空列表 } return resultList; } } }