dengjunjie
4 天以前 1b8daa902b075c7cedee7bbcc13b914b7a5b4ad4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
 
        public EquipmentAlarmInforService(IRepository<Dt_EquipmentAlarmInfor> BaseDal, IMessageInfoService messageInfoService, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
        {
            _messageInfoService = messageInfoService;
            _unitOfWorkManage = unitOfWorkManage;
        }
 
        public WebResponseContent getDeviceStatus()
        {
            WebResponseContent content = new WebResponseContent();
            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" || response.data == null) return content.Error($"获取设备信息失败: {response?.msg}");
                List<string> codes = new List<string>();
                if (response.data.robot.Count < 1 || response.data.sorters.Count < 0) return content.Error($"获取设备信息为空: {response?.msg}");
 
                // 处理机器人设备数据
                codes.AddRange(response.data.robot.Select(x => x.robotCode).ToList());
 
                // 处理分拣台设备数据
                codes.AddRange(response.data.sorters.Select(x => x.sorterCode).ToList());
 
                if (codes.Count < 1) return content;
                List<Dt_EquipmentAlarmInfor> equipmentAlarmInfors = BaseDal.QueryData(x => codes.Contains(x.RobotCode));
                List<Dt_EquipmentAlarmInfor> equipmentAlarmInforsAdd = new List<Dt_EquipmentAlarmInfor>();
                List<Dt_EquipmentAlarmInfor> equipmentAlarmInforsUp = new List<Dt_EquipmentAlarmInfor>();
                foreach (var item in response.data.robot)
                {
                    Dt_EquipmentAlarmInfor? equipmentAlarmInfor = equipmentAlarmInfors.Where(x => x.RobotCode == item.robotCode).FirstOrDefault();
                    if (equipmentAlarmInfor == null)
                    {
                        equipmentAlarmInfor = new Dt_EquipmentAlarmInfor()
                        {
                            RobotCode = item.robotCode,
                            RobotName = item.robotName,
                            Status = item.status,
                            SyncTime = DateTime.Now,
                            CreateDate = DateTime.Now,
                        };
                        equipmentAlarmInforsAdd.Add(equipmentAlarmInfor);
                    }
                    else
                    {
                        equipmentAlarmInfor.RobotName = item.robotName;
                        equipmentAlarmInfor.Status = item.status;
                        equipmentAlarmInfor.SyncTime = DateTime.Now;
                        equipmentAlarmInforsUp.Add(equipmentAlarmInfor);
                    }
                    if (string.Equals(item.status, nameof(DeviceStatus.Error), StringComparison.OrdinalIgnoreCase))
                    {
                        _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm,"小车编号"+ item.robotCode, item.status);
                    }
                }
                foreach (var item in response.data.sorters)
                {
                    Dt_EquipmentAlarmInfor? equipmentAlarmInfor = equipmentAlarmInfors.Where(x => x.RobotCode == item.sorterCode).FirstOrDefault();
                    if (equipmentAlarmInfor == null)
                    {
                        equipmentAlarmInfor = new Dt_EquipmentAlarmInfor()
                        {
                            RobotCode = item.sorterCode,
                            RobotName = item.sorterName,
                            Status = item.status,
                            SyncTime = DateTime.Now,
                            CreateDate = DateTime.Now,
                        };
                        equipmentAlarmInforsAdd.Add(equipmentAlarmInfor);
                    }
                    else
                    {
                        equipmentAlarmInfor.RobotName = item.sorterCode;
                        equipmentAlarmInfor.Status = item.status;
                        equipmentAlarmInfor.SyncTime = DateTime.Now;
                        equipmentAlarmInforsUp.Add(equipmentAlarmInfor);
                    }
                    if (string.Equals(item.status, nameof(DeviceStatus.Error), StringComparison.OrdinalIgnoreCase))
                    {
                        _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "分拣台名字"+ item.sorterCode, item.status);
                    }
                }
                if (equipmentAlarmInforsAdd.Count > 0) BaseDal.AddData(equipmentAlarmInforsAdd);
                if (equipmentAlarmInforsUp.Count > 0) BaseDal.UpdateData(equipmentAlarmInforsUp);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
 
    
    }
}