Entities.cs
12.7 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
namespace RobotProductionSystem.Api.Domain;
public sealed class User
{
public int Id { get; set; }
public string Username { get; set; } = "";
public string PasswordHash { get; set; } = "";
public string Name { get; set; } = "";
public string Email { get; set; } = "";
public string Station { get; set; } = "";
public string? AvatarSrc { get; set; }
public string? AvatarAlt { get; set; }
public List<UserRole> Roles { get; set; } = [];
}
public sealed class UserRole
{
public int Id { get; set; }
public int UserId { get; set; }
public string Role { get; set; } = "";
public User? User { get; set; }
}
public sealed class Member
{
public int Id { get; set; }
public string Name { get; set; } = "";
public string Email { get; set; } = "";
public string Username { get; set; } = "";
public string Role { get; set; } = "member";
public string? Bio { get; set; }
public string? AvatarSrc { get; set; }
public string? AvatarAlt { get; set; }
}
public sealed class SettingsProfile
{
public int Id { get; set; }
public string Name { get; set; } = "";
public string Email { get; set; } = "";
public string Username { get; set; } = "";
public string? Avatar { get; set; }
public string? Bio { get; set; }
}
public sealed class SettingsNotification
{
public int Id { get; set; }
public bool Email { get; set; }
public bool Desktop { get; set; }
public bool ProductUpdates { get; set; }
public bool WeeklyDigest { get; set; }
public bool ImportantUpdates { get; set; }
}
public sealed class SecurityAccount
{
public int Id { get; set; }
public string PasswordHash { get; set; } = "";
public bool AccountDeleted { get; set; }
}
public sealed class DeviceType
{
public int Id { get; set; }
public string Name { get; set; } = "";
public string Model { get; set; } = "";
public string Category { get; set; } = "other";
public int LengthMm { get; set; }
public int WidthMm { get; set; }
public int HeightMm { get; set; }
public decimal WeightKg { get; set; }
public bool HasBattery { get; set; }
public string? BatterySpec { get; set; }
public string? Description { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
public sealed class WorkOrder
{
public int Id { get; set; }
public string OrderNo { get; set; } = "";
public string DeviceCode { get; set; } = "";
public string BatchNo { get; set; } = "";
public string Line { get; set; } = "";
public string OwnerUsername { get; set; } = "";
public string OwnerName { get; set; } = "";
public DateOnly PlannedDate { get; set; }
public string Status { get; set; } = "draft";
public int CompletedSn { get; set; }
public int TotalSn { get; set; }
public string CreatedBy { get; set; } = "";
public DateTimeOffset CreatedAt { get; set; }
public string UpdatedBy { get; set; } = "";
public DateTimeOffset UpdatedAt { get; set; }
public string LastAction { get; set; } = "create";
public DateTimeOffset LastActionAt { get; set; }
public string LastActionBy { get; set; } = "";
public List<WorkOrderEvent> Events { get; set; } = [];
}
public sealed class WorkOrderEvent
{
public int Id { get; set; }
public string EventId { get; set; } = "";
public int WorkOrderId { get; set; }
public string Action { get; set; } = "";
public string? FromStatus { get; set; }
public string ToStatus { get; set; } = "";
public string Operator { get; set; } = "";
public DateTimeOffset At { get; set; }
public string? Remark { get; set; }
public WorkOrder? WorkOrder { get; set; }
}
public sealed class SnItem
{
public int Id { get; set; }
public string Sn { get; set; } = "";
public string WorkOrderNo { get; set; } = "";
public string Status { get; set; } = "pending";
public ProcessStep CurrentStep { get; private set; } = ProcessStep.Assembly;
public string ExceptionStatus { get; set; } = "none";
public string? FreezeReason { get; set; }
public string? ScrapReason { get; set; }
public string CreatedBy { get; set; } = "";
public DateTimeOffset CreatedAt { get; set; }
public string UpdatedBy { get; set; } = "";
public DateTimeOffset UpdatedAt { get; set; }
public string LastAction { get; set; } = "import";
public DateTimeOffset LastActionAt { get; set; }
public string LastActionBy { get; set; } = "";
public List<SnEvent> Events { get; set; } = [];
public bool TryMoveToAssembly(out string? error)
{
if (CurrentStep == ProcessStep.Assembly)
{
error = null;
return true;
}
error = "仅支持在初始化时设置为装配工序。";
return false;
}
public bool TryMoveToDebug(out string? error)
{
if (CurrentStep == ProcessStep.Debug)
{
error = null;
return true;
}
if (CurrentStep != ProcessStep.Assembly)
{
error = "进入调试前必须处于装配工序。";
return false;
}
CurrentStep = ProcessStep.Debug;
error = null;
return true;
}
public bool TryMoveToTesting(out string? error)
{
if (CurrentStep == ProcessStep.Testing)
{
error = null;
return true;
}
if (CurrentStep != ProcessStep.Debug)
{
error = "进入测试前必须处于调试工序。";
return false;
}
CurrentStep = ProcessStep.Testing;
error = null;
return true;
}
public bool TryMoveToFinalInspection(out string? error)
{
if (CurrentStep == ProcessStep.FinalInspection)
{
error = null;
return true;
}
if (CurrentStep != ProcessStep.Testing)
{
error = "进入终检前必须处于测试工序。";
return false;
}
CurrentStep = ProcessStep.FinalInspection;
error = null;
return true;
}
public bool TryMoveToRework(out string? error)
{
if (CurrentStep == ProcessStep.Rework)
{
error = null;
return true;
}
if (CurrentStep != ProcessStep.Testing && CurrentStep != ProcessStep.FinalInspection)
{
error = "进入返修前必须处于测试或终检工序。";
return false;
}
CurrentStep = ProcessStep.Rework;
error = null;
return true;
}
public bool TryMoveToWarehousing(out string? error)
{
if (CurrentStep == ProcessStep.Warehousing)
{
error = null;
return true;
}
if (CurrentStep != ProcessStep.FinalInspection)
{
error = "进入入库前必须处于终检工序。";
return false;
}
CurrentStep = ProcessStep.Warehousing;
error = null;
return true;
}
public bool TryMoveTo(ProcessStep targetStep, out string? error)
{
return targetStep switch
{
ProcessStep.Assembly => TryMoveToAssembly(out error),
ProcessStep.Debug => TryMoveToDebug(out error),
ProcessStep.Testing => TryMoveToTesting(out error),
ProcessStep.FinalInspection => TryMoveToFinalInspection(out error),
ProcessStep.Rework => TryMoveToRework(out error),
ProcessStep.Warehousing => TryMoveToWarehousing(out error),
_ => Fail("未知工序,不允许切换。", out error)
};
}
public bool TryInitializeCurrentStep(string? stepText, out string? error)
{
if (!ProcessStepMapper.TryParse(stepText, out var step))
{
return Fail("工序参数不正确。", out error);
}
return TryInitializeCurrentStep(step, out error);
}
public bool TryInitializeCurrentStep(ProcessStep step, out string? error)
{
if (step == ProcessStep.Unknown)
{
return Fail("工序参数不正确。", out error);
}
// 初始化默认是装配,目标工序需要沿着受控状态机推进。
return step switch
{
ProcessStep.Assembly => TryMoveToAssembly(out error),
ProcessStep.Debug => TryMoveToDebug(out error),
ProcessStep.Testing => TryMoveSequence([ProcessStep.Debug, ProcessStep.Testing], out error),
ProcessStep.FinalInspection => TryMoveSequence([ProcessStep.Debug, ProcessStep.Testing, ProcessStep.FinalInspection], out error),
ProcessStep.Rework => TryMoveSequence([ProcessStep.Debug, ProcessStep.Testing, ProcessStep.Rework], out error),
ProcessStep.Warehousing => TryMoveSequence([ProcessStep.Debug, ProcessStep.Testing, ProcessStep.FinalInspection, ProcessStep.Warehousing], out error),
_ => Fail("未知工序,不允许初始化。", out error)
};
}
public ProcessStep? GetNextStep()
{
return CurrentStep switch
{
ProcessStep.Assembly => ProcessStep.Debug,
ProcessStep.Debug => ProcessStep.Testing,
ProcessStep.Testing => ProcessStep.FinalInspection,
ProcessStep.FinalInspection => ProcessStep.Warehousing,
ProcessStep.Rework => ProcessStep.Testing,
ProcessStep.Warehousing => null,
_ => null
};
}
private bool TryMoveSequence(ProcessStep[] sequence, out string? error)
{
foreach (var step in sequence)
{
if (!TryMoveTo(step, out error))
{
return false;
}
}
error = null;
return true;
}
private static bool Fail(string message, out string? error)
{
error = message;
return false;
}
public void OverrideCurrentStep(ProcessStep step)
{
CurrentStep = step == ProcessStep.Unknown ? ProcessStep.Assembly : step;
}
}
public sealed class SnEvent
{
public int Id { get; set; }
public string EventId { get; set; } = "";
public int SnItemId { get; set; }
public string Action { get; set; } = "";
public string? FromStatus { get; set; }
public string ToStatus { get; set; } = "";
public string Operator { get; set; } = "";
public DateTimeOffset At { get; set; }
public string? Reason { get; set; }
public string? EvidencePath { get; set; }
public ProcessStep CurrentStep { get; private set; } = ProcessStep.Assembly;
public string ExceptionStatus { get; set; } = "none";
public SnItem? SnItem { get; set; }
public void CaptureCurrentStep(ProcessStep step)
{
CurrentStep = step == ProcessStep.Unknown ? ProcessStep.Assembly : step;
}
}
public sealed class OperationTask
{
public int Id { get; set; }
public string WorkOrderNo { get; set; } = "";
public string Sn { get; set; } = "";
public ProcessStep StepName { get; set; } = ProcessStep.Assembly;
public string Workstation { get; set; } = "";
public string Device { get; set; } = "";
public string Operator { get; set; } = "";
public DateTimeOffset? StartedAt { get; set; }
public DateTimeOffset? EndedAt { get; set; }
public string Result { get; set; } = "pending";
public string Status { get; set; } = "pending";
public string NextAction { get; set; } = "start";
public List<OperationTaskEvent> AuditEvents { get; set; } = [];
}
public sealed class OperationTaskEvent
{
public int Id { get; set; }
public string EventId { get; set; } = "";
public int OperationTaskId { get; set; }
public string Action { get; set; } = "";
public string? FromStatus { get; set; }
public string ToStatus { get; set; } = "";
public string Operator { get; set; } = "";
public DateTimeOffset At { get; set; }
public string? Remark { get; set; }
public string? EvidencePath { get; set; }
public string NextAction { get; set; } = "";
public OperationTask? OperationTask { get; set; }
}
public sealed class DashboardWorkOrderSnapshot
{
public int Id { get; set; }
public string OrderNo { get; set; } = "";
public string Line { get; set; } = "";
public string Status { get; set; } = "";
public DateOnly PlannedDate { get; set; }
public int CompletedSn { get; set; }
public int TotalSn { get; set; }
public int InProcessSn { get; set; }
public int FrozenSn { get; set; }
public int FirstTestPassed { get; set; }
public int FirstTestTotal { get; set; }
public int RetestPassed { get; set; }
public int RetestTotal { get; set; }
public int ExceptionCount { get; set; }
}
public sealed class ShellJsonItem
{
public int Id { get; set; }
public string Kind { get; set; } = "";
public string PayloadJson { get; set; } = "{}";
}