using Admin.NET.Application;
|
using iWareCommon.Common.Globle;
|
using iWareCommon.Utils;
|
using iWareModel;
|
using iWareSql.WmsDBModel;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using WZ.Useful.Commons.Collections;
|
|
namespace iWareCC
|
{
|
public class DeviceWarningHandler
|
{
|
|
/// <summary>
|
/// 获取配置报警信息列表
|
/// </summary>
|
/// <returns></returns>
|
public static DeviceWarningOutput GetConfigWarningList()
|
{
|
DeviceWarningOutput output = new DeviceWarningOutput();
|
System.Collections.Generic.List<iWareCC.StationService.WmsConfigDeviceWarning> retList = new System.Collections.Generic.List<iWareCC.StationService.WmsConfigDeviceWarning>();
|
System.Collections.Generic.List<wms_config_device_warning> dbList = new System.Collections.Generic.List<wms_config_device_warning>();
|
try
|
{
|
using (WmsDBModel edm = new WmsDBModel())
|
{
|
//注意:只查询 安全报警、硬件报警信息
|
var query1 = (int)DeviceWarningTypeEnum.安全报警;
|
var query2 = (int)DeviceWarningTypeEnum.硬件报警;
|
dbList = edm.wms_config_device_warning.Where(x => x.DeviceWarningType == query1 || x.DeviceWarningType == query2).ToList();
|
}
|
foreach (var item in dbList)
|
{
|
retList.Add(new StationService.WmsConfigDeviceWarning()
|
{
|
WarningCode = item.WarningCode
|
});
|
}
|
}
|
catch (Exception ex)
|
{
|
|
}
|
|
output.wmsConfigDeviceWarnings = retList;
|
output.wms_config_device_warning_list = dbList;
|
return output;
|
}
|
|
/// <summary>
|
/// 新建报警信息
|
/// </summary>
|
/// <param name="deviceCode"></param>
|
/// <param name="deviceName"></param>
|
/// <param name="warningCode"></param>
|
/// <param name="warningContent"></param>
|
public static void SaveWarning(EDevice device, LogType _LogType, string warningCode, int deviceAreaCode, string warningContent, int deviceWarningType)
|
{
|
Task.Run(() =>
|
{
|
try
|
{
|
wms_record_device_warning request = new wms_record_device_warning()
|
{
|
Id = Yitter.IdGenerator.YitIdHelper.NextId(),
|
DeviceWarningStatus = 0,
|
WarningCode = warningCode,
|
WarningContent = warningContent,
|
WarningTime = DateTime.Now,
|
CreateUserName = SysGloble.WCSSystem,
|
DeviceAreaCode = deviceAreaCode,
|
DeviceWarningType = deviceWarningType,
|
DurationTime = "",
|
|
CreateTime = DateTime.Now,
|
|
};
|
|
using (WmsDBModel edm = new WmsDBModel())
|
{
|
var data = edm.wms_record_device_warning.Where(x => x.DeviceWarningStatus == 0 && x.WarningCode == warningCode).FirstOrDefault();
|
if (data == null)
|
{
|
edm.wms_record_device_warning.Add(request);
|
edm.SaveChanges();
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Log4NetHelper.WriteErrorLog(_LogType, "保存报警出现异常:" + ex.Message, ex);
|
}
|
});
|
|
}
|
|
/// <summary>
|
/// 自动关闭报警信息
|
/// </summary>
|
/// <param name="deviceId">设备区域</param>
|
/// <param name="_LogType"></param>
|
/// <returns></returns>
|
public static void AutoCloseWarning(EDevice device, LogType _LogType, System.Collections.Generic.List<string> warningCodeList)
|
{
|
Task.Run(() =>
|
{
|
try
|
{
|
using (WmsDBModel edm = new WmsDBModel())
|
{
|
var dataList = edm.wms_record_device_warning.Where(x => x.DeviceWarningStatus == 0).ToList();
|
if (dataList != null && dataList.Count > 0)
|
{
|
var msg = "";
|
var nowDate = DateTime.Now;
|
foreach (var detail in dataList)
|
{
|
if (!warningCodeList.Contains(detail.WarningCode))
|
{
|
nowDate = DateTime.Now;
|
detail.DeviceWarningStatus = 1; //状态(0:新建 1:已处理)
|
detail.FinishTime = nowDate;
|
DateTimeHelper.GetTimeDiffer(detail.CreateTime, nowDate, ref msg);
|
detail.DurationTime = msg;
|
}
|
}
|
edm.SaveChanges();
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Log4NetHelper.WriteErrorLog(_LogType, "自动关闭报警出现异常:" + ex.Message, ex);
|
}
|
});
|
}
|
}
|
|
|
public class DeviceWarningOutput
|
{
|
public System.Collections.Generic.List<iWareCC.StationService.WmsConfigDeviceWarning> wmsConfigDeviceWarnings { get; set; }
|
public System.Collections.Generic.List<wms_config_device_warning> wms_config_device_warning_list { get; set; }
|
|
}
|
}
|