@pksep/zod-shared 0.0.548 → 0.0.550

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/assemble/dto/get-assemble-operation-count.dto.d.ts +14 -0
  2. package/dist/assemble/interfaces/interfaces.d.ts +1 -0
  3. package/dist/assemble/schemas/assemble-coming.schema.d.ts +10 -0
  4. package/dist/assemble/schemas/assemble.schema.d.ts +10 -0
  5. package/dist/assemble-kit/dto/assemble-kit-paginate.dto.d.ts +2 -2
  6. package/dist/deliveries/dto/create-deliveries.dto.d.ts +185 -0
  7. package/dist/deliveries/dto/create-deliveries.dto.js +70 -1
  8. package/dist/deliveries/schemas/deliveries-position.schema.d.ts +46 -26
  9. package/dist/deliveries/schemas/deliveries-position.schema.js +16 -9
  10. package/dist/deliveries/schemas/deliveries.schema.d.ts +5 -6
  11. package/dist/deliveries/schemas/deliveries.schema.js +0 -1
  12. package/dist/detal/default-values/default-values.d.ts +4 -0
  13. package/dist/detal/default-values/default-values.js +4 -0
  14. package/dist/detal/schemas/detal-deficit.schema.d.ts +170 -0
  15. package/dist/detal/schemas/detal.schema.d.ts +170 -0
  16. package/dist/equipment/schemas/equipment.schema.d.ts +0 -5
  17. package/dist/expenditure/schema/expenditure-consumption.schema.d.ts +2 -2
  18. package/dist/material/dto/create-material.dto.d.ts +136 -0
  19. package/dist/material/dto/create-material.dto.js +16 -0
  20. package/dist/material/dto/get-deficit.dto.d.ts +19 -5
  21. package/dist/material/dto/get-deficit.dto.js +10 -2
  22. package/dist/material/dto/up-create-type-material.dto.d.ts +4 -0
  23. package/dist/material/dto/up-create-type-material.dto.js +6 -1
  24. package/dist/material/enum/enum.d.ts +10 -0
  25. package/dist/material/enum/enum.js +12 -1
  26. package/dist/material/index.d.ts +1 -0
  27. package/dist/material/index.js +1 -0
  28. package/dist/material/interfaces/interface.d.ts +2 -0
  29. package/dist/material/schemas/material-characteristics.schema.d.ts +56 -0
  30. package/dist/material/schemas/material-characteristics.schema.js +3 -1
  31. package/dist/material/schemas/material-shipments-response.schema.d.ts +124 -8
  32. package/dist/material/schemas/material.schema.d.ts +125 -0
  33. package/dist/material/schemas/type-material.schema.d.ts +116 -0
  34. package/dist/material/schemas/type-material.schema.js +9 -2
  35. package/dist/material/utils/workpiece-mass.d.ts +56 -0
  36. package/dist/material/utils/workpiece-mass.js +538 -0
  37. package/dist/material/workpiece-mass.d.ts +45 -0
  38. package/dist/material/workpiece-mass.js +400 -0
  39. package/dist/metaloworking/dto/get-metallworking-pagination.dto.d.ts +3 -0
  40. package/dist/metaloworking/dto/get-metallworking-pagination.dto.js +1 -0
  41. package/dist/movement-object/schemas/get-one-object-history.schema.d.ts +40 -6
  42. package/dist/movement-object/schemas/get-one-object-history.schema.js +7 -1
  43. package/dist/production-tasks/interfaces/online-board.d.ts +1 -0
  44. package/dist/shipments/dto/format-list-shipment.dto.d.ts +3 -0
  45. package/dist/shipments/dto/format-list-shipment.dto.js +1 -0
  46. package/dist/shipments/dto/up-create-shipments.dto.d.ts +342 -4
  47. package/dist/shipments/dto/up-create-shipments.dto.js +97 -3
  48. package/dist/shipments/index.d.ts +1 -0
  49. package/dist/shipments/index.js +1 -0
  50. package/dist/shipments/types/types.d.ts +1 -0
  51. package/dist/specification/schema/attributes.schema.d.ts +386 -0
  52. package/dist/specification/type/type.d.ts +47 -1
  53. package/dist/utils/default-value/default-value.js +2 -1
  54. package/dist/utils/enums.d.ts +4 -2
  55. package/dist/utils/enums.js +2 -0
  56. package/dist/utils/interface/status-flags.interface.d.ts +4 -0
  57. package/dist/utils/sorting.d.ts +5 -1
  58. package/dist/utils/types.d.ts +6 -0
  59. package/dist/waybill/dto/create-waybill-product.dto.d.ts +3 -3
  60. package/dist/waybill/dto/create-waybill-product.dto.js +1 -1
  61. package/dist/waybill/dto/create-waybill.dto.d.ts +5 -5
  62. package/dist/waybill/schemas/waybill.schema.d.ts +6 -0
  63. package/dist/waybill/schemas/waybill.schema.js +3 -1
  64. package/package.json +1 -1
  65. package/dist/issue/dto/up-create-issue.dto.d.ts +0 -49
  66. package/dist/issue/dto/up-create-issue.dto.js +0 -21
  67. package/dist/issue/index.d.ts +0 -5
  68. package/dist/issue/index.js +0 -21
  69. package/dist/issue/interfaces/interface.d.ts +0 -4
  70. package/dist/issue/schemas/issue-user-controller.schema.d.ts +0 -15
  71. package/dist/issue/schemas/issue-user-controller.schema.js +0 -9
  72. package/dist/issue/schemas/issue-user.schema.d.ts +0 -15
  73. package/dist/issue/schemas/issue-user.schema.js +0 -9
  74. package/dist/issue/schemas/issue.schema.d.ts +0 -51
  75. package/dist/issue/schemas/issue.schema.js +0 -21
  76. package/dist/library/dto/create-chapter.dto.d.ts +0 -12
  77. package/dist/library/dto/create-chapter.dto.js +0 -8
  78. package/dist/library/dto/create-link.dto.d.ts +0 -30
  79. package/dist/library/dto/create-link.dto.js +0 -14
  80. package/dist/library/index.d.ts +0 -5
  81. package/dist/library/index.js +0 -21
  82. package/dist/library/interfaces/interface.d.ts +0 -3
  83. package/dist/library/interfaces/interface.js +0 -2
  84. package/dist/library/schemas/links-user.schema.d.ts +0 -15
  85. package/dist/library/schemas/links-user.schema.js +0 -9
  86. package/dist/library/schemas/links.schema.d.ts +0 -30
  87. package/dist/library/schemas/links.schema.js +0 -14
  88. package/dist/production-tasks/dto/update-marks.dto.d.ts +0 -13
  89. package/dist/production-tasks/dto/update-marks.dto.js +0 -8
  90. package/dist/production-tasks/dto/update-responsible.dto.d.ts +0 -12
  91. package/dist/production-tasks/dto/update-responsible.dto.js +0 -8
  92. package/dist/production-tasks/dto/update-status.dto.d.ts +0 -13
  93. package/dist/production-tasks/dto/update-status.dto.js +0 -9
  94. package/dist/tech-process/schemas/tech-process-with-options.schema.d.ts +0 -306
  95. package/dist/tech-process/schemas/tech-process-with-options.schema.js +0 -8
  96. package/dist/utils/interface/mat.interface.d.ts +0 -10
  97. package/dist/utils/interface/mat.interface.js +0 -2
  98. /package/dist/{issue/interfaces/interface.js → utils/interface/status-flags.interface.js} +0 -0
@@ -0,0 +1,56 @@
1
+ import { WorkpieceMassFormulaKey } from '../enum/enum';
2
+ import type { ModelMaterial } from '../schemas/material.schema';
3
+ import type { ModelTypeMaterial } from '../schemas/type-material.schema';
4
+ export type TWorkpieceMassVariableKey = 'density' | 'length' | 'width' | 'height' | 'thickness' | 'wallThickness' | 'outsideDiameter' | 'areaCrossSectional' | 'acrossFlats' | 'massPerMeter';
5
+ export interface IWorkpieceMassFormulaVariable {
6
+ key: TWorkpieceMassVariableKey;
7
+ name: string;
8
+ }
9
+ export interface IWorkpieceMassFormula {
10
+ key: WorkpieceMassFormulaKey;
11
+ name: string;
12
+ description: string;
13
+ variables: IWorkpieceMassFormulaVariable[];
14
+ }
15
+ export type TResolvedWorkpieceMassVariables = Partial<Record<TWorkpieceMassVariableKey, number>>;
16
+ export interface ICalculateWorkpieceMassContext {
17
+ typeMaterial: ModelTypeMaterial;
18
+ material: ModelMaterial;
19
+ workpieceCharacterization?: Record<string, number | null | undefined>;
20
+ workpieceMassFormulaKey?: WorkpieceMassFormulaKey;
21
+ }
22
+ export interface ICalculateWorkpieceMassResult {
23
+ formulaKey: WorkpieceMassFormulaKey;
24
+ mass: number;
25
+ variables: TResolvedWorkpieceMassVariables;
26
+ }
27
+ export interface IDefaultTypeMaterialCharacteristic {
28
+ id: number;
29
+ name: string;
30
+ measure: string;
31
+ }
32
+ export type TDefaultTypeMaterialCharacteristicKey = Exclude<TWorkpieceMassVariableKey, 'density'>;
33
+ export type TDefaultTypeMaterialCharacteristics = Record<TDefaultTypeMaterialCharacteristicKey, IDefaultTypeMaterialCharacteristic>;
34
+ export interface IWorkpieceMassFormulasResponse {
35
+ defaultFormulas: IWorkpieceMassFormula[];
36
+ defaultCharacteristics: TDefaultTypeMaterialCharacteristics;
37
+ }
38
+ type TPreparedWorkpieceValues = Partial<Record<TWorkpieceMassVariableKey | 'mass' | 'trash', number>>;
39
+ type TWorkpieceMassVariableResolver = (context: ICalculateWorkpieceMassContext, prepared: TPreparedWorkpieceValues) => number | null;
40
+ type TWorkpieceMassCalculator = (vars: TResolvedWorkpieceMassVariables) => number;
41
+ export declare const WORKPIECE_MASS_FORMULAS: IWorkpieceMassFormula[];
42
+ export declare const WORKPIECE_MASS_VARIABLE_CHARACTERISTIC_KEYS: Record<TWorkpieceMassVariableKey, string>;
43
+ export declare const normalizeWorkpieceMassVariables: (context: ICalculateWorkpieceMassContext, variables: TResolvedWorkpieceMassVariables, variableKeys: TWorkpieceMassVariableKey[]) => TResolvedWorkpieceMassVariables;
44
+ /**
45
+ * Реестр источников значений переменных.
46
+ * Здесь описано, откуда брать каждую переменную под расчет массы заготовки.
47
+ */
48
+ export declare const WORKPIECE_MASS_VARIABLE_RESOLVERS: Record<TWorkpieceMassVariableKey, TWorkpieceMassVariableResolver>;
49
+ /**
50
+ * Реестр математических алгоритмов расчета.
51
+ * Здесь только математика, без поиска значений по моделям.
52
+ */
53
+ export declare const WORKPIECE_MASS_CALCULATORS: Record<WorkpieceMassFormulaKey, TWorkpieceMassCalculator>;
54
+ export declare const resolveWorkpieceMassVariables: (context: ICalculateWorkpieceMassContext, variableKeys: TWorkpieceMassVariableKey[]) => TResolvedWorkpieceMassVariables;
55
+ export declare const calculateWorkpieceMassPreview: (context: ICalculateWorkpieceMassContext) => ICalculateWorkpieceMassResult | null;
56
+ export {};
@@ -0,0 +1,538 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateWorkpieceMassPreview = exports.resolveWorkpieceMassVariables = exports.WORKPIECE_MASS_CALCULATORS = exports.WORKPIECE_MASS_VARIABLE_RESOLVERS = exports.normalizeWorkpieceMassVariables = exports.WORKPIECE_MASS_VARIABLE_CHARACTERISTIC_KEYS = exports.WORKPIECE_MASS_FORMULAS = void 0;
4
+ const enum_1 = require("../enum/enum");
5
+ const utils_1 = require("../../utils");
6
+ exports.WORKPIECE_MASS_FORMULAS = [
7
+ {
8
+ key: enum_1.WorkpieceMassFormulaKey.boundingBox,
9
+ name: 'Прямоугольная заготовка',
10
+ description: 'ρ * L * B * H',
11
+ variables: [
12
+ {
13
+ key: 'density',
14
+ name: 'Плотность'
15
+ },
16
+ {
17
+ key: 'length',
18
+ name: 'Длина'
19
+ },
20
+ {
21
+ key: 'width',
22
+ name: 'Ширина'
23
+ },
24
+ {
25
+ key: 'height',
26
+ name: 'Высота'
27
+ }
28
+ ]
29
+ },
30
+ {
31
+ key: enum_1.WorkpieceMassFormulaKey.rectangularSection,
32
+ name: 'Прямоугольное сечение',
33
+ description: 'ρ * L * B * t',
34
+ variables: [
35
+ {
36
+ key: 'density',
37
+ name: 'Плотность'
38
+ },
39
+ {
40
+ key: 'length',
41
+ name: 'Длина'
42
+ },
43
+ {
44
+ key: 'width',
45
+ name: 'Ширина'
46
+ },
47
+ {
48
+ key: 'thickness',
49
+ name: 'Толщина'
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ key: enum_1.WorkpieceMassFormulaKey.solidRoundSection,
55
+ name: 'Полнотелое круглое сечение',
56
+ description: 'ρ * π * D² / 4 * L',
57
+ variables: [
58
+ {
59
+ key: 'density',
60
+ name: 'Плотность'
61
+ },
62
+ {
63
+ key: 'outsideDiameter',
64
+ name: 'Наружный диаметр'
65
+ },
66
+ {
67
+ key: 'length',
68
+ name: 'Длина'
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ key: enum_1.WorkpieceMassFormulaKey.hollowRoundSection,
74
+ name: 'Полое круглое сечение',
75
+ description: 'ρ * π * t * (D - t) * L',
76
+ variables: [
77
+ {
78
+ key: 'density',
79
+ name: 'Плотность'
80
+ },
81
+ {
82
+ key: 'outsideDiameter',
83
+ name: 'Наружный диаметр'
84
+ },
85
+ {
86
+ key: 'wallThickness',
87
+ name: 'Толщина стенки'
88
+ },
89
+ {
90
+ key: 'length',
91
+ name: 'Длина'
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ key: enum_1.WorkpieceMassFormulaKey.hollowProfileSection,
97
+ name: 'Полое профильное сечение',
98
+ description: 'ρ * (B * H - (B - 2t) * (H - 2t)) * L',
99
+ variables: [
100
+ {
101
+ key: 'density',
102
+ name: 'Плотность'
103
+ },
104
+ {
105
+ key: 'width',
106
+ name: 'Ширина профиля'
107
+ },
108
+ {
109
+ key: 'height',
110
+ name: 'Высота профиля'
111
+ },
112
+ {
113
+ key: 'wallThickness',
114
+ name: 'Толщина стенки'
115
+ },
116
+ {
117
+ key: 'length',
118
+ name: 'Длина'
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ key: enum_1.WorkpieceMassFormulaKey.hexSection,
124
+ name: 'Шестигранное сечение',
125
+ description: 'ρ * 0.866025 * S² * L',
126
+ variables: [
127
+ {
128
+ key: 'density',
129
+ name: 'Плотность'
130
+ },
131
+ {
132
+ key: 'acrossFlats',
133
+ name: 'Размер под ключ'
134
+ },
135
+ {
136
+ key: 'length',
137
+ name: 'Длина'
138
+ }
139
+ ]
140
+ },
141
+ {
142
+ key: enum_1.WorkpieceMassFormulaKey.sectionArea,
143
+ name: 'По площади сечения',
144
+ description: 'ρ * A * L',
145
+ variables: [
146
+ {
147
+ key: 'density',
148
+ name: 'Плотность'
149
+ },
150
+ {
151
+ key: 'areaCrossSectional',
152
+ name: 'Площадь поперечного сечения'
153
+ },
154
+ {
155
+ key: 'length',
156
+ name: 'Длина'
157
+ }
158
+ ]
159
+ },
160
+ {
161
+ key: enum_1.WorkpieceMassFormulaKey.linearMass,
162
+ name: 'По массе погонного метра',
163
+ description: 'q * L',
164
+ variables: [
165
+ {
166
+ key: 'massPerMeter',
167
+ name: 'Масса погонного метра'
168
+ },
169
+ {
170
+ key: 'length',
171
+ name: 'Длина'
172
+ }
173
+ ]
174
+ }
175
+ ];
176
+ const getMaterialCharacteristicValue = (context, key) => {
177
+ var _a, _b;
178
+ const item = (_b = (_a = context.material) === null || _a === void 0 ? void 0 : _a.characteristics) === null || _b === void 0 ? void 0 : _b[key];
179
+ return typeof (item === null || item === void 0 ? void 0 : item.znach) === 'number' && !Number.isNaN(item.znach)
180
+ ? item.znach
181
+ : null;
182
+ };
183
+ const getWorkpieceCharacteristicValue = (context, key) => {
184
+ var _a;
185
+ const value = (_a = context.workpieceCharacterization) === null || _a === void 0 ? void 0 : _a[key];
186
+ return typeof value === 'number' && !Number.isNaN(value) ? value : null;
187
+ };
188
+ /**
189
+ * Возвращаем первое осмысленное положительное значение.
190
+ * Это нужен совместимый fallback на переходный период,
191
+ * пока старый фронтенд еще может присылать permanent-поля в detail payload.
192
+ */
193
+ const pickPreparedCharacteristicValue = (...values) => {
194
+ for (const value of values) {
195
+ if (typeof value === 'number' && !Number.isNaN(value) && value > 0) {
196
+ return value;
197
+ }
198
+ }
199
+ for (const value of values) {
200
+ if (typeof value === 'number' && !Number.isNaN(value)) {
201
+ return value;
202
+ }
203
+ }
204
+ return undefined;
205
+ };
206
+ const getPreparedWorkpieceValues = (context) => {
207
+ var _a, _b;
208
+ const result = {};
209
+ const typeMaterialCharacteristics = ((_a = context.typeMaterial) === null || _a === void 0 ? void 0 : _a.characteristics) || {};
210
+ for (const characteristicKey of Object.keys(typeMaterialCharacteristics)) {
211
+ const characteristicMode = (_b = typeMaterialCharacteristics[characteristicKey]) === null || _b === void 0 ? void 0 : _b.znach;
212
+ if (!characteristicMode)
213
+ continue;
214
+ result[characteristicKey] =
215
+ characteristicMode === utils_1.TypeMaterialCharZnachEnum.permanent
216
+ ? pickPreparedCharacteristicValue(getMaterialCharacteristicValue(context, characteristicKey), getWorkpieceCharacteristicValue(context, characteristicKey))
217
+ : pickPreparedCharacteristicValue(getWorkpieceCharacteristicValue(context, characteristicKey), getMaterialCharacteristicValue(context, characteristicKey));
218
+ }
219
+ const density = getMaterialCharacteristicValue(context, 'density');
220
+ if (density !== null)
221
+ result.density = density;
222
+ const mass = getWorkpieceCharacteristicValue(context, 'mass');
223
+ if (mass !== null)
224
+ result.mass = mass;
225
+ const trash = getWorkpieceCharacteristicValue(context, 'trash');
226
+ if (trash !== null)
227
+ result.trash = trash;
228
+ return result;
229
+ };
230
+ const getPreparedValue = (prepared, key) => {
231
+ const value = prepared[key];
232
+ return typeof value === 'number' && !Number.isNaN(value) ? value : null;
233
+ };
234
+ exports.WORKPIECE_MASS_VARIABLE_CHARACTERISTIC_KEYS = {
235
+ density: 'density',
236
+ length: 'length',
237
+ width: 'width',
238
+ height: 'height',
239
+ thickness: 'thickness',
240
+ wallThickness: 'wallThickness',
241
+ outsideDiameter: 'outsideDiameter',
242
+ areaCrossSectional: 'areaCrossSectional',
243
+ acrossFlats: 'acrossFlats',
244
+ massPerMeter: 'massPerMeter'
245
+ };
246
+ const WORKPIECE_MASS_VARIABLE_UNIT_KINDS = {
247
+ density: 'density',
248
+ length: 'length',
249
+ width: 'length',
250
+ height: 'length',
251
+ thickness: 'length',
252
+ wallThickness: 'length',
253
+ outsideDiameter: 'length',
254
+ areaCrossSectional: 'area',
255
+ acrossFlats: 'length',
256
+ massPerMeter: 'linearMass'
257
+ };
258
+ const normalizeUnitShortName = (shortName) => {
259
+ return String(shortName || '')
260
+ .trim()
261
+ .toLowerCase()
262
+ .replace(/\s+/g, '')
263
+ .replace(/²/g, '2')
264
+ .replace(/³/g, '3')
265
+ .replace(/\^2/g, '2')
266
+ .replace(/\^3/g, '3')
267
+ .replace(/\.кв/g, '2')
268
+ .replace(/кв/g, '2')
269
+ .replace(/\.sq/g, '2')
270
+ .replace(/sq/g, '2')
271
+ .replace(/\.куб/g, '3')
272
+ .replace(/куб/g, '3')
273
+ .replace(/\.cub/g, '3')
274
+ .replace(/cub/g, '3');
275
+ };
276
+ const getMaterialCharacteristicUnitMeta = (context, key) => {
277
+ var _a, _b;
278
+ return (((_b = (_a = context.material) === null || _a === void 0 ? void 0 : _a.characteristics) === null || _b === void 0 ? void 0 : _b[key]) || null);
279
+ };
280
+ const getTypeMaterialCharacteristicUnitMeta = (context, key) => {
281
+ var _a, _b;
282
+ return (((_b = (_a = context.typeMaterial) === null || _a === void 0 ? void 0 : _a.characteristics) === null || _b === void 0 ? void 0 : _b[key]) || null);
283
+ };
284
+ const getVariableCharacteristicUnitMeta = (context, key) => {
285
+ const characteristicKey = exports.WORKPIECE_MASS_VARIABLE_CHARACTERISTIC_KEYS[key];
286
+ if (!characteristicKey)
287
+ return null;
288
+ if (key === 'density' || key === 'massPerMeter') {
289
+ return getMaterialCharacteristicUnitMeta(context, characteristicKey);
290
+ }
291
+ const typeMaterialCharacteristic = getTypeMaterialCharacteristicUnitMeta(context, characteristicKey);
292
+ const characteristicMode = typeMaterialCharacteristic === null || typeMaterialCharacteristic === void 0 ? void 0 : typeMaterialCharacteristic.znach;
293
+ if (characteristicMode === utils_1.TypeMaterialCharZnachEnum.variable) {
294
+ return (typeMaterialCharacteristic ||
295
+ getMaterialCharacteristicUnitMeta(context, characteristicKey));
296
+ }
297
+ if (characteristicMode === utils_1.TypeMaterialCharZnachEnum.permanent) {
298
+ return (getMaterialCharacteristicUnitMeta(context, characteristicKey) ||
299
+ typeMaterialCharacteristic);
300
+ }
301
+ return (getMaterialCharacteristicUnitMeta(context, characteristicKey) ||
302
+ typeMaterialCharacteristic);
303
+ };
304
+ const getUnitErrorText = (key, unit) => {
305
+ const unitName = (unit === null || unit === void 0 ? void 0 : unit.shortName) || (unit === null || unit === void 0 ? void 0 : unit.edizmId) || 'unknown';
306
+ return `Не удалось привести единицу "${unitName}" для переменной "${key}"`;
307
+ };
308
+ const normalizeLengthValue = (value, key, unit) => {
309
+ const token = normalizeUnitShortName(unit === null || unit === void 0 ? void 0 : unit.shortName);
310
+ if (token === 'мм' || token === 'mm' || (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 6) {
311
+ return value / 1000;
312
+ }
313
+ if (token === 'см' || token === 'cm') {
314
+ return value / 100;
315
+ }
316
+ if (token === 'дм' || token === 'dm') {
317
+ return value / 10;
318
+ }
319
+ if (token === 'м' || token === 'm' || (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 4) {
320
+ return value;
321
+ }
322
+ if (!token && typeof (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 'undefined') {
323
+ return value;
324
+ }
325
+ throw new Error(getUnitErrorText(key, unit));
326
+ };
327
+ const normalizeAreaValue = (value, key, unit) => {
328
+ const token = normalizeUnitShortName(unit === null || unit === void 0 ? void 0 : unit.shortName);
329
+ if (token === 'мм2' || token === 'mm2') {
330
+ return value / 1000000;
331
+ }
332
+ if (token === 'см2' || token === 'cm2') {
333
+ return value / 10000;
334
+ }
335
+ if (token === 'дм2' || token === 'dm2') {
336
+ return value / 100;
337
+ }
338
+ if (token === 'м2' || token === 'm2' || (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 8) {
339
+ return value;
340
+ }
341
+ if (!token && typeof (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 'undefined') {
342
+ return value;
343
+ }
344
+ throw new Error(getUnitErrorText(key, unit));
345
+ };
346
+ const normalizeDensityValue = (value, key, unit) => {
347
+ const token = normalizeUnitShortName(unit === null || unit === void 0 ? void 0 : unit.shortName);
348
+ if (token === 'кг/м3' || token === 'kg/m3') {
349
+ return value;
350
+ }
351
+ if (token === 'г/см3' || token === 'g/cm3') {
352
+ return value * 1000;
353
+ }
354
+ if (token === 'т/м3' || token === 't/m3') {
355
+ return value * 1000;
356
+ }
357
+ if (!token && typeof (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 'undefined') {
358
+ return value;
359
+ }
360
+ throw new Error(getUnitErrorText(key, unit));
361
+ };
362
+ const normalizeLinearMassValue = (value, key, unit) => {
363
+ const token = normalizeUnitShortName(unit === null || unit === void 0 ? void 0 : unit.shortName);
364
+ if (token === 'кг/м' || token === 'kg/m') {
365
+ return value;
366
+ }
367
+ if (token === 'г/м' || token === 'g/m') {
368
+ return value / 1000;
369
+ }
370
+ if (token === 'г/мм' || token === 'g/mm') {
371
+ return value;
372
+ }
373
+ if (token === 'кг/мм' || token === 'kg/mm') {
374
+ return value * 1000;
375
+ }
376
+ if (!token && typeof (unit === null || unit === void 0 ? void 0 : unit.edizmId) === 'undefined') {
377
+ return value;
378
+ }
379
+ throw new Error(getUnitErrorText(key, unit));
380
+ };
381
+ const normalizeWorkpieceMassVariableValue = (context, key, value) => {
382
+ const unitKind = WORKPIECE_MASS_VARIABLE_UNIT_KINDS[key];
383
+ if (!unitKind)
384
+ return value;
385
+ const unitMeta = getVariableCharacteristicUnitMeta(context, key);
386
+ switch (unitKind) {
387
+ case 'length':
388
+ return normalizeLengthValue(value, key, unitMeta);
389
+ case 'area':
390
+ return normalizeAreaValue(value, key, unitMeta);
391
+ case 'density':
392
+ return normalizeDensityValue(value, key, unitMeta);
393
+ case 'linearMass':
394
+ return normalizeLinearMassValue(value, key, unitMeta);
395
+ default:
396
+ return value;
397
+ }
398
+ };
399
+ const normalizeWorkpieceMassVariables = (context, variables, variableKeys) => {
400
+ const result = Object.assign({}, variables);
401
+ for (const key of variableKeys) {
402
+ const value = result[key];
403
+ if (typeof value !== 'number' || Number.isNaN(value))
404
+ continue;
405
+ result[key] = normalizeWorkpieceMassVariableValue(context, key, value);
406
+ }
407
+ return result;
408
+ };
409
+ exports.normalizeWorkpieceMassVariables = normalizeWorkpieceMassVariables;
410
+ /**
411
+ * Реестр источников значений переменных.
412
+ * Здесь описано, откуда брать каждую переменную под расчет массы заготовки.
413
+ */
414
+ exports.WORKPIECE_MASS_VARIABLE_RESOLVERS = {
415
+ density: (context, prepared) => {
416
+ var _a;
417
+ return (_a = getPreparedValue(prepared, 'density')) !== null && _a !== void 0 ? _a : getMaterialCharacteristicValue(context, 'density');
418
+ },
419
+ length: (_context, prepared) => getPreparedValue(prepared, 'length'),
420
+ width: (_context, prepared) => getPreparedValue(prepared, 'width'),
421
+ height: (_context, prepared) => getPreparedValue(prepared, 'height'),
422
+ thickness: (_context, prepared) => getPreparedValue(prepared, 'thickness'),
423
+ wallThickness: (_context, prepared) => getPreparedValue(prepared, 'wallThickness'),
424
+ outsideDiameter: (_context, prepared) => getPreparedValue(prepared, 'outsideDiameter'),
425
+ areaCrossSectional: (_context, prepared) => getPreparedValue(prepared, 'areaCrossSectional'),
426
+ // TODO: добавить поле в model/type_material/material/workpiece_characterization
427
+ acrossFlats: (context, prepared) => {
428
+ var _a;
429
+ return (_a = getPreparedValue(prepared, 'acrossFlats')) !== null && _a !== void 0 ? _a : getMaterialCharacteristicValue(context, 'acrossFlats');
430
+ },
431
+ // TODO: добавить поле в material.characteristics или отдельную модель
432
+ massPerMeter: (context, prepared) => {
433
+ var _a;
434
+ return (_a = getPreparedValue(prepared, 'massPerMeter')) !== null && _a !== void 0 ? _a : getMaterialCharacteristicValue(context, 'massPerMeter');
435
+ }
436
+ };
437
+ const getRequiredVar = (vars, key) => {
438
+ const value = vars[key];
439
+ if (typeof value !== 'number' || Number.isNaN(value)) {
440
+ throw new Error(`Не заполнена переменная "${key}" для расчета массы заготовки`);
441
+ }
442
+ return value;
443
+ };
444
+ /**
445
+ * Реестр математических алгоритмов расчета.
446
+ * Здесь только математика, без поиска значений по моделям.
447
+ */
448
+ exports.WORKPIECE_MASS_CALCULATORS = {
449
+ [enum_1.WorkpieceMassFormulaKey.boundingBox]: vars => {
450
+ const density = getRequiredVar(vars, 'density');
451
+ const length = getRequiredVar(vars, 'length');
452
+ const width = getRequiredVar(vars, 'width');
453
+ const height = getRequiredVar(vars, 'height');
454
+ return density * length * width * height;
455
+ },
456
+ [enum_1.WorkpieceMassFormulaKey.rectangularSection]: vars => {
457
+ const density = getRequiredVar(vars, 'density');
458
+ const length = getRequiredVar(vars, 'length');
459
+ const width = getRequiredVar(vars, 'width');
460
+ const thickness = getRequiredVar(vars, 'thickness');
461
+ return density * length * width * thickness;
462
+ },
463
+ [enum_1.WorkpieceMassFormulaKey.solidRoundSection]: vars => {
464
+ const density = getRequiredVar(vars, 'density');
465
+ const outsideDiameter = getRequiredVar(vars, 'outsideDiameter');
466
+ const length = getRequiredVar(vars, 'length');
467
+ return (density * Math.PI * Math.pow(outsideDiameter, 2) * length) / 4;
468
+ },
469
+ [enum_1.WorkpieceMassFormulaKey.hollowRoundSection]: vars => {
470
+ const density = getRequiredVar(vars, 'density');
471
+ const outsideDiameter = getRequiredVar(vars, 'outsideDiameter');
472
+ const wallThickness = getRequiredVar(vars, 'wallThickness');
473
+ const length = getRequiredVar(vars, 'length');
474
+ return (density *
475
+ Math.PI *
476
+ wallThickness *
477
+ (outsideDiameter - wallThickness) *
478
+ length);
479
+ },
480
+ [enum_1.WorkpieceMassFormulaKey.hollowProfileSection]: vars => {
481
+ const density = getRequiredVar(vars, 'density');
482
+ const width = getRequiredVar(vars, 'width');
483
+ const height = getRequiredVar(vars, 'height');
484
+ const wallThickness = getRequiredVar(vars, 'wallThickness');
485
+ const length = getRequiredVar(vars, 'length');
486
+ return (density *
487
+ (width * height -
488
+ (width - 2 * wallThickness) * (height - 2 * wallThickness)) *
489
+ length);
490
+ },
491
+ [enum_1.WorkpieceMassFormulaKey.hexSection]: vars => {
492
+ const density = getRequiredVar(vars, 'density');
493
+ const acrossFlats = getRequiredVar(vars, 'acrossFlats');
494
+ const length = getRequiredVar(vars, 'length');
495
+ return density * 0.866025 * Math.pow(acrossFlats, 2) * length;
496
+ },
497
+ [enum_1.WorkpieceMassFormulaKey.sectionArea]: vars => {
498
+ const density = getRequiredVar(vars, 'density');
499
+ const areaCrossSectional = getRequiredVar(vars, 'areaCrossSectional');
500
+ const length = getRequiredVar(vars, 'length');
501
+ return density * areaCrossSectional * length;
502
+ },
503
+ [enum_1.WorkpieceMassFormulaKey.linearMass]: vars => {
504
+ const massPerMeter = getRequiredVar(vars, 'massPerMeter');
505
+ const length = getRequiredVar(vars, 'length');
506
+ return massPerMeter * length;
507
+ }
508
+ };
509
+ const resolveWorkpieceMassVariables = (context, variableKeys) => {
510
+ var _a;
511
+ const prepared = getPreparedWorkpieceValues(context);
512
+ const result = {};
513
+ for (const key of variableKeys) {
514
+ result[key] =
515
+ (_a = exports.WORKPIECE_MASS_VARIABLE_RESOLVERS[key](context, prepared)) !== null && _a !== void 0 ? _a : undefined;
516
+ }
517
+ return (0, exports.normalizeWorkpieceMassVariables)(context, result, variableKeys);
518
+ };
519
+ exports.resolveWorkpieceMassVariables = resolveWorkpieceMassVariables;
520
+ const calculateWorkpieceMassPreview = (context) => {
521
+ var _a;
522
+ const formulaKey = context.workpieceMassFormulaKey ||
523
+ ((_a = context.typeMaterial) === null || _a === void 0 ? void 0 : _a.workpieceMassFormulaKey) ||
524
+ null;
525
+ if (!formulaKey)
526
+ return null;
527
+ const formula = exports.WORKPIECE_MASS_FORMULAS.find(currentFormula => currentFormula.key === formulaKey);
528
+ if (!formula) {
529
+ throw new Error(`Формула расчета массы заготовки "${formulaKey}" не найдена`);
530
+ }
531
+ const variables = (0, exports.resolveWorkpieceMassVariables)(context, formula.variables.map(variable => variable.key));
532
+ return {
533
+ formulaKey,
534
+ mass: exports.WORKPIECE_MASS_CALCULATORS[formulaKey](variables),
535
+ variables
536
+ };
537
+ };
538
+ exports.calculateWorkpieceMassPreview = calculateWorkpieceMassPreview;
@@ -0,0 +1,45 @@
1
+ import { WorkpieceMassFormulaKey } from './enum/enum';
2
+ import type { ModelMaterial } from './schemas/material.schema';
3
+ import type { ModelTypeMaterial } from './schemas/type-material.schema';
4
+ export type TWorkpieceMassVariableKey = 'density' | 'length' | 'width' | 'height' | 'thickness' | 'wallThickness' | 'outsideDiameter' | 'areaCrossSectional' | 'acrossFlats' | 'massPerMeter';
5
+ export interface IWorkpieceMassFormulaVariable {
6
+ key: TWorkpieceMassVariableKey;
7
+ name: string;
8
+ source: 'material' | 'workpiece';
9
+ required: boolean;
10
+ }
11
+ export interface IWorkpieceMassFormula {
12
+ key: WorkpieceMassFormulaKey;
13
+ name: string;
14
+ description: string;
15
+ variables: IWorkpieceMassFormulaVariable[];
16
+ }
17
+ export type TResolvedWorkpieceMassVariables = Partial<Record<TWorkpieceMassVariableKey, number>>;
18
+ export interface ICalculateWorkpieceMassContext {
19
+ typeMaterial: ModelTypeMaterial;
20
+ material: ModelMaterial;
21
+ workpieceCharacterization?: Record<string, number | null | undefined>;
22
+ workpieceMassFormulaKey?: WorkpieceMassFormulaKey;
23
+ }
24
+ export interface ICalculateWorkpieceMassResult {
25
+ formulaKey: WorkpieceMassFormulaKey;
26
+ mass: number;
27
+ variables: TResolvedWorkpieceMassVariables;
28
+ }
29
+ type TPreparedWorkpieceValues = Partial<Record<TWorkpieceMassVariableKey | 'mass' | 'trash', number>>;
30
+ type TWorkpieceMassVariableResolver = (context: ICalculateWorkpieceMassContext, prepared: TPreparedWorkpieceValues) => number | null;
31
+ type TWorkpieceMassCalculator = (vars: TResolvedWorkpieceMassVariables) => number;
32
+ export declare const WORKPIECE_MASS_FORMULAS: IWorkpieceMassFormula[];
33
+ /**
34
+ * Реестр источников значений переменных.
35
+ * Здесь описано, откуда брать каждую переменную под расчет массы заготовки.
36
+ */
37
+ export declare const WORKPIECE_MASS_VARIABLE_RESOLVERS: Record<TWorkpieceMassVariableKey, TWorkpieceMassVariableResolver>;
38
+ /**
39
+ * Реестр математических алгоритмов расчета.
40
+ * Здесь только математика, без поиска значений по моделям.
41
+ */
42
+ export declare const WORKPIECE_MASS_CALCULATORS: Record<WorkpieceMassFormulaKey, TWorkpieceMassCalculator>;
43
+ export declare const resolveWorkpieceMassVariables: (context: ICalculateWorkpieceMassContext, variableKeys: TWorkpieceMassVariableKey[]) => TResolvedWorkpieceMassVariables;
44
+ export declare const calculateWorkpieceMassPreview: (context: ICalculateWorkpieceMassContext) => ICalculateWorkpieceMassResult | null;
45
+ export {};