From 9cc10b88efc3a4a65a2a750a2227f2829c641575 Mon Sep 17 00:00:00 2001 From: lyx <2027667395@qq.com> Date: Mon, 8 Apr 2024 12:10:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=88=E5=90=8C=E6=96=B9=E6=A1=88?= =?UTF-8?q?=E7=A7=9F=E9=87=91=E4=BA=A7=E5=93=81=E6=A0=A1=E9=AA=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E9=95=BF=E5=BA=A6=E7=9B=B8=E5=90=8C=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/early-goats-give.md | 5 ++++ .../server/services/contract-rule-service.ts | 30 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .changeset/early-goats-give.md diff --git a/.changeset/early-goats-give.md b/.changeset/early-goats-give.md new file mode 100644 index 000000000..a93727a05 --- /dev/null +++ b/.changeset/early-goats-give.md @@ -0,0 +1,5 @@ +--- +"@hera/plugin-rental": patch +--- + +合同方案租金重复校验,产品长度内容形同进行校验 diff --git a/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts b/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts index ba71e746a..4a0d5d451 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts @@ -24,8 +24,8 @@ export class ContractRuleService { */ async contractPlansBeforeSave(model: MagicAttributeModel, options: CreateOptions): Promise { if (!options.values) return; - const leaseData = options.values.lease_items.map((item) => item.products).flat(); - const repeatData = this.repeatQuery(leaseData); + const leaseData2 = options.values.lease_items.map((item) => item.products); + const repeatData = this.repeatQuery2(leaseData2); if (repeatData.length > 0) { const products = repeatData.map((item) => item.label).join(','); throw new Error('租金规则中的产品重复!重复产品:' + products); @@ -144,4 +144,30 @@ export class ContractRuleService { return []; } } + + /** + * 与原实现相差较多,新写一实现方法 + * 租金产品多选重复查询,一个组合算是一个整体进行比较 + * @param data + * @returns + */ + repeatQuery2(data: any[]): any[] { + const result = data.reduce((acc, curr) => { + const found = acc.find((subArr) => subArr.length === curr.length); + if (found) { + found.push(...curr); + } else { + acc.push(curr); + } + return acc; + }, []); + const rep = []; + result.forEach((item) => { + const repeatData = this.repeatQuery(item); + if (repeatData.length > 0) { + rep.push(...item); + } + }); + return rep; + } }