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;