银行示例库 使用说明

1 银行业务系统设计

系统包含以下实体,以模拟真实的银行业务系统:


2 ER 图描述

ER 图包括以下实体及其关系:

关系

3 数据导入

3.1 数据库创建

dropdb -U system banking;
createdb -U system banking;

3.2 二进制格式导入

sys_restore -U system -d banking -c -Fc /install/banking_data.dmp

3.3 文本格式导入

#kingbase>
ksql banking system
#test>
\i /install/banking_data.sql

4 应用程序

4.1 上传后端应用程序与前端页面

#kingbase>
ls -ltra /install/main.py
ls -ltra /install/index.html

4.2 运行后端

4.3 运行前端

4.4 使用管理界面

以下展示如何使用 curl 工具调用之前提供的 FastAPI 后端接口(main.py)来执行银行业务系统的增删改查操作。接口运行在 http://localhost:8000,以下示例涵盖客户(Customers)、账户(Accounts)和交易(Transactions)的常见操作,包括分页查询、搜索等功能。每个示例都包括请求和可能的响应。


5 API 接口说明

5.1 客户(Customers)接口示例

5.1.1 创建客户(POST /customers/)

请求

#kingbase>
curl -X POST "http://localhost:8000/customers/" \
-H "Content-Type: application/json" \
-d '{
    "first_name": "张",
    "last_name": "伟",
    "email": "zhang.wei@example.com",
    "phone": "13812345678",
    "address": "北京市朝阳区幸福路1号",
    "date_of_birth": "1985-05-20"
}'

响应(成功):

{
    "customer_id": 1,
    "first_name": "张",
    "last_name": "伟",
    "email": "zhang.wei@example.com",
    "phone": "13812345678",
    "address": "北京市朝阳区幸福路1号",
    "date_of_birth": "1985-05-20",
    "created_at": "2025-07-15T12:30:00.123456"
}

5.1.2 查询客户列表(GET /customers/,支持分页和搜索)

请求(分页:第1页,每页10条,搜索“张”):

#kingbase>
curl -X GET "http://localhost:8000/customers/?page=1&per_page=10&search=张"

响应(成功,返回匹配的客户列表):

[
    {
        "customer_id": 1,
        "first_name": "张",
        "last_name": "伟",
        "email": "zhang.wei@example.com",
        "phone": "13812345678",
        "address": "北京市朝阳区幸福路1号",
        "date_of_birth": "1985-05-20",
        "created_at": "2025-07-15T12:30:00.123456"
    }
]

5.1.3 获取单个客户(GET /customers/{id})

请求

#kingbase>
curl -X GET "http://localhost:8000/customers/1"

响应(成功):

{
    "customer_id": 1,
    "first_name": "张",
    "last_name": "伟",
    "email": "zhang.wei@example.com",
    "phone": "13812345678",
    "address": "北京市朝阳区幸福路1号",
    "date_of_birth": "1985-05-20",
    "created_at": "2025-07-15T12:30:00.123456"
}

响应(失败,客户不存在):

{
    "detail": "客户未找到"
}

5.1.4 更新客户(PUT /customers/{id})

请求

#kingbase>
curl -X PUT "http://localhost:8000/customers/1" \
-H "Content-Type: application/json" \
-d '{
    "first_name": "张",
    "last_name": "伟",
    "email": "zhang.wei2@example.com",
    "phone": "13987654321",
    "address": "北京市海淀区幸福路2号",
    "date_of_birth": "1985-05-20"
}'

响应(成功):

{
    "customer_id": 1,
    "first_name": "张",
    "last_name": "伟",
    "email": "zhang.wei2@example.com",
    "phone": "13987654321",
    "address": "北京市海淀区幸福路2号",
    "date_of_birth": "1985-05-20",
    "created_at": "2025-07-15T12:30:00.123456"
}

5.1.5 删除客户(DELETE /customers/{id})

请求

#kingbase>
curl -X DELETE "http://localhost:8000/customers/1"

响应(成功):

{
    "message": "客户已删除"
}

5.2 账户(Accounts)接口示例

5.2.1 创建账户(POST /accounts/)

请求

#kingbase>
curl -X POST "http://localhost:8000/accounts/" \
-H "Content-Type: application/json" \
-d '{
    "customer_id": 1,
    "branch_id": 1,
    "account_type": "savings",
    "balance": 1000.00
}'

响应(成功):

{
    "account_id": 1,
    "customer_id": 1,
    "branch_id": 1,
    "account_type": "savings",
    "balance": 1000.00,
    "created_at": "2025-07-15T12:30:00.123456"
}

5.2.2 查询账户列表(GET /accounts/,支持分页和搜索)

请求(分页:第1页,每页10条,搜索“savings”):

#kingbase>
curl -X GET "http://localhost:8000/accounts/?page=1&per_page=10&search=savings"

响应(成功):

[
    {
        "account_id": 1,
        "customer_id": 1,
        "branch_id": 1,
        "account_type": "savings",
        "balance": 1000.00,
        "created_at": "2025-07-15T12:30:00.123456"
    }
]

5.3 交易(Transactions)接口示例

5.3.1 创建交易(POST /transactions/)

请求

#kingbase>
curl -X POST "http://localhost:8000/transactions/" \
-H "Content-Type: application/json" \
-d '{
    "account_id": 1,
    "transaction_type": "deposit",
    "amount": 500.00,
    "description": "存款"
}'

响应(成功):

{
    "transaction_id": 1,
    "account_id": 1,
    "transaction_type": "deposit",
    "amount": 500.00,
    "description": "存款",
    "transaction_date": "2025-07-15T12:30:00.123456"
}

5.3.2 查询交易列表(GET /transactions/,支持分页和搜索)

请求(分页:第1页,每页10条,搜索“deposit”):

curl -X GET "http://localhost:8000/transactions/?page=1&per_page=10&search=deposit"

响应(成功):

[
    {
        "transaction_id": 1,
        "account_id": 1,
        "transaction_type": "deposit",
        "amount": 500.00,
        "description": "存款",
        "transaction_date": "2025-07-15T12:30:00.123456"
    }
]