1
schangxiang@126.com
2024-12-09 2ef8eda1ea4ef302d86dff34d722da0cce950eff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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())
                {
                    dbList = edm.wms_config_device_warning.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> warningAddressList)
        {
            Task.Run(() =>
           {
               try
               {
                   string deviceCode = ((int)device).ToString();
                   using (WmsDBModel edm = new WmsDBModel())
                   {
                       var dataList = edm.wms_record_device_warning.Where(x => x.WarningCode == deviceCode && x.DeviceWarningStatus == 0).ToList();
                       if (dataList != null && dataList.Count > 0)
                       {
                           var msg = "";
                           var nowDate = DateTime.Now;
                           foreach (var detail in dataList)
                           {
                               if (!warningAddressList.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; }
 
    }
}