arm-web/scripts/demo-prepare.sh

51 lines
2.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Подготовка демо: загрузить квартальные ОСВ РБ и Счастливочной за 2024 Q1–Q3 в версию и подтвердить ОСВ-документы.
# Использование: scripts/demo-prepare.sh <version_id> [email] (стенд arm-core на localhost:8000, DEBUG=true)
# Каталог фикстур: FIXTURES_DIR (по умолчанию ../../fixtures относительно репозитория arm-web, т.е. workspace/fixtures).
set -euo pipefail
V="${1:?version_id}"
EMAIL="${2:-ka_go@armka.local}"
API="${API:-localhost:8000/api/v1}"
F="${FIXTURES_DIR:-$(cd "$(dirname "$0")/../.." && pwd)/fixtures}/osv"
H="Authorization: Bearer $(curl -sf -X POST "$API/dev/token" -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\"}" | python3 -c 'import sys,json;print(json.load(sys.stdin)["access_token"])')"
members=$(curl -sf "$API/consolidations/versions/$V" -H "$H" | python3 -c '
import sys,json
for m in json.load(sys.stdin)["members"]: print(m["id"], m["inn"], m["name"])')
# ЮЛ ищем по ИНН (в справочнике имена могут быть в верхнем регистре)
le_by_inn() { echo "$members" | awk -v inn="$1" '$2 == inn { print $1; exit }'; }
LE_RB=$(le_by_inn 3528052718)
LE_SCH=$(le_by_inn 3528104476)
[ -n "$LE_RB" ] && [ -n "$LE_SCH" ] || { echo "В периметре версии нет РБ или Счастливочной:"; echo "$members"; exit 1; }
upload() { for f in "$F/$2"/2024-Q{1,2,3}/*; do
curl -s -X POST "$API/legal-entities/$1/files?consolidation_version_id=$V" -H "$H" -F "files=@$f" \
| python3 -c 'import sys,json;d=json.load(sys.stdin);print("принят" if d.get("accepted") else d.get("rejected") or d)'
done; }
upload "$LE_RB" rb
upload "$LE_SCH" schastl
echo "Жду распознавания…"
for _ in $(seq 1 60); do
pending=0
for LE in $LE_RB $LE_SCH; do
n=$(curl -sf "$API/legal-entities/$LE/files?limit=100" -H "$H" | python3 -c 'import sys,json;print(sum(f["status"] in ("UPLOADED","PROCESSING") for f in json.load(sys.stdin)["items"]))')
pending=$((pending + n))
done
[ "$pending" -eq 0 ] && break
sleep 5
done
for LE in $LE_RB $LE_SCH; do
curl -sf "$API/legal-entities/$LE/files?limit=100" -H "$H" | python3 -c '
import sys,json
for f in json.load(sys.stdin)["items"]:
for d in f["documents"]:
if d["document_type"] == "OSV" and d["status"] in ("RECOGNIZED","NEEDS_CHECK"): print(d["id"])' \
| while read -r DOC; do curl -s -o /dev/null -w "%{http_code} $DOC\n" -X POST "$API/documents/$DOC/confirm" -H "$H"; done
done
curl -sf "$API/consolidations/versions/$V/osv/summary" -H "$H" | python3 -c '
import sys,json
s=json.load(sys.stdin); print("строк:", s["rows_total"], "документов:", s["documents_total"], "несопоставленных:", s["unmapped_total"], "пробелов:", len(s["gaps"]))'