1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 管理端列表筛选、导出、写入字段裁剪(供 controller_admin 配合 baseModel)
|
||||
* 管理端:筛选条件、写入字段裁剪(分页/导出在各 controller 内直接 findAndCountAll / findAll)
|
||||
*/
|
||||
const Sequelize = require("sequelize");
|
||||
const { Op } = Sequelize;
|
||||
@@ -76,53 +76,7 @@ function normalize_for_write(model, data, { for_create } = {}) {
|
||||
return out;
|
||||
}
|
||||
|
||||
function list_query_extra(model_name, model) {
|
||||
if (model_name === "biz_audit_log") {
|
||||
const tn = model.tableName;
|
||||
return {
|
||||
attributes: {
|
||||
include: [[model.sequelize.col(`${tn}.created_at`), "created_at"]],
|
||||
},
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
async function find_page(model, model_name, body, extra_find_options = {}) {
|
||||
const param = body.param || body;
|
||||
const page_option = param.pageOption || {};
|
||||
const seach_option = param.seachOption || {};
|
||||
const page_num = parseInt(page_option.page, 10) || 1;
|
||||
const page_size = parseInt(page_option.pageSize, 10) || 20;
|
||||
const offset = (page_num - 1) * page_size;
|
||||
const where = build_search_where(model, seach_option);
|
||||
return model.findAndCountAll({
|
||||
where,
|
||||
offset,
|
||||
limit: page_size,
|
||||
order: [["id", "DESC"]],
|
||||
...list_query_extra(model_name, model),
|
||||
...extra_find_options,
|
||||
});
|
||||
}
|
||||
|
||||
async function find_for_export(model, model_name, body, extra_find_options = {}) {
|
||||
const param = body.param || body;
|
||||
const where = build_search_where(model, param.seachOption || {});
|
||||
const rows = await model.findAll({
|
||||
where,
|
||||
limit: 10000,
|
||||
order: [["id", "DESC"]],
|
||||
...list_query_extra(model_name, model),
|
||||
...extra_find_options,
|
||||
});
|
||||
return { rows };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
build_search_where,
|
||||
normalize_for_write,
|
||||
list_query_extra,
|
||||
find_page,
|
||||
find_for_export,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user