|
|
@@ -7,7 +7,6 @@ using IMCS.CCS.Models.vo;
|
|
|
using IMCS.CCS.Services;
|
|
|
using IMCS_CCS.Model.vo;
|
|
|
using IMCS_CCS.Utils;
|
|
|
-using IMCS_CCS.Utils.DeviceProtocol;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Newtonsoft.Json;
|
|
|
using S7.Net;
|
|
|
@@ -18,7 +17,6 @@ using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using IMCS.CCS.Models;
|
|
|
|
|
|
-
|
|
|
namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
/// <summary>
|
|
|
@@ -109,19 +107,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- List<Device> deviceList = new List<Device>();
|
|
|
- var deviceListData = await _redisService.Database.StringGetAsync(device_redis_key);
|
|
|
- if (deviceListData.IsNullOrEmpty)
|
|
|
- {
|
|
|
- deviceList = _deviceService.GetDeviceList();
|
|
|
- await _redisService.Database.StringSetAsync(device_redis_key, JsonConvert.SerializeObject(deviceList));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- deviceList = JsonConvert.DeserializeObject<List<Device>>(deviceListData);
|
|
|
- }
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
|
|
|
- deviceList = deviceList.Where(x => x.ProtocolType.Equals(ProtocalTypeEnum.OPCUA.ToString())).ToList();
|
|
|
+ deviceList = deviceList.Where(x => x.ProtocolType.Equals(ProtocalTypeEnum.OPCUA.ToString()) && x.State).ToList();
|
|
|
|
|
|
foreach (Device device in deviceList)
|
|
|
{
|
|
|
@@ -239,19 +227,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
public async Task<string> DataCollectS7Job()
|
|
|
{
|
|
|
try
|
|
|
- {
|
|
|
- List<Device> deviceList = new List<Device>();
|
|
|
- var deviceListData = await _redisService.Database.StringGetAsync(device_redis_key);
|
|
|
- if (deviceListData.IsNullOrEmpty)
|
|
|
- {
|
|
|
- deviceList = _deviceService.GetDeviceList();
|
|
|
- await _redisService.Database.StringSetAsync(device_redis_key, JsonConvert.SerializeObject(deviceList));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- deviceList = JsonConvert.DeserializeObject<List<Device>>(deviceListData);
|
|
|
- }
|
|
|
- deviceList = deviceList.Where(x => x.ProtocolType.Equals(ProtocalTypeEnum.S7_1500.ToString())).ToList();
|
|
|
+ {
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
+ deviceList = deviceList.Where(x => x.ProtocolType.Equals(ProtocalTypeEnum.S7_1500.ToString()) && x.State).ToList();
|
|
|
foreach (Device device in deviceList)
|
|
|
{
|
|
|
List<CcsTagValue> tagValues = new List<CcsTagValue>();
|
|
|
@@ -350,19 +328,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
public async Task<string> DataCollectFanucJob()
|
|
|
{
|
|
|
try
|
|
|
- {
|
|
|
- List<Device> deviceList = new List<Device>();
|
|
|
- var deviceListData = await _redisService.Database.StringGetAsync(device_redis_key);
|
|
|
- if (deviceListData.IsNullOrEmpty)
|
|
|
- {
|
|
|
- deviceList = _deviceService.GetDeviceList();
|
|
|
- await _redisService.Database.StringSetAsync(device_redis_key, JsonConvert.SerializeObject(deviceList));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- deviceList = JsonConvert.DeserializeObject<List<Device>>(deviceListData);
|
|
|
- }
|
|
|
- deviceList = deviceList.Where(x => x.ProtocolType.Equals(ProtocalTypeEnum.FANUC.ToString())).ToList();
|
|
|
+ {
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
+ deviceList = deviceList.Where(x => x.ProtocolType.Equals(ProtocalTypeEnum.FANUC.ToString()) && x.State).ToList();
|
|
|
foreach (Device device in deviceList)
|
|
|
{
|
|
|
List<CcsTagValue> tagValues = new List<CcsTagValue>();
|
|
|
@@ -513,8 +481,8 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
taskList = JsonConvert.DeserializeObject<List<TaskCallback>>(taskCallbackListData);
|
|
|
}
|
|
|
- //在线设备
|
|
|
- List<Device> deviceList = _deviceService.GetDeviceList();
|
|
|
+ //在线设备
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
|
|
|
taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.GetFlexibleWire.ToString())
|
|
|
|| x.OperateType.Equals(ActionTypeEnum.SendFlexibleWire.ToString())
|
|
|
@@ -645,10 +613,10 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
taskList = JsonConvert.DeserializeObject<List<TaskCallback>>(taskCallbackListData);
|
|
|
}
|
|
|
+
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
//在线设备
|
|
|
- List<Device> deviceList = _deviceService.GetDeviceList();
|
|
|
-
|
|
|
- taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.StartLabelMachine.ToString())).ToList();
|
|
|
+ taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.StartLabelMachine.ToString()) && x.State).ToList();
|
|
|
TaskCallback task = taskList.Where(key => deviceList.Any(device => device.Ip == key.IP)).FirstOrDefault();
|
|
|
if (task == null)
|
|
|
{
|
|
|
@@ -781,10 +749,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
taskList = JsonConvert.DeserializeObject<List<TaskCallback>>(taskCallbackListData);
|
|
|
}
|
|
|
- //在线设备
|
|
|
- List<Device> deviceList = _deviceService.GetDeviceList();
|
|
|
-
|
|
|
- taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.StartNCProgram.ToString())).ToList();
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
+ //在线设备
|
|
|
+ taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.StartNCProgram.ToString()) && x.State).ToList();
|
|
|
TaskCallback task = taskList.Where(key => deviceList.Any(device => device.Ip == key.IP)).FirstOrDefault();
|
|
|
if (task == null)
|
|
|
{
|
|
|
@@ -903,10 +870,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
taskList = JsonConvert.DeserializeObject<List<TaskCallback>>(taskCallbackListData);
|
|
|
}
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
//在线设备
|
|
|
- List<Device> deviceList = _deviceService.GetDeviceList();
|
|
|
-
|
|
|
- taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.StartCleanMachine.ToString())).ToList();
|
|
|
+ taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.StartCleanMachine.ToString()) && x.State).ToList();
|
|
|
TaskCallback task = taskList.Where(key => deviceList.Any(device => device.Ip == key.IP)).FirstOrDefault();
|
|
|
if (task == null)
|
|
|
{
|
|
|
@@ -1023,10 +989,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
taskList = JsonConvert.DeserializeObject<List<TaskCallback>>(taskCallbackListData);
|
|
|
}
|
|
|
+ List<Device> deviceList = await getDeviceList();
|
|
|
//在线设备
|
|
|
- List<Device> deviceList = _deviceService.GetDeviceList();
|
|
|
-
|
|
|
- taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.SendThreeCoordinates.ToString())).ToList();
|
|
|
+ taskList = taskList.Where(x => x.OperateType.Equals(ActionTypeEnum.SendThreeCoordinates.ToString()) && x.State).ToList();
|
|
|
TaskCallback task = taskList.Where(key => deviceList.Any(device => device.Ip == key.IP)).FirstOrDefault();
|
|
|
if (task == null)
|
|
|
{
|
|
|
@@ -1247,16 +1212,8 @@ namespace IMCS.CCS.Service.Impl
|
|
|
try
|
|
|
{
|
|
|
string message = "MonitorEquipmentStatusJob调度成功";
|
|
|
- List<Device> devices = new List<Device>();
|
|
|
- var deviceData = await _redisService.Database.StringGetAsync(device_redis_key);
|
|
|
- if (deviceData.IsNullOrEmpty)
|
|
|
- {
|
|
|
- devices = _deviceService.GetDeviceList();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- devices = JsonConvert.DeserializeObject<List<Device>>(deviceData);
|
|
|
- }
|
|
|
+ List<Device> devices = await getDeviceList();
|
|
|
+ //在线设备
|
|
|
//ftp不监控
|
|
|
devices = devices.Where(x => !x.ProtocolType.Equals(ProtocalTypeEnum.FTP.ToString()) && x.State).ToList();
|
|
|
CcsTagValue tagQuery = new CcsTagValue();
|
|
|
@@ -1457,18 +1414,9 @@ namespace IMCS.CCS.Service.Impl
|
|
|
try
|
|
|
{
|
|
|
string message = "";
|
|
|
- List<Device> devices = new List<Device>();
|
|
|
- List<Device> changeDevices = new List<Device>();
|
|
|
- var data = await _redisService.Database.StringGetAsync(device_redis_key);
|
|
|
- if (data.IsNullOrEmpty)
|
|
|
- {
|
|
|
- devices = _deviceService.GetDeviceAllList();
|
|
|
- await _redisService.Database.StringSetAsync(device_redis_key, JsonConvert.SerializeObject(devices));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- devices = JsonConvert.DeserializeObject<List<Device>>(data);
|
|
|
- }
|
|
|
+ List<Device> devices = await getDeviceList();
|
|
|
+ //在线设备
|
|
|
+ List<Device> changeDevices = new List<Device>();
|
|
|
|
|
|
//ftp不监控
|
|
|
devices = devices.Where(x => !x.ProtocolType.Equals(ProtocalTypeEnum.FTP.ToString())).ToList();
|
|
|
@@ -1500,8 +1448,8 @@ namespace IMCS.CCS.Service.Impl
|
|
|
Device oldDevice = await _deviceService.GetDeviceById(device.Id);
|
|
|
if (oldDevice != null && !oldDevice.State)
|
|
|
{
|
|
|
- device.State = true;
|
|
|
- await _deviceService.UpdateDevice(device);
|
|
|
+ oldDevice.State = true;
|
|
|
+ await _deviceService.UpdateDevice(oldDevice);
|
|
|
changeDevices.Add(device);
|
|
|
}
|
|
|
s7.Close();
|
|
|
@@ -1514,7 +1462,7 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
Device oldDevice = await _deviceService.GetDeviceById(device.Id);
|
|
|
if (oldDevice != null && oldDevice.State)
|
|
|
- {
|
|
|
+ {
|
|
|
device.State = false;
|
|
|
await _deviceService.UpdateDevice(device);
|
|
|
changeDevices.Add(device);
|
|
|
@@ -1741,6 +1689,26 @@ namespace IMCS.CCS.Service.Impl
|
|
|
dData = Convert.ToDecimal(strData);
|
|
|
}
|
|
|
return dData;
|
|
|
- }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取redis 设备列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="strData"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<List<Device>> getDeviceList()
|
|
|
+ {
|
|
|
+ List<Device> deviceList = new List<Device>();
|
|
|
+ var deviceListData = await _redisService.Database.StringGetAsync(device_redis_key);
|
|
|
+ if (deviceListData.IsNullOrEmpty)
|
|
|
+ {
|
|
|
+ deviceList = _deviceService.GetDeviceList();
|
|
|
+ await _redisService.Database.StringSetAsync(device_redis_key, JsonConvert.SerializeObject(deviceList));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ deviceList = JsonConvert.DeserializeObject<List<Device>>(deviceListData);
|
|
|
+ }
|
|
|
+ return deviceList;
|
|
|
+ }
|
|
|
}
|
|
|
}
|