Fix API compatibility and add user/role/permission and asset import/export
This commit is contained in:
152
backend_new/app/schemas/allocation.py
Normal file
152
backend_new/app/schemas/allocation.py
Normal file
@@ -0,0 +1,152 @@
|
||||
"""
|
||||
资产分配相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime, date
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 分配单Schema =====
|
||||
|
||||
class AllocationOrderBase(BaseModel):
|
||||
"""分配单基础Schema"""
|
||||
order_type: str = Field(..., description="单据类型(allocation/transfer/recovery/maintenance/scrap)")
|
||||
title: str = Field(..., min_length=1, max_length=200, description="标题")
|
||||
source_organization_id: Optional[int] = Field(None, gt=0, description="调出网点ID")
|
||||
target_organization_id: int = Field(..., gt=0, description="调入网点ID")
|
||||
expect_execute_date: Optional[date] = Field(None, description="预计执行日期")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AllocationOrderCreate(AllocationOrderBase):
|
||||
"""创建分配单Schema"""
|
||||
asset_ids: List[int] = Field(..., min_items=1, description="资产ID列表")
|
||||
|
||||
|
||||
class AllocationOrderUpdate(BaseModel):
|
||||
"""更新分配单Schema"""
|
||||
title: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
expect_execute_date: Optional[date] = None
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
class AllocationOrderApproval(BaseModel):
|
||||
"""分配单审批Schema"""
|
||||
approval_status: str = Field(..., description="审批状态(approved/rejected)")
|
||||
approval_remark: Optional[str] = Field(None, description="审批备注")
|
||||
|
||||
|
||||
class AllocationOrderExecute(BaseModel):
|
||||
"""分配单执行Schema"""
|
||||
remark: Optional[str] = Field(None, description="执行备注")
|
||||
|
||||
|
||||
class AllocationOrderInDB(BaseModel):
|
||||
"""数据库中的分配单Schema"""
|
||||
id: int
|
||||
order_code: str
|
||||
order_type: str
|
||||
title: str
|
||||
source_organization_id: Optional[int]
|
||||
target_organization_id: int
|
||||
applicant_id: int
|
||||
approver_id: Optional[int]
|
||||
approval_status: str
|
||||
approval_time: Optional[datetime]
|
||||
approval_remark: Optional[str]
|
||||
expect_execute_date: Optional[date]
|
||||
actual_execute_date: Optional[date]
|
||||
executor_id: Optional[int]
|
||||
execute_status: str
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AllocationOrderResponse(AllocationOrderInDB):
|
||||
"""分配单响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class AllocationOrderWithRelations(AllocationOrderResponse):
|
||||
"""带关联信息的分配单响应Schema"""
|
||||
source_organization: Optional[Dict[str, Any]] = None
|
||||
target_organization: Optional[Dict[str, Any]] = None
|
||||
applicant: Optional[Dict[str, Any]] = None
|
||||
approver: Optional[Dict[str, Any]] = None
|
||||
executor: Optional[Dict[str, Any]] = None
|
||||
items: Optional[List[Dict[str, Any]]] = None
|
||||
|
||||
|
||||
class AllocationOrderListResponse(BaseModel):
|
||||
"""分配单列表响应Schema"""
|
||||
total: int
|
||||
page: int
|
||||
page_size: int
|
||||
total_pages: int
|
||||
items: List[AllocationOrderWithRelations]
|
||||
|
||||
|
||||
# ===== 分配单明细Schema =====
|
||||
|
||||
class AllocationItemBase(BaseModel):
|
||||
"""分配单明细基础Schema"""
|
||||
asset_id: int = Field(..., gt=0, description="资产ID")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AllocationItemInDB(BaseModel):
|
||||
"""数据库中的分配单明细Schema"""
|
||||
id: int
|
||||
order_id: int
|
||||
asset_id: int
|
||||
asset_code: str
|
||||
asset_name: str
|
||||
from_organization_id: Optional[int]
|
||||
to_organization_id: Optional[int]
|
||||
from_status: Optional[str]
|
||||
to_status: Optional[str]
|
||||
execute_status: str
|
||||
execute_time: Optional[datetime]
|
||||
failure_reason: Optional[str]
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AllocationItemResponse(AllocationItemInDB):
|
||||
"""分配单明细响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
# ===== 查询参数Schema =====
|
||||
|
||||
class AllocationOrderQueryParams(BaseModel):
|
||||
"""分配单查询参数"""
|
||||
order_type: Optional[str] = Field(None, description="单据类型")
|
||||
approval_status: Optional[str] = Field(None, description="审批状态")
|
||||
execute_status: Optional[str] = Field(None, description="执行状态")
|
||||
applicant_id: Optional[int] = Field(None, gt=0, description="申请人ID")
|
||||
target_organization_id: Optional[int] = Field(None, gt=0, description="目标网点ID")
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
# ===== 统计Schema =====
|
||||
|
||||
class AllocationOrderStatistics(BaseModel):
|
||||
"""分配单统计Schema"""
|
||||
total: int = Field(..., description="总数")
|
||||
pending: int = Field(..., description="待审批数")
|
||||
approved: int = Field(..., description="已审批数")
|
||||
rejected: int = Field(..., description="已拒绝数")
|
||||
executing: int = Field(..., description="执行中数")
|
||||
completed: int = Field(..., description="已完成数")
|
||||
163
backend_new/app/schemas/asset.py
Normal file
163
backend_new/app/schemas/asset.py
Normal file
@@ -0,0 +1,163 @@
|
||||
"""
|
||||
资产相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime, date
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 资产Schema =====
|
||||
|
||||
class AssetBase(BaseModel):
|
||||
"""资产基础Schema"""
|
||||
asset_name: str = Field(..., min_length=1, max_length=200, description="资产名称")
|
||||
device_type_id: int = Field(..., gt=0, description="设备类型ID")
|
||||
brand_id: Optional[int] = Field(None, gt=0, description="品牌ID")
|
||||
model: Optional[str] = Field(None, max_length=200, description="规格型号")
|
||||
serial_number: Optional[str] = Field(None, max_length=200, description="序列号")
|
||||
supplier_id: Optional[int] = Field(None, gt=0, description="供应商ID")
|
||||
purchase_date: Optional[date] = Field(None, description="采购日期")
|
||||
purchase_price: Optional[Decimal] = Field(None, ge=0, description="采购价格")
|
||||
warranty_period: Optional[int] = Field(None, ge=0, description="保修期(月)")
|
||||
organization_id: int = Field(..., gt=0, description="所属网点ID")
|
||||
location: Optional[str] = Field(None, max_length=500, description="存放位置")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetCreate(AssetBase):
|
||||
"""创建资产Schema"""
|
||||
dynamic_attributes: Dict[str, Any] = Field(default_factory=dict, description="动态字段值")
|
||||
|
||||
|
||||
class AssetUpdate(BaseModel):
|
||||
"""更新资产Schema"""
|
||||
asset_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
brand_id: Optional[int] = Field(None, gt=0)
|
||||
model: Optional[str] = Field(None, max_length=200)
|
||||
serial_number: Optional[str] = Field(None, max_length=200)
|
||||
supplier_id: Optional[int] = Field(None, gt=0)
|
||||
purchase_date: Optional[date] = None
|
||||
purchase_price: Optional[Decimal] = Field(None, ge=0)
|
||||
warranty_period: Optional[int] = Field(None, ge=0)
|
||||
warranty_expire_date: Optional[date] = None
|
||||
organization_id: Optional[int] = Field(None, gt=0)
|
||||
location: Optional[str] = Field(None, max_length=500)
|
||||
dynamic_attributes: Optional[Dict[str, Any]] = None
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
class AssetInDB(BaseModel):
|
||||
"""数据库中的资产Schema"""
|
||||
id: int
|
||||
asset_code: str
|
||||
asset_name: str
|
||||
device_type_id: int
|
||||
brand_id: Optional[int]
|
||||
model: Optional[str]
|
||||
serial_number: Optional[str]
|
||||
supplier_id: Optional[int]
|
||||
purchase_date: Optional[date]
|
||||
purchase_price: Optional[Decimal]
|
||||
warranty_period: Optional[int]
|
||||
warranty_expire_date: Optional[date]
|
||||
organization_id: int
|
||||
location: Optional[str]
|
||||
status: str
|
||||
dynamic_attributes: Dict[str, Any]
|
||||
qr_code_url: Optional[str]
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AssetResponse(AssetInDB):
|
||||
"""资产响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class AssetWithRelations(AssetResponse):
|
||||
"""带关联信息的资产响应Schema"""
|
||||
device_type: Optional[Dict[str, Any]] = None
|
||||
brand: Optional[Dict[str, Any]] = None
|
||||
supplier: Optional[Dict[str, Any]] = None
|
||||
organization: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
# ===== 资产状态历史Schema =====
|
||||
|
||||
class AssetStatusHistoryBase(BaseModel):
|
||||
"""资产状态历史基础Schema"""
|
||||
old_status: Optional[str] = Field(None, description="原状态")
|
||||
new_status: str = Field(..., description="新状态")
|
||||
operation_type: str = Field(..., description="操作类型")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetStatusHistoryInDB(BaseModel):
|
||||
"""数据库中的资产状态历史Schema"""
|
||||
id: int
|
||||
asset_id: int
|
||||
old_status: Optional[str]
|
||||
new_status: str
|
||||
operation_type: str
|
||||
operator_id: int
|
||||
operator_name: Optional[str]
|
||||
organization_id: Optional[int]
|
||||
remark: Optional[str]
|
||||
extra_data: Optional[Dict[str, Any]]
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AssetStatusHistoryResponse(AssetStatusHistoryInDB):
|
||||
"""资产状态历史响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
# ===== 批量操作Schema =====
|
||||
|
||||
class AssetBatchImport(BaseModel):
|
||||
"""批量导入Schema"""
|
||||
file_path: str = Field(..., description="Excel文件路径")
|
||||
|
||||
|
||||
class AssetBatchImportResult(BaseModel):
|
||||
"""批量导入结果Schema"""
|
||||
total: int = Field(..., description="总数")
|
||||
success: int = Field(..., description="成功数")
|
||||
failed: int = Field(..., description="失败数")
|
||||
errors: List[Dict[str, Any]] = Field(default_factory=list, description="错误列表")
|
||||
|
||||
|
||||
class AssetBatchDelete(BaseModel):
|
||||
"""批量删除Schema"""
|
||||
asset_ids: List[int] = Field(..., min_items=1, description="资产ID列表")
|
||||
|
||||
|
||||
# ===== 查询参数Schema =====
|
||||
|
||||
class AssetQueryParams(BaseModel):
|
||||
"""资产查询参数"""
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
device_type_id: Optional[int] = Field(None, gt=0, description="设备类型ID")
|
||||
organization_id: Optional[int] = Field(None, gt=0, description="网点ID")
|
||||
status: Optional[str] = Field(None, description="状态")
|
||||
purchase_date_start: Optional[date] = Field(None, description="采购日期开始")
|
||||
purchase_date_end: Optional[date] = Field(None, description="采购日期结束")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
# ===== 状态转换Schema =====
|
||||
|
||||
class AssetStatusTransition(BaseModel):
|
||||
"""资产状态转换Schema"""
|
||||
new_status: str = Field(..., description="目标状态")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
extra_data: Optional[Dict[str, Any]] = Field(None, description="额外数据")
|
||||
113
backend_new/app/schemas/brand_supplier.py
Normal file
113
backend_new/app/schemas/brand_supplier.py
Normal file
@@ -0,0 +1,113 @@
|
||||
"""
|
||||
品牌和供应商相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field, EmailStr
|
||||
|
||||
|
||||
# ===== 品牌Schema =====
|
||||
|
||||
class BrandBase(BaseModel):
|
||||
"""品牌基础Schema"""
|
||||
brand_code: str = Field(..., min_length=1, max_length=50, description="品牌代码")
|
||||
brand_name: str = Field(..., min_length=1, max_length=200, description="品牌名称")
|
||||
logo_url: Optional[str] = Field(None, max_length=500, description="Logo URL")
|
||||
website: Optional[str] = Field(None, max_length=500, description="官网地址")
|
||||
sort_order: int = Field(default=0, description="排序")
|
||||
|
||||
|
||||
class BrandCreate(BrandBase):
|
||||
"""创建品牌Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class BrandUpdate(BaseModel):
|
||||
"""更新品牌Schema"""
|
||||
brand_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
logo_url: Optional[str] = Field(None, max_length=500)
|
||||
website: Optional[str] = Field(None, max_length=500)
|
||||
status: Optional[str] = Field(None, pattern="^(active|inactive)$")
|
||||
sort_order: Optional[int] = None
|
||||
|
||||
|
||||
class BrandInDB(BaseModel):
|
||||
"""数据库中的品牌Schema"""
|
||||
id: int
|
||||
brand_code: str
|
||||
brand_name: str
|
||||
logo_url: Optional[str]
|
||||
website: Optional[str]
|
||||
status: str
|
||||
sort_order: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class BrandResponse(BrandInDB):
|
||||
"""品牌响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
# ===== 供应商Schema =====
|
||||
|
||||
class SupplierBase(BaseModel):
|
||||
"""供应商基础Schema"""
|
||||
supplier_code: str = Field(..., min_length=1, max_length=50, description="供应商代码")
|
||||
supplier_name: str = Field(..., min_length=1, max_length=200, description="供应商名称")
|
||||
contact_person: Optional[str] = Field(None, max_length=100, description="联系人")
|
||||
contact_phone: Optional[str] = Field(None, max_length=20, description="联系电话")
|
||||
email: Optional[EmailStr] = Field(None, description="邮箱")
|
||||
address: Optional[str] = Field(None, max_length=500, description="地址")
|
||||
credit_code: Optional[str] = Field(None, max_length=50, description="统一社会信用代码")
|
||||
bank_name: Optional[str] = Field(None, max_length=200, description="开户银行")
|
||||
bank_account: Optional[str] = Field(None, max_length=100, description="银行账号")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class SupplierCreate(SupplierBase):
|
||||
"""创建供应商Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class SupplierUpdate(BaseModel):
|
||||
"""更新供应商Schema"""
|
||||
supplier_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
contact_person: Optional[str] = Field(None, max_length=100)
|
||||
contact_phone: Optional[str] = Field(None, max_length=20)
|
||||
email: Optional[EmailStr] = None
|
||||
address: Optional[str] = Field(None, max_length=500)
|
||||
credit_code: Optional[str] = Field(None, max_length=50)
|
||||
bank_name: Optional[str] = Field(None, max_length=200)
|
||||
bank_account: Optional[str] = Field(None, max_length=100)
|
||||
status: Optional[str] = Field(None, pattern="^(active|inactive)$")
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
class SupplierInDB(BaseModel):
|
||||
"""数据库中的供应商Schema"""
|
||||
id: int
|
||||
supplier_code: str
|
||||
supplier_name: str
|
||||
contact_person: Optional[str]
|
||||
contact_phone: Optional[str]
|
||||
email: Optional[str]
|
||||
address: Optional[str]
|
||||
credit_code: Optional[str]
|
||||
bank_name: Optional[str]
|
||||
bank_account: Optional[str]
|
||||
status: str
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class SupplierResponse(SupplierInDB):
|
||||
"""供应商响应Schema"""
|
||||
pass
|
||||
152
backend_new/app/schemas/device_type.py
Normal file
152
backend_new/app/schemas/device_type.py
Normal file
@@ -0,0 +1,152 @@
|
||||
"""
|
||||
设备类型相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
# ===== 设备类型Schema =====
|
||||
|
||||
class DeviceTypeBase(BaseModel):
|
||||
"""设备类型基础Schema"""
|
||||
type_code: str = Field(..., min_length=1, max_length=50, description="设备类型代码")
|
||||
type_name: str = Field(..., min_length=1, max_length=200, description="设备类型名称")
|
||||
category: Optional[str] = Field(None, max_length=50, description="设备分类")
|
||||
description: Optional[str] = Field(None, description="描述")
|
||||
icon: Optional[str] = Field(None, max_length=100, description="图标名称")
|
||||
sort_order: int = Field(default=0, description="排序")
|
||||
|
||||
|
||||
class DeviceTypeCreate(DeviceTypeBase):
|
||||
"""创建设备类型Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class DeviceTypeUpdate(BaseModel):
|
||||
"""更新设备类型Schema"""
|
||||
type_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
category: Optional[str] = Field(None, max_length=50)
|
||||
description: Optional[str] = None
|
||||
icon: Optional[str] = Field(None, max_length=100)
|
||||
status: Optional[str] = Field(None, pattern="^(active|inactive)$")
|
||||
sort_order: Optional[int] = None
|
||||
|
||||
|
||||
class DeviceTypeInDB(BaseModel):
|
||||
"""数据库中的设备类型Schema"""
|
||||
id: int
|
||||
type_code: str
|
||||
type_name: str
|
||||
category: Optional[str]
|
||||
description: Optional[str]
|
||||
icon: Optional[str]
|
||||
status: str
|
||||
sort_order: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class DeviceTypeResponse(DeviceTypeInDB):
|
||||
"""设备类型响应Schema"""
|
||||
field_count: int = Field(default=0, description="字段数量")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class DeviceTypeWithFields(DeviceTypeResponse):
|
||||
"""带字段列表的设备类型响应Schema"""
|
||||
fields: List["DeviceTypeFieldResponse"] = Field(default_factory=list, description="字段列表")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# ===== 设备类型字段Schema =====
|
||||
|
||||
class DeviceTypeFieldBase(BaseModel):
|
||||
"""设备类型字段基础Schema"""
|
||||
field_code: str = Field(..., min_length=1, max_length=50, description="字段代码")
|
||||
field_name: str = Field(..., min_length=1, max_length=100, description="字段名称")
|
||||
field_type: str = Field(..., pattern="^(text|number|date|select|multiselect|boolean|textarea)$", description="字段类型")
|
||||
is_required: bool = Field(default=False, description="是否必填")
|
||||
default_value: Optional[str] = Field(None, description="默认值")
|
||||
placeholder: Optional[str] = Field(None, max_length=200, description="占位符")
|
||||
help_text: Optional[str] = Field(None, description="帮助文本")
|
||||
sort_order: int = Field(default=0, description="排序")
|
||||
|
||||
|
||||
class DeviceTypeFieldCreate(DeviceTypeFieldBase):
|
||||
"""创建设备类型字段Schema"""
|
||||
options: Optional[List[Dict[str, Any]]] = Field(None, description="选项列表(用于select/multiselect类型)")
|
||||
validation_rules: Optional[Dict[str, Any]] = Field(None, description="验证规则")
|
||||
|
||||
@field_validator("field_type")
|
||||
@classmethod
|
||||
def validate_field_type(cls, v: str) -> str:
|
||||
"""验证字段类型"""
|
||||
valid_types = ["text", "number", "date", "select", "multiselect", "boolean", "textarea"]
|
||||
if v not in valid_types:
|
||||
raise ValueError(f"字段类型必须是以下之一: {', '.join(valid_types)}")
|
||||
return v
|
||||
|
||||
|
||||
class DeviceTypeFieldUpdate(BaseModel):
|
||||
"""更新设备类型字段Schema"""
|
||||
field_name: Optional[str] = Field(None, min_length=1, max_length=100)
|
||||
field_type: Optional[str] = Field(None, pattern="^(text|number|date|select|multiselect|boolean|textarea)$")
|
||||
is_required: Optional[bool] = None
|
||||
default_value: Optional[str] = None
|
||||
options: Optional[List[Dict[str, Any]]] = None
|
||||
validation_rules: Optional[Dict[str, Any]] = None
|
||||
placeholder: Optional[str] = Field(None, max_length=200)
|
||||
help_text: Optional[str] = None
|
||||
status: Optional[str] = Field(None, pattern="^(active|inactive)$")
|
||||
sort_order: Optional[int] = None
|
||||
|
||||
|
||||
class DeviceTypeFieldInDB(BaseModel):
|
||||
"""数据库中的设备类型字段Schema"""
|
||||
id: int
|
||||
device_type_id: int
|
||||
field_code: str
|
||||
field_name: str
|
||||
field_type: str
|
||||
is_required: bool
|
||||
default_value: Optional[str]
|
||||
options: Optional[List[Dict[str, Any]]]
|
||||
validation_rules: Optional[Dict[str, Any]]
|
||||
placeholder: Optional[str]
|
||||
help_text: Optional[str]
|
||||
sort_order: int
|
||||
status: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class DeviceTypeFieldResponse(DeviceTypeFieldInDB):
|
||||
"""设备类型字段响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
# ===== 查询参数Schema =====
|
||||
|
||||
class DeviceTypeQueryParams(BaseModel):
|
||||
"""设备类型查询参数"""
|
||||
category: Optional[str] = Field(None, description="设备分类")
|
||||
status: Optional[str] = Field(None, pattern="^(active|inactive)$", description="状态")
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
# 更新前向引用
|
||||
DeviceTypeWithFields.model_rebuild()
|
||||
|
||||
159
backend_new/app/schemas/file_management.py
Normal file
159
backend_new/app/schemas/file_management.py
Normal file
@@ -0,0 +1,159 @@
|
||||
"""
|
||||
文件管理相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 文件Schema =====
|
||||
|
||||
class UploadedFileBase(BaseModel):
|
||||
"""上传文件基础Schema"""
|
||||
original_name: str = Field(..., min_length=1, max_length=255, description="原始文件名")
|
||||
file_size: int = Field(..., gt=0, description="文件大小(字节)")
|
||||
file_type: str = Field(..., description="文件类型(MIME)")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class UploadedFileCreate(UploadedFileBase):
|
||||
"""创建文件记录Schema"""
|
||||
file_name: str = Field(..., description="存储文件名")
|
||||
file_path: str = Field(..., description="文件存储路径")
|
||||
file_ext: str = Field(..., description="文件扩展名")
|
||||
uploader_id: int = Field(..., gt=0, description="上传者ID")
|
||||
|
||||
|
||||
class UploadedFileUpdate(BaseModel):
|
||||
"""更新文件记录Schema"""
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
class UploadedFileInDB(BaseModel):
|
||||
"""数据库中的文件Schema"""
|
||||
id: int
|
||||
file_name: str
|
||||
original_name: str
|
||||
file_path: str
|
||||
file_size: int
|
||||
file_type: str
|
||||
file_ext: str
|
||||
uploader_id: int
|
||||
upload_time: datetime
|
||||
thumbnail_path: Optional[str]
|
||||
share_code: Optional[str]
|
||||
share_expire_time: Optional[datetime]
|
||||
download_count: int
|
||||
is_deleted: int
|
||||
deleted_at: Optional[datetime]
|
||||
deleted_by: Optional[int]
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class UploadedFileResponse(UploadedFileInDB):
|
||||
"""文件响应Schema"""
|
||||
uploader_name: Optional[str] = None
|
||||
|
||||
|
||||
class UploadedFileWithUrl(UploadedFileResponse):
|
||||
"""带访问URL的文件响应Schema"""
|
||||
download_url: Optional[str] = None
|
||||
preview_url: Optional[str] = None
|
||||
share_url: Optional[str] = None
|
||||
|
||||
|
||||
# ===== 文件上传Schema =====
|
||||
|
||||
class FileUploadResponse(BaseModel):
|
||||
"""文件上传响应Schema"""
|
||||
id: int
|
||||
file_name: str
|
||||
original_name: str
|
||||
file_size: int
|
||||
file_type: str
|
||||
file_path: str
|
||||
download_url: str
|
||||
preview_url: Optional[str] = None
|
||||
message: str = "上传成功"
|
||||
|
||||
|
||||
# ===== 文件分享Schema =====
|
||||
|
||||
class FileShareCreate(BaseModel):
|
||||
"""创建文件分享Schema"""
|
||||
expire_days: int = Field(default=7, ge=1, le=30, description="有效期(天)")
|
||||
|
||||
|
||||
class FileShareResponse(BaseModel):
|
||||
"""文件分享响应Schema"""
|
||||
share_code: str
|
||||
share_url: str
|
||||
expire_time: datetime
|
||||
|
||||
|
||||
class FileShareVerify(BaseModel):
|
||||
"""验证分享码Schema"""
|
||||
share_code: str = Field(..., description="分享码")
|
||||
|
||||
|
||||
# ===== 批量操作Schema =====
|
||||
|
||||
class FileBatchDelete(BaseModel):
|
||||
"""批量删除文件Schema"""
|
||||
file_ids: List[int] = Field(..., min_items=1, description="文件ID列表")
|
||||
|
||||
|
||||
# ===== 查询参数Schema =====
|
||||
|
||||
class FileQueryParams(BaseModel):
|
||||
"""文件查询参数"""
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
file_type: Optional[str] = Field(None, description="文件类型")
|
||||
uploader_id: Optional[int] = Field(None, gt=0, description="上传者ID")
|
||||
start_date: Optional[str] = Field(None, description="开始日期(YYYY-MM-DD)")
|
||||
end_date: Optional[str] = Field(None, description="结束日期(YYYY-MM-DD)")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
# ===== 统计Schema =====
|
||||
|
||||
class FileStatistics(BaseModel):
|
||||
"""文件统计Schema"""
|
||||
total_files: int = Field(..., description="总文件数")
|
||||
total_size: int = Field(..., description="总大小(字节)")
|
||||
total_size_human: str = Field(..., description="总大小(人类可读)")
|
||||
type_distribution: Dict[str, int] = Field(default_factory=dict, description="文件类型分布")
|
||||
upload_today: int = Field(..., description="今日上传数")
|
||||
upload_this_week: int = Field(..., description="本周上传数")
|
||||
upload_this_month: int = Field(..., description="本月上传数")
|
||||
top_uploaders: List[Dict[str, Any]] = Field(default_factory=list, description="上传排行")
|
||||
|
||||
|
||||
# ===== 分片上传Schema =====
|
||||
|
||||
class ChunkUploadInit(BaseModel):
|
||||
"""初始化分片上传Schema"""
|
||||
file_name: str = Field(..., description="文件名")
|
||||
file_size: int = Field(..., gt=0, description="文件大小")
|
||||
file_type: str = Field(..., description="文件类型")
|
||||
total_chunks: int = Field(..., gt=0, description="总分片数")
|
||||
file_hash: Optional[str] = Field(None, description="文件哈希(MD5/SHA256)")
|
||||
|
||||
|
||||
class ChunkUploadInfo(BaseModel):
|
||||
"""分片上传信息Schema"""
|
||||
upload_id: str = Field(..., description="上传ID")
|
||||
chunk_index: int = Field(..., ge=0, description="分片索引")
|
||||
|
||||
|
||||
class ChunkUploadComplete(BaseModel):
|
||||
"""完成分片上传Schema"""
|
||||
upload_id: str = Field(..., description="上传ID")
|
||||
file_name: str = Field(..., description="文件名")
|
||||
file_hash: Optional[str] = Field(None, description="文件哈希")
|
||||
127
backend_new/app/schemas/maintenance.py
Normal file
127
backend_new/app/schemas/maintenance.py
Normal file
@@ -0,0 +1,127 @@
|
||||
"""
|
||||
维修管理相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime, date
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 维修记录Schema =====
|
||||
|
||||
class MaintenanceRecordBase(BaseModel):
|
||||
"""维修记录基础Schema"""
|
||||
asset_id: int = Field(..., gt=0, description="资产ID")
|
||||
fault_description: str = Field(..., min_length=1, description="故障描述")
|
||||
fault_type: Optional[str] = Field(None, description="故障类型(hardware/software/network/other)")
|
||||
priority: str = Field(default="normal", description="优先级(low/normal/high/urgent)")
|
||||
maintenance_type: Optional[str] = Field(None, description="维修类型(self_repair/vendor_repair/warranty)")
|
||||
vendor_id: Optional[int] = Field(None, gt=0, description="维修供应商ID")
|
||||
maintenance_cost: Optional[Decimal] = Field(None, ge=0, description="维修费用")
|
||||
maintenance_result: Optional[str] = Field(None, description="维修结果描述")
|
||||
replaced_parts: Optional[str] = Field(None, description="更换的配件")
|
||||
images: Optional[str] = Field(None, description="维修图片URL(多个逗号分隔)")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class MaintenanceRecordCreate(MaintenanceRecordBase):
|
||||
"""创建维修记录Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class MaintenanceRecordUpdate(BaseModel):
|
||||
"""更新维修记录Schema"""
|
||||
fault_description: Optional[str] = Field(None, min_length=1)
|
||||
fault_type: Optional[str] = None
|
||||
priority: Optional[str] = None
|
||||
maintenance_type: Optional[str] = None
|
||||
vendor_id: Optional[int] = Field(None, gt=0)
|
||||
maintenance_cost: Optional[Decimal] = Field(None, ge=0)
|
||||
maintenance_result: Optional[str] = None
|
||||
replaced_parts: Optional[str] = None
|
||||
images: Optional[str] = None
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
class MaintenanceRecordStart(BaseModel):
|
||||
"""开始维修Schema"""
|
||||
maintenance_type: str = Field(..., description="维修类型")
|
||||
vendor_id: Optional[int] = Field(None, gt=0, description="维修供应商ID(vendor_repair时必填)")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class MaintenanceRecordComplete(BaseModel):
|
||||
"""完成维修Schema"""
|
||||
maintenance_result: str = Field(..., description="维修结果描述")
|
||||
maintenance_cost: Optional[Decimal] = Field(None, ge=0, description="维修费用")
|
||||
replaced_parts: Optional[str] = Field(None, description="更换的配件")
|
||||
images: Optional[str] = Field(None, description="维修图片URL")
|
||||
asset_status: str = Field(default="in_stock", description="资产维修后状态(in_stock/in_use)")
|
||||
|
||||
|
||||
class MaintenanceRecordInDB(BaseModel):
|
||||
"""数据库中的维修记录Schema"""
|
||||
id: int
|
||||
record_code: str
|
||||
asset_id: int
|
||||
asset_code: str
|
||||
fault_description: str
|
||||
fault_type: Optional[str]
|
||||
report_user_id: Optional[int]
|
||||
report_time: datetime
|
||||
priority: str
|
||||
maintenance_type: Optional[str]
|
||||
vendor_id: Optional[int]
|
||||
maintenance_cost: Optional[Decimal]
|
||||
start_time: Optional[datetime]
|
||||
complete_time: Optional[datetime]
|
||||
maintenance_user_id: Optional[int]
|
||||
maintenance_result: Optional[str]
|
||||
replaced_parts: Optional[str]
|
||||
status: str
|
||||
images: Optional[str]
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class MaintenanceRecordResponse(MaintenanceRecordInDB):
|
||||
"""维修记录响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class MaintenanceRecordWithRelations(MaintenanceRecordResponse):
|
||||
"""带关联信息的维修记录响应Schema"""
|
||||
asset: Optional[Dict[str, Any]] = None
|
||||
vendor: Optional[Dict[str, Any]] = None
|
||||
report_user: Optional[Dict[str, Any]] = None
|
||||
maintenance_user: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
# ===== 查询参数Schema =====
|
||||
|
||||
class MaintenanceRecordQueryParams(BaseModel):
|
||||
"""维修记录查询参数"""
|
||||
asset_id: Optional[int] = Field(None, gt=0, description="资产ID")
|
||||
status: Optional[str] = Field(None, description="状态")
|
||||
fault_type: Optional[str] = Field(None, description="故障类型")
|
||||
priority: Optional[str] = Field(None, description="优先级")
|
||||
maintenance_type: Optional[str] = Field(None, description="维修类型")
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
# ===== 统计Schema =====
|
||||
|
||||
class MaintenanceStatistics(BaseModel):
|
||||
"""维修统计Schema"""
|
||||
total: int = Field(..., description="总数")
|
||||
pending: int = Field(..., description="待处理数")
|
||||
in_progress: int = Field(..., description="维修中数")
|
||||
completed: int = Field(..., description="已完成数")
|
||||
cancelled: int = Field(..., description="已取消数")
|
||||
total_cost: Decimal = Field(..., description="总维修费用")
|
||||
192
backend_new/app/schemas/notification.py
Normal file
192
backend_new/app/schemas/notification.py
Normal file
@@ -0,0 +1,192 @@
|
||||
"""
|
||||
消息通知相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class NotificationTypeEnum(str, Enum):
|
||||
"""通知类型枚举"""
|
||||
SYSTEM = "system" # 系统通知
|
||||
APPROVAL = "approval" # 审批通知
|
||||
MAINTENANCE = "maintenance" # 维修通知
|
||||
ALLOCATION = "allocation" # 调拨通知
|
||||
ASSET = "asset" # 资产通知
|
||||
WARRANTY = "warranty" # 保修到期通知
|
||||
REMINDER = "reminder" # 提醒通知
|
||||
|
||||
|
||||
class PriorityEnum(str, Enum):
|
||||
"""优先级枚举"""
|
||||
LOW = "low"
|
||||
NORMAL = "normal"
|
||||
HIGH = "high"
|
||||
URGENT = "urgent"
|
||||
|
||||
|
||||
class NotificationBase(BaseModel):
|
||||
"""消息通知基础Schema"""
|
||||
recipient_id: int = Field(..., description="接收人ID")
|
||||
title: str = Field(..., min_length=1, max_length=200, description="通知标题")
|
||||
content: str = Field(..., min_length=1, description="通知内容")
|
||||
notification_type: NotificationTypeEnum = Field(..., description="通知类型")
|
||||
priority: PriorityEnum = Field(default=PriorityEnum.NORMAL, description="优先级")
|
||||
related_entity_type: Optional[str] = Field(None, max_length=50, description="关联实体类型")
|
||||
related_entity_id: Optional[int] = Field(None, description="关联实体ID")
|
||||
action_url: Optional[str] = Field(None, max_length=500, description="操作链接")
|
||||
extra_data: Optional[Dict[str, Any]] = Field(None, description="额外数据")
|
||||
send_email: bool = Field(default=False, description="是否发送邮件")
|
||||
send_sms: bool = Field(default=False, description="是否发送短信")
|
||||
expire_at: Optional[datetime] = Field(None, description="过期时间")
|
||||
|
||||
|
||||
class NotificationCreate(NotificationBase):
|
||||
"""创建消息通知Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class NotificationUpdate(BaseModel):
|
||||
"""更新消息通知Schema"""
|
||||
is_read: Optional[bool] = Field(None, description="是否已读")
|
||||
|
||||
|
||||
class NotificationInDB(BaseModel):
|
||||
"""数据库中的消息通知Schema"""
|
||||
id: int
|
||||
recipient_id: int
|
||||
recipient_name: str
|
||||
title: str
|
||||
content: str
|
||||
notification_type: str
|
||||
priority: str
|
||||
is_read: bool
|
||||
read_at: Optional[datetime]
|
||||
related_entity_type: Optional[str]
|
||||
related_entity_id: Optional[int]
|
||||
action_url: Optional[str]
|
||||
extra_data: Optional[Dict[str, Any]]
|
||||
sent_via_email: bool
|
||||
sent_via_sms: bool
|
||||
created_at: datetime
|
||||
expire_at: Optional[datetime]
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class NotificationResponse(NotificationInDB):
|
||||
"""消息通知响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class NotificationQueryParams(BaseModel):
|
||||
"""消息通知查询参数"""
|
||||
recipient_id: Optional[int] = Field(None, description="接收人ID")
|
||||
notification_type: Optional[NotificationTypeEnum] = Field(None, description="通知类型")
|
||||
priority: Optional[PriorityEnum] = Field(None, description="优先级")
|
||||
is_read: Optional[bool] = Field(None, description="是否已读")
|
||||
start_time: Optional[datetime] = Field(None, description="开始时间")
|
||||
end_time: Optional[datetime] = Field(None, description="结束时间")
|
||||
keyword: Optional[str] = Field(None, description="关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
class NotificationBatchCreate(BaseModel):
|
||||
"""批量创建通知Schema"""
|
||||
recipient_ids: List[int] = Field(..., min_items=1, description="接收人ID列表")
|
||||
title: str = Field(..., min_length=1, max_length=200, description="通知标题")
|
||||
content: str = Field(..., min_length=1, description="通知内容")
|
||||
notification_type: NotificationTypeEnum = Field(..., description="通知类型")
|
||||
priority: PriorityEnum = Field(default=PriorityEnum.NORMAL, description="优先级")
|
||||
action_url: Optional[str] = Field(None, max_length=500, description="操作链接")
|
||||
extra_data: Optional[Dict[str, Any]] = Field(None, description="额外数据")
|
||||
|
||||
|
||||
class NotificationBatchUpdate(BaseModel):
|
||||
"""批量更新通知Schema"""
|
||||
notification_ids: List[int] = Field(..., min_items=1, description="通知ID列表")
|
||||
is_read: bool = Field(..., description="是否已读")
|
||||
|
||||
|
||||
class NotificationStatistics(BaseModel):
|
||||
"""通知统计Schema"""
|
||||
total_count: int = Field(..., description="总通知数")
|
||||
unread_count: int = Field(..., description="未读数")
|
||||
read_count: int = Field(..., description="已读数")
|
||||
high_priority_count: int = Field(..., description="高优先级数")
|
||||
urgent_count: int = Field(..., description="紧急通知数")
|
||||
type_distribution: List[Dict[str, Any]] = Field(default_factory=list, description="类型分布")
|
||||
|
||||
|
||||
# ===== 通知模板Schema =====
|
||||
|
||||
class NotificationTemplateBase(BaseModel):
|
||||
"""通知模板基础Schema"""
|
||||
template_code: str = Field(..., min_length=1, max_length=50, description="模板编码")
|
||||
template_name: str = Field(..., min_length=1, max_length=200, description="模板名称")
|
||||
notification_type: NotificationTypeEnum = Field(..., description="通知类型")
|
||||
title_template: str = Field(..., min_length=1, max_length=200, description="标题模板")
|
||||
content_template: str = Field(..., min_length=1, description="内容模板")
|
||||
variables: Optional[Dict[str, str]] = Field(None, description="变量说明")
|
||||
priority: PriorityEnum = Field(default=PriorityEnum.NORMAL, description="默认优先级")
|
||||
send_email: bool = Field(default=False, description="是否发送邮件")
|
||||
send_sms: bool = Field(default=False, description="是否发送短信")
|
||||
is_active: bool = Field(default=True, description="是否启用")
|
||||
description: Optional[str] = Field(None, description="模板描述")
|
||||
|
||||
|
||||
class NotificationTemplateCreate(NotificationTemplateBase):
|
||||
"""创建通知模板Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class NotificationTemplateUpdate(BaseModel):
|
||||
"""更新通知模板Schema"""
|
||||
template_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
title_template: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
content_template: Optional[str] = Field(None, min_length=1)
|
||||
variables: Optional[Dict[str, str]] = None
|
||||
priority: Optional[PriorityEnum] = None
|
||||
send_email: Optional[bool] = None
|
||||
send_sms: Optional[bool] = None
|
||||
is_active: Optional[bool] = None
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
class NotificationTemplateInDB(BaseModel):
|
||||
"""数据库中的通知模板Schema"""
|
||||
id: int
|
||||
template_code: str
|
||||
template_name: str
|
||||
notification_type: str
|
||||
title_template: str
|
||||
content_template: str
|
||||
variables: Optional[Dict[str, str]]
|
||||
priority: str
|
||||
send_email: bool
|
||||
send_sms: bool
|
||||
is_active: bool
|
||||
description: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class NotificationTemplateResponse(NotificationTemplateInDB):
|
||||
"""通知模板响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class NotificationSendFromTemplate(BaseModel):
|
||||
"""从模板发送通知Schema"""
|
||||
template_code: str = Field(..., description="模板编码")
|
||||
recipient_ids: List[int] = Field(..., min_items=1, description="接收人ID列表")
|
||||
variables: Dict[str, Any] = Field(default_factory=dict, description="模板变量")
|
||||
related_entity_type: Optional[str] = Field(None, description="关联实体类型")
|
||||
related_entity_id: Optional[int] = Field(None, description="关联实体ID")
|
||||
action_url: Optional[str] = Field(None, description="操作链接")
|
||||
126
backend_new/app/schemas/operation_log.py
Normal file
126
backend_new/app/schemas/operation_log.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
操作日志相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class OperationModuleEnum(str, Enum):
|
||||
"""操作模块枚举"""
|
||||
AUTH = "auth" # 认证模块
|
||||
ASSET = "asset" # 资产模块
|
||||
DEVICE_TYPE = "device_type" # 设备类型模块
|
||||
ORGANIZATION = "organization" # 机构模块
|
||||
BRAND_SUPPLIER = "brand_supplier" # 品牌供应商模块
|
||||
ALLOCATION = "allocation" # 调拨模块
|
||||
MAINTENANCE = "maintenance" # 维修模块
|
||||
SYSTEM_CONFIG = "system_config" # 系统配置模块
|
||||
USER = "user" # 用户模块
|
||||
STATISTICS = "statistics" # 统计模块
|
||||
|
||||
|
||||
class OperationTypeEnum(str, Enum):
|
||||
"""操作类型枚举"""
|
||||
CREATE = "create" # 创建
|
||||
UPDATE = "update" # 更新
|
||||
DELETE = "delete" # 删除
|
||||
QUERY = "query" # 查询
|
||||
EXPORT = "export" # 导出
|
||||
IMPORT = "import" # 导入
|
||||
LOGIN = "login" # 登录
|
||||
LOGOUT = "logout" # 登出
|
||||
APPROVE = "approve" # 审批
|
||||
REJECT = "reject" # 拒绝
|
||||
ASSIGN = "assign" # 分配
|
||||
TRANSFER = "transfer" # 调拨
|
||||
SCRAP = "scrap" # 报废
|
||||
|
||||
|
||||
class OperationResultEnum(str, Enum):
|
||||
"""操作结果枚举"""
|
||||
SUCCESS = "success"
|
||||
FAILED = "failed"
|
||||
|
||||
|
||||
class OperationLogBase(BaseModel):
|
||||
"""操作日志基础Schema"""
|
||||
operator_id: int = Field(..., description="操作人ID")
|
||||
operator_name: str = Field(..., min_length=1, max_length=100, description="操作人姓名")
|
||||
operator_ip: Optional[str] = Field(None, max_length=50, description="操作人IP")
|
||||
module: OperationModuleEnum = Field(..., description="模块名称")
|
||||
operation_type: OperationTypeEnum = Field(..., description="操作类型")
|
||||
method: str = Field(..., min_length=1, max_length=10, description="请求方法")
|
||||
url: str = Field(..., min_length=1, max_length=500, description="请求URL")
|
||||
params: Optional[str] = Field(None, description="请求参数")
|
||||
result: OperationResultEnum = Field(default=OperationResultEnum.SUCCESS, description="操作结果")
|
||||
error_msg: Optional[str] = Field(None, description="错误信息")
|
||||
duration: Optional[int] = Field(None, ge=0, description="执行时长(毫秒)")
|
||||
user_agent: Optional[str] = Field(None, max_length=500, description="用户代理")
|
||||
extra_data: Optional[Dict[str, Any]] = Field(None, description="额外数据")
|
||||
|
||||
|
||||
class OperationLogCreate(OperationLogBase):
|
||||
"""创建操作日志Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class OperationLogInDB(BaseModel):
|
||||
"""数据库中的操作日志Schema"""
|
||||
id: int
|
||||
operator_id: int
|
||||
operator_name: str
|
||||
operator_ip: Optional[str]
|
||||
module: str
|
||||
operation_type: str
|
||||
method: str
|
||||
url: str
|
||||
params: Optional[str]
|
||||
result: str
|
||||
error_msg: Optional[str]
|
||||
duration: Optional[int]
|
||||
user_agent: Optional[str]
|
||||
extra_data: Optional[Dict[str, Any]]
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class OperationLogResponse(OperationLogInDB):
|
||||
"""操作日志响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class OperationLogQueryParams(BaseModel):
|
||||
"""操作日志查询参数"""
|
||||
operator_id: Optional[int] = Field(None, description="操作人ID")
|
||||
operator_name: Optional[str] = Field(None, description="操作人姓名")
|
||||
module: Optional[OperationModuleEnum] = Field(None, description="模块名称")
|
||||
operation_type: Optional[OperationTypeEnum] = Field(None, description="操作类型")
|
||||
result: Optional[OperationResultEnum] = Field(None, description="操作结果")
|
||||
start_time: Optional[datetime] = Field(None, description="开始时间")
|
||||
end_time: Optional[datetime] = Field(None, description="结束时间")
|
||||
keyword: Optional[str] = Field(None, description="关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
class OperationLogStatistics(BaseModel):
|
||||
"""操作日志统计Schema"""
|
||||
total_count: int = Field(..., description="总操作次数")
|
||||
success_count: int = Field(..., description="成功次数")
|
||||
failed_count: int = Field(..., description="失败次数")
|
||||
today_count: int = Field(..., description="今日操作次数")
|
||||
module_distribution: List[Dict[str, Any]] = Field(default_factory=list, description="模块分布")
|
||||
operation_distribution: List[Dict[str, Any]] = Field(default_factory=list, description="操作类型分布")
|
||||
|
||||
|
||||
class OperationLogExport(BaseModel):
|
||||
"""操作日志导出Schema"""
|
||||
start_time: Optional[datetime] = Field(None, description="开始时间")
|
||||
end_time: Optional[datetime] = Field(None, description="结束时间")
|
||||
operator_id: Optional[int] = Field(None, description="操作人ID")
|
||||
module: Optional[str] = Field(None, description="模块名称")
|
||||
operation_type: Optional[str] = Field(None, description="操作类型")
|
||||
80
backend_new/app/schemas/organization.py
Normal file
80
backend_new/app/schemas/organization.py
Normal file
@@ -0,0 +1,80 @@
|
||||
"""
|
||||
机构网点相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 机构网点Schema =====
|
||||
|
||||
class OrganizationBase(BaseModel):
|
||||
"""机构基础Schema"""
|
||||
org_code: str = Field(..., min_length=1, max_length=50, description="机构代码")
|
||||
org_name: str = Field(..., min_length=1, max_length=200, description="机构名称")
|
||||
org_type: str = Field(..., pattern="^(province|city|outlet)$", description="机构类型")
|
||||
parent_id: Optional[int] = Field(None, description="父机构ID")
|
||||
address: Optional[str] = Field(None, max_length=500, description="地址")
|
||||
contact_person: Optional[str] = Field(None, max_length=100, description="联系人")
|
||||
contact_phone: Optional[str] = Field(None, max_length=20, description="联系电话")
|
||||
sort_order: int = Field(default=0, description="排序")
|
||||
|
||||
|
||||
class OrganizationCreate(OrganizationBase):
|
||||
"""创建机构Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class OrganizationUpdate(BaseModel):
|
||||
"""更新机构Schema"""
|
||||
org_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
org_type: Optional[str] = Field(None, pattern="^(province|city|outlet)$")
|
||||
parent_id: Optional[int] = None
|
||||
address: Optional[str] = Field(None, max_length=500)
|
||||
contact_person: Optional[str] = Field(None, max_length=100)
|
||||
contact_phone: Optional[str] = Field(None, max_length=20)
|
||||
status: Optional[str] = Field(None, pattern="^(active|inactive)$")
|
||||
sort_order: Optional[int] = None
|
||||
|
||||
|
||||
class OrganizationInDB(BaseModel):
|
||||
"""数据库中的机构Schema"""
|
||||
id: int
|
||||
org_code: str
|
||||
org_name: str
|
||||
org_type: str
|
||||
parent_id: Optional[int]
|
||||
tree_path: Optional[str]
|
||||
tree_level: int
|
||||
address: Optional[str]
|
||||
contact_person: Optional[str]
|
||||
contact_phone: Optional[str]
|
||||
status: str
|
||||
sort_order: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class OrganizationResponse(OrganizationInDB):
|
||||
"""机构响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class OrganizationTreeNode(OrganizationResponse):
|
||||
"""机构树节点Schema"""
|
||||
children: List["OrganizationTreeNode"] = []
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class OrganizationWithParent(OrganizationResponse):
|
||||
"""带父机构信息的Schema"""
|
||||
parent: Optional[OrganizationResponse] = None
|
||||
|
||||
|
||||
# 更新前向引用
|
||||
OrganizationTreeNode.model_rebuild()
|
||||
118
backend_new/app/schemas/recovery.py
Normal file
118
backend_new/app/schemas/recovery.py
Normal file
@@ -0,0 +1,118 @@
|
||||
"""
|
||||
资产回收相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 回收单Schema =====
|
||||
|
||||
class AssetRecoveryOrderBase(BaseModel):
|
||||
"""回收单基础Schema"""
|
||||
recovery_type: str = Field(..., description="回收类型(user=使用人回收/org=机构回收/scrap=报废回收)")
|
||||
title: str = Field(..., min_length=1, max_length=200, description="标题")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetRecoveryOrderCreate(AssetRecoveryOrderBase):
|
||||
"""创建回收单Schema"""
|
||||
asset_ids: List[int] = Field(..., min_items=1, description="资产ID列表")
|
||||
|
||||
|
||||
class AssetRecoveryOrderUpdate(BaseModel):
|
||||
"""更新回收单Schema"""
|
||||
title: Optional[str] = Field(None, min_length=1, max_length=200, description="标题")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetRecoveryOrderInDB(BaseModel):
|
||||
"""数据库中的回收单Schema"""
|
||||
id: int
|
||||
order_code: str
|
||||
recovery_type: str
|
||||
title: str
|
||||
asset_count: int
|
||||
apply_user_id: int
|
||||
apply_time: datetime
|
||||
approval_status: str
|
||||
approval_user_id: Optional[int]
|
||||
approval_time: Optional[datetime]
|
||||
approval_remark: Optional[str]
|
||||
execute_status: str
|
||||
execute_user_id: Optional[int]
|
||||
execute_time: Optional[datetime]
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AssetRecoveryOrderResponse(AssetRecoveryOrderInDB):
|
||||
"""回收单响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class AssetRecoveryOrderWithRelations(AssetRecoveryOrderResponse):
|
||||
"""带关联信息的回收单响应Schema"""
|
||||
apply_user: Optional[Dict[str, Any]] = None
|
||||
approval_user: Optional[Dict[str, Any]] = None
|
||||
execute_user: Optional[Dict[str, Any]] = None
|
||||
items: Optional[List[Dict[str, Any]]] = None
|
||||
|
||||
|
||||
class AssetRecoveryOrderQueryParams(BaseModel):
|
||||
"""回收单查询参数"""
|
||||
recovery_type: Optional[str] = Field(None, description="回收类型")
|
||||
approval_status: Optional[str] = Field(None, description="审批状态")
|
||||
execute_status: Optional[str] = Field(None, description="执行状态")
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
class AssetRecoveryOrderListResponse(BaseModel):
|
||||
"""回收单列表响应Schema"""
|
||||
total: int
|
||||
page: int
|
||||
page_size: int
|
||||
total_pages: int
|
||||
items: List[AssetRecoveryOrderWithRelations]
|
||||
|
||||
|
||||
class AssetRecoveryStatistics(BaseModel):
|
||||
"""回收单统计Schema"""
|
||||
total: int = Field(..., description="总数")
|
||||
pending: int = Field(..., description="待审批数")
|
||||
approved: int = Field(..., description="已审批数")
|
||||
rejected: int = Field(..., description="已拒绝数")
|
||||
executing: int = Field(..., description="执行中数")
|
||||
completed: int = Field(..., description="已完成数")
|
||||
|
||||
|
||||
# ===== 回收单明细Schema =====
|
||||
|
||||
class AssetRecoveryItemBase(BaseModel):
|
||||
"""回收单明细基础Schema"""
|
||||
asset_id: int = Field(..., gt=0, description="资产ID")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetRecoveryItemInDB(BaseModel):
|
||||
"""数据库中的回收单明细Schema"""
|
||||
id: int
|
||||
order_id: int
|
||||
asset_id: int
|
||||
asset_code: str
|
||||
recovery_status: str
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AssetRecoveryItemResponse(AssetRecoveryItemInDB):
|
||||
"""回收单明细响应Schema"""
|
||||
pass
|
||||
108
backend_new/app/schemas/statistics.py
Normal file
108
backend_new/app/schemas/statistics.py
Normal file
@@ -0,0 +1,108 @@
|
||||
"""
|
||||
统计分析相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime, date
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class StatisticsOverview(BaseModel):
|
||||
"""总览统计Schema"""
|
||||
total_assets: int = Field(..., description="资产总数")
|
||||
total_value: Decimal = Field(..., description="资产总价值")
|
||||
in_stock_count: int = Field(..., description="库存中数量")
|
||||
in_use_count: int = Field(..., description="使用中数量")
|
||||
maintenance_count: int = Field(..., description="维修中数量")
|
||||
scrapped_count: int = Field(..., description="已报废数量")
|
||||
today_purchase_count: int = Field(..., description="今日采购数量")
|
||||
this_month_purchase_count: int = Field(..., description="本月采购数量")
|
||||
organization_count: int = Field(..., description="机构网点数")
|
||||
supplier_count: int = Field(..., description="供应商数")
|
||||
|
||||
|
||||
class PurchaseStatistics(BaseModel):
|
||||
"""采购统计Schema"""
|
||||
total_purchase_count: int = Field(..., description="总采购数量")
|
||||
total_purchase_value: Decimal = Field(..., description="总采购金额")
|
||||
monthly_trend: List[Dict[str, Any]] = Field(default_factory=list, description="月度趋势")
|
||||
supplier_distribution: List[Dict[str, Any]] = Field(default_factory=list, description="供应商分布")
|
||||
category_distribution: List[Dict[str, Any]] = Field(default_factory=list, description="分类分布")
|
||||
|
||||
|
||||
class DepreciationStatistics(BaseModel):
|
||||
"""折旧统计Schema"""
|
||||
total_depreciation_value: Decimal = Field(..., description="总折旧金额")
|
||||
average_depreciation_rate: Decimal = Field(..., description="平均折旧率")
|
||||
depreciation_by_category: List[Dict[str, Any]] = Field(default_factory=list, description="分类折旧")
|
||||
assets_near_end_life: List[Dict[str, Any]] = Field(default_factory=list, description="接近使用年限的资产")
|
||||
|
||||
|
||||
class ValueStatistics(BaseModel):
|
||||
"""价值统计Schema"""
|
||||
total_value: Decimal = Field(..., description="资产总价值")
|
||||
net_value: Decimal = Field(..., description="资产净值")
|
||||
depreciation_value: Decimal = Field(..., description="累计折旧")
|
||||
value_by_category: List[Dict[str, Any]] = Field(default_factory=list, description="分类价值")
|
||||
value_by_organization: List[Dict[str, Any]] = Field(default_factory=list, description="网点价值")
|
||||
high_value_assets: List[Dict[str, Any]] = Field(default_factory=list, description="高价值资产")
|
||||
|
||||
|
||||
class TrendAnalysis(BaseModel):
|
||||
"""趋势分析Schema"""
|
||||
asset_trend: List[Dict[str, Any]] = Field(default_factory=list, description="资产数量趋势")
|
||||
value_trend: List[Dict[str, Any]] = Field(default_factory=list, description="资产价值趋势")
|
||||
purchase_trend: List[Dict[str, Any]] = Field(default_factory=list, description="采购趋势")
|
||||
maintenance_trend: List[Dict[str, Any]] = Field(default_factory=list, description="维修趋势")
|
||||
allocation_trend: List[Dict[str, Any]] = Field(default_factory=list, description="调拨趋势")
|
||||
|
||||
|
||||
class MaintenanceStatistics(BaseModel):
|
||||
"""维修统计Schema"""
|
||||
total_maintenance_count: int = Field(..., description="总维修次数")
|
||||
total_maintenance_cost: Decimal = Field(..., description="总维修费用")
|
||||
pending_count: int = Field(..., description="待维修数量")
|
||||
in_progress_count: int = Field(..., description="维修中数量")
|
||||
completed_count: int = Field(..., description="已完成数量")
|
||||
monthly_trend: List[Dict[str, Any]] = Field(default_factory=list, description="月度趋势")
|
||||
type_distribution: List[Dict[str, Any]] = Field(default_factory=list, description="维修类型分布")
|
||||
cost_by_category: List[Dict[str, Any]] = Field(default_factory=list, description="分类维修费用")
|
||||
|
||||
|
||||
class AllocationStatistics(BaseModel):
|
||||
"""分配统计Schema"""
|
||||
total_allocation_count: int = Field(..., description="总分配次数")
|
||||
pending_count: int = Field(..., description="待审批数量")
|
||||
approved_count: int = Field(..., description="已批准数量")
|
||||
rejected_count: int = Field(..., description="已拒绝数量")
|
||||
monthly_trend: List[Dict[str, Any]] = Field(default_factory=list, description="月度趋势")
|
||||
by_organization: List[Dict[str, Any]] = Field(default_factory=list, description="网点分配统计")
|
||||
transfer_statistics: List[Dict[str, Any]] = Field(default_factory=list, description="调拨统计")
|
||||
|
||||
|
||||
class StatisticsQueryParams(BaseModel):
|
||||
"""统计查询参数"""
|
||||
start_date: Optional[date] = Field(None, description="开始日期")
|
||||
end_date: Optional[date] = Field(None, description="结束日期")
|
||||
organization_id: Optional[int] = Field(None, description="网点ID")
|
||||
device_type_id: Optional[int] = Field(None, description="设备类型ID")
|
||||
group_by: Optional[str] = Field(None, description="分组字段")
|
||||
|
||||
|
||||
class ExportStatisticsRequest(BaseModel):
|
||||
"""导出统计请求"""
|
||||
report_type: str = Field(..., description="报表类型")
|
||||
start_date: Optional[date] = Field(None, description="开始日期")
|
||||
end_date: Optional[date] = Field(None, description="结束日期")
|
||||
organization_id: Optional[int] = Field(None, description="网点ID")
|
||||
device_type_id: Optional[int] = Field(None, description="设备类型ID")
|
||||
format: str = Field(default="xlsx", description="导出格式")
|
||||
include_charts: bool = Field(default=False, description="是否包含图表")
|
||||
|
||||
|
||||
class ExportStatisticsResponse(BaseModel):
|
||||
"""导出统计响应"""
|
||||
file_url: str = Field(..., description="文件URL")
|
||||
file_name: str = Field(..., description="文件名")
|
||||
file_size: int = Field(..., description="文件大小(字节)")
|
||||
record_count: int = Field(..., description="记录数量")
|
||||
102
backend_new/app/schemas/system_config.py
Normal file
102
backend_new/app/schemas/system_config.py
Normal file
@@ -0,0 +1,102 @@
|
||||
"""
|
||||
系统配置相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ValueTypeEnum(str, Enum):
|
||||
"""配置值类型枚举"""
|
||||
STRING = "string"
|
||||
NUMBER = "number"
|
||||
BOOLEAN = "boolean"
|
||||
JSON = "json"
|
||||
|
||||
|
||||
class SystemConfigBase(BaseModel):
|
||||
"""系统配置基础Schema"""
|
||||
config_key: str = Field(..., min_length=1, max_length=100, description="配置键")
|
||||
config_name: str = Field(..., min_length=1, max_length=200, description="配置名称")
|
||||
config_value: Optional[str] = Field(None, description="配置值")
|
||||
value_type: ValueTypeEnum = Field(default=ValueTypeEnum.STRING, description="值类型")
|
||||
category: str = Field(..., min_length=1, max_length=50, description="配置分类")
|
||||
description: Optional[str] = Field(None, description="配置描述")
|
||||
is_system: bool = Field(default=False, description="是否系统配置")
|
||||
is_encrypted: bool = Field(default=False, description="是否加密存储")
|
||||
validation_rule: Optional[str] = Field(None, description="验证规则")
|
||||
options: Optional[Dict[str, Any]] = Field(None, description="可选值配置")
|
||||
default_value: Optional[str] = Field(None, description="默认值")
|
||||
sort_order: int = Field(default=0, description="排序序号")
|
||||
is_active: bool = Field(default=True, description="是否启用")
|
||||
|
||||
|
||||
class SystemConfigCreate(SystemConfigBase):
|
||||
"""创建系统配置Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class SystemConfigUpdate(BaseModel):
|
||||
"""更新系统配置Schema"""
|
||||
config_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
config_value: Optional[str] = None
|
||||
value_type: Optional[ValueTypeEnum] = None
|
||||
category: Optional[str] = Field(None, min_length=1, max_length=50)
|
||||
description: Optional[str] = None
|
||||
validation_rule: Optional[str] = None
|
||||
options: Optional[Dict[str, Any]] = None
|
||||
default_value: Optional[str] = None
|
||||
sort_order: Optional[int] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class SystemConfigInDB(BaseModel):
|
||||
"""数据库中的系统配置Schema"""
|
||||
id: int
|
||||
config_key: str
|
||||
config_name: str
|
||||
config_value: Optional[str]
|
||||
value_type: str
|
||||
category: str
|
||||
description: Optional[str]
|
||||
is_system: bool
|
||||
is_encrypted: bool
|
||||
validation_rule: Optional[str]
|
||||
options: Optional[Dict[str, Any]]
|
||||
default_value: Optional[str]
|
||||
sort_order: int
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
updated_by: Optional[int]
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class SystemConfigResponse(SystemConfigInDB):
|
||||
"""系统配置响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class SystemConfigBatchUpdate(BaseModel):
|
||||
"""批量更新配置Schema"""
|
||||
configs: Dict[str, Any] = Field(..., description="配置键值对")
|
||||
|
||||
|
||||
class SystemConfigQueryParams(BaseModel):
|
||||
"""系统配置查询参数"""
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
category: Optional[str] = Field(None, description="配置分类")
|
||||
is_active: Optional[bool] = Field(None, description="是否启用")
|
||||
is_system: Optional[bool] = Field(None, description="是否系统配置")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
class ConfigCategoryResponse(BaseModel):
|
||||
"""配置分类响应Schema"""
|
||||
category: str = Field(..., description="分类名称")
|
||||
count: int = Field(..., description="配置数量")
|
||||
description: Optional[str] = Field(None, description="分类描述")
|
||||
138
backend_new/app/schemas/transfer.py
Normal file
138
backend_new/app/schemas/transfer.py
Normal file
@@ -0,0 +1,138 @@
|
||||
"""
|
||||
资产调拨相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ===== 调拨单Schema =====
|
||||
|
||||
class AssetTransferOrderBase(BaseModel):
|
||||
"""调拨单基础Schema"""
|
||||
source_org_id: int = Field(..., gt=0, description="调出网点ID")
|
||||
target_org_id: int = Field(..., gt=0, description="调入网点ID")
|
||||
transfer_type: str = Field(..., description="调拨类型(internal=内部调拨/external=跨机构调拨)")
|
||||
title: str = Field(..., min_length=1, max_length=200, description="标题")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetTransferOrderCreate(AssetTransferOrderBase):
|
||||
"""创建调拨单Schema"""
|
||||
asset_ids: List[int] = Field(..., min_items=1, description="资产ID列表")
|
||||
|
||||
|
||||
class AssetTransferOrderUpdate(BaseModel):
|
||||
"""更新调拨单Schema"""
|
||||
title: Optional[str] = Field(None, min_length=1, max_length=200, description="标题")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetTransferOrderStart(BaseModel):
|
||||
"""开始调拨Schema"""
|
||||
remark: Optional[str] = Field(None, description="开始备注")
|
||||
|
||||
|
||||
class AssetTransferOrderComplete(BaseModel):
|
||||
"""完成调拨Schema"""
|
||||
remark: Optional[str] = Field(None, description="完成备注")
|
||||
|
||||
|
||||
class AssetTransferOrderInDB(BaseModel):
|
||||
"""数据库中的调拨单Schema"""
|
||||
id: int
|
||||
order_code: str
|
||||
source_org_id: int
|
||||
target_org_id: int
|
||||
transfer_type: str
|
||||
title: str
|
||||
asset_count: int
|
||||
apply_user_id: int
|
||||
apply_time: datetime
|
||||
approval_status: str
|
||||
approval_user_id: Optional[int]
|
||||
approval_time: Optional[datetime]
|
||||
approval_remark: Optional[str]
|
||||
execute_status: str
|
||||
execute_user_id: Optional[int]
|
||||
execute_time: Optional[datetime]
|
||||
remark: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AssetTransferOrderResponse(AssetTransferOrderInDB):
|
||||
"""调拨单响应Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class AssetTransferOrderWithRelations(AssetTransferOrderResponse):
|
||||
"""带关联信息的调拨单响应Schema"""
|
||||
source_organization: Optional[Dict[str, Any]] = None
|
||||
target_organization: Optional[Dict[str, Any]] = None
|
||||
apply_user: Optional[Dict[str, Any]] = None
|
||||
approval_user: Optional[Dict[str, Any]] = None
|
||||
execute_user: Optional[Dict[str, Any]] = None
|
||||
items: Optional[List[Dict[str, Any]]] = None
|
||||
|
||||
|
||||
class AssetTransferOrderQueryParams(BaseModel):
|
||||
"""调拨单查询参数"""
|
||||
transfer_type: Optional[str] = Field(None, description="调拨类型")
|
||||
approval_status: Optional[str] = Field(None, description="审批状态")
|
||||
execute_status: Optional[str] = Field(None, description="执行状态")
|
||||
source_org_id: Optional[int] = Field(None, gt=0, description="调出网点ID")
|
||||
target_org_id: Optional[int] = Field(None, gt=0, description="调入网点ID")
|
||||
keyword: Optional[str] = Field(None, description="搜索关键词")
|
||||
page: int = Field(default=1, ge=1, description="页码")
|
||||
page_size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
||||
|
||||
|
||||
class AssetTransferOrderListResponse(BaseModel):
|
||||
"""调拨单列表响应Schema"""
|
||||
total: int
|
||||
page: int
|
||||
page_size: int
|
||||
total_pages: int
|
||||
items: List[AssetTransferOrderWithRelations]
|
||||
|
||||
|
||||
class AssetTransferStatistics(BaseModel):
|
||||
"""调拨单统计Schema"""
|
||||
total: int = Field(..., description="总数")
|
||||
pending: int = Field(..., description="待审批数")
|
||||
approved: int = Field(..., description="已审批数")
|
||||
rejected: int = Field(..., description="已拒绝数")
|
||||
executing: int = Field(..., description="执行中数")
|
||||
completed: int = Field(..., description="已完成数")
|
||||
|
||||
|
||||
# ===== 调拨单明细Schema =====
|
||||
|
||||
class AssetTransferItemBase(BaseModel):
|
||||
"""调拨单明细基础Schema"""
|
||||
asset_id: int = Field(..., gt=0, description="资产ID")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
class AssetTransferItemInDB(BaseModel):
|
||||
"""数据库中的调拨单明细Schema"""
|
||||
id: int
|
||||
order_id: int
|
||||
asset_id: int
|
||||
asset_code: str
|
||||
source_organization_id: int
|
||||
target_organization_id: int
|
||||
transfer_status: str
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class AssetTransferItemResponse(AssetTransferItemInDB):
|
||||
"""调拨单明细响应Schema"""
|
||||
pass
|
||||
231
backend_new/app/schemas/user.py
Normal file
231
backend_new/app/schemas/user.py
Normal file
@@ -0,0 +1,231 @@
|
||||
"""
|
||||
用户相关的Pydantic Schema
|
||||
"""
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field, EmailStr, field_validator
|
||||
|
||||
|
||||
# ===== 用户Schema =====
|
||||
|
||||
class UserBase(BaseModel):
|
||||
"""用户基础Schema"""
|
||||
real_name: str = Field(..., min_length=1, max_length=100, description="真实姓名")
|
||||
email: Optional[EmailStr] = Field(None, description="邮箱")
|
||||
phone: Optional[str] = Field(None, max_length=20, description="手机号")
|
||||
|
||||
|
||||
class UserCreate(UserBase):
|
||||
"""创建用户Schema"""
|
||||
username: str = Field(..., min_length=4, max_length=50, description="用户名")
|
||||
password: str = Field(..., min_length=8, max_length=100, description="密码")
|
||||
role_ids: List[int] = Field(..., min_items=1, description="角色ID列表")
|
||||
|
||||
@field_validator("username")
|
||||
@classmethod
|
||||
def validate_username(cls, v: str) -> str:
|
||||
"""验证用户名格式"""
|
||||
if not v.replace("_", "").isalnum():
|
||||
raise ValueError("用户名只能包含字母、数字和下划线")
|
||||
return v
|
||||
|
||||
@field_validator("password")
|
||||
@classmethod
|
||||
def validate_password(cls, v: str) -> str:
|
||||
"""验证密码强度"""
|
||||
if not any(c.isupper() for c in v):
|
||||
raise ValueError("密码必须包含至少一个大写字母")
|
||||
if not any(c.islower() for c in v):
|
||||
raise ValueError("密码必须包含至少一个小写字母")
|
||||
if not any(c.isdigit() for c in v):
|
||||
raise ValueError("密码必须包含至少一个数字")
|
||||
return v
|
||||
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
"""更新用户Schema"""
|
||||
real_name: Optional[str] = Field(None, min_length=1, max_length=100)
|
||||
email: Optional[EmailStr] = None
|
||||
phone: Optional[str] = Field(None, max_length=20)
|
||||
status: Optional[str] = Field(None, pattern="^(active|disabled|locked)$")
|
||||
role_ids: Optional[List[int]] = None
|
||||
|
||||
|
||||
class UserInDB(BaseModel):
|
||||
"""数据库中的用户Schema"""
|
||||
id: int
|
||||
username: str
|
||||
real_name: str
|
||||
email: Optional[str]
|
||||
phone: Optional[str]
|
||||
avatar_url: Optional[str]
|
||||
status: str
|
||||
is_admin: bool
|
||||
last_login_at: Optional[datetime]
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class UserResponse(UserInDB):
|
||||
"""用户响应Schema"""
|
||||
roles: List["RoleResponse"] = []
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class UserInfo(BaseModel):
|
||||
"""用户信息Schema(不含敏感信息)"""
|
||||
id: int
|
||||
username: str
|
||||
real_name: str
|
||||
email: Optional[str]
|
||||
avatar_url: Optional[str]
|
||||
is_admin: bool
|
||||
status: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# ===== 登录认证Schema =====
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
"""登录请求Schema"""
|
||||
username: str = Field(..., min_length=1, description="用户名")
|
||||
password: str = Field(..., min_length=1, description="密码")
|
||||
captcha: str = Field(..., min_length=4, description="验证码")
|
||||
captcha_key: str = Field(..., description="验证码UUID")
|
||||
|
||||
|
||||
class LoginResponse(BaseModel):
|
||||
"""登录响应Schema"""
|
||||
access_token: str = Field(..., description="访问令牌")
|
||||
refresh_token: str = Field(..., description="刷新令牌")
|
||||
token_type: str = Field(default="Bearer", description="令牌类型")
|
||||
expires_in: int = Field(..., description="过期时间(秒)")
|
||||
user: UserInfo = Field(..., description="用户信息")
|
||||
|
||||
|
||||
class RefreshTokenRequest(BaseModel):
|
||||
"""刷新令牌请求Schema"""
|
||||
refresh_token: str = Field(..., description="刷新令牌")
|
||||
|
||||
|
||||
class RefreshTokenResponse(BaseModel):
|
||||
"""刷新令牌响应Schema"""
|
||||
access_token: str = Field(..., description="新的访问令牌")
|
||||
expires_in: int = Field(..., description="过期时间(秒)")
|
||||
|
||||
|
||||
class ChangePasswordRequest(BaseModel):
|
||||
"""修改密码请求Schema"""
|
||||
old_password: str = Field(..., min_length=1, description="旧密码")
|
||||
new_password: str = Field(..., min_length=8, max_length=100, description="新密码")
|
||||
confirm_password: str = Field(..., min_length=8, max_length=100, description="确认密码")
|
||||
|
||||
@field_validator("confirm_password")
|
||||
@classmethod
|
||||
def validate_passwords_match(cls, v: str, info) -> str:
|
||||
"""验证两次密码是否一致"""
|
||||
if "new_password" in info.data and v != info.data["new_password"]:
|
||||
raise ValueError("两次输入的密码不一致")
|
||||
return v
|
||||
|
||||
|
||||
class ResetPasswordRequest(BaseModel):
|
||||
"""重置密码请求Schema"""
|
||||
new_password: str = Field(..., min_length=8, max_length=100, description="新密码")
|
||||
|
||||
|
||||
# ===== 角色Schema =====
|
||||
|
||||
class RoleBase(BaseModel):
|
||||
"""角色基础Schema"""
|
||||
role_name: str = Field(..., min_length=1, max_length=50, description="角色名称")
|
||||
role_code: str = Field(..., min_length=1, max_length=50, description="角色代码")
|
||||
description: Optional[str] = Field(None, description="角色描述")
|
||||
|
||||
|
||||
class RoleCreate(RoleBase):
|
||||
"""创建角色Schema"""
|
||||
permission_ids: List[int] = Field(default_factory=list, description="权限ID列表")
|
||||
|
||||
|
||||
class RoleUpdate(BaseModel):
|
||||
"""更新角色Schema"""
|
||||
role_name: Optional[str] = Field(None, min_length=1, max_length=50)
|
||||
description: Optional[str] = None
|
||||
permission_ids: Optional[List[int]] = None
|
||||
|
||||
|
||||
class RoleInDB(BaseModel):
|
||||
"""数据库中的角色Schema"""
|
||||
id: int
|
||||
role_name: str
|
||||
role_code: str
|
||||
description: Optional[str]
|
||||
status: str
|
||||
sort_order: int
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class RoleResponse(RoleInDB):
|
||||
"""角色响应Schema"""
|
||||
permissions: List["PermissionResponse"] = []
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class RoleWithUserCount(RoleResponse):
|
||||
"""带用户数量的角色响应Schema"""
|
||||
user_count: int = Field(..., description="用户数量")
|
||||
|
||||
|
||||
# ===== 权限Schema =====
|
||||
|
||||
class PermissionBase(BaseModel):
|
||||
"""权限基础Schema"""
|
||||
permission_name: str = Field(..., min_length=1, max_length=100)
|
||||
permission_code: str = Field(..., min_length=1, max_length=100)
|
||||
module: str = Field(..., min_length=1, max_length=50)
|
||||
resource: Optional[str] = Field(None, max_length=50)
|
||||
action: Optional[str] = Field(None, max_length=50)
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
class PermissionCreate(PermissionBase):
|
||||
"""创建权限Schema"""
|
||||
pass
|
||||
|
||||
|
||||
class PermissionUpdate(BaseModel):
|
||||
"""更新权限Schema"""
|
||||
permission_name: Optional[str] = Field(None, min_length=1, max_length=100)
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
class PermissionResponse(PermissionBase):
|
||||
"""权限响应Schema"""
|
||||
id: int
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class PermissionTreeNode(PermissionResponse):
|
||||
"""权限树节点Schema"""
|
||||
children: List["PermissionTreeNode"] = []
|
||||
|
||||
|
||||
# 更新前向引用
|
||||
UserResponse.model_rebuild()
|
||||
RoleResponse.model_rebuild()
|
||||
PermissionTreeNode.model_rebuild()
|
||||
Reference in New Issue
Block a user