wbc
2025-05-30 1167bba23716eeda7ad6342b8d6ca736adca16c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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;
        }
 
 
    }
}