zhuhao 2 лет назад
Родитель
Сommit
8668d03cf4

+ 11 - 1
IMCS_CCS/Entitys/Device.cs

@@ -1,4 +1,5 @@
- using System.ComponentModel.DataAnnotations;
+using System;
+using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;
  
 
@@ -37,6 +38,15 @@ namespace IMCS.CCS.Entitys
 
         [Column("use_state")]
         public bool UseState { get; set; }
+
+        [Column("disconnect_update_time")]
+        public DateTime DisconnectUpdateTime { get; set; } = DateTime.Now;
+
+        [Column("offline_update_time")]
+        public DateTime OfflineUpdateTime { get; set; } = DateTime.Now;
+
+        [Column("timeout_remind_duration")]
+        public float TimeoutRemindDuration { get; set; }
     }
 
     /// <summary>

+ 3 - 4
IMCS_CCS/Entitys/Dictionary.cs

@@ -5,15 +5,14 @@ using System.ComponentModel.DataAnnotations.Schema;
 namespace IMCS.CCS.Entitys
 {
     [Table("ccs_dictionary")]
-    public class ToolDto
+    public class Dictionary
     {
         [Key]
         [Column("id")]
         [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 
-        public int Id { get; set; }
-
+        public int Id { get; set; } 
         /// <summary>
-        /// ip
+        /// type
         /// </summary>
         [Column("type")]
         public string Type { get; set; }

+ 5 - 0
IMCS_CCS/Entitys/RequestData.cs

@@ -181,6 +181,11 @@ namespace IMCS.CCS.Models
     public class ProductionStatus
     {
         public string id { get; set; }
+
+        /// <summary>
+        /// 设备ip
+        /// </summary>
+        public string ip { get; set; }
         /// <summary>
         /// 设备状态
         /// </summary>

+ 3 - 1
IMCS_CCS/Model/RedisKeyEnum.cs

@@ -16,6 +16,8 @@ namespace IMCS_CCS.Model
         //回调任务key
         CallbackTaskList,
         //监控设备状态key
-        MonitorEquipmentStatusJob
+        MonitorEquipmentStatusJob,
+        //字典key
+        DictKeyList
     }
 }

+ 1 - 1
IMCS_CCS/Repository/CcsContext.cs

@@ -23,7 +23,7 @@ namespace IMCS.CCS.Repository
 
         public DbSet<TaskCallback> TaskCallback { get; set; }
 
-        public DbSet<ToolDto> Dictionary { get; set; } 
+        public DbSet<Dictionary> Dictionary { get; set; } 
 
         public DbSet<CcsAction> CcsAction { get; set; }
 

+ 7 - 7
IMCS_CCS/Repository/DictionaryRepository.cs

@@ -16,13 +16,13 @@ namespace IMCS.CCS.Repository
             _context = context;
         }
         //查询列表
-        public async Task<List<ToolDto>> GetList(ToolDto vo)
+        public async Task<List<Dictionary>> GetList(Dictionary vo)
         {
-            IQueryable<ToolDto> list = _context.Dictionary;
+            IQueryable<Dictionary> list = _context.Dictionary;
 
             if (!string.IsNullOrEmpty(vo.Type))
             {
-                list = list.Where(x => x.Type.Contains(vo.Type));
+                list = list.Where(x => x.Type == vo.Type);
             } 
              
             return await list.ToListAsync();
@@ -30,15 +30,15 @@ namespace IMCS.CCS.Repository
         } 
 
         //查询详情
-        public async Task<ToolDto> GetById(int id)
+        public async Task<Dictionary> GetById(int id)
         {
-            ToolDto device = await _context.Dictionary.FindAsync(id);
+            Dictionary device = await _context.Dictionary.FindAsync(id);
             return device;
 
         }
 
         //添加详情
-        public async Task<bool> Create(ToolDto vo)
+        public async Task<bool> Create(Dictionary vo)
         { 
             _context.Dictionary.Add(vo);
             await _context.SaveChangesAsync();
@@ -46,7 +46,7 @@ namespace IMCS.CCS.Repository
         }
 
         //更新详情
-        public async Task<bool> Update(ToolDto vo)
+        public async Task<bool> Update(Dictionary vo)
         {
             _context.Entry(vo).State = EntityState.Modified;
             try

+ 4 - 4
IMCS_CCS/Repository/IDictionaryRepository.cs

@@ -8,15 +8,15 @@ namespace IMCS.CCS.Repository
 {
     public interface IDictionaryRepository
     {
-        Task<List<ToolDto>> GetList(ToolDto vo);
+        Task<List<Dictionary>> GetList(Dictionary vo);
         //查询详情
-        Task<ToolDto> GetById(int id);
+        Task<Dictionary> GetById(int id);
 
         //添加
-        Task<bool> Create(ToolDto vo);
+        Task<bool> Create(Dictionary vo);
 
         //更新
-        Task<bool> Update(ToolDto vo);
+        Task<bool> Update(Dictionary vo);
 
  
     }

+ 4 - 4
IMCS_CCS/Service/IDictionaryService.cs

@@ -7,16 +7,16 @@ namespace IMCS.CCS.Services
 {
     public interface IDictionaryService
     {
-        Task<List<ToolDto>> GetList(ToolDto vo);
+        Task<List<Dictionary>> GetList(Dictionary vo);
           
         //查询详情
-        Task<ToolDto> GetById(int id);
+        Task<Dictionary> GetById(int id);
 
         //添加
-        Task<bool> Create(ToolDto vo);
+        Task<bool> Create(Dictionary vo);
 
         //更新
-        Task<bool> Update(ToolDto vo);
+        Task<bool> Update(Dictionary vo);
  
     }
 }

+ 4 - 4
IMCS_CCS/Service/Impl/DictionaryService.cs

@@ -14,24 +14,24 @@ namespace IMCS.CCS.Services
         public DictionaryService(IDictionaryRepository repository) {
             _repository = repository;
         }
-        public async Task<List<ToolDto>> GetList(ToolDto vo)
+        public async Task<List<Dictionary>> GetList(Dictionary vo)
         {
             return await _repository.GetList(vo);
         }
         //查询详情
-        public async Task<ToolDto> GetById(int id)
+        public async Task<Dictionary> GetById(int id)
         {
             return await _repository.GetById(id);
         }
 
         //添加
-        public async Task<bool> Create(ToolDto vo)
+        public async Task<bool> Create(Dictionary vo)
         {
             return await _repository.Create(vo);
         }
 
         //更新
-        public async Task<bool> Update(ToolDto vo)
+        public async Task<bool> Update(Dictionary vo)
         {
             return await _repository.Update(vo);
         }

+ 2 - 1
IMCS_CCS/Service/Impl/HttpRequestService.cs

@@ -2333,7 +2333,8 @@ namespace IMCS.CCS.Services
                     responseData.result = "false";
                     return responseData;
                 }
-                device.UseState = req.useState; 
+                device.UseState = req.useState;
+                device.OfflineUpdateTime = DateTime.Now;
                 await _deviceService.UpdateAndCache(device); 
                 return responseData;
             }

+ 34 - 18
IMCS_CCS/Service/Impl/TaskJobService.cs

@@ -1272,7 +1272,7 @@ namespace IMCS.CCS.Service.Impl
                 foreach (EquipmentMonitor equipment in equipmentMonitors)
                 {
                     Device device = devices.Where(x => x.Ip == equipment.IP).FirstOrDefault();
-                     if (device != null && !device.UseState)
+                    if (device != null && !device.UseState)
                     {
                         if (equipment.Status != "离线")
                         {
@@ -1291,7 +1291,7 @@ namespace IMCS.CCS.Service.Impl
 
                         continue;
                     } 
-                    else if (device != null && equipment.Name == "机械手")
+                    else if (device != null && (equipment.Name == "机械手" || equipment.Name == "保障中心_伺服舵机"))
                     {
                         //缓存取PLC tagvalue 值
                         List<CcsTagValue> tagValues = new List<CcsTagValue>();
@@ -1404,6 +1404,7 @@ namespace IMCS.CCS.Service.Impl
                             {
                                 ProductionStatus productionStatus = new ProductionStatus();
                                 productionStatus.id = alarmEquipment.Id.ToString();
+                                productionStatus.ip = onlineDevice.Ip;
                                 productionStatus.alertMsg = responseData.errorsInfo;
                                 productionStatus.alarmState = true;//报警
                                 productionStatusList.Add(productionStatus);
@@ -1428,6 +1429,7 @@ namespace IMCS.CCS.Service.Impl
                                 {
                                     ProductionStatus productionStatus = new ProductionStatus();
                                     productionStatus.id = alarmEquipment.Id.ToString();
+                                    productionStatus.ip = onlineDevice.Ip;
                                     productionStatus.alertMsg = string.Join(",", msgs.ToArray());
                                     productionStatus.alarmState = true;//报警
                                     productionStatusList.Add(productionStatus);
@@ -1462,26 +1464,38 @@ namespace IMCS.CCS.Service.Impl
                         //获取机械手报警信息
                         CcsTagValue plcWarnValue = tagValues.Where(x => x.Ip == alarmEquipment.IP && x.Address == "DB200.34").FirstOrDefault();
                         if (plcWarnValue != null && plcWarnValue.TagValue != "0")
-                        {
-                            ToolDto ccsDictionary = new ToolDto();
-                            ccsDictionary.Type = "PlcWarnInfo";
-
-                            List<ToolDto> dictList = await _dictionaryService.GetList(ccsDictionary);
-                            if (dictList.Count > 0 && dictList[0] != null)
+                        { 
+                            //从字典中查询具体描述
+                            List<Dictionary> dictList = new List<Dictionary>() ;
+                            string dict_value_redis_key = imcs_redis_key + RedisKeyEnum.DictKeyList;
+                            var dictData = await _redisService.Database.StringGetAsync(dict_value_redis_key);
+                            if (dictData.IsNullOrEmpty)
                             {
-
-                                ToolDto dictObj = dictList.Where(x => x.Code.ToString() == plcWarnValue.TagValue  && x.state).FirstOrDefault();
-                                if (null != dictObj && !string.IsNullOrEmpty(dictObj.DictValue.Trim()))
+                                Dictionary ccsDictionary = new Dictionary();
+                                dictList = await _dictionaryService.GetList(ccsDictionary);
+                                //首次设置redis
+                                if (dictList != null && dictList.Count > 0)
                                 {
-                                    ProductionStatus productionStatus = new ProductionStatus();
-                                    productionStatus.id = alarmEquipment.Id.ToString();
-                                    productionStatus.alertMsg = dictObj.Description.Trim();
-                                    productionStatus.onlineStatus = "1";
-                                    productionStatus.alarmState = true; //报警 
-                                    productionStatusList.Add(productionStatus);
+                                    await _redisService.Database.StringSetAsync(dict_value_redis_key, JsonConvert.SerializeObject(dictList));
                                 }
-                                
                             }
+                            else
+                            {
+                                dictList = JsonConvert.DeserializeObject<List<Dictionary>>(dictData);
+                            } 
+
+                            Dictionary dictObj = dictList.Where(x => x.Type == onlineDevice.Ip && x.Code.ToString() == plcWarnValue.TagValue  && x.state).FirstOrDefault();
+                            if (null != dictObj && !string.IsNullOrEmpty(dictObj.DictValue.Trim()))
+                            {
+                                ProductionStatus productionStatus = new ProductionStatus();
+                                productionStatus.id = alarmEquipment.Id.ToString();
+                                productionStatus.ip = onlineDevice.Ip;
+                                productionStatus.alertMsg = dictObj.Description.Trim();
+                                productionStatus.onlineStatus = "1";
+                                productionStatus.alarmState = true; //报警 
+                                productionStatusList.Add(productionStatus);
+                            }
+                           
                         }
                     }
                 }
@@ -1551,6 +1565,7 @@ namespace IMCS.CCS.Service.Impl
                         if (oldDevice != null && oldDevice.State)
                         {
                             device.State = false;
+                            device.DisconnectUpdateTime = DateTime.Now;
                             await _deviceService.UpdateAndCache(device); 
                         }
 
@@ -1564,6 +1579,7 @@ namespace IMCS.CCS.Service.Impl
                         if (oldDevice != null && !oldDevice.State)
                         {
                             oldDevice.State = true;
+                            device.DisconnectUpdateTime = DateTime.Now;
                             await _deviceService.UpdateAndCache(oldDevice); 
                         }
                         Log.Instance.WriteLogAdd(device.Ip + ":"+ device.ProtocolType +  "连接成功", LOG_TITLE_DEVICE);