This commit is contained in:
张成
2026-04-01 10:53:26 +08:00
parent c2205188d1
commit 03c5579c86
11 changed files with 211 additions and 580 deletions

View File

@@ -1,16 +1,17 @@
const crud = require("../service/biz_admin_crud");
const baseModel = require("../../middleware/baseModel");
const { find_page, find_for_export, normalize_for_write } = require("../service/biz_query_helpers");
const audit = require("../service/biz_audit_service");
module.exports = {
"POST /biz_plan/page": async (ctx) => {
const body = ctx.getBody();
const data = await crud.page("biz_plan", body);
ctx.success({ rows: data.rows, count: data.count });
const { count, rows } = await find_page(baseModel.biz_plan, "biz_plan", body);
ctx.success({ rows, count });
},
"POST /biz_plan/add": async (ctx) => {
const body = ctx.getBody();
const row = await crud.add("biz_plan", body);
const payload = normalize_for_write(baseModel.biz_plan, body, { for_create: true });
const row = await baseModel.biz_plan.create(payload);
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),
action: "biz_plan.add",
@@ -22,7 +23,11 @@ module.exports = {
},
"POST /biz_plan/edit": async (ctx) => {
const body = ctx.getBody();
await crud.edit("biz_plan", body);
const id = body.id;
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
const payload = normalize_for_write(baseModel.biz_plan, body, { for_create: false });
delete payload.id;
await baseModel.biz_plan.update(payload, { where: { id } });
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),
action: "biz_plan.edit",
@@ -33,22 +38,29 @@ module.exports = {
},
"POST /biz_plan/del": async (ctx) => {
const body = ctx.getBody();
await crud.del("biz_plan", body);
const id = body.id !== undefined ? body.id : body;
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
await baseModel.biz_plan.destroy({ where: { id } });
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),
action: "biz_plan.del",
resource_type: "biz_plan",
resource_id: body.id,
resource_id: id,
});
ctx.success({});
},
"GET /biz_plan/detail": async (ctx) => {
const q = ctx.query || {};
const row = await crud.detail("biz_plan", { id: q.id || q.ID });
const id = q.id || q.ID;
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
const row = await baseModel.biz_plan.findByPk(id);
ctx.success(row);
},
"GET /biz_plan/all": async (ctx) => {
const rows = await crud.all("biz_plan");
const rows = await baseModel.biz_plan.findAll({
limit: 2000,
order: [["id", "DESC"]],
});
ctx.success(rows);
},
"POST /biz_plan/toggle": async (ctx) => {
@@ -70,7 +82,7 @@ module.exports = {
},
"POST /biz_plan/export": async (ctx) => {
const body = ctx.getBody();
const res = await crud.exportCsv("biz_plan", body);
const res = await find_for_export(baseModel.biz_plan, "biz_plan", body);
ctx.success(res);
},
};