467 lines
19 KiB
C#
467 lines
19 KiB
C#
|
using DeviceRepair.DataAccess.Data;
|
|||
|
using DeviceRepair.Models;
|
|||
|
using DeviceRepair.Models.History;
|
|||
|
using DeviceRepair.Models.Preserve;
|
|||
|
using DeviceRepair.Utils;
|
|||
|
using NLog;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace DeviceRepair.DataAccess.CheckForm
|
|||
|
{
|
|||
|
public class CheckFormDa : BaseDa
|
|||
|
{
|
|||
|
private static readonly Logger log = LogManager.GetCurrentClassLogger();
|
|||
|
|
|||
|
public CheckFormDa() : base()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public CheckFormDa(IDictionary<string, string> apiParams) : base(apiParams)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取点检表数据
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public DataSet Get_PM_CheckForm_Datas()
|
|||
|
{
|
|||
|
DataSet dsDatas = new DataSet("Datas");
|
|||
|
try
|
|||
|
{
|
|||
|
string FormName = string.Empty;
|
|||
|
if (ApiParameters.ContainsKey("FormName"))
|
|||
|
{
|
|||
|
FormName = ApiParameters["FormName"];
|
|||
|
}
|
|||
|
|
|||
|
var exp = Expressionable.Create<MaintenanceFormVersionInfo>()
|
|||
|
.AndIF(!FormName.IsNull(), x => SqlFunc.Contains(x.FormName, SqlFunc.Trim(FormName))).ToExpression();//拼接表达式
|
|||
|
|
|||
|
List<MaintenanceFormVersionInfo> Datas = devMain.Queryable<MaintenanceFormVersionInfo>().Where(exp).ToList();
|
|||
|
DataTable table = Datas.OrderByDescending(x => x.ChangeDate).OrderByDescending(x => x.ChangeDate).ToList().ToDataTable();
|
|||
|
dsDatas.Tables.Add(table);
|
|||
|
|
|||
|
return dsDatas;
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取单条数据
|
|||
|
/// </summary>
|
|||
|
/// <param name="AutoID"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Get_CheckForm_Single(int PlanAutoID, out DataSet dsDatas)
|
|||
|
{
|
|||
|
dsDatas = new DataSet("Datas");
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
if (devMain.Queryable<MaintenanceRecordInfo, DeviceInformationInfo>((x1, x2) => new object[] { JoinType.Inner, x1.PlanPrimaryID == PlanAutoID && x1.EquipmentPrimaryID == x2.AutoID && x1.FormPrimaryID == x2.MaintenanceFormVersion }).Any())
|
|||
|
{
|
|||
|
var datas = devMain.Queryable<DriveMaintencePlanInfo, DeviceInformationInfo, MaintenanceRecordInfo, MaintenanceFormVersionInfo>((maintencePlan, dev, record, form) =>
|
|||
|
new object[] {
|
|||
|
JoinType.Inner,maintencePlan.EquipmentID == dev.AutoID,
|
|||
|
JoinType.Left,maintencePlan.AutoID == record.PlanPrimaryID && record.FormPrimaryID == dev.MaintenanceFormVersion && record.EquipmentPrimaryID == dev.AutoID,
|
|||
|
JoinType.Left,record.FormPrimaryID == form.AutoID
|
|||
|
}).Where((maintencePlan, dev, record, form) => maintencePlan.AutoID == PlanAutoID).Select((maintencePlan, dev, record, form) => new { maintencePlan, form }).First();
|
|||
|
|
|||
|
if (datas == null)
|
|||
|
{
|
|||
|
throw new ArgumentException($"获取数据失败,数据库不存在【主键编号】为【{PlanAutoID}】的数据!");
|
|||
|
}
|
|||
|
|
|||
|
DataTable table = new List<DriveMaintencePlanInfo> { datas.maintencePlan }.ToDataTable();
|
|||
|
DataTable table2 = new List<MaintenanceFormVersionInfo> { datas.form }.ToDataTable();
|
|||
|
dsDatas.Tables.Add(table);
|
|||
|
dsDatas.Tables.Add(table2);
|
|||
|
return new APIResponseData { Code = 1, Message = "操作成功!" };
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var datas = devMain.Queryable<DriveMaintencePlanInfo, DeviceInformationInfo, MaintenanceFormVersionInfo>((maintencePlan, dev, form) =>
|
|||
|
new object[] {
|
|||
|
JoinType.Left,maintencePlan.EquipmentID == dev.AutoID,
|
|||
|
JoinType.Left,dev.MaintenanceFormVersion == form.AutoID
|
|||
|
}).Where((maintencePlan, dev, form) => maintencePlan.AutoID == PlanAutoID).Select((maintencePlan, dev, form) => new { maintencePlan, form }).First();
|
|||
|
|
|||
|
if (datas == null)
|
|||
|
{
|
|||
|
throw new ArgumentException($"获取数据失败,数据库不存在【主键编号】为【{PlanAutoID}】的数据!");
|
|||
|
}
|
|||
|
|
|||
|
DataTable table = new List<DriveMaintencePlanInfo> { datas.maintencePlan }.ToDataTable();
|
|||
|
DataTable table2 = new List<MaintenanceFormVersionInfo> { datas.form }.ToDataTable();
|
|||
|
dsDatas.Tables.Add(table);
|
|||
|
dsDatas.Tables.Add(table2);
|
|||
|
return new APIResponseData { Code = 1, Message = "操作成功!" };
|
|||
|
}
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取点检表表单信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="PrimaryKey"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public MaintenanceFormVersionInfo GetSingle(int PrimaryKey)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return devMain.Queryable<MaintenanceFormVersionInfo>().First(x => x.AutoID == PrimaryKey);
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 修改点检表状态
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Change_PM_CheckForm_Status()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (!ApiParameters.ContainsKey("FormID"))
|
|||
|
{
|
|||
|
throw new ArgumentException("传入的点检表编号不能为空!");
|
|||
|
}
|
|||
|
int FormID = 0;
|
|||
|
if (!int.TryParse(ApiParameters["FormID"], out FormID))
|
|||
|
{
|
|||
|
throw new ArgumentException("传入的点检表编号不正确!");
|
|||
|
}
|
|||
|
|
|||
|
if (!ApiParameters.ContainsKey("BeStatus"))
|
|||
|
{
|
|||
|
throw new ArgumentException("传入的点检表状态不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
MaintenanceFormVersionInfo Item = devMain.Queryable<MaintenanceFormVersionInfo>().First(x => x.AutoID == FormID);
|
|||
|
if (Item == null)
|
|||
|
{
|
|||
|
throw new ArgumentException($"传入的点检表编号不正确,找不到编号为:{FormID}的点检表!");
|
|||
|
}
|
|||
|
|
|||
|
bool beStatus = ApiParameters["BeStatus"].Equals("A", StringComparison.CurrentCultureIgnoreCase);
|
|||
|
if (Item.FormStatus == beStatus)
|
|||
|
{
|
|||
|
throw new ArgumentException($"当前信息已被他人更改,请刷新后再试!");
|
|||
|
}
|
|||
|
|
|||
|
Item.FormStatus = beStatus;
|
|||
|
devMain.BeginTran();
|
|||
|
if (devMain.Updateable(Item).ExecuteCommand() > 0)
|
|||
|
{
|
|||
|
devMain.CommitTran();
|
|||
|
return new APIResponseData { Code = 1, Message = "操作成功!" };
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
return new APIResponseData { Code = -1, Message = "操作失败!" };
|
|||
|
}
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分配点检表到指定设备
|
|||
|
/// </summary>
|
|||
|
/// <param name="lst"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData AssigFormToDevice(List<SubmitAssignFormsToDevices> lst)
|
|||
|
{
|
|||
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"新增失败或当前数据无更改,请重试!" };
|
|||
|
if (lst == null)
|
|||
|
throw new Exception("待修改的对象为空!");
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
DateTime CurrentDate = DateTime.Now;
|
|||
|
if (!ApiParameters.ContainsKey("OPERATORAUTOID"))
|
|||
|
{
|
|||
|
throw new ArgumentException("非法的操作,当前操作人参数不正确!");
|
|||
|
}
|
|||
|
|
|||
|
int OperationID = Convert.ToInt32(ApiParameters["OPERATORAUTOID"] + "");
|
|||
|
|
|||
|
devMain.BeginTran();
|
|||
|
|
|||
|
bool execSuccess = true;
|
|||
|
|
|||
|
//解除绑定
|
|||
|
if (lst.Any(x => x.OperationType == EnumOperationType.UnBind))
|
|||
|
{
|
|||
|
int[] editData = lst.Where(x => x.OperationType == EnumOperationType.UnBind).Select(x => x.EquipmentAutoID).ToArray();
|
|||
|
execSuccess = devMain.Updateable<DeviceInformationInfo>()
|
|||
|
.UpdateColumns(x => new { x.MaintenanceFormVersion, x.ChangeDate, x.ChangeUser })
|
|||
|
.ReSetValue(x => x.MaintenanceFormVersion == 0)
|
|||
|
.ReSetValue(x => x.ChangeUser == OperationID)
|
|||
|
.ReSetValue(x => x.ChangeDate == CurrentDate)
|
|||
|
.Where(x => editData.Contains(x.AutoID)).ExecuteCommand() > 0;
|
|||
|
}
|
|||
|
|
|||
|
//新增绑定
|
|||
|
if (execSuccess && lst.Any(x => x.OperationType == EnumOperationType.Bind))
|
|||
|
{
|
|||
|
int[] editData = lst.Where(x => x.OperationType == EnumOperationType.Bind).Select(x => x.EquipmentAutoID).ToArray();
|
|||
|
execSuccess = devMain.Updateable<DeviceInformationInfo>()
|
|||
|
.UpdateColumns(x => new { x.MaintenanceFormVersion, x.ChangeDate, x.ChangeUser })
|
|||
|
.ReSetValue(x => x.MaintenanceFormVersion == lst[0].FormAutoID)
|
|||
|
.ReSetValue(x => x.ChangeUser == OperationID)
|
|||
|
.ReSetValue(x => x.ChangeDate == CurrentDate)
|
|||
|
.Where(x => editData.Contains(x.AutoID)).ExecuteCommand() > 0;
|
|||
|
}
|
|||
|
|
|||
|
if (execSuccess)
|
|||
|
{
|
|||
|
apiResponseData.Code = 1;
|
|||
|
apiResponseData.Message = "";
|
|||
|
devMain.CommitTran();
|
|||
|
}
|
|||
|
|
|||
|
List<DeviceHistory> logs = new List<DeviceHistory>();
|
|||
|
|
|||
|
foreach (SubmitAssignFormsToDevices item in lst)
|
|||
|
{
|
|||
|
logs.Add(new DeviceHistory
|
|||
|
{
|
|||
|
FormAutoID = item.FormAutoID,
|
|||
|
FormCode = item.VersionCode,
|
|||
|
FormName = item.FormName,
|
|||
|
FormRev = item.VersionRev,
|
|||
|
EquipmentAutoID = item.EquipmentAutoID,
|
|||
|
EquipmentID = item.EquipmentID,
|
|||
|
EquipmentName = item.EquipmentName,
|
|||
|
Specification = (item.Specification ?? ""),
|
|||
|
OperationComputer = ApiParameters["CLIENTNAME"],
|
|||
|
OperationDate = CurrentDate,
|
|||
|
OperationIP = ApiParameters["CLIENTIP"],
|
|||
|
OperationType = item.OperationType == EnumOperationType.Bind ? "绑定" : "解除绑定",
|
|||
|
OperationUser = OperationID,
|
|||
|
OperationUserName = ApiParameters["OPERATORNAME"]
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
devLog.Insertable(logs).ExecuteCommand();
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
return apiResponseData;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 判断数据是否存在
|
|||
|
/// </summary>
|
|||
|
/// <param name="Count"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Get_CheckForm_Exists(out int Count)
|
|||
|
{
|
|||
|
Count = 0;
|
|||
|
try
|
|||
|
{
|
|||
|
if (!ApiParameters.ContainsKey("VersionCode"))
|
|||
|
{
|
|||
|
throw new ArgumentException("传入的点检表编码不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
if (!ApiParameters.ContainsKey("VersionRev"))
|
|||
|
{
|
|||
|
throw new ArgumentException("传入的点检表版本不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
MaintenanceFormVersionInfo Data = devMain.Queryable<MaintenanceFormVersionInfo>().First(x =>
|
|||
|
x.VersionCode.Equals(SqlFunc.Trim(ApiParameters["VersionCode"]), StringComparison.CurrentCultureIgnoreCase) &&
|
|||
|
x.VersionRev.Equals(SqlFunc.Trim(ApiParameters["VersionRev"]), StringComparison.CurrentCultureIgnoreCase));
|
|||
|
|
|||
|
Count = (Data == null ? 0 : 1);
|
|||
|
return new APIResponseData { Code = 1, Message = "操作成功!" };
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 新增点检表
|
|||
|
/// </summary>
|
|||
|
/// <param name="Item"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Insert_CheckForm_Data(MaintenanceFormVersionInfo Item)
|
|||
|
{
|
|||
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"新增失败或当前数据无更改,请重试!" };
|
|||
|
if (Item == null)
|
|||
|
throw new Exception("传入的参数对象为空!");
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
if (!ApiParameters.ContainsKey("OPERATORAUTOID"))
|
|||
|
{
|
|||
|
throw new ArgumentException("非法的操作,当前操作人参数不正确!");
|
|||
|
}
|
|||
|
|
|||
|
int OperationID = Convert.ToInt32(ApiParameters["OPERATORAUTOID"] + "");
|
|||
|
DateTime CurrentDate = DateTime.Now;
|
|||
|
Item.CreatDate = CurrentDate;
|
|||
|
Item.CreatUser = OperationID;
|
|||
|
|
|||
|
MaintenanceFormVersionInfo CurrentData = devMain.Insertable(Item).ExecuteReturnEntity();
|
|||
|
if (CurrentData.AutoID > 0)
|
|||
|
{
|
|||
|
apiResponseData.Code = 1;
|
|||
|
apiResponseData.Message = "";
|
|||
|
|
|||
|
FormLogInfo log = new FormLogInfo
|
|||
|
{
|
|||
|
FormID = CurrentData.AutoID,
|
|||
|
FormName = Item.FormName,
|
|||
|
FormVersionRev = Item.VersionRev,
|
|||
|
OperationComputer = ApiParameters["CLIENTNAME"],
|
|||
|
OperationDate = CurrentDate,
|
|||
|
OperationIP = ApiParameters["CLIENTIP"],
|
|||
|
OperationType = "新增",
|
|||
|
OperationUser = OperationID,
|
|||
|
OperationUserName = ApiParameters["OPERATORNAME"]
|
|||
|
};
|
|||
|
devLog.Insertable(log).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
return apiResponseData;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 修改备注
|
|||
|
/// </summary>
|
|||
|
/// <param name="Item"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public APIResponseData Change_CheckForm_Remark(MaintenanceFormVersionInfo Item)
|
|||
|
{
|
|||
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"新增失败或当前数据无更改,请重试!" };
|
|||
|
if (Item == null)
|
|||
|
throw new Exception("传入的参数对象为空!");
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
if (!ApiParameters.ContainsKey("OPERATORAUTOID"))
|
|||
|
{
|
|||
|
throw new ArgumentException("非法的操作,当前操作人参数不正确!");
|
|||
|
}
|
|||
|
|
|||
|
int OperationID = Convert.ToInt32(ApiParameters["OPERATORAUTOID"] + "");
|
|||
|
DateTime CurrentDate = DateTime.Now;
|
|||
|
|
|||
|
devMain.BeginTran();
|
|||
|
MaintenanceFormVersionInfo oItem = devMain.Queryable<MaintenanceFormVersionInfo>().First(x => x.AutoID == Item.AutoID);
|
|||
|
if (oItem == null)
|
|||
|
throw new Exception($"找不到主键编号为【{Item.AutoID}】的点检表信息!");
|
|||
|
|
|||
|
bool IsSuccess = devMain.Updateable<MaintenanceFormVersionInfo>()
|
|||
|
.UpdateColumns(x => new { x.Remarks, x.ChangeDate, x.ChangeUser })
|
|||
|
.ReSetValue(x => x.Remarks == Item.Remarks)
|
|||
|
.ReSetValue(x => x.ChangeDate == CurrentDate)
|
|||
|
.ReSetValue(x => x.ChangeUser == OperationID)
|
|||
|
.Where(x => x.AutoID == Item.AutoID).ExecuteCommandHasChange();
|
|||
|
|
|||
|
devMain.CommitTran();
|
|||
|
|
|||
|
if (IsSuccess)
|
|||
|
{
|
|||
|
apiResponseData.Code = 1;
|
|||
|
apiResponseData.Message = "";
|
|||
|
|
|||
|
MaintenanceFormVersionHistoryInfo log = new MaintenanceFormVersionHistoryInfo
|
|||
|
{
|
|||
|
ClientMac = ApiParameters["CLIENTMAC"],
|
|||
|
ClientName = ApiParameters["CLIENTNAME"],
|
|||
|
CreatDate = CurrentDate,
|
|||
|
CreatUser = OperationID,
|
|||
|
FormName = oItem.FormName,
|
|||
|
FormPath = oItem.FormPath,
|
|||
|
FormStatus = oItem.FormStatus,
|
|||
|
Guid = new Guid(),
|
|||
|
IPAddress = ApiParameters["CLIENTIP"],
|
|||
|
MaintenanceFormVersionAutoID = oItem.AutoID,
|
|||
|
Remarks = oItem.Remarks,
|
|||
|
VersionCode = oItem.VersionCode,
|
|||
|
VersionRev = oItem.VersionRev
|
|||
|
};
|
|||
|
devLog.Insertable(log).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (SqlException sqlEx)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw sqlEx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
devMain.RollbackTran();
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
return apiResponseData;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|