This commit is contained in:
张成
2026-03-26 09:40:55 +08:00
parent 7d0a921805
commit 60258c6c7d
11 changed files with 58 additions and 20 deletions

View File

@@ -94,6 +94,19 @@ function buildSearchWhere(model, seachOption) {
return { [key]: { [op.like]: `%${str}%` } };
}
/** 模型未声明但表中存在的列(列表/导出需要带出) */
function extraListAttributes(modelName, model) {
if (modelName === "biz_audit_log") {
const tn = model.tableName;
return {
attributes: {
include: [[model.sequelize.col(`${tn}.created_at`), "created_at"]],
},
};
}
return {};
}
async function page(modelName, body) {
const model = getModel(modelName);
const param = body.param || body;
@@ -111,6 +124,7 @@ async function page(modelName, body) {
offset,
limit: pageSize,
order: [["id", "DESC"]],
...extraListAttributes(modelName, model),
});
return { rows, count };
@@ -151,7 +165,7 @@ async function detail(modelName, query) {
if (id === undefined || id === null || id === "") {
throw new Error("缺少 id");
}
const row = await model.findByPk(id);
const row = await model.findByPk(id, extraListAttributes(modelName, model));
return row;
}
@@ -160,6 +174,7 @@ async function all(modelName) {
const rows = await model.findAll({
limit: 2000,
order: [["id", "DESC"]],
...extraListAttributes(modelName, model),
});
return rows;
}
@@ -172,6 +187,7 @@ async function exportCsv(modelName, body) {
where,
limit: 10000,
order: [["id", "DESC"]],
...extraListAttributes(modelName, model),
});
return { rows };
}