- 修复前端路由守卫:未登录时不显示提示,直接跳转登录页 - 修复API拦截器:401错误不显示提示,直接跳转 - 增强验证码显示:图片尺寸从120x40增加到200x80 - 增大验证码字体:从28号增加到48号 - 优化验证码字符:排除易混淆的0和1 - 减少干扰线:从5条减少到3条,添加背景色优化 - 增强登录API日志:添加详细的调试日志 - 增强验证码生成和验证日志 - 优化异常处理和错误追踪 影响文件: - src/router/index.ts - src/api/request.ts - app/services/auth_service.py - app/api/v1/auth.py - app/schemas/user.py 测试状态: - 前端构建通过 - 后端语法检查通过 - 验证码显示效果优化完成 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
135 lines
3.5 KiB
Python
135 lines
3.5 KiB
Python
"""
|
|
品牌和供应商业务服务层
|
|
"""
|
|
from typing import List, Optional, Tuple
|
|
from sqlalchemy.orm import Session
|
|
from app.crud.brand_supplier import brand, supplier
|
|
from app.schemas.brand_supplier import (
|
|
BrandCreate,
|
|
BrandUpdate,
|
|
SupplierCreate,
|
|
SupplierUpdate
|
|
)
|
|
from app.core.exceptions import NotFoundException, AlreadyExistsException
|
|
|
|
|
|
class BrandService:
|
|
"""品牌服务类"""
|
|
|
|
def get_brand(self, db: Session, brand_id: int):
|
|
"""获取品牌详情"""
|
|
obj = brand.get(db, brand_id)
|
|
if not obj:
|
|
raise NotFoundException("品牌")
|
|
return obj
|
|
|
|
def get_brands(
|
|
self,
|
|
db: Session,
|
|
skip: int = 0,
|
|
limit: int = 20,
|
|
status: Optional[str] = None,
|
|
keyword: Optional[str] = None
|
|
) -> Tuple[List, int]:
|
|
"""获取品牌列表"""
|
|
return brand.get_multi(db, skip, limit, status, keyword)
|
|
|
|
def create_brand(
|
|
self,
|
|
db: Session,
|
|
obj_in: BrandCreate,
|
|
creator_id: Optional[int] = None
|
|
):
|
|
"""创建品牌"""
|
|
try:
|
|
return brand.create(db, obj_in, creator_id)
|
|
except ValueError as e:
|
|
raise AlreadyExistsException("品牌") from e
|
|
|
|
def update_brand(
|
|
self,
|
|
db: Session,
|
|
brand_id: int,
|
|
obj_in: BrandUpdate,
|
|
updater_id: Optional[int] = None
|
|
):
|
|
"""更新品牌"""
|
|
db_obj = brand.get(db, brand_id)
|
|
if not db_obj:
|
|
raise NotFoundException("品牌")
|
|
return brand.update(db, db_obj, obj_in, updater_id)
|
|
|
|
def delete_brand(
|
|
self,
|
|
db: Session,
|
|
brand_id: int,
|
|
deleter_id: Optional[int] = None
|
|
) -> bool:
|
|
"""删除品牌"""
|
|
if not brand.get(db, brand_id):
|
|
raise NotFoundException("品牌")
|
|
return brand.delete(db, brand_id, deleter_id)
|
|
|
|
|
|
class SupplierService:
|
|
"""供应商服务类"""
|
|
|
|
def get_supplier(self, db: Session, supplier_id: int):
|
|
"""获取供应商详情"""
|
|
obj = supplier.get(db, supplier_id)
|
|
if not obj:
|
|
raise NotFoundException("供应商")
|
|
return obj
|
|
|
|
def get_suppliers(
|
|
self,
|
|
db: Session,
|
|
skip: int = 0,
|
|
limit: int = 20,
|
|
status: Optional[str] = None,
|
|
keyword: Optional[str] = None
|
|
) -> Tuple[List, int]:
|
|
"""获取供应商列表"""
|
|
return supplier.get_multi(db, skip, limit, status, keyword)
|
|
|
|
def create_supplier(
|
|
self,
|
|
db: Session,
|
|
obj_in: SupplierCreate,
|
|
creator_id: Optional[int] = None
|
|
):
|
|
"""创建供应商"""
|
|
try:
|
|
return supplier.create(db, obj_in, creator_id)
|
|
except ValueError as e:
|
|
raise AlreadyExistsException("供应商") from e
|
|
|
|
def update_supplier(
|
|
self,
|
|
db: Session,
|
|
supplier_id: int,
|
|
obj_in: SupplierUpdate,
|
|
updater_id: Optional[int] = None
|
|
):
|
|
"""更新供应商"""
|
|
db_obj = supplier.get(db, supplier_id)
|
|
if not db_obj:
|
|
raise NotFoundException("供应商")
|
|
return supplier.update(db, db_obj, obj_in, updater_id)
|
|
|
|
def delete_supplier(
|
|
self,
|
|
db: Session,
|
|
supplier_id: int,
|
|
deleter_id: Optional[int] = None
|
|
) -> bool:
|
|
"""删除供应商"""
|
|
if not supplier.get(db, supplier_id):
|
|
raise NotFoundException("供应商")
|
|
return supplier.delete(db, supplier_id, deleter_id)
|
|
|
|
|
|
# 创建全局实例
|
|
brand_service = BrandService()
|
|
supplier_service = SupplierService()
|