From bed28c72acd774ad988eb9f0227808e2aa4359c6 Mon Sep 17 00:00:00 2001 From: "hello@lv" <2256334253@qq.com> Date: Sun, 7 Apr 2024 20:14:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=86=E7=BB=84=E5=8C=BA=E5=9D=97=EF=BC=8C=E9=87=8D=E9=87=8F?= =?UTF-8?q?/=E9=87=91=E9=A2=9D=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F=20feat?= =?UTF-8?q?=20#600=20(#604)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachycode/pulls/604 Co-authored-by: hello@lv <2256334253@qq.com> Co-committed-by: hello@lv <2256334253@qq.com> --- .changeset/shaggy-spies-push.md | 5 ++ .../src/server/actions/records-controller.ts | 51 ++++++++++++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 .changeset/shaggy-spies-push.md diff --git a/.changeset/shaggy-spies-push.md b/.changeset/shaggy-spies-push.md new file mode 100644 index 000000000..9d1fc3eb9 --- /dev/null +++ b/.changeset/shaggy-spies-push.md @@ -0,0 +1,5 @@ +--- +"@hera/plugin-rental": patch +--- + +重新订单分组统计区块重量总金额写法 diff --git a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts index 211b98666..f79631a2f 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts @@ -93,16 +93,34 @@ export class RecordPreviewController { @Action('allweight') async groupWeight(ctx: Context) { const { filter } = ctx.action.params.values; + const collectionName = 'records'; + const collection = ctx.db.getCollection(collectionName); + const fields = collection.fields; + const filterParser = new FilterParser(filter, { + collection, + }); const { sequelize } = ctx.db; - const records = await ctx.db.getRepository('records').find({ - filter, + const { where, include } = filterParser.toSequelizeParams(); + const parsedFilterInclude = + include?.map((item) => { + if (fields.get(item.association)?.type === 'belongsToMany') { + item.through = { attributes: [] }; + } + return item; + }) || []; + const query = { + where: where || {}, attributes: [ [sequelize.fn('sum', sequelize.col('records.weight')), 'weight'], [sequelize.col('records.movement'), 'movement'], ], group: [sequelize.col('records.movement')], - }); - + include: [...parsedFilterInclude], + order: [], + subQuery: false, + raw: true, + } as any; + const records = await ctx.db.getModel('records').findAll(query); const inNum = records.find((item) => item.movement === Movement.in)?.weight ?? 0; const outNum = records.find((item) => item.movement === Movement.out)?.weight ?? 0; const data = { @@ -114,15 +132,34 @@ export class RecordPreviewController { @Action('allprice') async groupPrice(ctx: Context) { const { filter } = ctx.action.params.values; + const collectionName = 'records'; + const collection = ctx.db.getCollection(collectionName); + const fields = collection.fields; + const filterParser = new FilterParser(filter, { + collection, + }); const { sequelize } = ctx.db; - const records = await ctx.db.getRepository('records').find({ - filter, + const { where, include } = filterParser.toSequelizeParams(); + const parsedFilterInclude = + include?.map((item) => { + if (fields.get(item.association)?.type === 'belongsToMany') { + item.through = { attributes: [] }; + } + return item; + }) || []; + const query = { + where: where || {}, attributes: [ [sequelize.fn('sum', sequelize.col('records.all_price')), 'all_price'], [sequelize.col('records.movement'), 'movement'], ], group: [sequelize.col('records.movement')], - }); + include: [...parsedFilterInclude], + order: [], + subQuery: false, + raw: true, + } as any; + const records = await ctx.db.getModel('records').findAll(query); const inNum = records.find((item) => item.movement === Movement.in)?.all_price ?? 0; const outNum = records.find((item) => item.movement === Movement.out)?.all_price ?? 0;