From 96ae769d99b0a216de2f95438d522a666227050b Mon Sep 17 00:00:00 2001 From: wjh Date: Wed, 21 Aug 2024 17:10:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E5=8D=95=E6=9F=A5=E7=9C=8B=E6=B2=A1=E6=9C=89=E8=80=83=E8=99=91?= =?UTF-8?q?=E6=9B=BF=E8=BA=AB=E5=90=88=E5=90=8C=E9=97=AE=E9=A2=98=20(#1475?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1475 Reviewed-by: sealday Co-authored-by: wjh Co-committed-by: wjh --- .../client/src/block-provider/hooks/index.ts | 5 ++-- .../server/actions/settlement-controller.ts | 13 ++++++++--- .../src/server/sqls/settlement_select.sql | 23 ++++++++++++++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index f98951c68..4d49e6d76 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -419,11 +419,11 @@ export const useFilterBlockActionProps = () => { const storedFilter = block.service.params?.[1]?.filters || {}; const filter = { - formValues: {}, + formValues: { ...form.values }, customValues: {}, customFilter: {}, }; - if (Object.keys(form.values)?.includes('__custom')) { + if (Object.keys(filter.formValues)?.includes('__custom')) { const values = { ...form.values }; delete values['__custom']; filter.formValues = { ...values }; @@ -438,7 +438,6 @@ export const useFilterBlockActionProps = () => { storedFilter[uid] = removeNullCondition( transformToFilter(filter.formValues, fieldSchema, getCollectionJoinField, name), ); - const mergedFilter = mergeFilter([ ...Object.values(storedFilter).map((filter) => removeNullCondition(filter)), block.defaultFilter, diff --git a/packages/plugins/@hera/plugin-rental/src/server/actions/settlement-controller.ts b/packages/plugins/@hera/plugin-rental/src/server/actions/settlement-controller.ts index 19f69d797..91e0eb920 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/actions/settlement-controller.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/actions/settlement-controller.ts @@ -58,8 +58,11 @@ export class SettlementController { type: QueryTypes.SELECT, }); const utcOffset = ctx.get('X-Timezone'); - const { calc, contracts } = await this.settlmentService.settlement(settlement as any, utcOffset); - + const { calc, contracts: settlementContracts } = await this.settlmentService.settlement( + settlement as any, + utcOffset, + ); + const contracts = { ...settlementContracts, ...settlementContracts['alternative_contract'][0] }; const cache = ctx.app.cacheManager.getCache('@hera/plugin-rental') as Cache; const key = stringify({ calc, contracts, result: systemSetting }); @@ -98,7 +101,11 @@ export class SettlementController { type: QueryTypes.SELECT, }); const utcOffset = ctx.get('X-Timezone'); - const { calc, contracts } = await this.settlmentService.settlement(settlement as any, utcOffset); + const { calc, contracts: settlementContracts } = await this.settlmentService.settlement( + settlement as any, + utcOffset, + ); + const contracts = { ...settlementContracts, ...settlementContracts['alternative_contract'][0] }; const excel = { calc, contracts, result: systemSetting }; ctx.body = excel; } diff --git a/packages/plugins/@hera/plugin-rental/src/server/sqls/settlement_select.sql b/packages/plugins/@hera/plugin-rental/src/server/sqls/settlement_select.sql index 7fe182edf..40f31fffa 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/sqls/settlement_select.sql +++ b/packages/plugins/@hera/plugin-rental/src/server/sqls/settlement_select.sql @@ -48,6 +48,17 @@ SELECT WHERE contracts."updatedById" = u.id ) + ) || JSONB_SET( + TO_JSONB(contracts), + '{alternative_contract}', + ( + SELECT + COALESCE(JSONB_AGG(c3), '{}'::jsonb) + FROM + contracts c3 + WHERE + c3.id = settlements.contract_id + ) ) ) AS contracts, ( @@ -83,7 +94,17 @@ FROM settlement_items."type" = :type OR settlement_items."type" = 'fee' ) - JOIN contracts ON contracts."id" = settlements.contract_id + JOIN contracts ON contracts."id" = ( + SELECT + CASE + WHEN c.project_id IS NULL THEN c.alternative_contract_id + ELSE c.id + END AS result_id + FROM + contracts c + WHERE + c.id = settlements.contract_id + ) WHERE settlements.id = :settlementsId GROUP BY