如洲 陈
2025-05-29 8179d11bf6e45093ceabf0449ddac3fd7a73e818
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
using MES.Service.DB;
using MES.Service.Dto.service;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using MES.Service.util;
using Microsoft.Data.SqlClient;
using SqlSugar;
using System.Data;
using System.Dynamic;
 
namespace MES.Service.service
{
    public class SysUserService : Repository<SysUser>
    {
 
            public List<UserPermission> QueryPurview(string userNo)
            {
                // 获取用户权限列表
                List<string> purviewData = this.DoPurview(userNo);
                List<UserPermission> resultList = new List<UserPermission>();
 
                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[] { '#' });
 
                            UserPermission permission = new UserPermission
                            {
                                Name = itemArray[0],
                                Category = "全部应用",
                                IconType = itemArray[1],
                                Path = "input" ,
                                Color = itemArray[2]
                            };
 
                            resultList.Add(permission);
                        }
                    }
                }
 
                // 添加退出选项
               /* resultList.Add(new UserPermission
                {
                    Name = "退出",
                    Category = "全部应用",
                    IconType = "close",
                    Path = "/logout",
                    Color = "red"
                });*/
 
                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_j2_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;
        }
 
 
        /// <summary>
        /// 获取功能界面设置
        /// </summary>
        /// <param name="functionName">功能名称</param>
 
 
        /// <summary>
        /// 获取功能界面设置
        /// </summary>
        /// <param name="functionName">功能名称</param>
        /// <returns>功能界面设置信息</returns>
        public ResponseResult GetRfSetup(string functionName)
        {
            try
            {
                List<string> setupData = DoRfSetup(functionName);
 
                if (setupData.Count > 0 && !string.IsNullOrEmpty(setupData[0]))
                {
                    dynamic resultInfos = new ExpandoObject();
                    resultInfos.setupData = setupData[0];
 
                    return new ResponseResult
                    {
                        status = 0,
                        message = "查询功能界面成功!",
                        data = resultInfos
                    };
                }
                else
                {
                    return new ResponseResult
                    {
                        status = 1,
                        message = "未找到功能界面设置!"
                    };
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return new ResponseResult
                {
                    status = 1,
                    message = "查询功能界面失败!"
                };
            }
        }
 
 
        /// <summary>
        /// 获取功能界面设置数据
        /// </summary>
        /// <param name="functionName">功能名称</param>
        /// <returns>功能界面设置数据列表</returns>
        private List<string> DoRfSetup(string functionName)
        {
            List<string> resultList = new List<string>();
 
            try
            {
                // 定义输入参数
                var inputParam1 = new SugarParameter("functionName", functionName);
                var inputParam2 = new SugarParameter("deviceType", "AN");
 
                // 定义输出参数
                var outParam = new SugarParameter("result", null, true);
 
                // 使用SqlSugar执行存储过程
                Db.Ado.ExecuteCommand("BEGIN Prc_rf_setup(:functionName, :deviceType, :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;
        }
 
 
 
        public ResponseResult GetExcProc(string functionName, string fileName, string pmachtype, string fileValue, string outFiles)
        {
            try
            {
                List<string> resultList = DoExcProc(functionName, fileName, pmachtype, fileValue);
                Console.WriteLine(string.Join(", ", resultList));
 
                if (resultList.Count > 0)
                {
                    string s = resultList[0];
                    string[] strs = s.Split('[');
 
                    if (strs.Length < 1)
                    {
                        return new ResponseResult
                        {
                            status = 1,
                            message = "返回值的格式不正确!" + string.Join(", ", resultList)
                        };
                    }
 
                    // 判断取值是否成功
                    string str = strs[0];
                    if (str.Equals("002"))
                    {
                        return new ResponseResult
                        {
                            status = 1,
                            message = strs[1]
                        };
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(outFiles))
                        {
                            if (strs.Length < 2)
                            {
                                return new ResponseResult
                                {
                                    status = 0,
                                    data = ""
                                };
                            }
                            return new ResponseResult
                            {
                                status = 0,
                                data = strs[1]
                            };
                        }
                        else
                        {
                            List<string[]> at = new List<string[]>();
                            // [001[4500108372,80000123,100,物料80000123今日已收货 100]
                            string[] files = outFiles.Split(',');
                            string[] res = strs[1].Split(new char[] { ',' }, StringSplitOptions.None);
 
                            for (int i = 0; i < files.Length; i++)
                            {
                                string[] temp = new string[2];
                                temp[0] = files[i];
                                temp[1] = res[i];
                                at.Add(temp);
                            }
 
                            return new ResponseResult
                            {
                                status = 0,
                                data = at
                            };
                        }
                    }
                }
 
                return new ResponseResult
                {
                    status = 0,
                    data = resultList
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return new ResponseResult
                {
                    status = 1,
                    message = "执行存储过程失败:" + ex.Message
                };
            }
        }
 
 
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="functionName">功能名称</param>
        /// <param name="fileName">字段名</param>
        /// <param name="pmachtype">设备类型</param>
        /// <param name="fileValue">参数值</param>
        /// <returns>存储过程执行结果</returns>
        private List<string> DoExcProc(string functionName, string fileName, string pmachtype, string fileValue)
        {
            List<string> resultList = new List<string>();
 
            try
            {
                // 定义输入参数
                var inputParam1 = new SugarParameter("functionName", functionName);
                var inputParam2 = new SugarParameter("fileName", fileName?.Trim());
                var inputParam3 = new SugarParameter("pmachtype", "AN"); // 设备类型 wince5,wmb5,wmb6
                var inputParam4 = new SugarParameter("fileValue", fileValue); // 参数值[第一位是用户]
 
                // 定义输出参数
                var outParam = new SugarParameter("result", null, true);
 
                // 使用SqlSugar执行存储过程
                Db.Ado.ExecuteCommand("BEGIN Prc_rf_setup_ExcProc(:functionName, :fileName, :pmachtype, :fileValue, :result); END;",
                    inputParam1, inputParam2, inputParam3, inputParam4, 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;
        }
 
    }
}