Merge pull request 'feat: 合同方案租金产品校验修改,长度相同进行校验' (#623) from feat_contract_plan_check into dev

Reviewed-on: daoyoucloud/tachycode#623
This commit is contained in:
sealday 2024-04-08 12:14:12 +08:00
commit 9bc3493c9d
2 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"@hera/plugin-rental": patch
---
合同方案租金重复校验,产品长度内容形同进行校验

View File

@ -24,8 +24,8 @@ export class ContractRuleService {
*/ */
async contractPlansBeforeSave(model: MagicAttributeModel, options: CreateOptions): Promise<void> { async contractPlansBeforeSave(model: MagicAttributeModel, options: CreateOptions): Promise<void> {
if (!options.values) return; if (!options.values) return;
const leaseData = options.values.lease_items.map((item) => item.products).flat(); const leaseData2 = options.values.lease_items.map((item) => item.products);
const repeatData = this.repeatQuery(leaseData); const repeatData = this.repeatQuery2(leaseData2);
if (repeatData.length > 0) { if (repeatData.length > 0) {
const products = repeatData.map((item) => item.label).join(','); const products = repeatData.map((item) => item.label).join(',');
throw new Error('租金规则中的产品重复!重复产品:' + products); throw new Error('租金规则中的产品重复!重复产品:' + products);
@ -144,4 +144,30 @@ export class ContractRuleService {
return []; 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;
}
} }