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;
|
}
|
|
}
|
}
|