⚒️ 重大重构 LoveACE V2
引入了 mongodb 对数据库进行了一定程度的数据加密 性能改善 代码简化 统一错误模型和响应 使用 apifox 作为文档
This commit is contained in:
42
loveace/router/endpoint/isim/model/isim.py
Normal file
42
loveace/router/endpoint/isim/model/isim.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
# ==================== 电费相关模型 ====================
|
||||
|
||||
|
||||
class ElectricityBalance(BaseModel):
|
||||
"""电费余额信息"""
|
||||
|
||||
remaining_purchased: float = Field(..., description="剩余购电(度)")
|
||||
remaining_subsidy: float = Field(..., description="剩余补助(度)")
|
||||
|
||||
|
||||
class ElectricityUsageRecord(BaseModel):
|
||||
"""用电记录"""
|
||||
|
||||
record_time: str = Field(..., description="记录时间,如:2025-08-29 00:04:58")
|
||||
usage_amount: float = Field(..., description="用电量(度)")
|
||||
meter_name: str = Field(..., description="电表名称,如:1-101 或 1-101空调")
|
||||
|
||||
|
||||
# ==================== 充值相关模型 ====================
|
||||
|
||||
|
||||
class PaymentRecord(BaseModel):
|
||||
"""充值记录"""
|
||||
|
||||
payment_time: str = Field(..., description="充值时间,如:2025-02-21 11:30:08")
|
||||
amount: float = Field(..., description="充值金额(元)")
|
||||
payment_type: str = Field(..., description="充值类型,如:下发补助、一卡通充值")
|
||||
|
||||
|
||||
class UniISIMInfoResponse(BaseModel):
|
||||
"""寝室电费信息"""
|
||||
|
||||
room_code: str = Field(..., description="寝室代码")
|
||||
room_text: str = Field(..., description="寝室显示名称")
|
||||
room_display: str = Field(..., description="寝室显示名称")
|
||||
balance: ElectricityBalance = Field(..., description="电费余额")
|
||||
usage_records: List[ElectricityUsageRecord] = Field(..., description="用电记录")
|
||||
payments: List[PaymentRecord] = Field(..., description="充值记录")
|
||||
18
loveace/router/endpoint/isim/model/protect_router.py
Normal file
18
loveace/router/endpoint/isim/model/protect_router.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from fastapi import status
|
||||
|
||||
from loveace.router.schemas.error import ErrorToCodeNode, ProtectRouterErrorToCode
|
||||
|
||||
|
||||
class ISIMRouterErrorToCode(ProtectRouterErrorToCode):
|
||||
"""ISIM 统一错误码"""
|
||||
|
||||
UNBOUNDROOM: ErrorToCodeNode = ErrorToCodeNode(
|
||||
error_code=status.HTTP_400_BAD_REQUEST,
|
||||
code="UNBOUND_ROOM",
|
||||
message="房间未绑定",
|
||||
)
|
||||
CACHEDROOMSEXPIRED: ErrorToCodeNode = ErrorToCodeNode(
|
||||
error_code=status.HTTP_400_BAD_REQUEST,
|
||||
code="CACHED_ROOMS_EXPIRED",
|
||||
message="房间缓存已过期,请稍后重新获取房间列表",
|
||||
)
|
||||
172
loveace/router/endpoint/isim/model/room.py
Normal file
172
loveace/router/endpoint/isim/model/room.py
Normal file
@@ -0,0 +1,172 @@
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
##############################################################
|
||||
# * 寝室绑定请求模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class BindRoomRequest(BaseModel):
|
||||
"""绑定寝室请求模型"""
|
||||
|
||||
room_id: str = Field(..., description="寝室ID")
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 寝室绑定响应模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class BindRoomResponse(BaseModel):
|
||||
"""绑定寝室响应模型"""
|
||||
|
||||
success: bool = Field(..., description="是否绑定成功")
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 楼栋信息模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class BuildingInfo(BaseModel):
|
||||
"""楼栋信息"""
|
||||
|
||||
code: str = Field(..., description="楼栋代码")
|
||||
name: str = Field(..., description="楼栋名称")
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 楼层信息模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class FloorInfo(BaseModel):
|
||||
"""楼层信息"""
|
||||
|
||||
code: str = Field(..., description="楼层代码")
|
||||
name: str = Field(..., description="楼层名称")
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 房间信息模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class RoomInfo(BaseModel):
|
||||
"""房间信息"""
|
||||
|
||||
code: str = Field(..., description="房间代码")
|
||||
name: str = Field(..., description="房间名称")
|
||||
|
||||
|
||||
###############################################################
|
||||
# * 楼栋-楼层-房间信息模型 *#
|
||||
###############################################################
|
||||
class CacheFloorData(BaseModel):
|
||||
"""缓存的楼层信息"""
|
||||
|
||||
code: str = Field(..., description="楼层代码")
|
||||
name: str = Field(..., description="楼层名称")
|
||||
rooms: List[RoomInfo] = Field(..., description="房间列表")
|
||||
|
||||
|
||||
class CacheBuildingData(BaseModel):
|
||||
"""缓存的楼栋信息"""
|
||||
|
||||
code: str = Field(..., description="楼栋代码")
|
||||
name: str = Field(..., description="楼栋名称")
|
||||
floors: List[CacheFloorData] = Field(..., description="楼层列表")
|
||||
|
||||
|
||||
class CacheRoomsData(BaseModel):
|
||||
"""缓存的寝室信息"""
|
||||
|
||||
datetime: str = Field(..., description="数据更新时间,格式:YYYY-MM-DD HH:MM:SS")
|
||||
data: List[CacheBuildingData] = Field(..., description="楼栋列表")
|
||||
|
||||
|
||||
class RoomBindingInfo(BaseModel):
|
||||
"""房间绑定信息"""
|
||||
|
||||
building: BuildingInfo
|
||||
floor: FloorInfo
|
||||
room: RoomInfo
|
||||
room_id: str = Field(..., description="完整房间ID")
|
||||
display_text: str = Field(
|
||||
..., description="显示文本,如:北苑11号学生公寓/11-6层/11-627"
|
||||
)
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 获取当前宿舍响应模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class CurrentRoomResponse(BaseModel):
|
||||
"""获取当前宿舍响应模型"""
|
||||
|
||||
room_code: str = Field(..., description="房间代码")
|
||||
display_text: str = Field(
|
||||
..., description="显示文本,如:北苑11号学生公寓/11-6层/11-627"
|
||||
)
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 强制刷新响应模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class ForceRefreshResponse(BaseModel):
|
||||
"""强制刷新响应模型"""
|
||||
|
||||
success: bool = Field(..., description="是否刷新成功")
|
||||
message: str = Field(..., description="响应消息")
|
||||
remaining_cooldown: float = Field(
|
||||
default=0.0, description="剩余冷却时间(秒),0表示无冷却"
|
||||
)
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 楼层房间查询响应模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class FloorRoomsResponse(BaseModel):
|
||||
"""楼层房间查询响应模型"""
|
||||
|
||||
floor_code: str = Field(..., description="楼层代码")
|
||||
floor_name: str = Field(..., description="楼层名称")
|
||||
building_code: str = Field(..., description="所属楼栋代码")
|
||||
rooms: List[RoomInfo] = Field(..., description="房间列表")
|
||||
room_count: int = Field(..., description="房间数量")
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 房间详情查询响应模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class RoomDetailResponse(BaseModel):
|
||||
"""房间详情查询响应模型"""
|
||||
|
||||
room_code: str = Field(..., description="房间代码")
|
||||
room_name: str = Field(..., description="房间名称")
|
||||
floor_code: str = Field(..., description="所属楼层代码")
|
||||
floor_name: str = Field(..., description="所属楼层名称")
|
||||
building_code: str = Field(..., description="所属楼栋代码")
|
||||
building_name: str = Field(..., description="所属楼栋名称")
|
||||
display_text: str = Field(..., description="完整显示文本")
|
||||
|
||||
|
||||
##############################################################
|
||||
# * 楼栋列表响应模型 *#
|
||||
##############################################################
|
||||
|
||||
|
||||
class BuildingListResponse(BaseModel):
|
||||
"""楼栋列表响应模型"""
|
||||
|
||||
buildings: List[BuildingInfo] = Field(..., description="楼栋列表")
|
||||
building_count: int = Field(..., description="楼栋数量")
|
||||
datetime: str = Field(..., description="数据更新时间")
|
||||
Reference in New Issue
Block a user