diff --git a/DIAGNOSIS.md b/DIAGNOSIS.md new file mode 100644 index 0000000..2cfe990 --- /dev/null +++ b/DIAGNOSIS.md @@ -0,0 +1,79 @@ +# NAS上数据库连接问题诊断 + +## 当前配置 + +- **数据库地址**: 192.168.0.61:55432 +- **数据库名**: njts_acct +- **用户**: njts_app + +## 可能的原因 + +### 1. 网络连接问题 + +- [ ] 确认NAS是否在同一网络中 +- [ ] 检查NAS是否能ping通数据库服务器 (192.168.0.61) +- [ ] 检查防火墙是否允许5432/55432端口访问 + +### 2. .env 文件缺失或配置不同 + +- [ ] 确认NAS上有 `.env` 文件 +- [ ] 检查NAS上的 `.env` 文件配置是否正确 +- [ ] 确认数据库服务器的IP地址在NAS所在网络中仍然有效 + +### 3. 容器网络问题 + +- [ ] 如果使用Docker,确保容器网络配置正确 +- [ ] 检查容器是否能解析数据库主机名/IP + +## 排查命令 + +### 在NAS上执行以下命令: + +```bash +# 1. 测试网络连接 +ping 192.168.0.61 + +# 2. 测试端口连接 (需要 psql 或 telnet) +psql -h 192.168.0.61 -p 55432 -U njts_app -d njts_acct + +# 或使用 telnet(如果可用) +telnet 192.168.0.61 55432 + +# 3. 查看应用日志 +docker logs njts_backend + +# 4. 检查容器网络 +docker network ls +docker network inspect njts_net +``` + +## 推荐解决方案 + +### 选项A: 使用主机名而不是IP(推荐) + +编辑 `.env` 文件,将IP地址改为主机名: + +``` +DB_HOST=db-server # 或具体的主机名 +DB_PORT=55432 +``` + +需要确保DNS能解析该主机名。 + +### 选项B: 确认NAS网络配置 + +- 检查NAS的IP地址范围是否允许与数据库所在网络通信 +- 可能需要调整网络路由或防火墙规则 + +### 选项C: 数据库服务器地址变化 + +- 如果数据库服务器的IP地址在NAS访问时不同,需要更新 `.env` +- 例如:可能需要用内网IP或DNS名称 + +## 立即检查 + +请告诉我: + +1. NAS上是否能访问 192.168.0.61:55432? +2. 应用在NAS上产生的错误日志是什么? +3. 数据库服务器和NAS是否在同一网络中? diff --git a/backend/app/modules/trial_balance/router.py b/backend/app/modules/trial_balance/router.py index 9eecdb9..9f8798a 100644 --- a/backend/app/modules/trial_balance/router.py +++ b/backend/app/modules/trial_balance/router.py @@ -11,8 +11,6 @@ def get_trial_balance( date_from: Optional[str] = Query(None, description="YYYY-MM-DD"), date_to: Optional[str] = Query(None, description="YYYY-MM-DD"), ): - print("trial-balance NEW VERSION (optional params)") - # 👉 没传参数时,给默认值(开发期非常推荐) if fiscal_year is None: fiscal_year = 2025 @@ -25,5 +23,4 @@ def get_trial_balance( raise HTTPException(status_code=400, detail="期間指定が不正です。") result = fetch_trial_balance(date_from, date_to) - return result diff --git a/backend/app/modules/trial_balance/service.py b/backend/app/modules/trial_balance/service.py index 6562346..6d8bd50 100644 --- a/backend/app/modules/trial_balance/service.py +++ b/backend/app/modules/trial_balance/service.py @@ -41,6 +41,7 @@ def fetch_trial_balance(date_from: str, date_to: str): """) accounts = cur.fetchall() + # 科目データを格納 account_data: Dict[str, Dict[str, Any]] = {} @@ -99,7 +100,7 @@ def fetch_trial_balance(date_from: str, date_to: str): row = cur.fetchone() debit = D(row["debit"]) credit = D(row["credit"]) - + closing = opening + debit - credit # 負債・資本は絶対値で表示(見やすくするため) @@ -295,7 +296,7 @@ def fetch_trial_balance(date_from: str, date_to: str): total_credit = sum(data["credit"] for data in account_data.values()) total_closing = sum(data["closing_balance"] for data in account_data.values()) - return { + result = { "totals": { "opening_balance": str(total_opening), "debit": str(total_debit), @@ -306,3 +307,5 @@ def fetch_trial_balance(date_from: str, date_to: str): "accounts": result_accounts, "grand_total_closing": str(grand_total_closing) } + + return result diff --git a/backend/app/static/cash.html b/backend/app/static/cash.html index a3e055e..149b5bb 100644 --- a/backend/app/static/cash.html +++ b/backend/app/static/cash.html @@ -1,4 +1,4 @@ - +
@@ -28,7 +28,7 @@ - +