feat(phase4): 全部业务模块迁移到 modules/(结构迁移)
- 21 个模块目录(auth/system/dictionary/configuration/cms/member/region/link/notice/job/log/upload/index) - 每个模块 router.py(合并模块导出多个 router)/schemas.py/service.py/repository.py/models.py - routers/v1.py 与 routers/__init__.py 改为直接引用 modules,前缀与权限串原样保留 - core/middleware.py 懒加载指向 modules.system.menu / modules.log;core/redis_client.py 指向 modules.job.scheduler - apps/views|services|forms 全部改为 re-export 垫片 - 迁移后 grep 守门通过:modules/core 无 apps/extensions 残留引用 - 实测登录、27+ 模块接口、写操作 commit、操作日志落库均正常 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+2
-114
@@ -1,114 +1,2 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from fastapi.logger import logger
|
||||
from sqlalchemy import and_
|
||||
|
||||
from apps.forms.dept import DeptForm
|
||||
from apps.models.dept import Dept
|
||||
from extensions import get_db_session
|
||||
from utils import R
|
||||
|
||||
from utils.security import get_user_id
|
||||
from utils.request import like_contains, parse_id_list
|
||||
|
||||
|
||||
# 查询部门数据
|
||||
|
||||
def get_dept_page(request):
|
||||
db = get_db_session()
|
||||
# 实例化查询对象
|
||||
query = db.query(Dept).filter(Dept.is_delete == 0)
|
||||
# 部门名称
|
||||
name = request.query_params.get('name')
|
||||
if name:
|
||||
# 部门名称模糊查询
|
||||
query = query.filter(Dept.name.like(like_contains(name), escape='\\'))
|
||||
# 查询数据
|
||||
dept_list = query.order_by(Dept.sort.asc()).all()
|
||||
# 实例化数组对象
|
||||
result = []
|
||||
# 遍历数据源
|
||||
if dept_list:
|
||||
for item in dept_list:
|
||||
# 对象转字典
|
||||
data = item.to_dict()
|
||||
# 加入列表
|
||||
result.append(data)
|
||||
# 返回结果
|
||||
return R.ok(data=result)
|
||||
# 根据ID查询部门
|
||||
|
||||
def get_dept_detail(dept_id):
|
||||
db = get_db_session()
|
||||
# 根据ID查询部门
|
||||
dept = db.query(Dept).filter(and_(Dept.id == dept_id, Dept.is_delete == 0)).first()
|
||||
# 查询结果判空
|
||||
if not dept:
|
||||
return None
|
||||
# 对象转字典
|
||||
data = dept.to_dict()
|
||||
# 返回结果
|
||||
return data
|
||||
# 添加部门
|
||||
|
||||
def add_dept(request, data: DeptForm):
|
||||
db = get_db_session()
|
||||
# 唯一性校验
|
||||
if db.query(Dept).filter(and_(Dept.name == data.name, Dept.is_delete == 0)).first():
|
||||
return R.failed("部门名称不能重复")
|
||||
# 表单数据赋值给对象
|
||||
dept = Dept(**data.model_dump(exclude={'id'}))
|
||||
dept.create_user = get_user_id(request)
|
||||
# 插入数据
|
||||
dept.save()
|
||||
# 返回结果
|
||||
return R.ok(msg="添加成功")
|
||||
|
||||
|
||||
# 更新部门
|
||||
|
||||
def update_dept(request, data: DeptForm):
|
||||
db = get_db_session()
|
||||
# 记录ID判空
|
||||
if not data.id or data.id <= 0:
|
||||
return R.failed("记录ID不能为空")
|
||||
# 唯一性校验(排除自身)
|
||||
if db.query(Dept).filter(and_(Dept.name == data.name, Dept.id != data.id, Dept.is_delete == 0)).first():
|
||||
return R.failed("部门名称不能重复")
|
||||
|
||||
# 根据ID查询记录
|
||||
dept = db.query(Dept).filter(and_(Dept.id == data.id, Dept.is_delete == 0)).first()
|
||||
# 查询结果判空
|
||||
if not dept:
|
||||
return R.failed("记录不存在")
|
||||
# 构造更新数据(排除 id)
|
||||
updData = data.model_dump(exclude={'id'})
|
||||
updData['update_user'] = get_user_id(request)
|
||||
updData['update_time'] = datetime.now(tz=timezone.utc)
|
||||
result = db.query(Dept).filter_by(id=data.id).update(updData)
|
||||
# 提交数据
|
||||
if not result:
|
||||
return R.failed("更新失败")
|
||||
# 返回结果
|
||||
return R.ok(msg="更新成功")
|
||||
# 删除部门
|
||||
|
||||
def delete_dept(dept_id):
|
||||
return Dept.batch_delete_r(dept_id)
|
||||
# 获取部门列表
|
||||
|
||||
def get_dept_list():
|
||||
db = get_db_session()
|
||||
# 查询部门数据列表
|
||||
dept_rows = db.query(Dept).filter(Dept.is_delete == 0).order_by(Dept.sort.asc()).all()
|
||||
# 实例化列表
|
||||
dept_list = []
|
||||
# 遍历数据源
|
||||
if dept_rows:
|
||||
for v in dept_rows:
|
||||
# 对象转字典
|
||||
item = v.to_dict()
|
||||
# 加入数组
|
||||
dept_list.append(item)
|
||||
# 返回结果
|
||||
return dept_list
|
||||
# 兼容垫片:由 modules.system.dept.service 迁移
|
||||
from modules.system.dept.service import * # noqa: F401,F403
|
||||
|
||||
Reference in New Issue
Block a user