Fosi Fossil Service
Small teams. Open source. Built on Fossil.

IaC / SwiftFlow

High-performance WMS with wave picking, smart routing, and real-time inventory visibility.

Public | Owner: IaC | Default branch: trunk | Last update: 2026-10-23 14:37

Artifact 47a942198cb4ca9bd0a219a31b667ecc598d3446860fd5744f54ebc0d75df381:


import gleam/string

pub type LocationCode {
  LocationCode(
    area: String,
    aisle: String,
    level: String,
    bin: String,
    code: String,
    compact: String,
  )
}

pub type Location {
  Location(
    warehouse_id: Int,
    area: String,
    aisle: String,
    level: String,
    bin: String,
    code: String,
    barcode: String,
    enabled: Bool,
    created_at: String,
    updated_at: String,
  )
}

pub fn build(
  area: String,
  aisle: String,
  level: String,
  bin: String,
) -> Result(LocationCode, String) {
  use area <- result_try(segment("库区", area))
  use aisle <- result_try(segment("货架", aisle))
  use level <- result_try(segment("层", level))
  use bin <- result_try(segment("位", bin))
  let compact = area <> aisle <> level <> bin
  Ok(LocationCode(
    area: area,
    aisle: aisle,
    level: level,
    bin: bin,
    code: area <> "-" <> aisle <> "-" <> level <> "-" <> bin,
    compact: compact,
  ))
}

pub fn barcode(warehouse_code: String, compact: String) -> String {
  "LOC-" <> warehouse_code <> "-" <> compact
}

fn segment(label: String, raw: String) -> Result(String, String) {
  let value = string.uppercase(string.trim(raw))
  case value == "" {
    True -> Error(label <> "不能为空")
    False ->
      case string.length(value) > 8 || !alphanumeric(value) {
        True -> Error(label <> "只能使用 1 到 8 位字母或数字")
        False -> Ok(value)
      }
  }
}

fn alphanumeric(value: String) -> Bool {
  case string.pop_grapheme(value) {
    Error(_) -> True
    Ok(#(char, rest)) -> {
      let ok =
        string.contains("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", char)
      case ok {
        True -> alphanumeric(rest)
        False -> False
      }
    }
  }
}

fn result_try(result: Result(a, b), next: fn(a) -> Result(c, b)) -> Result(c, b) {
  case result {
    Ok(value) -> next(value)
    Error(err) -> Error(err)
  }
}

Clone

You can clone this repository with the following command:

fossil clone https://fosi.dev/IaC/SwiftFlow

Contribute

The best way to contribute is through e-mail. See the project documentation for more details.