This commit is contained in:
admin
2025-12-22 17:30:32 +09:00
parent 87fa1aaa1f
commit 001b7bf08f
12 changed files with 1380 additions and 506 deletions

View File

@@ -0,0 +1,49 @@
from fastapi import APIRouter, HTTPException
from app.core.database import get_connection
router = APIRouter(prefix="/year-locks", tags=["年度锁定"])
@router.get("", summary="年度锁定一覧")
def get_year_locks():
with get_connection() as conn, conn.cursor() as cur:
cur.execute("""
SELECT fiscal_year, is_locked, locked_at, locked_by
FROM year_locks
ORDER BY fiscal_year
""")
return cur.fetchall()
@router.post("/lock", summary="年度锁定")
def lock_year(fiscal_year: int):
with get_connection() as conn, conn.cursor() as cur:
cur.execute("""
INSERT INTO year_locks (fiscal_year, is_locked, locked_at, locked_by)
VALUES (%s, true, NOW(), %s)
ON CONFLICT (fiscal_year)
DO UPDATE
SET is_locked = true,
locked_at = NOW(),
locked_by = EXCLUDED.locked_by
""", (fiscal_year, "system"))
conn.commit()
return {"status": "locked", "fiscal_year": fiscal_year}
@router.post("/unlock", summary="年度解锁")
def unlock_year(fiscal_year: int):
with get_connection() as conn, conn.cursor() as cur:
cur.execute("""
UPDATE year_locks
SET is_locked = false
WHERE fiscal_year = %s
""", (fiscal_year,))
if cur.rowcount == 0:
raise HTTPException(status_code=404, detail="指定年度不存在")
conn.commit()
return {"status": "unlocked", "fiscal_year": fiscal_year}