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 54875c6238dfc4f2c0b946917f722df05498f8333a3c4cb2a898054089a5619b:


import gleam/dynamic/decode
import gleam/json
import gleam/list
import gleam/result
import ql361api/client.{type Client}
import ql361api/json_codec
import ql361api/models.{type ApiError, type QlWarehouse, JsonError, QlWarehouse}

pub const list_store_method = "cc.erp.bll.bas.store.getlist"

pub fn fetch_warehouses(client: Client) -> Result(List(QlWarehouse), ApiError) {
  let payload =
    json.object([
      #(
        "reportparam",
        json.object([
          #("pagerow", json.int(200)),
          #("pagenumber", json.int(0)),
          #("parid", json.int(0)),
          #("displaytype", json.string("list")),
          #("orders", json.string("")),
        ]),
      ),
      #(
        "conditionparam",
        json.object([
          #("showstop", json.bool(True)),
          #("keywords", json.string("")),
        ]),
      ),
    ])
    |> json.to_string

  use raw_json <- result.try(
    client.post_rpc(client, list_store_method, "erp", payload),
  )
  parse_warehouses(raw_json)
}

pub fn parse_warehouses(body: String) -> Result(List(QlWarehouse), ApiError) {
  let item_decoder = {
    use id <- decode.field("sid", json_codec.int())
    use code <- decode.optional_field("code", "", decode.string)
    use fullname <- decode.optional_field("fullname", "", decode.string)
    use easycode <- decode.optional_field("easycode", "", decode.string)
    use is_parent <- decode.optional_field("isparent", 0, json_codec.int())
    decode.success(#(
      QlWarehouse(id: id, code: code, fullname: fullname, easycode: easycode),
      is_parent != 0,
    ))
  }

  let data_decoder = {
    use rows <- decode.field("datasource", decode.list(of: item_decoder))
    decode.success(rows)
  }

  let wrapper_decoder = {
    use data <- decode.field("data", data_decoder)
    decode.success(data)
  }

  case json.parse(body, wrapper_decoder) {
    Ok(rows) ->
      Ok(
        list.filter_map(rows, fn(row) {
          let #(warehouse, is_category) = row
          case is_category {
            True -> Error(Nil)
            False -> Ok(warehouse)
          }
        }),
      )
    Error(_) -> Error(JsonError("仓库列表响应无法解析"))
  }
}

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.