|
@@ -16,6 +16,8 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
+using IMCS.CCS.Models;
|
|
|
+
|
|
|
|
|
|
namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
@@ -36,16 +38,22 @@ namespace IMCS.CCS.Service.Impl
|
|
|
|
|
|
private readonly IEquipmentMonitorService _equipmentMonitorService;
|
|
|
|
|
|
+ private readonly IDictionaryService _dictionaryService;
|
|
|
+
|
|
|
private readonly ICcsActionAddressService _ccsActionAddressService;
|
|
|
|
|
|
private string ecsUrlContext;
|
|
|
|
|
|
+ private string ecsRootUrlContext;
|
|
|
+
|
|
|
private string fanucUrlContext;
|
|
|
|
|
|
private string opcuacUrlContext;
|
|
|
|
|
|
private string hdhUrlContext;
|
|
|
|
|
|
+ private Dictionary<String, int> syncStatusMap = new Dictionary<String, int>();
|
|
|
+
|
|
|
private string LOG_TITLE_OPCUA = "OPCUA采集";
|
|
|
|
|
|
private string LOG_TITLE_S7 = "S7采集";
|
|
@@ -67,6 +75,7 @@ namespace IMCS.CCS.Service.Impl
|
|
|
IApiRequestService apiRequestService,
|
|
|
ICcsTagValueService ccsTagValueService,
|
|
|
IEquipmentMonitorService equipmentMonitorService,
|
|
|
+ IDictionaryService dictionaryService,
|
|
|
ICcsActionAddressService ccsActionAddressService,
|
|
|
IConfiguration configuration)
|
|
|
{
|
|
@@ -76,12 +85,20 @@ namespace IMCS.CCS.Service.Impl
|
|
|
_apiRequestService = apiRequestService;
|
|
|
_ccsTagValueService = ccsTagValueService;
|
|
|
_equipmentMonitorService = equipmentMonitorService;
|
|
|
+ _dictionaryService = dictionaryService;
|
|
|
_ccsActionAddressService = ccsActionAddressService;
|
|
|
Configuration = configuration;
|
|
|
ecsUrlContext = Configuration.GetConnectionString("ecsUrlContext");
|
|
|
fanucUrlContext = Configuration.GetConnectionString("fanucUrlContext");
|
|
|
opcuacUrlContext = Configuration.GetConnectionString("opcuacUrlContext");
|
|
|
hdhUrlContext = Configuration.GetConnectionString("hdhUrlContext");
|
|
|
+ ecsRootUrlContext = Configuration.GetConnectionString("ecsRootUrlContext");
|
|
|
+ syncStatusMap.Add("离线", 0);
|
|
|
+ syncStatusMap.Add("空闲", 1);
|
|
|
+ syncStatusMap.Add("生产中", 2);
|
|
|
+ syncStatusMap.Add("报警", 3);
|
|
|
+ //在线状态默认传参后台空闲状态
|
|
|
+ syncStatusMap.Add("在线", 1);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1158,8 +1175,19 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
var operateResult = s7.ReadString(actionAddress.Address);
|
|
|
requestData.workId = operateResult.ToString();
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ else if (actionAddress.Value == "procedureNo")
|
|
|
+ {
|
|
|
+ var operateResult = s7.ReadString(actionAddress.Address);
|
|
|
+ requestData.procedureNo = operateResult.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.Value == "workProgramName")
|
|
|
+ {
|
|
|
+ var operateResult = s7.ReadString(actionAddress.Address);
|
|
|
+ requestData.workProgramName = operateResult.ToString();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1305,14 +1333,14 @@ namespace IMCS.CCS.Service.Impl
|
|
|
}
|
|
|
else if (equipment.Name == "机械手")
|
|
|
{
|
|
|
- CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip.Equals(equipment.IP) && x.Address.Equals(equipment.Address)).FirstOrDefault();
|
|
|
- if (ccsTagValue != null)
|
|
|
+ CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip.Equals(equipment.IP) && x.Address.Equals(equipment.Address)).FirstOrDefault();
|
|
|
+ if (ccsTagValue != null)
|
|
|
{
|
|
|
if (ccsTagValue.TagValue == "3")
|
|
|
{
|
|
|
if (equipment.Status != "报警")
|
|
|
- {
|
|
|
- equipment.Status = "报警";
|
|
|
+ {
|
|
|
+ equipment.Status = "报警";
|
|
|
changeEquipmentMonitors.Add(equipment);
|
|
|
}
|
|
|
|
|
@@ -1359,14 +1387,93 @@ namespace IMCS.CCS.Service.Impl
|
|
|
|
|
|
}
|
|
|
//变化的修改 并且更新缓存
|
|
|
- if(changeEquipmentMonitors != null)
|
|
|
+ if(changeEquipmentMonitors.Count > 0)
|
|
|
{
|
|
|
- foreach (EquipmentMonitor equipment in changeEquipmentMonitors)
|
|
|
+ List<ProductionStatus> productionStatusList = new List<ProductionStatus>();
|
|
|
+ foreach (EquipmentMonitor changeEquipment in changeEquipmentMonitors)
|
|
|
{
|
|
|
- await _equipmentMonitorService.Update(equipment);
|
|
|
+ ProductionStatus productionStatus = new ProductionStatus();
|
|
|
+ productionStatus.id = changeEquipment.Id.ToString();
|
|
|
+ productionStatus.onlineStatus = syncStatusMap[changeEquipment.Status].ToString();
|
|
|
+ //equipment.Status == "离线" ? "0" : "1";
|
|
|
+ //productionStatus.alertMsg = equipment.AlertMsg;
|
|
|
+ if (productionStatus.onlineStatus !="3" && !string.IsNullOrEmpty(changeEquipment.Type))
|
|
|
+ {
|
|
|
+ if(changeEquipment.Type == "HEIDEHAIN")
|
|
|
+ {
|
|
|
+ RequestHeidhData hdhReq = new RequestHeidhData();
|
|
|
+ Device device = devices.Where(x => x.Ip.Equals(changeEquipment.IP)).FirstOrDefault();
|
|
|
+ hdhReq.ServerUrl = device.ServerUrl;
|
|
|
+ hdhReq.MachineName = device.UserName;
|
|
|
+ hdhReq.Type = OpcUaActionTypeEnum.Connect.ToString();
|
|
|
+ var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Post, hdhUrlContext, hdhReq, null);
|
|
|
+ if (Result.IsSuccess)
|
|
|
+ {
|
|
|
+ ResponseHeidhData responseData = JsonConvert.DeserializeObject<ResponseHeidhData>(Result.Message);
|
|
|
+ if (!string.IsNullOrEmpty(responseData.errorsInfo))
|
|
|
+ {
|
|
|
+ productionStatus.alertMsg = responseData.errorsInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(changeEquipment.Type == "FANUC")
|
|
|
+ {
|
|
|
+ Device device = devices.Where(x => x.Ip.Equals(changeEquipment.IP)).FirstOrDefault();
|
|
|
+ string Url = fanucUrlContext + "?ip=" + device.Ip + "&port=" + device.Port;
|
|
|
+ //调用发那科接口
|
|
|
+ var Result = await _apiRequestService.RequestAsync(RequsetModeEnum.Get, Url + "&fun=AlmInfo", null, null);
|
|
|
+ if (Result.IsSuccess)
|
|
|
+ {
|
|
|
+ ResponseFanucData fncReq = new ResponseFanucData();
|
|
|
+ fncReq = JsonConvert.DeserializeObject<ResponseFanucData>(Result.Message);
|
|
|
+ List<AlmInfo> AlmMsg = fncReq.AlmMsg;
|
|
|
+ if (AlmMsg!=null && AlmMsg.Count>0)
|
|
|
+ {
|
|
|
+ var msgs = from o in AlmMsg select o.msg;
|
|
|
+ productionStatus.alertMsg = string.Join(",", msgs.ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //获取机械手报警信息
|
|
|
+ CcsTagValue plcWarnValue = tagValues.Where(x => x.Ip.Equals(changeEquipment.IP) && x.Address.Equals("DB200.34")).FirstOrDefault();
|
|
|
+ ToolDto ccsDictionary = new ToolDto();
|
|
|
+ ccsDictionary.Type = "PlcWarnInfo";
|
|
|
+ ccsDictionary.state = true;
|
|
|
+ ccsDictionary.Code = plcWarnValue.TagValue;
|
|
|
+
|
|
|
+ List<ToolDto> dictList = await _dictionaryService.GetList(ccsDictionary);
|
|
|
+ if (dictList.Count > 0 && dictList[0]!=null)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(dictList[0].DictValue))
|
|
|
+ {
|
|
|
+ productionStatus.alertMsg = dictList[0].DictValue.Trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ productionStatusList.Add(productionStatus);
|
|
|
+ await _equipmentMonitorService.Update(changeEquipment);
|
|
|
}
|
|
|
await _redisService.Database.StringSetAsync(redis_key, JsonConvert.SerializeObject(equipmentMonitors));
|
|
|
|
|
|
+
|
|
|
+ //主动推送同步状态数据接口
|
|
|
+ RequestSynStatusData requestData = new RequestSynStatusData();
|
|
|
+ requestData.productionStatus = JsonConvert.SerializeObject(productionStatusList);
|
|
|
+ String synStatusUrl = ecsRootUrlContext + "api/authority/synStatus/synProductionStatus";
|
|
|
+ var result = await _apiRequestService.RequestAsync(RequsetModeEnum.Post, synStatusUrl, requestData, null);
|
|
|
+ //解析回调数据结果
|
|
|
+ ResponseECSCallbackData responseECSCallback = JsonConvert.DeserializeObject<ResponseECSCallbackData>(result.Message);
|
|
|
+ if(responseECSCallback!=null && responseECSCallback.code == 0)
|
|
|
+ {
|
|
|
+ Log.Instance.WriteLogAdd("同步设备状态成功", LOG_TITLE_CALLBACK);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log.Instance.WriteLogAdd("同步设备状态操作失败:" + responseECSCallback.msg, LOG_TITLE_CALLBACK);
|
|
|
+ }
|
|
|
}
|
|
|
return message;
|
|
|
}
|