techtools

topology.ts

TypeScript · 51 рядків

1// TOPOLOGY — СПРАВЖНІЙ домен products/wts (shared/domain) на шаблоні «Дослідний склад приймання» (R-26 T6).
2// У житті WMS питає Topology по HTTP: POST /plans/:id/sorting/directions, /route/options, /placement/candidates.
3// Тут — ті самі функції напряму, без сервера: результат той самий, а прогону не треба піднімати сервер і план у базі.
4// Topology нічого не запускає й стану товару не знає: стан адрес (вага, об'єм, той самий товар) їй передає WMS (R-17).
5import { receivingWarehouse } from '../../../products/wts/shared/domain/demo-receiving.ts'
6import { sortingDirections, type SortingDirections } from '../../../products/wts/shared/domain/sorting.ts'
7import { addresses, placementCandidates, type AddressState, type Candidate } from '../../../products/wts/shared/domain/placement.ts'
8import { itemCode } from '../../../products/wts/shared/domain/model.ts'
9import type { Card } from './erp.ts'
10
11const w = receivingWarehouse()
12const addrIndex = new Map(addresses(w).map((a) => [a.code, a]))
13
14export const warehouse = w
15
16/** POST /plans/:id/sorting/directions — станція, ліміт коробів, напрямки «поверх × зона», крос-док. */
17export function directions(): SortingDirections {
18  const d = sortingDirections(w)
19  if (!d) throw new Error('no sorting station in the plan')
20  return d
21}
22
23/** Зона очікування розвантажень (R-26 T2): код, місця й лінії. Запиту «куди поставити місце» в Topology немає. */
24export function waitingZone() {
25  const z: any = w.items.find((i: any) => i.kind === 'zone' && i.zoneType === 'waiting')
26  return { id: z.id, code: itemCode(w, z), slots: Number(z.slots || 0), lines: Number(z.lines || 1) }
27}
28
29/** Код елемента плану за id (місце прийому, пакування, кінець конвеєра). */
30export const codeOf = (id: string) => {
31  const item: any = w.items.find((i: any) => i.id === id)
32  return item ? itemCode(w, item) : id
33}
34
35/** Адреса → поверх і зона стелажів: так WMS знає, до якого напрямку розкладки належить полиця. */
36export function addressInfo(address: string) {
37  const a: any = addrIndex.get(address)
38  if (!a) return null
39  const floorId = a.item.floorId
40  const zoneId = a.item.rackZoneId ?? null
41  return { floorId, zoneId, zone: zoneId ? (w.rackZones || []).find((z: any) => z.id === zoneId)?.name ?? zoneId : null }
42}
43
44/** POST /plans/:id/placement/candidates — допустимі адреси з маршрутом від точки `from`, ранжовані Topology. */
45export function candidates(card: Card, qty: number, from: string, state: AddressState[]): Candidate[] {
46  return placementCandidates(w, {
47    item: { sku: String(card.itemId), length: card.lengthM, width: card.widthM, height: card.heightM, weight: card.weightKg, groups: [] },
48    qty, from, state,
49  }).candidates
50}
51