312 lines
11 KiB
C#
312 lines
11 KiB
C#
|
using DeviceRepair.Models;
|
|||
|
using DeviceRepair.Models.DeviceRepair.ExportView;
|
|||
|
using DeviceRepair.Models.SFC;
|
|||
|
using DeviceRepair.Utils;
|
|||
|
using NLog;
|
|||
|
using NLog.Filters;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using TsSFCDevice.Client.Biz.Base.Service;
|
|||
|
using TsSFCDevice.Client.Biz.Base.Utils;
|
|||
|
|
|||
|
namespace TsSFCDevice.Client.Biz.Impl
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 设备维修
|
|||
|
/// </summary>
|
|||
|
public class MaintenanceRepository
|
|||
|
{
|
|||
|
private readonly Logger log;
|
|||
|
private static MaintenanceRepository manager;
|
|||
|
|
|||
|
private IDictionary<string, string> m_ApiParameters;
|
|||
|
/// <summary>
|
|||
|
/// API输入参数
|
|||
|
/// </summary>
|
|||
|
public IDictionary<string, string> ApiParameters
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return m_ApiParameters;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
m_ApiParameters = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static MaintenanceRepository Instance
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (manager == null)
|
|||
|
manager = new MaintenanceRepository();
|
|||
|
return manager;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public MaintenanceRepository()
|
|||
|
{
|
|||
|
log = LogManager.GetCurrentClassLogger();
|
|||
|
m_ApiParameters = new Dictionary<string, string>();
|
|||
|
}
|
|||
|
|
|||
|
internal string GetParameters(string cOperator = "", bool bFlag = true)
|
|||
|
{
|
|||
|
|
|||
|
return ParametersObject.GetInstance(cOperator).GetJsonSerialized(m_ApiParameters);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设备维修数据
|
|||
|
/// </summary>
|
|||
|
/// <param name="filter"></param>
|
|||
|
/// <returns></returns>
|
|||
|
/// <exception cref="Exception"></exception>
|
|||
|
public IList<DeviceWarrantyRequestFormView> GetDatas(DeviceWarrantyRequestFormFilter filter)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
byte[] btResults = null;
|
|||
|
int[] EquipmentIds = Utility.SystemRuntimeInfo.CurrentDeviceCaches?.Select(x => x.AutoID)?.ToArray();
|
|||
|
if (EquipmentIds == null || EquipmentIds.Length == 0)
|
|||
|
{
|
|||
|
return new List<DeviceWarrantyRequestFormView>();
|
|||
|
}
|
|||
|
|
|||
|
ApiParameters?.Clear();
|
|||
|
ApiParameters.Add("EquipmentID", filter.EquipmentID);
|
|||
|
ApiParameters.Add("Status", ((int)filter.Status) + "");
|
|||
|
ApiParameters.Add("DownStatus", ((int)filter.DownStatus) + "");
|
|||
|
if (filter.StartTime.HasValue)
|
|||
|
{
|
|||
|
ApiParameters.Add("StartTime", filter.StartTime.Value.ToString("yyyy-MM-dd hh:mm:ss"));
|
|||
|
}
|
|||
|
|
|||
|
if (filter.EndTime.HasValue)
|
|||
|
{
|
|||
|
ApiParameters.Add("EndTime", filter.EndTime.Value.ToString("yyyy-MM-dd hh:mm:ss"));
|
|||
|
}
|
|||
|
|
|||
|
var Rtn = Utility.SfcBizService.CurrentSvc.GetDatas(DeviceSvc.SysModelType.Maintenance, GetParameters(), out btResults);
|
|||
|
if (Rtn.Code != 1)
|
|||
|
{
|
|||
|
throw new Exception(Rtn.Message);
|
|||
|
}
|
|||
|
DataSet dsResults = CompressionHelper.ExactDataSet(btResults);
|
|||
|
if (dsResults.Tables["Form"] == null)
|
|||
|
{
|
|||
|
return new List<DeviceWarrantyRequestFormView>();
|
|||
|
}
|
|||
|
|
|||
|
IList<DeviceWarrantyRequestFormView> Datas = DTOHelper<DeviceWarrantyRequestFormView>.DataTableToList(dsResults.Tables["Form"]);
|
|||
|
Datas = Datas.Where(x => EquipmentIds.Contains(x.EquipmentPK))?.ToList();
|
|||
|
|
|||
|
IList<DeviceWarrantyRequestMaintaionView> Maintaion = DTOHelper<DeviceWarrantyRequestMaintaionView>.DataTableToList(dsResults.Tables["Maintaion"]);
|
|||
|
IList<DeviceWarrantyEvaluatorInfo> Evals = DTOHelper<DeviceWarrantyEvaluatorInfo>.DataTableToList(dsResults.Tables["Eval"]);
|
|||
|
|
|||
|
Dictionary<int, string> dictUser = Utility.SystemRuntimeInfo.CurrentUsersCaches?.ToDictionary(x => x.Id, x => x.UserName);
|
|||
|
|
|||
|
foreach (DeviceWarrantyRequestFormView item in Datas)
|
|||
|
{
|
|||
|
if (item.CreatBy.HasValue && dictUser.ContainsKey(item.CreatBy.Value))
|
|||
|
{
|
|||
|
item.CreatorName = dictUser[item.CreatBy.Value];
|
|||
|
}
|
|||
|
|
|||
|
if (item.ModifyBy.HasValue && dictUser.ContainsKey(item.ModifyBy.Value))
|
|||
|
{
|
|||
|
item.ModifyByName = dictUser[item.ModifyBy.Value];
|
|||
|
}
|
|||
|
//item.RestorationConfirmationBy
|
|||
|
if (item.RestorationConfirmationBy > 0 && dictUser.ContainsKey(item.RestorationConfirmationBy))
|
|||
|
{
|
|||
|
item.RestorationConfirmationOnName = dictUser[item.RestorationConfirmationBy];
|
|||
|
}
|
|||
|
|
|||
|
item.MaintaionItems = Maintaion.FirstOrDefault(x => x.FormID == item.AutoID);
|
|||
|
item.EvaluatorItems = Evals.Where(x => x.FormID == item.AutoID)?.ToList();
|
|||
|
}
|
|||
|
|
|||
|
return Datas.Where(x => Utility.SystemRuntimeInfo.CurrentDeviceAutoIDCaches.Contains(x.EquipmentPK)).ToList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
log.Error(ex.Message, ex);
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取维修单 维修配件列表
|
|||
|
/// </summary>
|
|||
|
/// <param name="MaintaionID"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public IList<DeviceWarrantyRequestAccessoriesInfo> GetFormAccessories(int MaintaionID)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
byte[] btResults = null;
|
|||
|
|
|||
|
ApiParameters?.Clear();
|
|||
|
ApiParameters.Add("MaintaionID", MaintaionID + "");
|
|||
|
|
|||
|
var Rtn = Utility.SfcBizService.CurrentSvc.GetDatas(DeviceSvc.SysModelType.MaintenanceAccessories, GetParameters(), out btResults);
|
|||
|
if (Rtn.Code != 1)
|
|||
|
{
|
|||
|
throw new Exception(Rtn.Message);
|
|||
|
}
|
|||
|
DataSet dsResults = CompressionHelper.ExactDataSet(btResults);
|
|||
|
IList<DeviceWarrantyRequestAccessoriesInfo> Datas = DTOHelper<DeviceWarrantyRequestAccessoriesInfo>.DataTableToList(dsResults.Tables[0]);
|
|||
|
return Datas;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
log.Error(ex.Message, ex);
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设备维修单 - 设备停机状态修改
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Update_Maintenance_Status(int FormID, bool Status)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
ApiParameters?.Clear();
|
|||
|
ApiParameters.Add("FormID", FormID + "");
|
|||
|
ApiParameters.Add("FormStatus", Status + "");
|
|||
|
|
|||
|
var Rtn = Utility.SfcBizService.CurrentSvc.Update_Maintenance_Status(GetParameters());
|
|||
|
if (Rtn.Code != 1)
|
|||
|
{
|
|||
|
throw new Exception(Rtn.Message);
|
|||
|
}
|
|||
|
return new APIResponseData { Code = 1, Message = Rtn.Message };
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
log.Error(ex.Message, ex);
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设备维修单列表导出
|
|||
|
/// </summary>
|
|||
|
/// <param name="filter"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public IList<MaintainOrderView> Get_Maintenance_Xlsx_Datas(DeviceWarrantyRequestFormFilter filter)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
byte[] btResults = null;
|
|||
|
ApiParameters?.Clear();
|
|||
|
ApiParameters.Add("EquipmentID", filter.EquipmentID);
|
|||
|
ApiParameters.Add("Status", ((int)filter.Status) + "");
|
|||
|
ApiParameters.Add("DownStatus", ((int)filter.DownStatus) + "");
|
|||
|
List<string> auths = new List<string>();
|
|||
|
if (Utility.SystemRuntimeInfo.AuthValidate(Utility.SystemRuntimeInfo.DEVICE_OEM))
|
|||
|
auths.Add("OEM");
|
|||
|
if (Utility.SystemRuntimeInfo.AuthValidate(Utility.SystemRuntimeInfo.DEVICE_KH))
|
|||
|
auths.Add("KH");
|
|||
|
ApiParameters.Add("Auths", string.Join(",", auths));
|
|||
|
|
|||
|
if (filter.StartTime.HasValue)
|
|||
|
{
|
|||
|
ApiParameters.Add("StartTime", filter.StartTime.Value.ToString("yyyy-MM-dd hh:mm:ss"));
|
|||
|
}
|
|||
|
|
|||
|
if (filter.EndTime.HasValue)
|
|||
|
{
|
|||
|
ApiParameters.Add("EndTime", filter.EndTime.Value.ToString("yyyy-MM-dd hh:mm:ss"));
|
|||
|
}
|
|||
|
var Rtn = Utility.SfcBizService.CurrentSvc.Get_Maintenance_Xlsx_Datas(GetParameters(), out btResults);
|
|||
|
if (Rtn.Code != 1)
|
|||
|
{
|
|||
|
throw new Exception(Rtn.Message);
|
|||
|
}
|
|||
|
DataSet dsResults = CompressionHelper.ExactDataSet(btResults);
|
|||
|
IList<MaintainOrderView> Datas = DTOHelper<MaintainOrderView>.DataTableToList(dsResults.Tables[0]);
|
|||
|
return Datas;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
log.Error(ex.Message, ex);
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设备维修单是否已提交
|
|||
|
/// </summary>
|
|||
|
/// <param name="FormID"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool DataBeSubmit(int FormID)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
bool BeSubmit = false;
|
|||
|
|
|||
|
ApiParameters?.Clear();
|
|||
|
ApiParameters.Add("FormID", FormID + "");
|
|||
|
|
|||
|
var Rtn = Utility.SfcBizService.CurrentSvc.Get_Maintenance_BeSubmit(GetParameters(), out BeSubmit);
|
|||
|
if (Rtn.Code != 1)
|
|||
|
{
|
|||
|
throw new Exception(Rtn.Message);
|
|||
|
}
|
|||
|
return BeSubmit;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
log.Error(ex.Message, ex);
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 保养数据新增
|
|||
|
/// </summary>
|
|||
|
/// <param name="Entity"></param>
|
|||
|
/// <param name="AccessoriesItems"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Insert(DeviceWarrantyRequestMaintaionInfo Entity, List<DeviceWarrantyRequestAccessoriesInfo> AccessoriesItems)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
ApiParameters?.Clear();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
DataSet DataContent = new DataSet();
|
|||
|
DataTable table = (new List<DeviceWarrantyRequestMaintaionInfo> { Entity }).ToDataTable();
|
|||
|
table.Namespace = "Maintaion";
|
|||
|
|
|||
|
DataTable table2 = AccessoriesItems.ToDataTable();
|
|||
|
table2.Namespace = "Accessories";
|
|||
|
|
|||
|
DataContent.Tables.Add(table);
|
|||
|
DataContent.Tables.Add(table2);
|
|||
|
|
|||
|
var apiResponseData = Utility.SfcBizService.CurrentSvc.Insert_Maintenance_Data(GetParameters(), DataContent);
|
|||
|
if (apiResponseData.Code != 1)
|
|||
|
{
|
|||
|
return new APIResponseData { Code = -1, Message = apiResponseData.Message };
|
|||
|
}
|
|||
|
|
|||
|
return new APIResponseData { Code = 1 };
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
log.Error(ex.Message, ex);
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|