using MES.Service.DB;
|
using MES.Service.Dto.webApi;
|
using MES.Service.Modes;
|
using SqlSugar;
|
|
namespace MES.Service.service
|
{
|
public class SysUserService : Repository<SysUser>
|
{
|
|
public List<Dictionary<string, object>> QueryPurview(string userNo)
|
{
|
// 获取用户权限列表
|
List<string> purviewData = this.DoPurview(userNo);
|
List<Dictionary<string, object>> resultList = new List<Dictionary<string, object>>();
|
|
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<string, object> itemDict = new Dictionary<string, object>();
|
itemDict["name"] = itemArray[0]; // 第一部分作为名称
|
|
if (itemArray.Length > 1)
|
{
|
itemDict["code"] = itemArray[1]; // 第二部分作为代码
|
}
|
else
|
{
|
itemDict["code"] = ""; // 如果没有第二部分,设置为空字符串
|
}
|
|
resultList.Add(itemDict);
|
}
|
}
|
}
|
|
// 添加退出选项
|
Dictionary<string, object> exitDict = new Dictionary<string, object>();
|
exitDict["name"] = "退出";
|
exitDict["code"] = "tuichu";
|
resultList.Add(exitDict);
|
|
return resultList;
|
}
|
|
|
private List<string> DoPurview(string userNo)
|
{
|
List<string> resultList = new List<string>();
|
|
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;
|
}
|
|
|
}
|
}
|