Blame view

ApiControllers/BoardController.cs 44 KB
唐召明 authored
1
2
3
4
5
using DataAcquisition.Common.Enums;
using DataAcquisition.DataAccess;
using DataAcquisition.Models;
using DataAcquisition.Services;
using DataAcquisition.ViewModels.Board;
唐召明 authored
6
7
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
唐召明 authored
8
using Microsoft.Extensions.Caching.Memory;
唐召明 authored
9
唐召明 authored
10
namespace DataAcquisition.ApiControllers
唐召明 authored
11
12
13
14
15
16
17
18
19
20
{
    /// <summary>
    /// 看板接口
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class BoardController : ControllerBase
    {
        private readonly IDbContextFactory<DataContext> _dbContextFactory;
        private readonly DataCacheService _dataCacheService;
唐召明 authored
21
22
        private readonly IMemoryCache _memoryCache;
        private readonly TimeSpan _absoluteExpirationRelativeToNow;
唐召明 authored
23
唐召明 authored
24
        public BoardController(IDbContextFactory<DataContext> dbContextFactory, DataCacheService dataCacheService, IMemoryCache memoryCache)
唐召明 authored
25
26
27
        {
            _dbContextFactory = dbContextFactory;
            _dataCacheService = dataCacheService;
唐召明 authored
28
            _memoryCache = memoryCache;
唐召明 authored
29
            _absoluteExpirationRelativeToNow = TimeSpan.FromSeconds(2);
唐召明 authored
30
31
32
        }

        /// <summary>
唐召明 authored
33
        /// 焊接看板1
唐召明 authored
34
        /// </summary>
唐召明 authored
35
        /// <param name="robotNo">机器人编号</param>
唐召明 authored
36
        /// <remarks>1号厂房</remarks>
唐召明 authored
37
38
        /// <returns></returns>
        [HttpGet]
唐召明 authored
39
        [Route("WeldBoard/{robotNo:int}")]
唐召明 authored
40
        public BoardResult<dynamic> GetWeldBoardData(int robotNo = 1)
唐召明 authored
41
        {
唐召明 authored
42
            var result = new BoardResult<dynamic>();
唐召明 authored
43
44
            try
            {
唐召明 authored
45
46
47
48
49
50
51
                var key = $"{nameof(GetWeldBoardData)}_{robotNo}";
                var cacheData = _memoryCache.Get<BoardResult<dynamic>>(key);
                if (cacheData != null)
                {
                    return cacheData;
                }
唐召明 authored
52
53
54
                //本月开始时间
                var monthStartTime = DateTime.Today.AddDays(1 - DateTime.Today.Day).Date;
                using var context = _dbContextFactory.CreateDbContext();
唐召明 authored
55
                var robotEquipment = robotNo switch
唐召明 authored
56
                {
唐召明 authored
57
58
59
60
                    1 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.KukaC4_1.ToString())!,
                    2 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.KukaC4_2.ToString())!,
                    3 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.KukaC2_1.ToString())!,
                    4 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.KukaC2_2.ToString())!,
唐召明 authored
61
62
                    5 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.Efort_1.ToString())!,
                    6 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.Fanuc_1.ToString())!,
唐召明 authored
63
                    _ => throw new NotImplementedException($"未找到编号为“{robotNo}”的设备数据!"),
唐召明 authored
64
                };
唐召明 authored
65
                var plc = robotNo switch
唐召明 authored
66
                {
唐召明 authored
67
68
69
                    1 or 2 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.SiemensPLC_1.ToString())!,
                    3 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.SiemensPLC_2.ToString())!,
                    4 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.SiemensPLC_3.ToString())!,
唐召明 authored
70
71
                    5 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.CoTrust_PLC1.ToString())!,
                    6 => _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.SiemensPLC_4.ToString())!,
唐召明 authored
72
                    _ => throw new NotImplementedException($"未找到编号为“{robotNo}”的PLC设备数据!"),
唐召明 authored
73
74
                };
唐召明 authored
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
                _ = double.TryParse(robotEquipment[RobotProps.Pos_X.ToString()].Value, out var pos_X);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_Y.ToString()].Value, out var pos_Y);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_Z.ToString()].Value, out var pos_Z);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_A.ToString()].Value, out var pos_A);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_B.ToString()].Value, out var pos_B);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_C.ToString()].Value, out var pos_C);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_E1.ToString()].Value, out var pos_E1);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_E2.ToString()].Value, out var pos_E2);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_E3.ToString()].Value, out var pos_E3);
                _ = double.TryParse(robotEquipment[RobotProps.Pos_E4.ToString()].Value, out var pos_E4);

                _ = bool.TryParse(robotEquipment[RobotProps.Weld_CleanGun.ToString()].Value, out var weld_CleanGun);
                _ = bool.TryParse(robotEquipment[RobotProps.WeldFlag.ToString()].Value, out var weldFlag);
                _ = bool.TryParse(robotEquipment[RobotProps.Weld_Gas.ToString()].Value, out var weld_Gas);
                _ = bool.TryParse(robotEquipment[RobotProps.WeldCompleteFlag.ToString()].Value, out var weldCompleteFlag);
                _ = bool.TryParse(robotEquipment[RobotProps.BootFlag.ToString()].Value, out var bootFalgValue);
                _ = bool.TryParse(robotEquipment[RobotProps.Alarm.ToString()].Value, out var alarmValue);
                _ = bool.TryParse(robotEquipment[RobotProps.WorkFlag.ToString()].Value, out var workFlagValue);
唐召明 authored
93
                _ = bool.TryParse(robotEquipment[RobotProps.Work_Time.ToString()].Value, out var workTime);
唐召明 authored
94
95
96
97
98
99
100

                _ = float.TryParse(robotEquipment[RobotProps.Weld_V.ToString()].Value, out var weld_V);
                _ = float.TryParse(robotEquipment[RobotProps.Weld_I.ToString()].Value, out var weld_I);
                _ = float.TryParse(robotEquipment[RobotProps.Weld_Speed.ToString()].Value, out var weld_Speed);
                _ = int.TryParse(robotEquipment[RobotProps.Work_Mode.ToString()].Value, out var work_Mode);
                _ = int.TryParse(robotEquipment[RobotProps.Program_No.ToString()].Value, out var program_no);
                _ = int.TryParse(robotEquipment[RobotProps.Type.ToString()].Value, out var type);
唐召明 authored
101
唐召明 authored
102
                var equipmentState = "在线";
唐召明 authored
103
104
105
106
                if (!bootFalgValue)
                {
                    equipmentState = "离线";
                }
唐召明 authored
107
108
                //仅自动模式显示
                else if (alarmValue && work_Mode >= 3)
唐召明 authored
109
110
111
                {
                    equipmentState = "报警";
                }
唐召明 authored
112
113
114
115
116
117
118
                else if (workFlagValue)
                {
                    equipmentState = "工作";
                }

                //加工状态
                var productStateName = "空闲";
唐召明 authored
119
                var timeSum = 0d;
唐召明 authored
120
                if (workTime)
唐召明 authored
121
                {
唐召明 authored
122
                    productStateName = weldFlag ? "焊接" : "加工";
唐召明 authored
123
                    timeSum = Math.Round(TimeSpan.FromTicks(context.WorkpieceProductions.Where(x => x.EquipmentCode == robotEquipment.Code && x.ProgramNo == type).OrderByDescending(x => x.CreateTime).Select(x => x.UpdateTime.Ticks - x.CreateTime.Ticks).FirstOrDefault()).TotalMinutes, 2);
唐召明 authored
124
                }
唐召明 authored
125
唐召明 authored
126
                //功率
唐召明 authored
127
                _ = double.TryParse(plc[RobotPlcProps.P_KW.ToString()].Value, out var kw);
唐召明 authored
128
唐召明 authored
129
130
                var lastProductionId = context.WorkpieceProductions.Where(x => x.EquipmentCode == robotEquipment.Code).OrderByDescending(x => x
                .CreateTime).Select(x => x.Id).FirstOrDefault();
唐召明 authored
131
132
                var days = 7;//显示最近N天的数据
                var xAxisData = Enumerable.Range(0, days).Select(x => DateTime.Today.AddDays(-x)).OrderBy(x => x).ToList();
唐召明 authored
133
                var bootFalgTicks = context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.BootFlag.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks);
唐召明 authored
134
135
136
137
                var vm = new Board1VM
                {
                    NowDayCountLeft = new NowDayCountLeft
                    {
唐召明 authored
138
                        WorkTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.WorkFlag.ToString() && x.CreateTime >= DateTime.Today).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
唐召明 authored
139
唐召明 authored
140
                        ArcingTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.WeldFlag.ToString() && x.CreateTime >= DateTime.Today).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
唐召明 authored
141
唐召明 authored
142
                        FinishCount = context.WorkpieceProductions.Where(x => x.EquipmentCode == robotEquipment.Code && x.CreateTime >= DateTime.Today && x.IsEnd).Count(),
唐召明 authored
143
唐召明 authored
144
                        PowerTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.BootFlag.ToString() && x.CreateTime >= DateTime.Today).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2)
唐召明 authored
145
146
147
                    },
                    EqCenter = new EquipmentStatusVM
                    {
唐召明 authored
148
149
                        EqCode = robotEquipment.Code,
                        EqName = robotEquipment.Name,
唐召明 authored
150
                        EqState = equipmentState,
唐召明 authored
151
152
153
154
155
156
                        Eqmode = work_Mode switch
                        {
                            1 => "T1模式",
                            2 => "T2模式",
                            3 => "自动模式",
                            4 => "外部自动模式",
唐召明 authored
157
                            _ => "无数据"
唐召明 authored
158
                        },
唐召明 authored
159
                        MonthDaoDian = context.WorkpieceProductions.Where(x => x.EquipmentCode == robotEquipment.Code && x.CreateTime >= monthStartTime && x.IsEnd).Count(),
160
唐召明 authored
161
                        MonthWeld = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.Weld_Speed.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
162
唐召明 authored
163
                        MonthVoltage = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == plc.Code && x.EquipmentPropertyCode == RobotPlcProps.Electricity.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
164
唐召明 authored
165
                        NowDayVoltage = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == plc.Code && x.EquipmentPropertyCode == RobotPlcProps.Electricity.ToString() && x.CreateTime >= DateTime.Today).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
唐召明 authored
166
唐召明 authored
167
                        MonthWeldVoltage = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == $"{RobotProps.WeldFlag}_{RobotPlcProps.Electricity}" && x.CreateTime >= monthStartTime).Select(x => x
唐召明 authored
168
169
                        .Value).AsEnumerable().Sum(Convert.ToSingle), 2),
唐召明 authored
170
                        TodayWeldVoltage = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == $"{RobotProps.WeldFlag}_{RobotPlcProps.Electricity}" && x.CreateTime >= DateTime.Today).Select(x => x
唐召明 authored
171
172
                        .Value).AsEnumerable().Sum(Convert.ToSingle), 2),
唐召明 authored
173
                        MonthGas = $"{context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.Gas_Flow.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle):N2}/L",
唐召明 authored
174
唐召明 authored
175
                        P_KW = kw,
唐召明 authored
176
177
178
                    },
                    MonthCountRight = new MonthCountRight
                    {
唐召明 authored
179
                        WorkTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.WorkFlag.ToString() && x.CreateTime >= monthStartTime).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
唐召明 authored
180
唐召明 authored
181
                        ArcingTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.WeldFlag.ToString() && x.CreateTime >= monthStartTime).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
唐召明 authored
182
唐召明 authored
183
                        PowerTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.BootFlag.ToString() && x.CreateTime >= monthStartTime).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
唐召明 authored
184
唐召明 authored
185
                        AlarmTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.Alarm.ToString() && x.CreateTime >= monthStartTime).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
唐召明 authored
186
187
188
189
190
191
192
                    },

                    EqInfoLeft = new EquipmentInfoLeftVM
                    {
                        ClearSpearState = weld_CleanGun,
                        ArcingState = weldFlag,
                        AspiratedState = weld_Gas,
唐召明 authored
193
                        NowProject = type == 0 ? "无" : $"程序{type}",
唐召明 authored
194
                        ProjectRow = program_no,
唐召明 authored
195
196
197
198
199
200
201
202
203
204
                        X = Math.Round(pos_X, 1),
                        Y = Math.Round(pos_Y, 1),
                        Z = Math.Round(pos_Z, 1),
                        A = Math.Round(pos_A, 1),
                        B = Math.Round(pos_B, 1),
                        C = Math.Round(pos_C, 1),
                        E1 = Math.Round(pos_E1, 1),
                        E2 = Math.Round(pos_E2, 1),
                        E3 = Math.Round(pos_E3, 1),
                        E4 = Math.Round(pos_E4, 1),
唐召明 authored
205
206
                        SsSpeed = Math.Round(weld_Speed, 1),
                        Current = Math.Round(weld_I, 1),
唐召明 authored
207
                        Voltage = GetVoltageVal(weld_I, weld_V, robotEquipment),
唐召明 authored
208
209
210
211
212
                    },
                    EqInfoRight = new EquipmentInfoRight
                    {
                        EfficiencyList = new Efficiency
                        {
唐召明 authored
213
                            Arcing = xAxisData.Select(x => Convert.ToInt32(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(r => r.EquipmentCode == robotEquipment.Code && r.EquipmentPropertyCode == RobotProps.WeldFlag.ToString() && r.CreateTime.Date == x).Sum(r => r.UpdateTime.Ticks - r.CreateTime.Ticks)).TotalMinutes)).ToList(),
唐召明 authored
214
唐召明 authored
215
                            PowerOn = xAxisData.Select(x => Convert.ToInt32(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(r => r.EquipmentCode == robotEquipment.Code && r.EquipmentPropertyCode == RobotProps.BootFlag.ToString() && r.CreateTime.Date == x).Sum(r => r.UpdateTime.Ticks - r.CreateTime.Ticks)).TotalMinutes)).ToList(),
唐召明 authored
216
唐召明 authored
217
                            Work = xAxisData.Select(x => Convert.ToInt32(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(r => r.EquipmentCode == robotEquipment.Code && r.EquipmentPropertyCode == RobotProps.Work_Time.ToString() && r.CreateTime.Date == x).Sum(r => r.UpdateTime.Ticks - r.CreateTime.Ticks)).TotalMinutes)).ToList(),
唐召明 authored
218
219
                            XAxisData = xAxisData.Select(x => x.ToString("M")).ToList(),
                        },
唐召明 authored
220
221
222
223
224
                        WeldFlagData = xAxisData.Select(x => new BoardChart
                        {
                            Name = x.ToString("M"),
                            Value = GetWeldFlagRate(context, robotEquipment, x)
                        }).ToList(),
唐召明 authored
225
                        ProductInfo = type.ToString(),
唐召明 authored
226
                        ProductState = productStateName,
唐召明 authored
227
                        TimeSum = timeSum,
唐召明 authored
228
229
230
                        YieldList = new YieldListVM
                        {
                            XAxisData = xAxisData.Select(x => x.ToString("M")).ToList(),
唐召明 authored
231
                            Yield = xAxisData.Select(x => context.WorkpieceProductions.Where(w => w.EquipmentCode == robotEquipment.Code && w.CreateTime.Date == x.Date && w.IsEnd).Count()).ToList(),
唐召明 authored
232
233
234
                        }
                    },
唐召明 authored
235
236
237
238
239
                    CurrentList = context.WeldProcessRecords.Where(x => x.ProductionId == lastProductionId && x.Code == RobotProps.Weld_I.ToString()).OrderBy(x => x.CreateTime).Select(x => x.Value).AsEnumerable().Select(x =>
                    {
                        _ = double.TryParse(x, out var val);
                        return Math.Round(val, 1);
                    }).ToList(),
唐召明 authored
240
                    EqEfficiencyCenter = new EquipmentEfficiency
唐召明 authored
241
                    {
唐召明 authored
242
243
                        AlarmRate = GetAlarmRate(context, robotEquipment),
                        AutoRate = GetAutoRate(context, robotEquipment),
唐召明 authored
244
                        OnLineRate = GetOnLineRate(context, robotEquipment),
唐召明 authored
245
                        UtilizeRate = UtilizeRate(context, robotEquipment),
唐召明 authored
246
                    },
唐召明 authored
247
248
249
250
251
                    VoltagetList = context.WeldProcessRecords.Where(x => x.ProductionId == lastProductionId && x.Code == RobotProps.Weld_V.ToString()).OrderBy(x => x.CreateTime).Select(x => x.Value).AsEnumerable().Select(x =>
                    {
                        _ = double.TryParse(x, out var val);
                        return Math.Round(val, 1);
                    }).ToList(),
唐召明 authored
252
253
                };
唐召明 authored
254
255
256
257
258
259
                //获取电压值
                double GetVoltageVal(float weld_I, float weld_V, Equipment robot)
                {
                    //Kuka C2设备数值有误差,电流值为0时,电压应显示0
                    var codes = new List<EquipmentConst>
                    {
唐召明 authored
260
261
                        EquipmentConst.KukaC2_1,
                        EquipmentConst.KukaC2_2,
唐召明 authored
262
263
264
265
266
267
268
269
                    }.Select(x => x.ToString()).ToList();
                    if (codes.Contains(robot.Code) && weld_I <= 0)
                    {
                        return 0;
                    }
                    return Math.Round(weld_V, 1);
                }
唐召明 authored
270
                //故障率
唐召明 authored
271
                int GetAlarmRate(DataContext context, Equipment robotEquipment)
唐召明 authored
272
273
                {
                    if (bootFalgTicks == 0) return 0;
唐召明 authored
274
                    return Convert.ToInt32(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.Alarm.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks) * 100 / bootFalgTicks);
唐召明 authored
275
276
                }
唐召明 authored
277
                int UtilizeRate(DataContext context, Equipment robotEquipment)
唐召明 authored
278
279
                {
                    if (bootFalgTicks == 0) return 0;
唐召明 authored
280
                    return Convert.ToInt32(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.WorkFlag.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks) * 100 / bootFalgTicks);
唐召明 authored
281
282
                }
唐召明 authored
283
                int GetAutoRate(DataContext context, Equipment robotEquipment)
唐召明 authored
284
285
                {
                    if (bootFalgTicks == 0) return 0;
唐召明 authored
286
                    return Convert.ToInt32(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.WeldFlag.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks) * 100 / bootFalgTicks);
唐召明 authored
287
288
289
290
291
                }

                //在线率
                int GetOnLineRate(DataContext context, Equipment robotEquipment)
                {
唐召明 authored
292
                    var bootFlagStartDay = context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.BootFlag.ToString()).OrderBy(x => x.CreateTime).Select(x => x.CreateTime).FirstOrDefault();
唐召明 authored
293
294
295
296
297
                    if (bootFlagStartDay == default) return 0;
                    else if (bootFlagStartDay <= DateTime.Today.AddMonths(-1))
                    {
                        bootFlagStartDay = DateTime.Today.AddMonths(-1);
                    }
唐召明 authored
298
                    return Convert.ToInt32(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robotEquipment.Code && x.EquipmentPropertyCode == RobotProps.BootFlag.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks) * 100 / (DateTime.Now - bootFlagStartDay).Ticks);
唐召明 authored
299
300
                }
唐召明 authored
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
                result.Data = new
                {
                    Head = new
                    {
                        vm.NowDayCountLeft,
                        vm.EqCenter,
                        vm.MonthCountRight,
                    },
                    Center = new
                    {
                        vm.EqInfoLeft,
                        vm.EqInfoRight,
                    },
                    Footer = new
                    {
                        vm.CurrentList,
                        vm.EqEfficiencyCenter,
                        vm.VoltagetList,
                    }
                };
唐召明 authored
321
                _memoryCache.Set(key, result, _absoluteExpirationRelativeToNow);
唐召明 authored
322
323
324
325
326
327
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
唐召明 authored
328
329
330
331
332
333
334
335
336
337
338
339
340
341
            return result;
        }

        /// <summary>
        /// 焊接看板2
        /// </summary>
        /// <remarks>2号厂房</remarks>
        /// <returns></returns>
        [HttpGet]
        [Route("WeldBoard")]
        public BoardResult<Board2VM> GetWeldBoardData()
        {
            try
            {
唐召明 authored
342
343
344
                var key = $"{nameof(GetWeldBoardData)}";
                var cacheData = _memoryCache.Get<BoardResult<Board2VM>>(key);
                if (cacheData != null)
唐召明 authored
345
                {
唐召明 authored
346
347
                    return cacheData;
                }
唐召明 authored
348
唐召明 authored
349
                using var context = _dbContextFactory.CreateDbContext();
唐召明 authored
350
351
352
353
354
355
356

                //本月开始时间
                var monthStartTime = DateTime.Today.AddDays(1 - DateTime.Today.Day).Date;
                var days = 7;//显示最近N天的数据
                var xAxisData = Enumerable.Range(0, days).Select(x => DateTime.Today.AddDays(-x)).OrderBy(x => x).ToList();
                var vm = new Board2VM
                {
唐召明 authored
357
358
359
360
                    Robot1 = GetRobotInfo(EquipmentConst.KukaC4_1),
                    Robot2 = GetRobotInfo(EquipmentConst.KukaC4_2),
                    Robot3 = GetRobotInfo(EquipmentConst.KukaC2_1),
                    Robot4 = GetRobotInfo(EquipmentConst.KukaC2_2),
唐召明 authored
361
362
363
                    Robot5 = GetRobotInfo(EquipmentConst.Efort_1),
                    Robot6 = GetRobotInfo(EquipmentConst.Fanuc_1),
                };
唐召明 authored
364
                var result = new BoardResult<Board2VM>
唐召明 authored
365
366
367
368
369
                {
                    Code = 200,
                    Data = vm,
                    Message = "成功"
                };
唐召明 authored
370
371
                _memoryCache.Set(key, result, _absoluteExpirationRelativeToNow);
                return result;
唐召明 authored
372
373
374
375
376
377
378
379
380
381
382
383

                RobotDto GetRobotInfo(EquipmentConst equipmentCode)
                {
                    var robot = context.Equipments.Where(x => x.Code == equipmentCode.ToString()).FirstOrDefault();
                    if (robot == null)
                    {
                        return new RobotDto();
                    }
                    var result = new RobotDto
                    {
                        RobotCode = robot.Code,
                        RobotName = robot.Name,
唐召明 authored
384
                        CompleteCount = context.WorkpieceProductions.Where(x => x.EquipmentCode == robot.Code && x.CreateTime >= monthStartTime).Count(),
唐召明 authored
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
                        WorkTime = Math.Round(TimeSpan.FromTicks(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robot.Code && x.EquipmentPropertyCode == RobotProps.WorkFlag.ToString() && x.CreateTime >= monthStartTime).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks)).TotalHours, 2),
                        MonthWeld = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robot.Code && x.EquipmentPropertyCode == RobotProps.Weld_Speed.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle)),
                        Charts = xAxisData.Select(x => new BoardChart
                        {
                            Name = x.ToString("M"),
                            Value = GetWeldFlagRate(context, robot, x)
                        }).ToList()
                    };
                    return result;
                }
            }
            catch (Exception ex)
            {
                return new BoardResult<Board2VM>
                {
                    Code = 500,
                    Message = ex.Message
                };
            }
        }
唐召明 authored
406
407
408
409
410
411
412
413
414
415
416
417
        /// <summary>
        /// 焊接总看板
        /// </summary>
        /// <remarks>1号厂房</remarks>
        /// <returns></returns>
        [HttpGet]
        [Route("MainWeldBoard")]
        public BoardResult<Board3VM> GetMainWeldBoard()
        {
            var result = new BoardResult<Board3VM>();
            try
            {
唐召明 authored
418
419
420
421
422
423
424
                var key = $"{nameof(GetMainWeldBoard)}";
                var cacheData = _memoryCache.Get<BoardResult<Board3VM>>(key);
                if (cacheData != null)
                {
                    return cacheData;
                }
唐召明 authored
425
426
427
428
                var monthStartTime = DateTime.Today.AddDays(1 - DateTime.Today.Day).Date;
                using var context = _dbContextFactory.CreateDbContext();
                var robotCodes = new List<EquipmentConst>
                {
唐召明 authored
429
430
431
432
                    EquipmentConst.KukaC4_1,
                    EquipmentConst.KukaC4_2,
                    EquipmentConst.KukaC2_1,
                    EquipmentConst.KukaC2_2,
唐召明 authored
433
434
435
436
437
438
                    EquipmentConst.Efort_1,
                    EquipmentConst.Fanuc_1,
                }.Select(x => x.ToString()).ToList();
                var days = 7;//显示最近N天的数据
                var xAxisData = Enumerable.Range(0, days).Select(x => DateTime.Today.AddDays(-x)).OrderBy(x => x).ToList();
                var robots = _dataCacheService.Equipments.Where(x => robotCodes.Contains(x.Code)).OrderBy(x => x.Code).ToList();
唐召明 authored
439
                var totalTicks = (DateTime.Now - DateTime.Today).Ticks;
唐召明 authored
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
                var vm = new Board3VM
                {
                    RobotStateMonitor = robots.Select(x =>
                    {
                        _ = bool.TryParse(x[RobotProps.BootFlag.ToString()].Value, out var bootFalgValue);
                        _ = bool.TryParse(x[RobotProps.Alarm.ToString()].Value, out var alarmValue);
                        _ = bool.TryParse(x[RobotProps.WorkFlag.ToString()].Value, out var workFlagValue);
                        _ = int.TryParse(x[RobotProps.Work_Mode.ToString()].Value, out var work_Mode);

                        var state = 2;//待机
                        if (!bootFalgValue)
                        {
                            state = 0;//离线
                        }
                        else if (workFlagValue)
                        {
                            state = 1;//工作
                        }
                        //仅自动模式显示
                        else if (alarmValue && work_Mode >= 3)
                        {
                            state = 3;//报警
                        }

                        var data = new RobotState
                        {
                            Code = x.Code,
                            Name = x.Name,
                            State = state,
                            StateName = state switch
                            {
                                1 => "运行",
                                2 => "待机",
                                3 => "报警",
                                _ => "离线",
                            }
                        };
                        return data;
                    }).ToList(),
                    RobotConditions = robots.Select(x =>
                    {
                        _ = int.TryParse(x[RobotProps.Work_Mode.ToString()].Value, out var mode);
                        _ = bool.TryParse(x[RobotProps.Weld_CleanGun.ToString()].Value, out var weld_CleanGun);
                        _ = float.TryParse(x[RobotProps.Weld_I.ToString()].Value, out var weld_I);
                        _ = float.TryParse(x[RobotProps.Weld_V.ToString()].Value, out var weld_V);
                        _ = float.TryParse(x[RobotProps.Weld_Speed.ToString()].Value, out var weld_Speed);
                        var data = new RobotCondition
                        {
                            EquipmentCode = x.Code,
                            Weld_CleanGun = weld_CleanGun,
                            Weld_I = Math.Round(weld_I, 1),
                            Weld_V = Math.Round(weld_V, 1),
                            Weld_Speed = Math.Round(weld_Speed, 1),
                            WorkMode = mode switch
                            {
                                1 => "T1模式",
                                2 => "T2模式",
                                3 => "自动模式",
                                4 => "外部自动模式",
                                _ => "无数据",
                            }
                        };
                        return data;
                    }).ToList(),
唐召明 authored
504
                    RobotStateStatistics = robots.Select(robot =>
唐召明 authored
505
                    {
唐召明 authored
506
                        var bootFlagTicks = context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robot.Code && x.EquipmentPropertyCode == RobotProps.BootFlag.ToString() && x.CreateTime >= DateTime.Today).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks);
唐召明 authored
507
508
509
                        var run = 0d;
                        var free = 0d;
                        var alarm = 0d;
唐召明 authored
510
511
                        var offLine = 0d;
                        if (totalTicks == 0 || bootFlagTicks == 0)
唐召明 authored
512
                        {
唐召明 authored
513
                            offLine = 100;
唐召明 authored
514
515
516
                        }
                        else
                        {
唐召明 authored
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
                            var workFlagRecords = context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robot.Code && x.EquipmentPropertyCode == RobotProps.WorkFlag.ToString() && x.CreateTime >= DateTime.Today).Select(x => new
                            {
                                x.CreateTime,
                                x.UpdateTime,
                            }).ToList();

                            var alarmFlagRecords = context.EquipmentPropertyRecords.Where(x => x.EquipmentCode == robot.Code && x.EquipmentPropertyCode == RobotProps.Alarm.ToString() && x.CreateTime >= DateTime.Today).Select(x => new
                            {
                                x.CreateTime,
                                x.UpdateTime,
                            }).ToList();

                            var workFlagTicks = workFlagRecords.Sum(workRecord =>
                            {
                                var alarmRecord = alarmFlagRecords.Where(x => x.CreateTime >= workRecord.CreateTime && x.CreateTime <= workRecord.UpdateTime).FirstOrDefault();
                                if (alarmRecord == null)
                                {
                                    return (workRecord.UpdateTime - workRecord.CreateTime).Ticks;
                                }

                                if (alarmRecord.UpdateTime > workRecord.UpdateTime)
                                {
                                    return (alarmRecord.CreateTime - workRecord.CreateTime).Ticks;
                                }
                                return (workRecord.UpdateTime - workRecord.CreateTime).Ticks - (alarmRecord.UpdateTime - alarmRecord.CreateTime).Ticks;
                            });

                            var alarmFlagTicks = alarmFlagRecords.Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks);
唐召明 authored
545
546
                            var freeTicks = bootFlagTicks - workFlagTicks - alarmFlagTicks;
                            var offLineTicks = totalTicks - bootFlagTicks;
唐召明 authored
547
唐召明 authored
548
549
550
551
                            run = Math.Round(workFlagTicks * 100d / totalTicks, 1);
                            alarm = Math.Round(alarmFlagTicks * 100d / totalTicks, 1);
                            free = Math.Round(freeTicks * 100d / totalTicks, 1);
                            offLine = Math.Round(offLineTicks * 100d / totalTicks, 1);
唐召明 authored
552
553
554
555
                        }

                        var data = new ChartBar
                        {
唐召明 authored
556
557
                            Code = robot.Code,
                            Name = robot.Name,
唐召明 authored
558
559
                            Run = run,
                            Free = free,
唐召明 authored
560
561
                            Alarm = alarm,
                            OffLine = offLine,
唐召明 authored
562
563
564
565
566
567
568
569
570
571
                        };
                        return data;
                    }).ToList(),
                    ProcessingStatistics = new ProcessingStatistics
                    {
                        XAxisDate = xAxisData.Select(x => x.ToString("M")).ToList(),
                        ChartLines = robots.Select(robot => new ChartLine
                        {
                            Code = robot.Code,
                            Name = robot.Name,
唐召明 authored
572
                            Values = xAxisData.Select(date => context.WorkpieceProductions.Where(x => x.EquipmentCode == robot.Code && x.CreateTime.Date == date && x.IsEnd).Count()).ToList()
唐召明 authored
573
574
575
576
577
578
579
580
581
582
                        }).ToList()
                    },
                    RobotStatistics = new RobotStatistics
                    {
                        TodayUtilizationRate = GetTodayUtilizationRate(),
                        TodayArcingRate = GetTodayArcingRate(),
                        TodayGasConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotProps.Gas_Flow.ToString() && x.CreateTime >= DateTime.Today).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
                        MonthGasConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotProps.Gas_Flow.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
                        TodayWireConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotProps.Weld_Speed.ToString() && x.CreateTime >= DateTime.Today).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
                        MonthWireConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotProps.Weld_Speed.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
唐召明 authored
583
584
                        TodayProductionCapacity = context.WorkpieceProductions.Where(x => x.CreateTime >= DateTime.Today && x.IsEnd).Count(),
                        MonthProductionCapacity = context.WorkpieceProductions.Where(x => x.CreateTime >= monthStartTime && x.IsEnd).Count(),
唐召明 authored
585
586
587
588
589
590
591

                        TodayPowerConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotPlcProps.Electricity.ToString() && x.CreateTime >= DateTime.Today).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
                        MonthPowerConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotPlcProps.Electricity.ToString() && x.CreateTime >= monthStartTime).Select(x => x.Value).AsEnumerable().Sum(Convert.ToSingle), 2),
                        TodayWeldPowerConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == $"{RobotProps.WeldFlag}_{RobotPlcProps.Electricity}" && x.CreateTime >= DateTime.Today).Select(x => x
                        .Value).AsEnumerable().Sum(Convert.ToSingle), 2),
                        MonthWeldPowerConsumption = Math.Round(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == $"{RobotProps.WeldFlag}_{RobotPlcProps.Electricity}" && x.CreateTime >= monthStartTime).Select(x => x
                        .Value).AsEnumerable().Sum(Convert.ToSingle), 2),
唐召明 authored
592
593
594
                    }
                };
                result.Data = vm;
唐召明 authored
595
596
597

                _memoryCache.Set(key, result, _absoluteExpirationRelativeToNow);
唐召明 authored
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
                return result;

                //获取当天利用率
                double GetTodayUtilizationRate()
                {
                    var bootFalgTicks = context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotProps.BootFlag.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks);
                    if (bootFalgTicks == 0) return 0;
                    return Convert.ToInt32(context.EquipmentPropertyRecords.Where(x => x.EquipmentPropertyCode == RobotProps.WorkFlag.ToString()).Sum(x => x.UpdateTime.Ticks - x.CreateTime.Ticks) * 100 / bootFalgTicks);
                }

                //获取当天燃弧率
                double GetTodayArcingRate()
                {
                    var runTicks = context.EquipmentPropertyRecords.Where(p => p.EquipmentPropertyCode == RobotProps.BootFlag.ToString() && p.CreateTime.Date == DateTime.Today.Date).Sum(s => s.UpdateTime.Ticks - s.CreateTime.Ticks);
                    if (runTicks == 0) return 0;
                    var weldTicks = context.EquipmentPropertyRecords.Where(p => p.EquipmentPropertyCode == RobotProps.WeldFlag.ToString() && p.CreateTime.Date == DateTime.Today.Date).Sum(s => s.UpdateTime.Ticks - s.CreateTime.Ticks);
                    return Convert.ToInt32(weldTicks * 100 / runTicks);
                }
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 焊接机器人数字孪生看板
        /// </summary>
        /// <remarks>机器人实时数据</remarks>
        /// <returns></returns>
        [HttpGet]
        [Route("RobotMonitorData")]
        public BoardResult<DigitalTwinVM1> GetRobotMonitorData()
        {
            var result = new BoardResult<DigitalTwinVM1>();
            try
            {
唐召明 authored
637
638
639
640
641
642
                var key = $"{nameof(GetRobotMonitorData)}";
                var cacheData = _memoryCache.Get<BoardResult<DigitalTwinVM1>>(key);
                if (cacheData != null)
                {
                    return cacheData;
                }
唐召明 authored
643
                using var context = _dbContextFactory.CreateDbContext();
唐召明 authored
644
645
                var robot1 = _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.KukaC4_1.ToString())!;
                var robot2 = _dataCacheService.Equipments.Find(x => x.Code == EquipmentConst.KukaC4_2.ToString())!;
唐召明 authored
646
647
648
649
650
651
652

                var vm = new DigitalTwinVM1
                {
                    RobotMonitor1 = GetRobotMonitor(robot1),
                    RobotMonitor2 = GetRobotMonitor(robot2),
                };
                result.Data = vm;
唐召明 authored
653
                _memoryCache.Set(key, result, _absoluteExpirationRelativeToNow);
唐召明 authored
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }

        private RobotMonitor GetRobotMonitor(Equipment robotEquipment)
        {
            _ = double.TryParse(robotEquipment[RobotProps.Pos_X.ToString()].Value, out var pos_X);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_Y.ToString()].Value, out var pos_Y);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_Z.ToString()].Value, out var pos_Z);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_A.ToString()].Value, out var pos_A);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_B.ToString()].Value, out var pos_B);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_C.ToString()].Value, out var pos_C);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_E1.ToString()].Value, out var pos_E1);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_E2.ToString()].Value, out var pos_E2);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_E3.ToString()].Value, out var pos_E3);
            _ = double.TryParse(robotEquipment[RobotProps.Pos_E4.ToString()].Value, out var pos_E4);

            _ = bool.TryParse(robotEquipment[RobotProps.Weld_CleanGun.ToString()].Value, out var weld_CleanGun);
            _ = bool.TryParse(robotEquipment[RobotProps.WeldFlag.ToString()].Value, out var weldFlag);
            _ = bool.TryParse(robotEquipment[RobotProps.Weld_Gas.ToString()].Value, out var weld_Gas);
            _ = bool.TryParse(robotEquipment[RobotProps.WeldCompleteFlag.ToString()].Value, out var weldCompleteFlag);
            _ = bool.TryParse(robotEquipment[RobotProps.BootFlag.ToString()].Value, out var bootFalgValue);
            _ = bool.TryParse(robotEquipment[RobotProps.Alarm.ToString()].Value, out var alarmValue);
            _ = bool.TryParse(robotEquipment[RobotProps.WorkFlag.ToString()].Value, out var workFlagValue);
            //_ = bool.TryParse(robotEquipment[RobotProps.Work_Time.ToString()].Value, out var workTime);

            _ = float.TryParse(robotEquipment[RobotProps.Weld_V.ToString()].Value, out var weld_V);
            _ = float.TryParse(robotEquipment[RobotProps.Weld_I.ToString()].Value, out var weld_I);
            _ = float.TryParse(robotEquipment[RobotProps.Weld_Speed.ToString()].Value, out var weld_Speed);
            _ = int.TryParse(robotEquipment[RobotProps.Work_Mode.ToString()].Value, out var work_Mode);
            //_ = int.TryParse(robotEquipment[RobotProps.Program_No.ToString()].Value, out var program_no);
            //_ = int.TryParse(robotEquipment[RobotProps.Type.ToString()].Value, out var type);

            var equipmentState = "在线";
            if (!bootFalgValue)
            {
                equipmentState = "离线";
            }
            //仅自动模式显示
            else if (alarmValue && work_Mode >= 3)
            {
                equipmentState = "报警";
            }
            else if (workFlagValue)
            {
                equipmentState = "工作";
            }

            var result = new RobotMonitor
            {
                EquipmentCode = robotEquipment.Code,
                EquipmentName = robotEquipment.Name,
                Status = equipmentState,
                Weld_V = Math.Round(weld_V, 1),
                Weld_I = Math.Round(weld_I, 1),
                Weld_Speed = Math.Round(weld_Speed, 1),
                Work_Mode = work_Mode switch
                {
                    1 => "T1模式",
                    2 => "T2模式",
                    3 => "T3模式",
                    4 => "外部自动",
                    _ => "无数据",
                },
                A1 = Math.Round(pos_X, 1),
                A2 = Math.Round(pos_Y, 1),
                A3 = Math.Round(pos_Z, 1),
                A4 = Math.Round(pos_A, 1),
                A5 = Math.Round(pos_B, 1),
                A6 = Math.Round(pos_C, 1),
                E1 = Math.Round(pos_E1 * 100 / 8200, 1),
                E2 = Math.Round(pos_E2, 1),
                E3 = Math.Round(pos_E3, 1),
                E4 = Math.Round(pos_E4, 1),
                BootFlag = bootFalgValue,
                WorkFlag = workFlagValue,
                WeldFlag = weldFlag,
                WeldCompleteFlag = weldCompleteFlag,
                Weld_Gas = weld_Gas,
                Weld_CleanGun = weld_CleanGun,
                Alarm = alarmValue,
                RedLight = false,
                GreenLight = false,
                YellowLight = false,
                //Work_Time = workTime,
            };
            return result;
        }
唐召明 authored
748
749
750
751
752
753
754
        //燃弧率
        private static int GetWeldFlagRate(DataContext context, Equipment robotEquipment, DateTime date)
        {
            var runTicks = context.EquipmentPropertyRecords.Where(p => p.EquipmentCode == robotEquipment.Code && p.EquipmentPropertyCode == RobotProps.BootFlag.ToString() && p.CreateTime.Date == date).Sum(s => s.UpdateTime.Ticks - s.CreateTime.Ticks);
            if (runTicks == 0) return 0;
            var weldTicks = context.EquipmentPropertyRecords.Where(p => p.EquipmentCode == robotEquipment.Code && p.EquipmentPropertyCode == RobotProps.WeldFlag.ToString() && p.CreateTime.Date == date).Sum(s => s.UpdateTime.Ticks - s.CreateTime.Ticks);
            return Convert.ToInt32(weldTicks * 100 / runTicks);
唐召明 authored
755
756
757
        }
    }
}