refactor: P3a 模型层迁入 src/modules/(22 模型)

- 19 个模块目录(system/association/cms/dictionary/configuration/log 等)
- 一对一 16 个 + 合并 3 组(dict+dict_item、config+config_item、login_log+operation_log)
- 重写模型 import:base_db/base_model→src.common、db→src.core.database、
  case_converter/rich_text/request→src.common.utils
- application/models/ 全部替换为 shim(指向 src.modules)
- src/models_registry.py 改为从 src.modules 全量导入

【修复】codemod 两处 bug:shim 与 registry 的 import 路径含斜杠(已改点分);
strip_license 误剥无许可头文件的 docstring 开头(log/models.py 已补回)

【验收】22 表全量识别;应用启动;pytest 5 passed

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DjangoAdmin Dev
2026-08-07 13:48:30 +08:00
co-authored by Claude
parent 658ee6d596
commit 6de4f3bef2
64 changed files with 3126 additions and 3399 deletions
+4 -191
View File
@@ -1,195 +1,8 @@
"""
操作日志模型模块
兼容 shim(绞杀者迁移期间保留)
=============================================================
提供操作日志管理的数据模型定义,用于记录用户操作行为日志。
模型已迁移至 src.modules.log.models。
本文件仅作兼容转发,最终在 P7(切尾)阶段删除。
"""
from application.models.base_db import BaseDB
from application.models.base_model import BaseModel
from config import DB_PREFIX
from extensions import db
from utils.case_converter import convert_camel_to_snake
# ============================================================
# 操作日志模型
# ============================================================
class OperationLog(BaseModel, BaseDB):
"""
操作日志模型
用于记录用户操作行为的详细信息,包括:操作标题、操作类型、
来源、请求信息、IP地址、归属地、设备信息、请求耗时、操作状态等。
Attributes:
id: 主键ID(继承自 BaseModel)
title: 请求标题(String(150),必填)
type: 请求类型(Integer,必填)
source: 请求来源(Integer,必填,0-后台,1-前台)
method: 请求方法(String(100),必填)
request_method: 请求方式(String(255),必填)
url: 请求URL(String(1000),必填)
param: 请求参数(Text,必填)
result: 请求结果(Text,必填)
ip: 请求IP(String(100),必填)
location: 请求所在区域(String(255),必填)
os: 操作系统(String(100),必填)
browser: 浏览器(String(100),必填)
consume_time: 请求耗时(Integer,必填,单位毫秒)
status: 请求状态(Integer,必填,0-正常,1-异常)
error: 错误描述(Text,必填)
"""
# ============================================================
# 表配置
# ============================================================
# 设置表名
__tablename__ = DB_PREFIX + "operation_log"
# ============================================================
# 字段定义
# ============================================================
# 请求标题
title = db.Column(
db.String(150),
nullable=False,
comment="请求标题"
)
# 请求类型
type = db.Column(
db.Integer,
nullable=False,
comment="请求类型"
)
# 请求来源:0-后台,1-前台
source = db.Column(
db.Integer,
nullable=False,
comment="请求来源:0-后台,1-前台"
)
# 请求方法(如:UserController.add)
method = db.Column(
db.String(100),
nullable=False,
comment="请求方法"
)
# 请求方式(如:GET、POST、PUT、DELETE)
request_method = db.Column(
db.String(255),
nullable=False,
comment="请求方式"
)
# 请求URL
url = db.Column(
db.String(1000),
nullable=False,
comment="请求URL"
)
# 请求参数
param = db.Column(
db.Text,
nullable=False,
comment="请求参数"
)
# 请求结果
result = db.Column(
db.Text,
nullable=False,
comment="请求结果"
)
# 请求IP
ip = db.Column(
db.String(100),
nullable=False,
comment="请求IP"
)
# 请求所在区域
location = db.Column(
db.String(255),
nullable=False,
comment="请求所在区域"
)
# 操作系统
os = db.Column(
db.String(100),
nullable=False,
comment="操作系统"
)
# 浏览器
browser = db.Column(
db.String(100),
nullable=False,
comment="浏览器"
)
# 请求耗时(毫秒)
consume_time = db.Column(
db.BigInteger,
nullable=False,
comment="请求耗时"
)
# 请求状态:0-正常,1-异常
status = db.Column(
db.Integer,
nullable=False,
comment="请求状态:0-正常,1-异常"
)
# 错误描述
error = db.Column(
db.Text,
nullable=False,
comment="错误描述"
)
# ============================================================
# 常量定义
# ============================================================
class Source:
"""请求来源常量"""
ADMIN = 0 # 后台
FRONT = 1 # 前台
class Status:
"""请求状态常量"""
NORMAL = 0 # 正常
ERROR = 1 # 异常
# ============================================================
# 魔法方法
# ============================================================
def __repr__(self):
"""
返回模型的字符串表示
Returns:
str: 格式为 "操作日志:{title} - {method}" 的字符串
"""
return '操作日志:{} - {}'.format(self.title, self.method)
def __str__(self):
"""
返回模型的字符串表示
Returns:
str: 格式为 "操作日志:{title} - {method}" 的字符串
"""
return self.__repr__()
from src.modules.log.models import * # noqa: F401,F403