using HslCommunication;
|
using Newtonsoft.Json;
|
using Quartz.Util;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Security.Policy;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_IWMsInfoServices;
|
using WIDESEA_Model.Models;
|
using static WIDESEA_DTO.SquareCabin.AlarmDto;
|
using static WIDESEA_DTO.SquareCabin.TowcsDto;
|
|
namespace WIDESEA_WMsInfoServices
|
{
|
public class EquipmentAlarmInforService : ServiceBase<Dt_EquipmentAlarmInfor, IRepository<Dt_EquipmentAlarmInfor>>, IEquipmentAlarmInforService
|
{
|
private readonly IMessageInfoService _messageInfoService;
|
|
public EquipmentAlarmInforService(IRepository<Dt_EquipmentAlarmInfor> BaseDal, IMessageInfoService messageInfoService) : base(BaseDal)
|
{
|
_messageInfoService = messageInfoService;
|
}
|
|
|
|
/// <summary>
|
/// 查看立库小车报警信息
|
/// </summary>
|
/// <returns></returns>
|
public WebResponseContent getDeviceStatus()
|
{
|
try
|
{
|
var url = "http://172.16.1.2:8080/cube/taskInfo/getDeviceStatus?token=wH5zdAUCv2BEHJIinmowyki8cdc5ge8fAwFDcYZs0bVldNgmORt0O0l4GJTDv1dglRdMxb9xDK5Qb3NJAqL1Li2GkfdVa3KnIkfrQZtsP7UXhMmUz6xEuztG6d5svAJO9HENLb8JWVqCfpO2EWV6ebo/g5tJ9x7kbwwAxvCBrWdiEJv09FvaRQ== ";
|
var result = HttpHelper.Get(url);
|
|
var response = JsonConvert.DeserializeObject<AGVResponse<DeviceStatusData>>(result);
|
|
|
|
// 检查接口响应是否成功
|
if (response == null || response.code != "0")
|
{
|
return new WebResponseContent { Status = false, Message = $"WCS接口调用失败: {response?.msg}" };
|
}
|
|
var syncTime = DateTime.Now;
|
var saveCount = 0;
|
|
// 处理机器人设备数据
|
if (response.data?.robot != null && response.data.robot.Any())
|
{
|
foreach (var robot in response.data.robot)
|
{
|
// 根据设备编码查询是否存在记录
|
var existingRecord = BaseDal.QueryData(x => x.RobotCode == robot.robotCode).FirstOrDefault();
|
|
if (existingRecord == null)
|
{
|
// 创建新记录
|
var newRecord = new Dt_EquipmentAlarmInfor
|
{
|
RobotName = robot.robotName,
|
RobotCode = robot.robotCode,
|
Status = robot.status,
|
SyncTime = syncTime,
|
CreateDate = syncTime,
|
Creater = "System"
|
};
|
BaseDal.AddData(newRecord);
|
if (robot.status == "error")
|
{
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "小车名称:" + robot.robotName, $"小车编号【{robot.robotCode}】发生错误", MessageStatusEnum.Emergency);
|
}
|
}
|
else
|
{
|
// 更新现有记录
|
existingRecord.RobotName = robot.robotName;
|
existingRecord.Status = robot.status;
|
existingRecord.SyncTime = syncTime;
|
existingRecord.ModifyDate = syncTime;
|
existingRecord.Modifier = "System";
|
BaseDal.UpdateData(existingRecord);
|
if (robot.status == "error")
|
{
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "小车名称:" + robot.robotName, $"小车编号【{robot.robotCode}】发生错误", MessageStatusEnum.Emergency);
|
}
|
}
|
saveCount++;
|
}
|
}
|
|
// 处理分拣台设备数据
|
if (response.data?.sorters != null && response.data.sorters.Any())
|
{
|
foreach (var sorter in response.data.sorters)
|
{
|
// 根据设备编码查询是否存在记录
|
var existingRecord = BaseDal.QueryData(x => x.RobotCode == sorter.sorterCode).FirstOrDefault();
|
|
if (existingRecord == null)
|
{
|
// 创建新记录
|
var newRecord = new Dt_EquipmentAlarmInfor
|
{
|
RobotName = sorter.sorterName,
|
RobotCode = sorter.sorterCode,
|
Status = sorter.status,
|
SyncTime = syncTime,
|
CreateDate = syncTime,
|
Creater = "System"
|
};
|
BaseDal.AddData(newRecord);
|
if (sorter.status == "error")
|
{
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "分拣台名称:" + sorter.sorterName, $"编号【{sorter.sorterCode}】发生错误", MessageStatusEnum.Emergency);
|
}
|
}
|
else
|
{
|
// 更新现有记录
|
existingRecord.RobotName = sorter.sorterName;
|
existingRecord.Status = sorter.status;
|
existingRecord.SyncTime = syncTime;
|
existingRecord.ModifyDate = syncTime;
|
existingRecord.Modifier = "System";
|
BaseDal.UpdateData(existingRecord);
|
if (sorter.status == "error")
|
{
|
_messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "分拣台名称:" + sorter.sorterName, $"编号【{sorter.sorterCode}】发生错误", MessageStatusEnum.Emergency);
|
}
|
}
|
saveCount++;
|
}
|
}
|
|
//// 返回状态统计信息
|
//var stateStats = response.data?.stateStatistics;
|
//var statsInfo = stateStats != null ?
|
// $"可用:{stateStats.enable}, 充电:{stateStats.charging}, 不可用:{stateStats.disabled}, 错误:{stateStats.error}, 离库:{stateStats.down}, 占用:{stateStats.occupied}"
|
// : "无统计信息";
|
|
return new WebResponseContent
|
{
|
Status = true,
|
Message = $"同步成功,共处理 {saveCount} 条设备记录。"
|
};
|
}
|
catch (Exception ex)
|
{
|
// 记录详细错误日志
|
Console.WriteLine($"获取设备状态异常: {ex.Message}, StackTrace: {ex.StackTrace}");
|
|
return new WebResponseContent
|
{
|
Status = false,
|
Message = $"获取设备状态失败: {ex.Message}"
|
};
|
}
|
}
|
}
|
}
|