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

+ 11 - 0
IMCS_CCS/Controllers/CcsController.cs

@@ -253,6 +253,17 @@ namespace IMCS.CCS.Controllers
             return await _httpRequestService.WriteRFID(data);
         }
 
+        /// <summary>
+        /// 设备上线离线: POST: api/UpdateDeviceState
+        /// </summary> 
+        /// <returns></returns>
+        [Route("api/UpdateDeviceState")]
+        [HttpPost]
+        public async Task<ResponseCommonData> UpdateDeviceState(RequestDeviceUpdateData req)
+        {
+            return await _httpRequestService.UpdateDeviceState(req);
+        }
+
         /// <summary>
         /// 刀具接口列表: POST: api/GetTools
         /// </summary> 

+ 12 - 0
IMCS_CCS/Entitys/RequestData.cs

@@ -141,6 +141,18 @@ namespace IMCS.CCS.Models
         /// </summary>
         public string ip { get; set; }
 
+    }
+    public class RequestDeviceUpdateData
+    {
+        /// <summary>
+        /// 设备状态
+        /// </summary>
+        public bool useState { get; set; }
+        /// <summary>
+        /// 设备ip
+        /// </summary>
+        public string ip { get; set; }
+
     }
     public class RequestData<T>
     {

+ 8 - 0
IMCS_CCS/Repository/DeviceRepository.cs

@@ -32,6 +32,14 @@ namespace IMCS.CCS.Repository
 
         }
 
+        public List<Device> GetDevices()
+        {
+            IQueryable<Device> devices = _context.Device;
+ 
+            return devices.ToList();
+
+        }
+
         //查询设备详情
         public async Task<Device> GetDeviceById(int id)
         {

+ 2 - 0
IMCS_CCS/Repository/IDeviceRepository.cs

@@ -14,6 +14,8 @@ namespace IMCS.CCS.Repository
         //查询所有设备列表
         List<Device> GetDeviceAllList();
 
+        List<Device> GetDevices();
+
         //查询设备详情
         Task<Device> GetDeviceById(int id);
 

+ 7 - 1
IMCS_CCS/Service/IDeviceService.cs

@@ -14,6 +14,9 @@ namespace IMCS.CCS.Services
         //查询所有设备列表
         List<Device> GetDeviceAllList();
 
+        //全部设备包含未使用的
+        List<Device> GetDevices();
+
         //查询设备详情
         Task<Device> GetDeviceById(int id);
 
@@ -22,6 +25,9 @@ namespace IMCS.CCS.Services
 
         //更新设备
         Task<bool> UpdateDevice(Device user);
- 
+
+        Task<bool> UpdateAndCache(Device vo);
+
+
     }
 }

+ 5 - 0
IMCS_CCS/Service/IHttpRequestService .cs

@@ -130,5 +130,10 @@ namespace IMCS.CCS.Services
         /// 写RFID
         /// </summary> 
         Task<ResponseECSData> WriteRFID(RequestData<RFIData> req);
+
+        /// <summary>
+        /// 设备更新上线离线
+        /// </summary> 
+        Task<ResponseCommonData> UpdateDeviceState(RequestDeviceUpdateData req);
     }
 }

+ 21 - 3
IMCS_CCS/Service/Impl/DeviceService.cs

@@ -2,6 +2,8 @@
 using System.Collections.Generic; 
 using System.Threading.Tasks;
 using IMCS.CCS.Entitys;
+using IMCS.CCS.Common.Redis;
+using Newtonsoft.Json;
 
 namespace IMCS.CCS.Services
 {
@@ -9,8 +11,11 @@ namespace IMCS.CCS.Services
     {
         private IDeviceRepository _repository;
 
-        public DeviceService(IDeviceRepository repository) {
+        private IRedisService _redisService;
+
+        public DeviceService(IDeviceRepository repository, IRedisService redisService) {
             _repository = repository;
+            _redisService = redisService;
         }
         public List<Device> GetDeviceList()
         {
@@ -21,7 +26,10 @@ namespace IMCS.CCS.Services
         {
             return _repository.GetDeviceAllList();
         }
-
+        public List<Device> GetDevices()
+        {
+            return _repository.GetDevices();
+        }
 
         //查询设备详情
         public async Task<Device> GetDeviceById(int id)
@@ -40,6 +48,16 @@ namespace IMCS.CCS.Services
         {
             return await _repository.UpdateDevice(device);
         }
- 
+
+        //添加或修改,放入缓存
+        public async Task<bool> UpdateAndCache(Device vo)
+        { 
+            await _repository.UpdateDevice(vo);
+            
+            string callback_redis_key = "IMCS_CCS:DeviceList";
+            List<Device> devices =  _repository.GetDeviceAllList();
+            await _redisService.Database.StringSetAsync(callback_redis_key, JsonConvert.SerializeObject(devices));
+            return true;
+        }
     }
 }

+ 29 - 0
IMCS_CCS/Service/Impl/HttpRequestService.cs

@@ -2306,6 +2306,35 @@ namespace IMCS.CCS.Services
             }
         }
 
+        /// <summary>
+        /// 设备上线离线
+        /// </summary> 
+        public async Task<ResponseCommonData> UpdateDeviceState(RequestDeviceUpdateData req)
+        {
+            ResponseCommonData responseData = new ResponseCommonData();
+            List<Device> devices = _deviceService.GetDevices();
+            try
+            {
+                Device device = devices.Where(x => x.Ip == req.ip).FirstOrDefault();
+
+                if (device == null)
+                {
+                    responseData.msg = "设备不存在";
+                    responseData.result = "false";
+                    return responseData;
+                }
+                device.UseState = req.useState; 
+                await _deviceService.UpdateAndCache(device); 
+                return responseData;
+            }
+            catch (Exception ex)
+            {
+                responseData.msg = ex.Message;
+                responseData.result = "false";
+                return responseData;
+            }
+        }
+
         //移动取放 条件限制
         private async Task<bool> robotActionCondition(string ip ,string isAllowFlag,string currentAction)
         {

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

@@ -1265,17 +1265,17 @@ namespace IMCS.CCS.Service.Impl
                 foreach (EquipmentMonitor equipment in equipmentMonitors)
                 {
                     Device device = devices.Where(x => x.Ip.Equals(equipment.IP)).FirstOrDefault();
-                    if (device == null)
+                    if (device == null && !device.State)
                     {
-                        if (equipment.Status != "线")
+                        if (equipment.Status != "线")
                         {
-                            equipment.Status = "线";
+                            equipment.Status = "线";
                             changeEquipmentMonitors.Add(equipment);
                         }
 
                         continue;
                     }
-                    else if (equipment.Name == "机械手")
+                    else if (device == null && equipment.Name == "机械手")
                     {
                         CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip.Equals(equipment.IP) && x.Address.Equals(equipment.Address)).FirstOrDefault();
                         if (ccsTagValue != null)