2024-05-28 14:36:38 +00:00
|
|
|
|
using DeviceRepair.Models;
|
|
|
|
|
using DeviceRepair.Models.Device;
|
|
|
|
|
using DeviceRepair.Models.History;
|
|
|
|
|
using DeviceRepair.Utils;
|
2024-07-22 07:50:10 +00:00
|
|
|
|
using NLog;
|
2024-05-28 14:36:38 +00:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2024-07-22 07:50:10 +00:00
|
|
|
|
using System.Xml.Linq;
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|
|
|
|
|
namespace DeviceRepair.DataAccess
|
|
|
|
|
{
|
|
|
|
|
public class DeviceAccess : DbContext<DeviceInformationInfo>
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
private static readonly Logger log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
private static DeviceAccess manager;
|
|
|
|
|
public static DeviceAccess Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (manager == null)
|
|
|
|
|
manager = new DeviceAccess();
|
|
|
|
|
return manager;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-22 07:50:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据用户权限获取设备信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="LoginCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<DeviceInformationInfo> GetDevsByLoginAuths(string LoginCode)
|
|
|
|
|
{
|
|
|
|
|
List<DeviceInformationInfo> Devs = new List<DeviceInformationInfo>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.ChangeDatabase("main");
|
|
|
|
|
Devs = db.Ado.SqlQuery<DeviceInformationInfo>("SELECT * FROM dbo.func_GetDeviceInfoByUserAuth(@LoginCode)", new { LoginCode }).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ex);
|
|
|
|
|
}
|
|
|
|
|
return Devs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public APIResponseData GetDeviceRoute(string LoginCode)
|
2024-06-02 16:38:52 +00:00
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.ChangeDatabase("main");
|
2024-07-22 07:50:10 +00:00
|
|
|
|
|
|
|
|
|
/* 获取用户权限 */
|
|
|
|
|
List<string> UserAuths = RoleAccess.Instance.GetUserAuthsByLoginCode(LoginCode);
|
|
|
|
|
if (UserAuths.Count == 0)
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
|
|
|
|
|
List<string> keys = new List<string>();
|
|
|
|
|
/* 判断是否存在康辉设备权限 */
|
|
|
|
|
if (UserAuths.Any(x => x.Equals(AuthCodeConstValue.DEVICE_KH, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
keys.Add("KH");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 判断是否存在OEM设备权限 */
|
|
|
|
|
if (UserAuths.Any(x => x.Equals(AuthCodeConstValue.DEVICE_OEM, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
keys.Add("OEM");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 获取权限分组 */
|
|
|
|
|
List<DeviceRouteInfo> route = db.Ado.SqlQuery<DeviceRouteInfo>(@";WITH cte
|
|
|
|
|
AS (SELECT AutoID,
|
|
|
|
|
Name
|
|
|
|
|
FROM dbo.DeviceRoute
|
|
|
|
|
WHERE (ParentID = 0)
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT dr.AutoID,
|
|
|
|
|
cte_1.Name
|
|
|
|
|
FROM dbo.DeviceRoute AS dr
|
|
|
|
|
INNER JOIN cte AS cte_1
|
|
|
|
|
ON dr.ParentID = cte_1.AutoID)
|
|
|
|
|
SELECT AutoID,Name
|
|
|
|
|
FROM cte WHERE Name IN (@Name)", new { Name = keys }).ToList();
|
|
|
|
|
|
|
|
|
|
int[] routeIds = route.Select(x => x.AutoID).ToArray();
|
|
|
|
|
|
|
|
|
|
List<DeviceRouteInfo> Data = db.Queryable<DeviceRouteInfo>().Where(x => x.Status && SqlFunc.ContainsArray(routeIds, x.AutoID)).ToList();
|
|
|
|
|
|
2024-06-02 16:38:52 +00:00
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = Data;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-06-02 16:38:52 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-06-02 16:38:52 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过设备编号查询设备信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="EquipmentID"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-07-22 07:50:10 +00:00
|
|
|
|
public APIResponseData GetModelByEquipmentID(string EquipmentID, string LoginCode)
|
2024-05-28 14:36:38 +00:00
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.ChangeDatabase("main");
|
2024-07-22 07:50:10 +00:00
|
|
|
|
List<DeviceInformationInfo> Devs = GetDevsByLoginAuths(LoginCode);
|
|
|
|
|
if (Devs.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
apiResponseData.Data = Devs.FirstOrDefault(x => x.EquipmentID.Equals(EquipmentID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="FilterValue"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-07-22 07:50:10 +00:00
|
|
|
|
public APIResponseData GetQuery(string FilterValue, string LoginCode)
|
2024-05-28 14:36:38 +00:00
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
/* 获取设备信息 */
|
|
|
|
|
List<DeviceInformationInfo> Devs = GetDevsByLoginAuths(LoginCode);
|
|
|
|
|
if (Devs.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
db.ChangeDatabase("main");
|
|
|
|
|
|
2024-07-22 07:50:10 +00:00
|
|
|
|
/* 设备主键编号 */
|
|
|
|
|
int[] Devids = Devs.Select(x => x.AutoID).ToArray();
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
int aid = 0;
|
|
|
|
|
int.TryParse(FilterValue, out aid);
|
|
|
|
|
|
|
|
|
|
var exp = Expressionable.Create<View_DriveInfomationModel>()
|
|
|
|
|
.OrIF(aid > 0, t1 => t1.AutoID == aid)
|
|
|
|
|
.OrIF(!string.IsNullOrEmpty(FilterValue),
|
2024-06-10 17:33:11 +00:00
|
|
|
|
t1 => t1.EquipmentID.Contains(FilterValue)
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|| t1.EquipmentName.Contains(FilterValue)
|
|
|
|
|
|| t1.Remarks.Contains(FilterValue)
|
|
|
|
|
|| t1.Specification.Contains(FilterValue)).ToExpression();//拼接表达式
|
|
|
|
|
|
2024-06-02 16:38:52 +00:00
|
|
|
|
var Datas = db.Queryable<DeviceInformationInfo, MaintenanceFormVersionInfo, DeviceRouteInfo>(
|
|
|
|
|
(t1, t2, t3) => new object[] {
|
|
|
|
|
JoinType.Left, t1.MaintenanceFormVersion == t2.AutoID,
|
|
|
|
|
JoinType.Left, t1.Route == t3.AutoID
|
|
|
|
|
}).Select((t1, t2, t3) => new View_DriveInfomationModel
|
2024-05-28 14:36:38 +00:00
|
|
|
|
{
|
|
|
|
|
AutoID = t1.AutoID,
|
|
|
|
|
ChangeDate = t1.ChangeDate,
|
|
|
|
|
ChangeUser = t1.ChangeUser,
|
|
|
|
|
CreatDate = t1.CreatDate,
|
|
|
|
|
CreatUser = t1.CreatUser,
|
|
|
|
|
EquipmentCategory = t1.EquipmentCategory,
|
|
|
|
|
EquipmentID = t1.EquipmentID,
|
|
|
|
|
EquipmentName = t1.EquipmentName,
|
|
|
|
|
EquipmentOriginalvalue = t1.EquipmentOriginalvalue,
|
|
|
|
|
EquipmentStatus = t1.EquipmentStatus,
|
|
|
|
|
InstallationLocation = t1.InstallationLocation,
|
|
|
|
|
MaintenanceFormVersion = t1.MaintenanceFormVersion,
|
|
|
|
|
MaintenanceFormVersionName = t2.FormName,
|
|
|
|
|
MaintenanceFormStatus = t2.FormStatus,
|
|
|
|
|
Manufacturer = t1.Manufacturer,
|
|
|
|
|
OperatingParameters = t1.OperatingParameters,
|
|
|
|
|
OwningUnit = t1.OwningUnit,
|
|
|
|
|
Remarks = t1.Remarks,
|
|
|
|
|
SerialNumber = t1.SerialNumber,
|
|
|
|
|
Specification = t1.Specification,
|
|
|
|
|
Totalcapacity = t1.Totalcapacity,
|
|
|
|
|
UsingDate = t1.UsingDate,
|
|
|
|
|
VersionCode = t2.VersionCode,
|
|
|
|
|
VersionRev = t2.VersionRev,
|
|
|
|
|
WarrantyPeriod = t1.WarrantyPeriod,
|
2024-06-02 16:38:52 +00:00
|
|
|
|
Route = t1.Route,
|
|
|
|
|
RouteText = t3.Name,
|
2024-05-28 14:36:38 +00:00
|
|
|
|
Weight = t1.Weight
|
2024-07-22 07:50:10 +00:00
|
|
|
|
}).Where(t1 => SqlFunc.ContainsArray(Devids, t1.AutoID)).Where(exp)
|
2024-05-28 14:36:38 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = Datas;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="FilterValue"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-07-22 07:50:10 +00:00
|
|
|
|
public APIResponseData GetDataByAutoID(int pk, string LoginCode)
|
2024-05-28 14:36:38 +00:00
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
/* 获取设备信息 */
|
|
|
|
|
List<DeviceInformationInfo> Devs = GetDevsByLoginAuths(LoginCode);
|
|
|
|
|
if (Devs.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|
2024-07-22 07:50:10 +00:00
|
|
|
|
apiResponseData.Data = Devs.FirstOrDefault(x => x.AutoID == pk);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
|
|
|
|
db.RollbackTran();//数据回滚
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
db.RollbackTran();//数据回滚
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改设备信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dictionary"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public APIResponseData UpdateDriveInformation(Dictionary<string, object> dictionary, HeaderModel Operation)
|
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
|
|
|
|
|
|
|
|
db.ChangeDatabase("main");
|
|
|
|
|
|
|
|
|
|
bool isSuccess = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!dictionary.ContainsKey("AutoID"))
|
|
|
|
|
throw new Exception("未能获取到主键编号");
|
|
|
|
|
int AutoID = Convert.ToInt32(dictionary["AutoID"]);
|
|
|
|
|
|
|
|
|
|
DateTime CurrentDate = DateTime.Now;
|
|
|
|
|
|
2024-06-03 17:21:11 +00:00
|
|
|
|
if (dictionary.ContainsKey("RouteText"))
|
|
|
|
|
dictionary.Remove("RouteText");
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|
|
|
|
|
if (AutoID == 0)
|
|
|
|
|
{
|
|
|
|
|
if (dictionary.ContainsKey("CreatDate"))
|
|
|
|
|
dictionary["CreatDate"] = CurrentDate;
|
|
|
|
|
|
|
|
|
|
if (dictionary.ContainsKey("ChangeDate"))
|
|
|
|
|
dictionary["ChangeDate"] = CurrentDate;
|
|
|
|
|
|
|
|
|
|
if (dictionary.ContainsKey("VersionCode"))
|
|
|
|
|
dictionary.Remove("VersionCode");
|
|
|
|
|
|
|
|
|
|
if (dictionary.ContainsKey("VersionRev"))
|
|
|
|
|
dictionary.Remove("VersionRev");
|
|
|
|
|
|
|
|
|
|
long aid = db.Insertable(dictionary).AS("DriveInformation").IgnoreColumns("AutoID").ExecuteReturnBigIdentity();
|
|
|
|
|
|
|
|
|
|
if (aid > 0)
|
|
|
|
|
{
|
|
|
|
|
db.CommitTran();
|
|
|
|
|
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
apiResponseData.Data = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DeviceInformationInfo model = db.Queryable<DeviceInformationInfo>().Single(x => x.AutoID == AutoID);
|
|
|
|
|
if (model == null)
|
|
|
|
|
throw new Exception("未能获取的设备信息");
|
|
|
|
|
|
|
|
|
|
db.BeginTran();
|
|
|
|
|
isSuccess = db.Updateable(dictionary).AS("DriveInformation").WhereColumns("AutoID").ExecuteCommandHasChange();
|
|
|
|
|
if (isSuccess)
|
|
|
|
|
{
|
|
|
|
|
db.CommitTran();
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
apiResponseData.Data = null;
|
|
|
|
|
|
|
|
|
|
db.ChangeDatabase("log");
|
|
|
|
|
DriveInformationHistory log = ObjectExtend.Mapper<DriveInformationHistory, DeviceInformationInfo>(model);
|
|
|
|
|
log.DriveInformationID = log.AutoID;
|
|
|
|
|
log.AutoID = 0;
|
|
|
|
|
log.Changer = Operation.Operator;
|
|
|
|
|
log.ApplyDate = CurrentDate;
|
|
|
|
|
long id = db.Insertable(log).ExecuteReturnIdentity();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
|
|
|
|
db.RollbackTran();//数据回滚
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
db.RollbackTran();//数据回滚
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取树形结构
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="FilterValue"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-07-22 07:50:10 +00:00
|
|
|
|
public APIResponseData GetDeviceTreeDatas(string FilterValue, string LoginCode)
|
2024-05-28 14:36:38 +00:00
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.ChangeDatabase("main");
|
|
|
|
|
|
2024-07-22 07:50:10 +00:00
|
|
|
|
/* 获取用户权限 */
|
|
|
|
|
List<string> UserAuths = RoleAccess.Instance.GetUserAuthsByLoginCode(LoginCode);
|
|
|
|
|
if (UserAuths.Count == 0)
|
|
|
|
|
return apiResponseData;
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|
2024-07-22 07:50:10 +00:00
|
|
|
|
List<string> keys = new List<string>();
|
|
|
|
|
/* 判断是否存在康辉设备权限 */
|
|
|
|
|
if (UserAuths.Any(x => x.Equals(AuthCodeConstValue.DEVICE_KH, StringComparison.OrdinalIgnoreCase)))
|
2024-06-04 09:25:13 +00:00
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
keys.Add("KH");
|
2024-06-10 17:33:11 +00:00
|
|
|
|
}
|
2024-07-22 07:50:10 +00:00
|
|
|
|
|
|
|
|
|
/* 判断是否存在OEM设备权限 */
|
|
|
|
|
if (UserAuths.Any(x => x.Equals(AuthCodeConstValue.DEVICE_OEM, StringComparison.OrdinalIgnoreCase)))
|
2024-06-10 17:33:11 +00:00
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
keys.Add("OEM");
|
2024-06-04 09:25:13 +00:00
|
|
|
|
}
|
2024-07-22 07:50:10 +00:00
|
|
|
|
|
|
|
|
|
/* 获取权限分组 */
|
|
|
|
|
List<DeviceRouteInfo> route = db.Ado.SqlQuery<DeviceRouteInfo>(@";WITH cte
|
|
|
|
|
AS (SELECT AutoID,
|
|
|
|
|
Name
|
|
|
|
|
FROM dbo.DeviceRoute
|
|
|
|
|
WHERE (ParentID = 0)
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT dr.AutoID,
|
|
|
|
|
cte_1.Name
|
|
|
|
|
FROM dbo.DeviceRoute AS dr
|
|
|
|
|
INNER JOIN cte AS cte_1
|
|
|
|
|
ON dr.ParentID = cte_1.AutoID)
|
|
|
|
|
SELECT DeviceRoute.*
|
|
|
|
|
FROM dbo.DeviceRoute
|
|
|
|
|
INNER JOIN cte ON cte.AutoID = DeviceRoute.AutoID WHERE cte.Name IN (@Name) AND Status = 1", new { Name = keys }).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int aid = 0;
|
|
|
|
|
int.TryParse(FilterValue, out aid);
|
|
|
|
|
var Root = route.ToDictionary(x => x.AutoID, x => x);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|
|
|
|
|
List<DeviceInformationInfoTree> Menus = new List<DeviceInformationInfoTree>();
|
2024-06-04 09:25:13 +00:00
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
foreach (KeyValuePair<int, DeviceRouteInfo> item in Root)
|
|
|
|
|
{
|
|
|
|
|
DeviceRouteInfo dev = item.Value;
|
|
|
|
|
Menus.Add(new DeviceInformationInfoTree
|
|
|
|
|
{
|
|
|
|
|
EquipmentName = dev.Name,
|
|
|
|
|
RouteAutoId = dev.GUID,
|
|
|
|
|
ParentRouteId = dev.ParentID != 0 ? Root[dev.ParentID].GUID : Guid.Empty
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int[] RouteIds = Root.Keys.ToArray();
|
2024-06-04 09:25:13 +00:00
|
|
|
|
|
|
|
|
|
var exp = Expressionable.Create<DeviceInformationInfoTree>()
|
|
|
|
|
.OrIF(aid > 0, t1 => t1.AutoID == aid)
|
|
|
|
|
.OrIF(!string.IsNullOrEmpty(FilterValue),
|
|
|
|
|
t1 => t1.EquipmentID.Equals(FilterValue, StringComparison.CurrentCultureIgnoreCase)
|
|
|
|
|
|| t1.EquipmentName.Contains(FilterValue)
|
|
|
|
|
|| t1.Remarks.Contains(FilterValue)
|
|
|
|
|
|| t1.Specification.Contains(FilterValue))
|
|
|
|
|
.And(t1 => SqlFunc.ContainsArray(RouteIds, t1.Route)).ToExpression();//拼接表达式
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
var Datas = db.Queryable<DeviceInformationInfo, MaintenanceFormVersionInfo, DeviceRouteInfo>(
|
|
|
|
|
(t1, t2, t3) => new object[] {
|
|
|
|
|
JoinType.Left, t1.MaintenanceFormVersion == t2.AutoID,
|
|
|
|
|
JoinType.Left, t1.Route == t3.AutoID
|
|
|
|
|
}
|
|
|
|
|
).Select((t1, t2, t3) => new DeviceInformationInfoTree
|
|
|
|
|
{
|
|
|
|
|
AutoID = t1.AutoID,
|
|
|
|
|
ChangeDate = t1.ChangeDate,
|
|
|
|
|
ChangeUser = t1.ChangeUser,
|
|
|
|
|
CreatDate = t1.CreatDate,
|
|
|
|
|
CreatUser = t1.CreatUser,
|
|
|
|
|
EquipmentCategory = t1.EquipmentCategory,
|
|
|
|
|
EquipmentID = t1.EquipmentID,
|
|
|
|
|
EquipmentName = t1.EquipmentName,
|
|
|
|
|
EquipmentOriginalvalue = t1.EquipmentOriginalvalue,
|
|
|
|
|
EquipmentStatus = t1.EquipmentStatus,
|
|
|
|
|
InstallationLocation = t1.InstallationLocation,
|
|
|
|
|
MaintenanceFormVersion = t1.MaintenanceFormVersion,
|
|
|
|
|
MaintenanceFormVersionName = t2.FormName,
|
|
|
|
|
Manufacturer = t1.Manufacturer,
|
|
|
|
|
OperatingParameters = t1.OperatingParameters,
|
|
|
|
|
OwningUnit = t1.OwningUnit,
|
|
|
|
|
Remarks = t1.Remarks,
|
|
|
|
|
SerialNumber = t1.SerialNumber,
|
|
|
|
|
Specification = t1.Specification,
|
|
|
|
|
Totalcapacity = t1.Totalcapacity,
|
|
|
|
|
UsingDate = t1.UsingDate,
|
|
|
|
|
VersionCode = t2.VersionCode,
|
|
|
|
|
VersionRev = t2.VersionRev,
|
|
|
|
|
WarrantyPeriod = t1.WarrantyPeriod,
|
|
|
|
|
Weight = t1.Weight,
|
|
|
|
|
Route = t3.AutoID,
|
|
|
|
|
RouteAutoId = t1.GUID,
|
|
|
|
|
//ParentRouteId = SqlFunc.ContainsArray(RouteIds, t1.Route) ? Root[t1.Route].Guid : Guid.Empty
|
|
|
|
|
}).Where(exp)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2024-05-30 02:11:52 +00:00
|
|
|
|
if ((Datas?.Count ?? 0) == 0)
|
|
|
|
|
{
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = new List<DeviceInformationInfoTree>();
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 09:25:13 +00:00
|
|
|
|
bool hasEmpty = Menus.Any(x => x.RouteAutoId == Guid.Empty);
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
foreach (DeviceInformationInfoTree item in Datas)
|
|
|
|
|
{
|
|
|
|
|
item.ParentRouteId = RouteIds.Contains(item.Route) ? Root[item.Route].GUID : Guid.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Guid> HasValues = new List<Guid>();
|
2024-05-30 02:11:52 +00:00
|
|
|
|
Guid[] gids = Datas.Select(x => x.ParentRouteId).Distinct().ToArray();
|
2024-05-28 14:36:38 +00:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (HasValues.Count == 0)
|
|
|
|
|
HasValues.AddRange(gids);
|
|
|
|
|
|
|
|
|
|
gids = Menus.Where(x => gids.Contains(x.RouteAutoId)).Select(s => s.ParentRouteId).Distinct().ToArray();
|
|
|
|
|
HasValues.AddRange(gids);
|
|
|
|
|
} while (gids.All(x => x == Guid.Empty));
|
|
|
|
|
|
2024-06-04 09:25:13 +00:00
|
|
|
|
Menus.RemoveAll(x => !HasValues.Contains(x.RouteAutoId) && x.ParentRouteId != Guid.Empty);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
Menus.AddRange(Datas);
|
|
|
|
|
|
2024-06-10 17:33:11 +00:00
|
|
|
|
|
2024-07-22 07:50:10 +00:00
|
|
|
|
foreach (DeviceRouteInfo item in route)
|
2024-06-10 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
DeviceInformationInfoTree Node = Menus.FirstOrDefault(x => x.RouteAutoId == item.GUID);
|
|
|
|
|
List<DeviceInformationInfoTree> Child = Menus.Where(x => x.Route == item.AutoID).ToList();
|
|
|
|
|
if (Node != null && Child.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Node.Totalcapacity = Child.Sum(x => x.Totalcapacity);
|
|
|
|
|
Node.Weight = Child.Sum(x => x.Weight);
|
|
|
|
|
Node.EquipmentOriginalvalue = Child.Sum(x => x.EquipmentOriginalvalue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = Menus;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public decimal GetSum(List<DeviceInformationInfoTree> t1, List<DeviceRouteInfo> t2, int RouteID)
|
|
|
|
|
{
|
|
|
|
|
decimal value = 0;
|
|
|
|
|
DeviceRouteInfo r = t2.FirstOrDefault(x => x.AutoID == RouteID);
|
|
|
|
|
if (r != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|