@wukongcrm/mcp-server 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -24
- package/dist/client.d.ts +35 -1
- package/dist/client.js +156 -29
- package/dist/nocode.js +75 -47
- package/dist/server.js +208 -34
- package/dist/tool-discovery.d.ts +18 -0
- package/dist/tool-discovery.js +186 -0
- package/dist/tools.js +327 -146
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -345,24 +345,32 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
345
345
|
if (isPoolModule(moduleDefinition)) {
|
|
346
346
|
const poolContext = await resolvePoolContext(client, moduleDefinition, args);
|
|
347
347
|
const [fields, listHead] = await Promise.all([
|
|
348
|
-
client.
|
|
349
|
-
client.
|
|
348
|
+
client.read(`${moduleDefinition.basePath}/queryPoolField`, undefined, cleanQuery({ poolId: poolContext.poolId, isFlat: args.isFlat ?? args.flat })),
|
|
349
|
+
client.read(`${moduleDefinition.basePath}/queryPoolListHead`, undefined, { poolId: poolContext.poolId })
|
|
350
350
|
]);
|
|
351
351
|
return { module: moduleDefinition.key, moduleName: moduleDefinition.name, pool: poolContext.pool, fields, listHead };
|
|
352
352
|
}
|
|
353
353
|
const id = args.id ?? args.recordId;
|
|
354
354
|
const [fields, listHead] = await Promise.all([
|
|
355
355
|
id
|
|
356
|
-
? client.
|
|
357
|
-
: client.
|
|
358
|
-
client.
|
|
356
|
+
? client.read(`${moduleDefinition.basePath}/field/${id}`, undefined, cleanQuery({ type: args.type, poolId: args.poolId }))
|
|
357
|
+
: client.read(`${moduleDefinition.basePath}/field`, undefined, cleanQuery({ type: args.type })),
|
|
358
|
+
client.read(`/crmField/queryListHead/${moduleDefinition.label}`, undefined, cleanQuery({ isHide: args.isHide ?? 0 }))
|
|
359
359
|
]);
|
|
360
360
|
return { module: moduleDefinition.key, moduleName: moduleDefinition.name, fields, listHead };
|
|
361
361
|
},
|
|
362
|
+
crm_get_business_status_groups: async (args) => {
|
|
363
|
+
const targetPath = "/crmFlow/queryBusinessSetting";
|
|
364
|
+
return {
|
|
365
|
+
module: "business",
|
|
366
|
+
targetPath,
|
|
367
|
+
data: await client.read(targetPath, undefined, cleanQuery({ businessId: args.businessId }))
|
|
368
|
+
};
|
|
369
|
+
},
|
|
362
370
|
crm_validate_field: async (args) => {
|
|
363
371
|
const path = args.contactDuplicateCheck ? "/crmField/contactDuplicateCheck" : "/crmField/verify";
|
|
364
372
|
return {
|
|
365
|
-
data: await client.
|
|
373
|
+
data: await client.read(path, args),
|
|
366
374
|
endpoint: path
|
|
367
375
|
};
|
|
368
376
|
},
|
|
@@ -384,7 +392,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
384
392
|
moduleLabel: moduleDefinition.label,
|
|
385
393
|
pool: poolContext?.pool,
|
|
386
394
|
searchMode: searchList.length > 0 ? "advancedFilter" : "none",
|
|
387
|
-
data: await client.
|
|
395
|
+
data: await client.read(`${moduleDefinition.basePath}/queryPageList`, cleanObject(body))
|
|
388
396
|
};
|
|
389
397
|
},
|
|
390
398
|
crm_get_record: async (args) => {
|
|
@@ -394,7 +402,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
394
402
|
return {
|
|
395
403
|
module: moduleDefinition.key,
|
|
396
404
|
pool: poolContext?.pool,
|
|
397
|
-
data: await client.
|
|
405
|
+
data: await client.read(`${recordModule.basePath}/queryById/${args.id}`, undefined, cleanQuery({ poolId: poolContext?.poolId ?? args.poolId }))
|
|
398
406
|
};
|
|
399
407
|
},
|
|
400
408
|
crm_get_record_information: async (args) => {
|
|
@@ -404,7 +412,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
404
412
|
return {
|
|
405
413
|
module: moduleDefinition.key,
|
|
406
414
|
pool: poolContext?.pool,
|
|
407
|
-
data: await client.
|
|
415
|
+
data: await client.read(`${recordModule.basePath}/information/${args.id}`, undefined, cleanQuery({ poolId: poolContext?.poolId ?? args.poolId }))
|
|
408
416
|
};
|
|
409
417
|
},
|
|
410
418
|
crm_get_related_records: async (args) => {
|
|
@@ -428,7 +436,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
428
436
|
return {
|
|
429
437
|
module: moduleDefinition.key,
|
|
430
438
|
pool: poolContext?.pool,
|
|
431
|
-
data: await client.
|
|
439
|
+
data: await client.read("/crmActivity/queryActivityList", cleanObject(body))
|
|
432
440
|
};
|
|
433
441
|
},
|
|
434
442
|
crm_get_action_records: async (args) => {
|
|
@@ -436,7 +444,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
436
444
|
const actionModule = isPoolModule(moduleDefinition) ? getPoolRecordModule(moduleDefinition) : moduleDefinition;
|
|
437
445
|
return {
|
|
438
446
|
module: moduleDefinition.key,
|
|
439
|
-
data: await client.
|
|
447
|
+
data: await client.read("/crmActionRecord/queryRecordList", undefined, {
|
|
440
448
|
actionId: args.id,
|
|
441
449
|
types: args.types ?? actionModule.label
|
|
442
450
|
})
|
|
@@ -450,7 +458,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
450
458
|
module: moduleDefinition.key,
|
|
451
459
|
pool: poolContext?.pool,
|
|
452
460
|
readonly: true,
|
|
453
|
-
data: await client.
|
|
461
|
+
data: await client.read(`${fileModule.basePath}/queryFileList`, undefined, cleanQuery({ id: args.id, fileType: args.fileType }))
|
|
454
462
|
};
|
|
455
463
|
},
|
|
456
464
|
crm_search_products: async (args) => {
|
|
@@ -460,7 +468,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
460
468
|
moduleName: "产品",
|
|
461
469
|
readonly: true,
|
|
462
470
|
targetPath,
|
|
463
|
-
data: await client.
|
|
471
|
+
data: await client.read(targetPath, await buildCrmProductSearchBody(client, args, false))
|
|
464
472
|
};
|
|
465
473
|
},
|
|
466
474
|
crm_search_sale_products: async (args) => {
|
|
@@ -470,7 +478,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
470
478
|
moduleName: "上架产品",
|
|
471
479
|
readonly: true,
|
|
472
480
|
targetPath,
|
|
473
|
-
data: await client.
|
|
481
|
+
data: await client.read(targetPath, await buildCrmProductSearchBody(client, args, true))
|
|
474
482
|
};
|
|
475
483
|
},
|
|
476
484
|
crm_get_product: async (args) => {
|
|
@@ -481,7 +489,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
481
489
|
moduleName: "产品",
|
|
482
490
|
readonly: true,
|
|
483
491
|
targetPath,
|
|
484
|
-
data: await client.
|
|
492
|
+
data: await client.read(targetPath)
|
|
485
493
|
};
|
|
486
494
|
},
|
|
487
495
|
crm_get_product_information: async (args) => {
|
|
@@ -492,7 +500,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
492
500
|
moduleName: "产品",
|
|
493
501
|
readonly: true,
|
|
494
502
|
targetPath,
|
|
495
|
-
data: await client.
|
|
503
|
+
data: await client.read(targetPath)
|
|
496
504
|
};
|
|
497
505
|
},
|
|
498
506
|
crm_get_product_schema: async (args) => {
|
|
@@ -503,7 +511,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
503
511
|
moduleName: "产品",
|
|
504
512
|
readonly: true,
|
|
505
513
|
targetPath,
|
|
506
|
-
data: await client.
|
|
514
|
+
data: await client.read(targetPath, undefined, cleanQuery({ type: args.type }))
|
|
507
515
|
};
|
|
508
516
|
},
|
|
509
517
|
crm_list_product_files: async (args) => {
|
|
@@ -513,7 +521,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
513
521
|
moduleName: "产品",
|
|
514
522
|
readonly: true,
|
|
515
523
|
targetPath,
|
|
516
|
-
data: await client.
|
|
524
|
+
data: await client.read(targetPath, undefined, cleanQuery({ id: requireCrmProductId(args, "查询 CRM 产品附件请提供 productId 或 id。"), fileType: args.fileType }))
|
|
517
525
|
};
|
|
518
526
|
},
|
|
519
527
|
crm_get_product_num: async (args) => {
|
|
@@ -523,7 +531,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
523
531
|
moduleName: "产品",
|
|
524
532
|
readonly: true,
|
|
525
533
|
targetPath,
|
|
526
|
-
data: await client.
|
|
534
|
+
data: await client.read(targetPath, undefined, cleanQuery({ id: requireCrmProductId(args, "查询 CRM 产品数量请提供 productId 或 id。") }))
|
|
527
535
|
};
|
|
528
536
|
},
|
|
529
537
|
crm_get_simple_products: async (args) => {
|
|
@@ -533,11 +541,11 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
533
541
|
moduleName: "产品",
|
|
534
542
|
readonly: true,
|
|
535
543
|
targetPath,
|
|
536
|
-
data: await client.
|
|
544
|
+
data: await client.read(targetPath, requireIdArray(args.productIds ?? args.ids, "查询 CRM 简要产品请提供 productIds 或 ids 数组。"))
|
|
537
545
|
};
|
|
538
546
|
},
|
|
539
547
|
crm_list_users: async (args) => ({
|
|
540
|
-
data: await client.
|
|
548
|
+
data: await client.read("/adminUser/queryUserList", cleanObject({
|
|
541
549
|
page: args.page ?? 1,
|
|
542
550
|
limit: args.limit ?? 15,
|
|
543
551
|
pageType: args.pageType ?? 1,
|
|
@@ -561,14 +569,14 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
561
569
|
}
|
|
562
570
|
return {
|
|
563
571
|
mode,
|
|
564
|
-
data: await client.
|
|
572
|
+
data: await client.read("/adminUser/getIdByUserName", undefined, { userName, companyId: args.companyId })
|
|
565
573
|
};
|
|
566
574
|
},
|
|
567
575
|
crm_list_departments: async (args) => ({
|
|
568
|
-
data: await client.
|
|
576
|
+
data: await client.read("/adminDept/queryDeptTree", cleanObject(args ?? {}))
|
|
569
577
|
}),
|
|
570
578
|
crm_find_dept_id: async (args) => ({
|
|
571
|
-
data: await client.
|
|
579
|
+
data: await client.read("/adminDept/getIdByDeptName", undefined, { deptName: args.deptName ?? args.name, companyId: args.companyId })
|
|
572
580
|
}),
|
|
573
581
|
crm_list_address_book_contacts: async (args) => {
|
|
574
582
|
const targetPath = "/adminUser/queryListName";
|
|
@@ -577,7 +585,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
577
585
|
moduleName: "通讯录",
|
|
578
586
|
readonly: true,
|
|
579
587
|
targetPath,
|
|
580
|
-
data: await client.
|
|
588
|
+
data: await client.read(targetPath, buildAddressBookListBody(args))
|
|
581
589
|
};
|
|
582
590
|
},
|
|
583
591
|
crm_get_address_book_contact: async (args) => {
|
|
@@ -587,7 +595,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
587
595
|
moduleName: "通讯录",
|
|
588
596
|
readonly: true,
|
|
589
597
|
targetPath,
|
|
590
|
-
data: await client.
|
|
598
|
+
data: await client.read(targetPath, undefined, cleanQuery({ userId: requireAddressBookUserId(args, "查询通讯录联系人详情请提供 userId 或 id。") }))
|
|
591
599
|
};
|
|
592
600
|
},
|
|
593
601
|
crm_list_address_book_departments: async (args) => {
|
|
@@ -597,7 +605,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
597
605
|
moduleName: "通讯录",
|
|
598
606
|
readonly: true,
|
|
599
607
|
targetPath,
|
|
600
|
-
data: await client.
|
|
608
|
+
data: await client.read(targetPath, buildAddressBookDepartmentBody(args))
|
|
601
609
|
};
|
|
602
610
|
},
|
|
603
611
|
crm_list_address_book_auth_departments: async (args) => {
|
|
@@ -607,7 +615,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
607
615
|
moduleName: "通讯录",
|
|
608
616
|
readonly: true,
|
|
609
617
|
targetPath,
|
|
610
|
-
data: await client.
|
|
618
|
+
data: await client.read(targetPath, cleanObject(args ?? {}))
|
|
611
619
|
};
|
|
612
620
|
},
|
|
613
621
|
crm_list_address_book_dept_user_ids: async (args) => {
|
|
@@ -619,7 +627,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
619
627
|
readonly: true,
|
|
620
628
|
targetPath,
|
|
621
629
|
body,
|
|
622
|
-
data: await client.
|
|
630
|
+
data: await client.read(targetPath, body)
|
|
623
631
|
};
|
|
624
632
|
},
|
|
625
633
|
crm_list_address_book_dept_users: async (args) => {
|
|
@@ -631,7 +639,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
631
639
|
readonly: true,
|
|
632
640
|
targetPath,
|
|
633
641
|
body,
|
|
634
|
-
data: await client.
|
|
642
|
+
data: await client.read(targetPath, body)
|
|
635
643
|
};
|
|
636
644
|
},
|
|
637
645
|
crm_list_address_book_auth_users: async () => {
|
|
@@ -641,7 +649,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
641
649
|
moduleName: "通讯录",
|
|
642
650
|
readonly: true,
|
|
643
651
|
targetPath,
|
|
644
|
-
data: await client.
|
|
652
|
+
data: await client.read(targetPath)
|
|
645
653
|
};
|
|
646
654
|
},
|
|
647
655
|
crm_get_address_book_user_dept_role_info: async (args) => {
|
|
@@ -653,7 +661,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
653
661
|
readonly: true,
|
|
654
662
|
targetPath,
|
|
655
663
|
body,
|
|
656
|
-
data: await client.
|
|
664
|
+
data: await client.read(targetPath, body)
|
|
657
665
|
};
|
|
658
666
|
},
|
|
659
667
|
crm_get_address_book_organization: async (args) => {
|
|
@@ -663,7 +671,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
663
671
|
moduleName: "通讯录",
|
|
664
672
|
readonly: true,
|
|
665
673
|
targetPath,
|
|
666
|
-
data: await client.
|
|
674
|
+
data: await client.read(targetPath, undefined, cleanQuery({ companyId: args.companyId }))
|
|
667
675
|
};
|
|
668
676
|
},
|
|
669
677
|
crm_get_address_book_user_count: async (args) => {
|
|
@@ -673,7 +681,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
673
681
|
moduleName: "通讯录",
|
|
674
682
|
readonly: true,
|
|
675
683
|
targetPath,
|
|
676
|
-
data: await client.
|
|
684
|
+
data: await client.read(targetPath, undefined, cleanQuery({ username: requireAddressBookUsername(args) }))
|
|
677
685
|
};
|
|
678
686
|
},
|
|
679
687
|
crm_toggle_address_book_attention: async (args) => {
|
|
@@ -687,7 +695,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
687
695
|
moduleName: "通讯录",
|
|
688
696
|
targetPath,
|
|
689
697
|
body,
|
|
690
|
-
data: await client.
|
|
698
|
+
data: await client.write(targetPath, undefined, cleanQuery(body))
|
|
691
699
|
};
|
|
692
700
|
},
|
|
693
701
|
crm_list_hrm_employees: async (args) => {
|
|
@@ -696,7 +704,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
696
704
|
module: "hrmEmployee",
|
|
697
705
|
readonly: true,
|
|
698
706
|
targetPath,
|
|
699
|
-
data: await client.
|
|
707
|
+
data: await client.read(targetPath, buildHrmEmployeeListBody(args))
|
|
700
708
|
};
|
|
701
709
|
},
|
|
702
710
|
crm_get_hrm_employee: async (args) => {
|
|
@@ -706,7 +714,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
706
714
|
module: "hrmEmployee",
|
|
707
715
|
readonly: true,
|
|
708
716
|
targetPath,
|
|
709
|
-
data: await client.
|
|
717
|
+
data: await client.read(targetPath)
|
|
710
718
|
};
|
|
711
719
|
},
|
|
712
720
|
crm_list_hrm_employee_fields: async () => {
|
|
@@ -715,7 +723,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
715
723
|
module: "hrmEmployee",
|
|
716
724
|
readonly: true,
|
|
717
725
|
targetPath,
|
|
718
|
-
data: await client.
|
|
726
|
+
data: await client.read(targetPath)
|
|
719
727
|
};
|
|
720
728
|
},
|
|
721
729
|
crm_list_hrm_departments: async (args) => {
|
|
@@ -724,7 +732,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
724
732
|
module: "hrmDept",
|
|
725
733
|
readonly: true,
|
|
726
734
|
targetPath,
|
|
727
|
-
data: await client.
|
|
735
|
+
data: await client.read(targetPath, buildHrmDepartmentListBody(args))
|
|
728
736
|
};
|
|
729
737
|
},
|
|
730
738
|
crm_get_hrm_department: async (args) => {
|
|
@@ -734,7 +742,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
734
742
|
module: "hrmDept",
|
|
735
743
|
readonly: true,
|
|
736
744
|
targetPath,
|
|
737
|
-
data: await client.
|
|
745
|
+
data: await client.read(targetPath)
|
|
738
746
|
};
|
|
739
747
|
},
|
|
740
748
|
crm_list_hrm_department_employees: async (args) => {
|
|
@@ -743,7 +751,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
743
751
|
module: "hrmDept",
|
|
744
752
|
readonly: true,
|
|
745
753
|
targetPath,
|
|
746
|
-
data: await client.
|
|
754
|
+
data: await client.read(targetPath, buildHrmDepartmentEmployeesBody(args))
|
|
747
755
|
};
|
|
748
756
|
},
|
|
749
757
|
crm_get_hrm_employee_post: async (args) => {
|
|
@@ -753,7 +761,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
753
761
|
module: "hrmEmployeePost",
|
|
754
762
|
readonly: true,
|
|
755
763
|
targetPath,
|
|
756
|
-
data: await client.
|
|
764
|
+
data: await client.read(targetPath)
|
|
757
765
|
};
|
|
758
766
|
},
|
|
759
767
|
crm_list_hrm_attendance_month_records: async (args) => {
|
|
@@ -762,7 +770,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
762
770
|
module: "hrmAttendance",
|
|
763
771
|
readonly: true,
|
|
764
772
|
targetPath,
|
|
765
|
-
data: await client.
|
|
773
|
+
data: await client.read(targetPath, buildHrmAttendanceMonthRecordBody(args))
|
|
766
774
|
};
|
|
767
775
|
},
|
|
768
776
|
crm_get_hrm_attendance_daily_detail: async (args) => {
|
|
@@ -771,7 +779,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
771
779
|
module: "hrmAttendance",
|
|
772
780
|
readonly: true,
|
|
773
781
|
targetPath,
|
|
774
|
-
data: await client.
|
|
782
|
+
data: await client.read(targetPath, buildHrmAttendanceDailyDetailBody(args))
|
|
775
783
|
};
|
|
776
784
|
},
|
|
777
785
|
crm_list_hrm_leave_records: async (args) => {
|
|
@@ -780,7 +788,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
780
788
|
module: "hrmLeaveRecord",
|
|
781
789
|
readonly: true,
|
|
782
790
|
targetPath,
|
|
783
|
-
data: await client.
|
|
791
|
+
data: await client.read(targetPath, buildHrmLeaveRecordBody(args))
|
|
784
792
|
};
|
|
785
793
|
},
|
|
786
794
|
crm_list_hrm_leave_types: async () => {
|
|
@@ -789,7 +797,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
789
797
|
module: "hrmLeaveRecord",
|
|
790
798
|
readonly: true,
|
|
791
799
|
targetPath,
|
|
792
|
-
data: await client.
|
|
800
|
+
data: await client.read(targetPath)
|
|
793
801
|
};
|
|
794
802
|
},
|
|
795
803
|
crm_list_finance_modules: () => ({
|
|
@@ -803,7 +811,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
803
811
|
moduleName: "凭证",
|
|
804
812
|
readonly: true,
|
|
805
813
|
targetPath,
|
|
806
|
-
data: await client.
|
|
814
|
+
data: await client.read(targetPath, buildFinanceSearchBody(args, { page: args.page ?? 1, limit: args.limit ?? 15, pageType: args.pageType ?? 1 }))
|
|
807
815
|
};
|
|
808
816
|
},
|
|
809
817
|
crm_get_finance_voucher: async (args) => {
|
|
@@ -813,7 +821,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
813
821
|
moduleName: "凭证",
|
|
814
822
|
readonly: true,
|
|
815
823
|
targetPath,
|
|
816
|
-
data: await client.
|
|
824
|
+
data: await client.read(targetPath, cleanObject({ certificateId: requireFinanceCertificateId(args), accountId: args.accountId }))
|
|
817
825
|
};
|
|
818
826
|
},
|
|
819
827
|
crm_summarize_finance_vouchers: async (args) => {
|
|
@@ -823,7 +831,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
823
831
|
moduleName: "凭证汇总",
|
|
824
832
|
readonly: true,
|
|
825
833
|
targetPath,
|
|
826
|
-
data: await client.
|
|
834
|
+
data: await client.read(targetPath, buildFinanceBody(args))
|
|
827
835
|
};
|
|
828
836
|
},
|
|
829
837
|
crm_query_finance_ledger: async (args) => {
|
|
@@ -834,7 +842,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
834
842
|
ledger: ledgerDefinition.key,
|
|
835
843
|
readonly: true,
|
|
836
844
|
targetPath: ledgerDefinition.targetPath,
|
|
837
|
-
data: await client.
|
|
845
|
+
data: await client.read(ledgerDefinition.targetPath, buildFinanceBody(args, ["ledger", "type", "kind"]))
|
|
838
846
|
};
|
|
839
847
|
},
|
|
840
848
|
crm_query_finance_report: async (args) => {
|
|
@@ -847,7 +855,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
847
855
|
balanceCheck: Boolean(args.checkBalance || args.balanceCheck),
|
|
848
856
|
readonly: true,
|
|
849
857
|
targetPath,
|
|
850
|
-
data: await client.
|
|
858
|
+
data: await client.read(targetPath, buildFinanceBody(args, ["report", "type", "kind", "checkBalance", "balanceCheck"]))
|
|
851
859
|
};
|
|
852
860
|
},
|
|
853
861
|
crm_list_finance_subjects: async (args) => {
|
|
@@ -857,7 +865,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
857
865
|
moduleName: "科目",
|
|
858
866
|
readonly: true,
|
|
859
867
|
targetPath,
|
|
860
|
-
data: await client.
|
|
868
|
+
data: await client.read(targetPath, buildFinanceBody(args))
|
|
861
869
|
};
|
|
862
870
|
},
|
|
863
871
|
crm_list_finance_currencies: async (args) => {
|
|
@@ -867,7 +875,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
867
875
|
moduleName: "币别",
|
|
868
876
|
readonly: true,
|
|
869
877
|
targetPath,
|
|
870
|
-
data: await client.
|
|
878
|
+
data: await client.read(targetPath, buildFinanceBody(args))
|
|
871
879
|
};
|
|
872
880
|
},
|
|
873
881
|
crm_list_finance_voucher_words: async (args) => {
|
|
@@ -877,7 +885,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
877
885
|
moduleName: "凭证字",
|
|
878
886
|
readonly: true,
|
|
879
887
|
targetPath,
|
|
880
|
-
data: await client.
|
|
888
|
+
data: await client.read(targetPath, buildFinanceBody(args))
|
|
881
889
|
};
|
|
882
890
|
},
|
|
883
891
|
crm_query_finance_dashboard: async (args) => {
|
|
@@ -888,7 +896,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
888
896
|
query: dashboardDefinition.key,
|
|
889
897
|
readonly: true,
|
|
890
898
|
targetPath: dashboardDefinition.targetPath,
|
|
891
|
-
data: await client.
|
|
899
|
+
data: await client.read(dashboardDefinition.targetPath, buildFinanceBody(args, ["query", "type", "kind"]))
|
|
892
900
|
};
|
|
893
901
|
},
|
|
894
902
|
crm_write_hrm: async (args) => executeDomainWrite(client, WRITE_DOMAINS.hrm, args),
|
|
@@ -916,7 +924,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
916
924
|
moduleName: moduleDefinition.name,
|
|
917
925
|
readonly: true,
|
|
918
926
|
targetPath,
|
|
919
|
-
data: await client.
|
|
927
|
+
data: await client.read(targetPath, buildJxcSearchBody(args, moduleDefinition))
|
|
920
928
|
};
|
|
921
929
|
},
|
|
922
930
|
crm_get_jxc_record: async (args) => {
|
|
@@ -928,7 +936,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
928
936
|
moduleName: moduleDefinition.name,
|
|
929
937
|
readonly: true,
|
|
930
938
|
targetPath,
|
|
931
|
-
data: await client.
|
|
939
|
+
data: await client.read(targetPath)
|
|
932
940
|
};
|
|
933
941
|
},
|
|
934
942
|
crm_get_jxc_record_information: async (args) => {
|
|
@@ -940,7 +948,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
940
948
|
moduleName: moduleDefinition.name,
|
|
941
949
|
readonly: true,
|
|
942
950
|
targetPath,
|
|
943
|
-
data: await client.
|
|
951
|
+
data: await client.read(targetPath)
|
|
944
952
|
};
|
|
945
953
|
},
|
|
946
954
|
crm_get_jxc_module_schema: async (args) => {
|
|
@@ -952,7 +960,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
952
960
|
moduleName: moduleDefinition.name,
|
|
953
961
|
readonly: true,
|
|
954
962
|
targetPath,
|
|
955
|
-
data: await client.
|
|
963
|
+
data: await client.read(targetPath, undefined, cleanQuery({ type: args.type }))
|
|
956
964
|
};
|
|
957
965
|
},
|
|
958
966
|
crm_list_jxc_files: async (args) => {
|
|
@@ -963,7 +971,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
963
971
|
moduleName: moduleDefinition.name,
|
|
964
972
|
readonly: true,
|
|
965
973
|
targetPath,
|
|
966
|
-
data: await client.
|
|
974
|
+
data: await client.read(targetPath, undefined, cleanQuery({ id: requireJxcId(args, "查询 JXC 附件请提供 id。"), fileType: args.fileType }))
|
|
967
975
|
};
|
|
968
976
|
},
|
|
969
977
|
crm_list_jxc_stock_products: async (args) => {
|
|
@@ -973,7 +981,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
973
981
|
moduleName: "产品库存",
|
|
974
982
|
readonly: true,
|
|
975
983
|
targetPath,
|
|
976
|
-
data: await client.
|
|
984
|
+
data: await client.read(targetPath, buildJxcStockProductsBody(args))
|
|
977
985
|
};
|
|
978
986
|
},
|
|
979
987
|
crm_get_jxc_product_inventory: async (args) => {
|
|
@@ -984,7 +992,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
984
992
|
moduleName: "产品库存",
|
|
985
993
|
readonly: true,
|
|
986
994
|
targetPath,
|
|
987
|
-
data: await client.
|
|
995
|
+
data: await client.read(targetPath, undefined, cleanQuery({ warehouseId: args.warehouseId }))
|
|
988
996
|
};
|
|
989
997
|
},
|
|
990
998
|
crm_list_jxc_stock_movements: async (args) => {
|
|
@@ -994,7 +1002,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
994
1002
|
moduleName: "出入库明细",
|
|
995
1003
|
readonly: true,
|
|
996
1004
|
targetPath,
|
|
997
|
-
data: await client.
|
|
1005
|
+
data: await client.read(targetPath, buildJxcStockMovementsBody(args))
|
|
998
1006
|
};
|
|
999
1007
|
},
|
|
1000
1008
|
crm_get_jxc_warehouse_product_stock: async (args) => {
|
|
@@ -1004,7 +1012,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1004
1012
|
moduleName: "仓库产品库存数量",
|
|
1005
1013
|
readonly: true,
|
|
1006
1014
|
targetPath,
|
|
1007
|
-
data: await client.
|
|
1015
|
+
data: await client.read(targetPath, requireWarehouseProductIdsMap(args))
|
|
1008
1016
|
};
|
|
1009
1017
|
},
|
|
1010
1018
|
crm_get_jxc_warehouse_names: async (args) => {
|
|
@@ -1014,7 +1022,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1014
1022
|
moduleName: "仓库",
|
|
1015
1023
|
readonly: true,
|
|
1016
1024
|
targetPath,
|
|
1017
|
-
data: await client.
|
|
1025
|
+
data: await client.read(targetPath, requireWarehouseIds(args))
|
|
1018
1026
|
};
|
|
1019
1027
|
},
|
|
1020
1028
|
crm_write_jxc: async (args) => executeDomainWrite(client, WRITE_DOMAINS.jxc, args),
|
|
@@ -1030,7 +1038,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1030
1038
|
moduleName: moduleDefinition.name,
|
|
1031
1039
|
targetPath,
|
|
1032
1040
|
body,
|
|
1033
|
-
data: await client.
|
|
1041
|
+
data: await client.write(targetPath, body, cleanQuery(args.query ?? {}))
|
|
1034
1042
|
};
|
|
1035
1043
|
},
|
|
1036
1044
|
crm_update_jxc_record: async (args) => {
|
|
@@ -1047,7 +1055,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1047
1055
|
moduleName: moduleDefinition.name,
|
|
1048
1056
|
targetPath,
|
|
1049
1057
|
body,
|
|
1050
|
-
data: await client.
|
|
1058
|
+
data: await client.write(targetPath, body, cleanQuery(args.query ?? {}))
|
|
1051
1059
|
};
|
|
1052
1060
|
},
|
|
1053
1061
|
crm_write_finance: async (args) => executeDomainWrite(client, WRITE_DOMAINS.finance, args),
|
|
@@ -1062,7 +1070,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1062
1070
|
moduleName: "凭证",
|
|
1063
1071
|
targetPath,
|
|
1064
1072
|
body,
|
|
1065
|
-
data: await client.
|
|
1073
|
+
data: await client.write(targetPath, body, cleanQuery(args.query ?? {}))
|
|
1066
1074
|
};
|
|
1067
1075
|
},
|
|
1068
1076
|
crm_update_finance_voucher: async (args) => {
|
|
@@ -1076,18 +1084,18 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1076
1084
|
moduleName: "凭证",
|
|
1077
1085
|
targetPath,
|
|
1078
1086
|
body,
|
|
1079
|
-
data: await client.
|
|
1087
|
+
data: await client.write(targetPath, body, cleanQuery(args.query ?? {}))
|
|
1080
1088
|
};
|
|
1081
1089
|
},
|
|
1082
1090
|
crm_list_calendar_events: async (args) => ({
|
|
1083
1091
|
module: "calendarEvent",
|
|
1084
1092
|
targetPath: "/oaEvent/queryList",
|
|
1085
|
-
data: await client.
|
|
1093
|
+
data: await client.read("/oaEvent/queryList", buildCalendarListBody(args))
|
|
1086
1094
|
}),
|
|
1087
1095
|
crm_get_calendar_event: async (args) => ({
|
|
1088
1096
|
module: "calendarEvent",
|
|
1089
1097
|
targetPath: "/oaEvent/queryById",
|
|
1090
|
-
data: await client.
|
|
1098
|
+
data: await client.read("/oaEvent/queryById", buildCalendarDetailBody(args))
|
|
1091
1099
|
}),
|
|
1092
1100
|
crm_list_oa_announcements: async (args) => {
|
|
1093
1101
|
const targetPath = "/oaAnnouncement/queryList";
|
|
@@ -1098,7 +1106,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1098
1106
|
readonly: true,
|
|
1099
1107
|
targetPath,
|
|
1100
1108
|
query,
|
|
1101
|
-
data: await client.
|
|
1109
|
+
data: await client.read(targetPath, undefined, query)
|
|
1102
1110
|
};
|
|
1103
1111
|
},
|
|
1104
1112
|
crm_get_oa_announcement: async (args) => {
|
|
@@ -1109,7 +1117,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1109
1117
|
moduleName: "公告",
|
|
1110
1118
|
readonly: true,
|
|
1111
1119
|
targetPath,
|
|
1112
|
-
data: await client.
|
|
1120
|
+
data: await client.read(targetPath)
|
|
1113
1121
|
};
|
|
1114
1122
|
},
|
|
1115
1123
|
crm_create_oa_announcement: async (args) => executeOaAnnouncementWrite(client, args, false),
|
|
@@ -1124,7 +1132,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1124
1132
|
module: "oaAnnouncement",
|
|
1125
1133
|
moduleName: "公告",
|
|
1126
1134
|
targetPath,
|
|
1127
|
-
data: await client.
|
|
1135
|
+
data: await client.write(targetPath)
|
|
1128
1136
|
};
|
|
1129
1137
|
},
|
|
1130
1138
|
crm_mark_oa_announcement_read: async (args) => {
|
|
@@ -1138,7 +1146,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1138
1146
|
moduleName: "公告",
|
|
1139
1147
|
targetPath,
|
|
1140
1148
|
body,
|
|
1141
|
-
data: await client.
|
|
1149
|
+
data: await client.write(targetPath, body)
|
|
1142
1150
|
};
|
|
1143
1151
|
},
|
|
1144
1152
|
crm_list_oa_logs: async (args) => {
|
|
@@ -1148,7 +1156,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1148
1156
|
moduleName: "日志",
|
|
1149
1157
|
readonly: true,
|
|
1150
1158
|
targetPath,
|
|
1151
|
-
data: await client.
|
|
1159
|
+
data: await client.read(targetPath, buildOaLogListBody(args))
|
|
1152
1160
|
};
|
|
1153
1161
|
},
|
|
1154
1162
|
crm_get_oa_log: async (args) => {
|
|
@@ -1160,7 +1168,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1160
1168
|
readonly: true,
|
|
1161
1169
|
targetPath,
|
|
1162
1170
|
query,
|
|
1163
|
-
data: await client.
|
|
1171
|
+
data: await client.read(targetPath, undefined, query)
|
|
1164
1172
|
};
|
|
1165
1173
|
},
|
|
1166
1174
|
crm_get_oa_log_information: async (args) => {
|
|
@@ -1171,7 +1179,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1171
1179
|
moduleName: "日志",
|
|
1172
1180
|
readonly: true,
|
|
1173
1181
|
targetPath,
|
|
1174
|
-
data: await client.
|
|
1182
|
+
data: await client.read(targetPath)
|
|
1175
1183
|
};
|
|
1176
1184
|
},
|
|
1177
1185
|
crm_list_oa_log_templates: async (args) => {
|
|
@@ -1181,7 +1189,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1181
1189
|
moduleName: "日志模板",
|
|
1182
1190
|
readonly: true,
|
|
1183
1191
|
targetPath,
|
|
1184
|
-
data: await client.
|
|
1192
|
+
data: await client.read(targetPath, buildOaLogTemplateListBody(args))
|
|
1185
1193
|
};
|
|
1186
1194
|
},
|
|
1187
1195
|
crm_get_oa_log_fields: async (args) => {
|
|
@@ -1192,7 +1200,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1192
1200
|
moduleName: "日志字段",
|
|
1193
1201
|
readonly: true,
|
|
1194
1202
|
targetPath,
|
|
1195
|
-
data: await client.
|
|
1203
|
+
data: await client.read(targetPath, undefined, buildOaLogFieldQuery(args))
|
|
1196
1204
|
};
|
|
1197
1205
|
},
|
|
1198
1206
|
crm_get_oa_log_welcome: async () => {
|
|
@@ -1202,7 +1210,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1202
1210
|
moduleName: "日志欢迎语",
|
|
1203
1211
|
readonly: true,
|
|
1204
1212
|
targetPath,
|
|
1205
|
-
data: await client.
|
|
1213
|
+
data: await client.read(targetPath)
|
|
1206
1214
|
};
|
|
1207
1215
|
},
|
|
1208
1216
|
crm_get_oa_log_bulletin: async () => {
|
|
@@ -1212,7 +1220,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1212
1220
|
moduleName: "日志概要",
|
|
1213
1221
|
readonly: true,
|
|
1214
1222
|
targetPath,
|
|
1215
|
-
data: await client.
|
|
1223
|
+
data: await client.read(targetPath)
|
|
1216
1224
|
};
|
|
1217
1225
|
},
|
|
1218
1226
|
crm_get_oa_log_complete_stats: async (args) => {
|
|
@@ -1224,7 +1232,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1224
1232
|
readonly: true,
|
|
1225
1233
|
targetPath,
|
|
1226
1234
|
query,
|
|
1227
|
-
data: await client.
|
|
1235
|
+
data: await client.read(targetPath, undefined, query)
|
|
1228
1236
|
};
|
|
1229
1237
|
},
|
|
1230
1238
|
crm_list_oa_log_complete_records: async (args) => {
|
|
@@ -1234,7 +1242,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1234
1242
|
moduleName: "日志已完成列表",
|
|
1235
1243
|
readonly: true,
|
|
1236
1244
|
targetPath,
|
|
1237
|
-
data: await client.
|
|
1245
|
+
data: await client.read(targetPath, buildOaLogListBody(args))
|
|
1238
1246
|
};
|
|
1239
1247
|
},
|
|
1240
1248
|
crm_list_oa_log_incomplete_records: async (args) => {
|
|
@@ -1244,7 +1252,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1244
1252
|
moduleName: "日志未完成列表",
|
|
1245
1253
|
readonly: true,
|
|
1246
1254
|
targetPath,
|
|
1247
|
-
data: await client.
|
|
1255
|
+
data: await client.read(targetPath, buildOaLogListBody(args))
|
|
1248
1256
|
};
|
|
1249
1257
|
},
|
|
1250
1258
|
crm_list_oa_examine_categories: async (args) => {
|
|
@@ -1254,7 +1262,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1254
1262
|
moduleName: "办公审批",
|
|
1255
1263
|
readonly: true,
|
|
1256
1264
|
targetPath,
|
|
1257
|
-
data: await client.
|
|
1265
|
+
data: await client.read(targetPath, buildOaExamineCategoryBody(args))
|
|
1258
1266
|
};
|
|
1259
1267
|
},
|
|
1260
1268
|
crm_list_oa_examine_groups: async (args) => {
|
|
@@ -1264,7 +1272,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1264
1272
|
moduleName: "办公审批",
|
|
1265
1273
|
readonly: true,
|
|
1266
1274
|
targetPath,
|
|
1267
|
-
data: await client.
|
|
1275
|
+
data: await client.read(targetPath, buildOaExamineGroupBody(args))
|
|
1268
1276
|
};
|
|
1269
1277
|
},
|
|
1270
1278
|
crm_list_oa_examines: async (args) => {
|
|
@@ -1276,7 +1284,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1276
1284
|
listType: listDefinition.key,
|
|
1277
1285
|
listName: listDefinition.name,
|
|
1278
1286
|
targetPath: listDefinition.targetPath,
|
|
1279
|
-
data: await client.
|
|
1287
|
+
data: await client.read(listDefinition.targetPath, buildOaExamineListBody(args))
|
|
1280
1288
|
};
|
|
1281
1289
|
},
|
|
1282
1290
|
crm_get_oa_examine: async (args) => {
|
|
@@ -1287,7 +1295,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1287
1295
|
moduleName: "办公审批",
|
|
1288
1296
|
readonly: true,
|
|
1289
1297
|
targetPath,
|
|
1290
|
-
data: await client.
|
|
1298
|
+
data: await client.read(targetPath)
|
|
1291
1299
|
};
|
|
1292
1300
|
},
|
|
1293
1301
|
crm_get_oa_examine_fields: async (args) => {
|
|
@@ -1300,7 +1308,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1300
1308
|
moduleName: "办公审批",
|
|
1301
1309
|
readonly: true,
|
|
1302
1310
|
targetPath,
|
|
1303
|
-
data: await client.
|
|
1311
|
+
data: await client.read(targetPath, useListEndpoint ? undefined : buildOaExamineCreateFieldQuery(args, categoryId))
|
|
1304
1312
|
};
|
|
1305
1313
|
}
|
|
1306
1314
|
const targetPath = "/oaExamine/getField";
|
|
@@ -1309,7 +1317,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1309
1317
|
moduleName: "办公审批",
|
|
1310
1318
|
readonly: true,
|
|
1311
1319
|
targetPath,
|
|
1312
|
-
data: await client.
|
|
1320
|
+
data: await client.read(targetPath, buildOaExamineFieldBody(args))
|
|
1313
1321
|
};
|
|
1314
1322
|
},
|
|
1315
1323
|
crm_list_oa_examine_record_logs: async (args) => {
|
|
@@ -1319,7 +1327,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1319
1327
|
moduleName: "办公审批",
|
|
1320
1328
|
readonly: true,
|
|
1321
1329
|
targetPath,
|
|
1322
|
-
data: await client.
|
|
1330
|
+
data: await client.read(targetPath, buildOaExamineRecordLogBody(args))
|
|
1323
1331
|
};
|
|
1324
1332
|
},
|
|
1325
1333
|
crm_list_oa_examine_flow_records: async (args) => {
|
|
@@ -1329,18 +1337,18 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1329
1337
|
moduleName: "办公审批",
|
|
1330
1338
|
readonly: true,
|
|
1331
1339
|
targetPath,
|
|
1332
|
-
data: await client.
|
|
1340
|
+
data: await client.read(targetPath, buildOaExamineFlowRecordBody(args))
|
|
1333
1341
|
};
|
|
1334
1342
|
},
|
|
1335
1343
|
crm_list_oa_tasks: async (args) => ({
|
|
1336
1344
|
module: "oaTask",
|
|
1337
1345
|
targetPath: "/oaTask/queryTaskList",
|
|
1338
|
-
data: await client.
|
|
1346
|
+
data: await client.read("/oaTask/queryTaskList", buildOaTaskListBody(args))
|
|
1339
1347
|
}),
|
|
1340
1348
|
crm_list_related_oa_tasks: async (args) => ({
|
|
1341
1349
|
module: "oaTask",
|
|
1342
1350
|
targetPath: "/oaTask/queryTypeTaskList",
|
|
1343
|
-
data: await client.
|
|
1351
|
+
data: await client.read("/oaTask/queryTypeTaskList", undefined, buildRelatedOaTaskQuery(args))
|
|
1344
1352
|
}),
|
|
1345
1353
|
crm_preview_write: (args) => previewWrite(args),
|
|
1346
1354
|
crm_update_customer: async (args) => {
|
|
@@ -1359,8 +1367,8 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1359
1367
|
const resolvedRecord = directId ? undefined : await resolveUniqueRecord(client, moduleDefinition, args);
|
|
1360
1368
|
const id = directId ?? resolvedRecord?.[moduleDefinition.primaryKey] ?? resolvedRecord?.id;
|
|
1361
1369
|
const body = await buildUpdateInformationBody(client, moduleDefinition, { ...args, id });
|
|
1362
|
-
const data = await client.
|
|
1363
|
-
const verification = args.verify === false ? undefined : await
|
|
1370
|
+
const data = await client.write(targetPath, body);
|
|
1371
|
+
const verification = args.verify === false ? undefined : await verifyInformationUpdateSafely(client, moduleDefinition, body);
|
|
1364
1372
|
return cleanObject({
|
|
1365
1373
|
module: moduleDefinition.key,
|
|
1366
1374
|
targetPath,
|
|
@@ -1377,10 +1385,16 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1377
1385
|
if (!args.confirm) {
|
|
1378
1386
|
return previewWrite({ ...args, operation: "create", targetPath });
|
|
1379
1387
|
}
|
|
1388
|
+
const body = buildModelSaveBody(args);
|
|
1389
|
+
const businessSelection = moduleDefinition.key === "business"
|
|
1390
|
+
? await validateBusinessCreate(client, body)
|
|
1391
|
+
: undefined;
|
|
1380
1392
|
return {
|
|
1381
1393
|
module: moduleDefinition.key,
|
|
1382
1394
|
targetPath,
|
|
1383
|
-
|
|
1395
|
+
body,
|
|
1396
|
+
...(businessSelection ? { businessSelection } : {}),
|
|
1397
|
+
data: await client.write(targetPath, body)
|
|
1384
1398
|
};
|
|
1385
1399
|
},
|
|
1386
1400
|
crm_update_record_fields: async (args) => {
|
|
@@ -1391,8 +1405,8 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1391
1405
|
return previewWrite({ ...args, operation: "updateInformation", targetPath });
|
|
1392
1406
|
}
|
|
1393
1407
|
const body = await buildUpdateInformationBody(client, moduleDefinition, args);
|
|
1394
|
-
const data = await client.
|
|
1395
|
-
const verification = args.verify === false ? undefined : await
|
|
1408
|
+
const data = await client.write(targetPath, body);
|
|
1409
|
+
const verification = args.verify === false ? undefined : await verifyInformationUpdateSafely(client, moduleDefinition, body);
|
|
1396
1410
|
return {
|
|
1397
1411
|
module: moduleDefinition.key,
|
|
1398
1412
|
targetPath,
|
|
@@ -1411,8 +1425,8 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1411
1425
|
return previewWrite({ ...args, module: "product", id, operation: "updateInformation", targetPath });
|
|
1412
1426
|
}
|
|
1413
1427
|
const body = await buildUpdateInformationBody(client, moduleDefinition, { ...args, id });
|
|
1414
|
-
const data = await client.
|
|
1415
|
-
const verification = args.verify === false ? undefined : await
|
|
1428
|
+
const data = await client.write(targetPath, body);
|
|
1429
|
+
const verification = args.verify === false ? undefined : await verifyInformationUpdateSafely(client, moduleDefinition, body);
|
|
1416
1430
|
return cleanObject({
|
|
1417
1431
|
module: "product",
|
|
1418
1432
|
moduleName: "产品",
|
|
@@ -1445,7 +1459,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1445
1459
|
module: "calendarEvent",
|
|
1446
1460
|
targetPath,
|
|
1447
1461
|
body,
|
|
1448
|
-
data: await client.
|
|
1462
|
+
data: await client.write(targetPath, body)
|
|
1449
1463
|
};
|
|
1450
1464
|
},
|
|
1451
1465
|
crm_update_calendar_event: async (args) => {
|
|
@@ -1458,7 +1472,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1458
1472
|
module: "calendarEvent",
|
|
1459
1473
|
targetPath,
|
|
1460
1474
|
body,
|
|
1461
|
-
data: await client.
|
|
1475
|
+
data: await client.write(targetPath, body)
|
|
1462
1476
|
};
|
|
1463
1477
|
},
|
|
1464
1478
|
crm_create_oa_log: async (args) => executeOaLogWrite(client, args, false),
|
|
@@ -1474,7 +1488,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1474
1488
|
moduleName: "日志",
|
|
1475
1489
|
targetPath,
|
|
1476
1490
|
query,
|
|
1477
|
-
data: await client.
|
|
1491
|
+
data: await client.write(targetPath, undefined, query)
|
|
1478
1492
|
};
|
|
1479
1493
|
},
|
|
1480
1494
|
crm_toggle_oa_log_favour: async (args) => {
|
|
@@ -1488,7 +1502,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1488
1502
|
moduleName: "日志",
|
|
1489
1503
|
targetPath,
|
|
1490
1504
|
query,
|
|
1491
|
-
data: await client.
|
|
1505
|
+
data: await client.write(targetPath, undefined, query)
|
|
1492
1506
|
};
|
|
1493
1507
|
},
|
|
1494
1508
|
crm_create_oa_examine: async (args) => {
|
|
@@ -1502,7 +1516,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1502
1516
|
moduleName: "办公审批",
|
|
1503
1517
|
targetPath,
|
|
1504
1518
|
body,
|
|
1505
|
-
data: await client.
|
|
1519
|
+
data: await client.write(targetPath, body)
|
|
1506
1520
|
};
|
|
1507
1521
|
},
|
|
1508
1522
|
crm_save_oa_examine_draft: async (args) => {
|
|
@@ -1516,7 +1530,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1516
1530
|
moduleName: "办公审批",
|
|
1517
1531
|
targetPath,
|
|
1518
1532
|
body,
|
|
1519
|
-
data: await client.
|
|
1533
|
+
data: await client.write(targetPath, body)
|
|
1520
1534
|
};
|
|
1521
1535
|
},
|
|
1522
1536
|
crm_audit_oa_examine: async (args) => {
|
|
@@ -1530,7 +1544,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1530
1544
|
moduleName: "办公审批",
|
|
1531
1545
|
targetPath,
|
|
1532
1546
|
body,
|
|
1533
|
-
data: await client.
|
|
1547
|
+
data: await client.write(targetPath, body)
|
|
1534
1548
|
};
|
|
1535
1549
|
},
|
|
1536
1550
|
crm_batch_audit_oa_examine: async (args) => {
|
|
@@ -1544,7 +1558,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1544
1558
|
moduleName: "办公审批",
|
|
1545
1559
|
targetPath,
|
|
1546
1560
|
body,
|
|
1547
|
-
data: await client.
|
|
1561
|
+
data: await client.write(targetPath, body)
|
|
1548
1562
|
};
|
|
1549
1563
|
},
|
|
1550
1564
|
crm_create_oa_task: async (args) => {
|
|
@@ -1557,7 +1571,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1557
1571
|
module: "oaTask",
|
|
1558
1572
|
targetPath,
|
|
1559
1573
|
body,
|
|
1560
|
-
data: await client.
|
|
1574
|
+
data: await client.write(targetPath, body)
|
|
1561
1575
|
};
|
|
1562
1576
|
},
|
|
1563
1577
|
crm_update_oa_task_fields: async (args) => {
|
|
@@ -1576,7 +1590,7 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1576
1590
|
for (const call of calls) {
|
|
1577
1591
|
results.push({
|
|
1578
1592
|
targetPath: call.targetPath,
|
|
1579
|
-
data: await client.
|
|
1593
|
+
data: await client.write(call.targetPath, call.body)
|
|
1580
1594
|
});
|
|
1581
1595
|
}
|
|
1582
1596
|
return {
|
|
@@ -1589,10 +1603,14 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1589
1603
|
if (!args.confirm) {
|
|
1590
1604
|
return previewWrite({ ...args, operation: "addFollowup", targetPath });
|
|
1591
1605
|
}
|
|
1606
|
+
const body = buildFollowupSaveBody(args);
|
|
1607
|
+
const target = await validateAndReadFollowupTarget(client, body, false);
|
|
1592
1608
|
return {
|
|
1593
1609
|
module: "activity",
|
|
1594
1610
|
targetPath,
|
|
1595
|
-
|
|
1611
|
+
target,
|
|
1612
|
+
body,
|
|
1613
|
+
data: await client.write(targetPath, body)
|
|
1596
1614
|
};
|
|
1597
1615
|
},
|
|
1598
1616
|
crm_update_followup: async (args) => {
|
|
@@ -1603,10 +1621,20 @@ export function createToolHandlers(config = {}, sharedClient) {
|
|
|
1603
1621
|
const body = args.useInformationUpdate
|
|
1604
1622
|
? cleanObject({ id: args.id, label: 19, list: args.list ?? args.fields ?? [], batchId: args.batchId })
|
|
1605
1623
|
: buildFollowupSaveBody(args);
|
|
1624
|
+
if (args.useInformationUpdate) {
|
|
1625
|
+
requireRecordId(args.id, "更新跟进记录字段必须提供 id。");
|
|
1626
|
+
if (!Array.isArray(body.list) || body.list.length === 0) {
|
|
1627
|
+
throw new Error("更新跟进记录字段必须提供非空 list。");
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
else {
|
|
1631
|
+
await validateAndReadFollowupTarget(client, body, true);
|
|
1632
|
+
}
|
|
1606
1633
|
return {
|
|
1607
1634
|
module: "activity",
|
|
1608
1635
|
targetPath,
|
|
1609
|
-
|
|
1636
|
+
body,
|
|
1637
|
+
data: await client.write(targetPath, body)
|
|
1610
1638
|
};
|
|
1611
1639
|
},
|
|
1612
1640
|
workorder_search_records: async (args) => searchWorkorders(client, args),
|
|
@@ -1639,7 +1667,7 @@ async function searchWorkorders(client, args) {
|
|
|
1639
1667
|
scope,
|
|
1640
1668
|
readonly: true,
|
|
1641
1669
|
targetPath,
|
|
1642
|
-
data: await client.
|
|
1670
|
+
data: await client.read(targetPath, body)
|
|
1643
1671
|
};
|
|
1644
1672
|
}
|
|
1645
1673
|
async function getWorkorder(client, args) {
|
|
@@ -1647,8 +1675,8 @@ async function getWorkorder(client, args) {
|
|
|
1647
1675
|
const id = requiredWorkorderId(args.id);
|
|
1648
1676
|
const prefix = scope === "offline" ? "/wkoOfflineWorkorder" : "/wkoWorkorder";
|
|
1649
1677
|
const [record, information] = await Promise.all([
|
|
1650
|
-
client.
|
|
1651
|
-
client.
|
|
1678
|
+
client.read(`${prefix}/queryById/${id}`),
|
|
1679
|
+
client.read(`${prefix}/information/${id}`)
|
|
1652
1680
|
]);
|
|
1653
1681
|
return {
|
|
1654
1682
|
module: "workorder",
|
|
@@ -1667,7 +1695,7 @@ async function getWorkorderSchema(client, args) {
|
|
|
1667
1695
|
scope,
|
|
1668
1696
|
readonly: true,
|
|
1669
1697
|
targetPath: `${prefix}/field${id}`,
|
|
1670
|
-
fields: await client.
|
|
1698
|
+
fields: await client.read(`${prefix}/field${id}`, cleanObject({ templateId: args.templateId }))
|
|
1671
1699
|
};
|
|
1672
1700
|
}
|
|
1673
1701
|
function previewWorkorderWrite(args) {
|
|
@@ -1688,11 +1716,14 @@ async function saveWorkorder(client, args, update) {
|
|
|
1688
1716
|
...prepared
|
|
1689
1717
|
};
|
|
1690
1718
|
}
|
|
1691
|
-
const data = await client.
|
|
1719
|
+
const data = await client.write(prepared.targetPath, prepared.body);
|
|
1692
1720
|
const id = extractSavedWorkorderId(data, prepared);
|
|
1693
1721
|
const verification = id
|
|
1694
|
-
? await
|
|
1695
|
-
: {
|
|
1722
|
+
? await verifyWorkorderWriteSafely(client, prepared.scope, id)
|
|
1723
|
+
: {
|
|
1724
|
+
status: "unknown",
|
|
1725
|
+
message: "写入已成功,但服务端未返回工单 ID;请稍后使用只读列表查询确认记录。"
|
|
1726
|
+
};
|
|
1696
1727
|
return {
|
|
1697
1728
|
preview: false,
|
|
1698
1729
|
scope: prepared.scope,
|
|
@@ -1701,6 +1732,19 @@ async function saveWorkorder(client, args, update) {
|
|
|
1701
1732
|
verification
|
|
1702
1733
|
};
|
|
1703
1734
|
}
|
|
1735
|
+
async function verifyWorkorderWriteSafely(client, scope, id) {
|
|
1736
|
+
try {
|
|
1737
|
+
return {
|
|
1738
|
+
status: "confirmed",
|
|
1739
|
+
ok: true,
|
|
1740
|
+
...await getWorkorder(client, { scope, id })
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
catch (error) {
|
|
1744
|
+
// 写接口已经 code=0 后,回读异常只能说明验证状态未知,不能推翻服务端确认的写入结果。
|
|
1745
|
+
return verificationUnavailable(`/${scope === "offline" ? "wkoOfflineWorkorder" : "wkoWorkorder"}/queryById/${id}`, error);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1704
1748
|
function prepareWorkorderWrite(args, update) {
|
|
1705
1749
|
const scope = normalizeWorkorderScope(args.scope, false);
|
|
1706
1750
|
if (scope === "offline") {
|
|
@@ -2267,7 +2311,7 @@ function looksLikeFieldName(value) {
|
|
|
2267
2311
|
async function fetchModuleFields(client, moduleDefinition, args) {
|
|
2268
2312
|
const id = args.id ?? args[moduleDefinition.primaryKey];
|
|
2269
2313
|
const path = id ? `${moduleDefinition.basePath}/field/${id}` : `${moduleDefinition.basePath}/field`;
|
|
2270
|
-
const data = await client.
|
|
2314
|
+
const data = await client.read(path, undefined, cleanQuery({ type: args.type, poolId: args.poolId }));
|
|
2271
2315
|
return flattenFieldDefinitions(data);
|
|
2272
2316
|
}
|
|
2273
2317
|
function flattenFieldDefinitions(input) {
|
|
@@ -2336,7 +2380,7 @@ async function resolveUpdateBatchId(client, moduleDefinition, body, list) {
|
|
|
2336
2380
|
if (body.batchId || !body.id || !updateNeedsBatchId(list)) {
|
|
2337
2381
|
return undefined;
|
|
2338
2382
|
}
|
|
2339
|
-
const data = await client.
|
|
2383
|
+
const data = await client.read(`${moduleDefinition.basePath}/queryById/${body.id}`);
|
|
2340
2384
|
return findFirstValueByKey(data, "batchId");
|
|
2341
2385
|
}
|
|
2342
2386
|
function updateNeedsBatchId(list) {
|
|
@@ -2429,7 +2473,7 @@ function parseFieldOptions(input) {
|
|
|
2429
2473
|
}
|
|
2430
2474
|
async function verifyInformationUpdate(client, moduleDefinition, body) {
|
|
2431
2475
|
const endpoint = `${moduleDefinition.basePath}/information/${body.id}`;
|
|
2432
|
-
const data = await client.
|
|
2476
|
+
const data = await client.read(endpoint);
|
|
2433
2477
|
const checked = (body.list ?? []).map((item) => {
|
|
2434
2478
|
const actualValue = findInformationValue(data, item);
|
|
2435
2479
|
return {
|
|
@@ -2440,12 +2484,34 @@ async function verifyInformationUpdate(client, moduleDefinition, body) {
|
|
|
2440
2484
|
matched: valuesMatch(item.value, actualValue)
|
|
2441
2485
|
};
|
|
2442
2486
|
});
|
|
2487
|
+
const ok = checked.every((item) => item.matched);
|
|
2443
2488
|
return {
|
|
2444
2489
|
endpoint,
|
|
2445
|
-
|
|
2490
|
+
status: ok ? "confirmed" : "mismatch",
|
|
2491
|
+
ok,
|
|
2446
2492
|
checked
|
|
2447
2493
|
};
|
|
2448
2494
|
}
|
|
2495
|
+
async function verifyInformationUpdateSafely(client, moduleDefinition, body) {
|
|
2496
|
+
try {
|
|
2497
|
+
return await verifyInformationUpdate(client, moduleDefinition, body);
|
|
2498
|
+
}
|
|
2499
|
+
catch (error) {
|
|
2500
|
+
// updateInformation 已被旧 CRM 以 code=0 接受;后续只读验证失败时禁止把成功写入改判为失败。
|
|
2501
|
+
return verificationUnavailable(`${moduleDefinition.basePath}/information/${body.id}`, error);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
function verificationUnavailable(endpoint, error) {
|
|
2505
|
+
return {
|
|
2506
|
+
endpoint,
|
|
2507
|
+
status: "unknown",
|
|
2508
|
+
message: "写入已成功,但后续回读失败;请稍后使用只读查询确认目标记录,禁止直接重放写请求。",
|
|
2509
|
+
error: {
|
|
2510
|
+
name: error instanceof Error ? error.name : "Error",
|
|
2511
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2512
|
+
}
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2449
2515
|
function findInformationValue(data, field) {
|
|
2450
2516
|
const direct = findDirectInformationValue(data, field);
|
|
2451
2517
|
if (direct.found) {
|
|
@@ -2522,7 +2588,7 @@ function normalizeText(value) {
|
|
|
2522
2588
|
return value === undefined || value === null ? "" : String(value).trim().toLowerCase();
|
|
2523
2589
|
}
|
|
2524
2590
|
async function listCustomerPools(client, args) {
|
|
2525
|
-
const pools = await client.
|
|
2591
|
+
const pools = await client.read("/crmCustomerPool/queryPoolNameListByAuth");
|
|
2526
2592
|
const poolList = Array.isArray(pools) ? pools : [];
|
|
2527
2593
|
const includeSamples = Boolean(args.includeSamples);
|
|
2528
2594
|
const limit = includeSamples ? positiveInteger(args.sampleLimit ?? args.limit, 3) : 1;
|
|
@@ -2583,7 +2649,7 @@ async function resolvePoolContext(client, moduleDefinition, args) {
|
|
|
2583
2649
|
if (args.poolId) {
|
|
2584
2650
|
return { poolId: args.poolId, pool: cleanObject({ poolId: args.poolId, poolName: args.poolName }) };
|
|
2585
2651
|
}
|
|
2586
|
-
const pools = await client.
|
|
2652
|
+
const pools = await client.read(`${moduleDefinition.basePath}/queryPoolNameListByAuth`);
|
|
2587
2653
|
const poolList = Array.isArray(pools) ? pools : [];
|
|
2588
2654
|
const selectedPool = args.poolName
|
|
2589
2655
|
? poolList.find((pool) => String(pool.poolName ?? pool.name ?? "").trim() === String(args.poolName).trim())
|
|
@@ -2601,22 +2667,22 @@ async function callRelatedRecords(client, moduleDefinition, args) {
|
|
|
2601
2667
|
const relation = String(args.relation ?? args.type ?? "").trim();
|
|
2602
2668
|
const pageBody = cleanObject({ page: args.page ?? 1, limit: args.limit ?? 15, pageType: 1, id: args.id, ...safeExtra(args.extra) });
|
|
2603
2669
|
if (moduleDefinition.key === "business" && relation === "product") {
|
|
2604
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2670
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmBusiness/queryProduct", pageBody) };
|
|
2605
2671
|
}
|
|
2606
2672
|
if (moduleDefinition.key === "business" && relation === "contacts") {
|
|
2607
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2673
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmBusiness/queryContacts", pageBody) };
|
|
2608
2674
|
}
|
|
2609
2675
|
if (moduleDefinition.key === "contacts" && relation === "business") {
|
|
2610
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2676
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmContacts/queryBusiness", pageBody) };
|
|
2611
2677
|
}
|
|
2612
2678
|
if (moduleDefinition.key === "contract" && relation === "product") {
|
|
2613
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2679
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmContract/queryProductListByContractId", pageBody) };
|
|
2614
2680
|
}
|
|
2615
2681
|
if (moduleDefinition.key === "contract" && relation === "receivablesPlan") {
|
|
2616
2682
|
return {
|
|
2617
2683
|
module: moduleDefinition.key,
|
|
2618
2684
|
relation,
|
|
2619
|
-
data: await client.
|
|
2685
|
+
data: await client.read("/crmContract/queryReceivablesPlansByContractId", undefined, {
|
|
2620
2686
|
contractId: args.id,
|
|
2621
2687
|
receivablesId: args.receivablesId,
|
|
2622
2688
|
productId: args.productId
|
|
@@ -2624,16 +2690,16 @@ async function callRelatedRecords(client, moduleDefinition, args) {
|
|
|
2624
2690
|
};
|
|
2625
2691
|
}
|
|
2626
2692
|
if (moduleDefinition.key === "receivables" && relation === "product") {
|
|
2627
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2693
|
+
return { module: moduleDefinition.key, relation, data: await client.read(`/crmReceivables/queryProductList/${args.id}`) };
|
|
2628
2694
|
}
|
|
2629
2695
|
if (moduleDefinition.key === "quotation" && relation === "product") {
|
|
2630
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2696
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmQuotation/queryProductList", pageBody) };
|
|
2631
2697
|
}
|
|
2632
2698
|
if (moduleDefinition.key === "product" && relation === "saleProduct") {
|
|
2633
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2699
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmProduct/querySaleProductPageList", pageBody) };
|
|
2634
2700
|
}
|
|
2635
2701
|
if (moduleDefinition.key === "receivablesPlan" && relation === "contractCustomer") {
|
|
2636
|
-
return { module: moduleDefinition.key, relation, data: await client.
|
|
2702
|
+
return { module: moduleDefinition.key, relation, data: await client.read("/crmReceivablesPlan/queryByContractAndCustomer", pageBody) };
|
|
2637
2703
|
}
|
|
2638
2704
|
throw new Error(`当前 MCP 未配置“${moduleDefinition.name} / ${relation}”关联查询白名单。`);
|
|
2639
2705
|
}
|
|
@@ -2865,7 +2931,7 @@ async function executeDomainWrite(client, domain, args) {
|
|
|
2865
2931
|
targetPath,
|
|
2866
2932
|
body,
|
|
2867
2933
|
query: Object.keys(query).length > 0 ? query : undefined,
|
|
2868
|
-
data: await client.
|
|
2934
|
+
data: await client.write(targetPath, body, query)
|
|
2869
2935
|
});
|
|
2870
2936
|
}
|
|
2871
2937
|
function previewDomainWrite(domain, targetPath, body, query) {
|
|
@@ -3033,7 +3099,7 @@ async function executeCrmProductSave(client, args, requireId) {
|
|
|
3033
3099
|
moduleName: "产品",
|
|
3034
3100
|
targetPath,
|
|
3035
3101
|
body,
|
|
3036
|
-
data: await client.
|
|
3102
|
+
data: await client.write(targetPath, body)
|
|
3037
3103
|
};
|
|
3038
3104
|
}
|
|
3039
3105
|
function buildCrmProductSaveBody(args, requireId) {
|
|
@@ -3076,7 +3142,7 @@ async function executeCrmProductSimpleWrite(client, args, operation, targetPath,
|
|
|
3076
3142
|
moduleName: "产品",
|
|
3077
3143
|
targetPath,
|
|
3078
3144
|
body,
|
|
3079
|
-
data: await client.
|
|
3145
|
+
data: await client.write(targetPath, body)
|
|
3080
3146
|
};
|
|
3081
3147
|
}
|
|
3082
3148
|
function buildCrmProductStatusBody(args) {
|
|
@@ -3140,7 +3206,7 @@ async function executeOaAnnouncementWrite(client, args, requireId) {
|
|
|
3140
3206
|
moduleName: "公告",
|
|
3141
3207
|
targetPath,
|
|
3142
3208
|
body,
|
|
3143
|
-
data: await client.
|
|
3209
|
+
data: await client.write(targetPath, body)
|
|
3144
3210
|
};
|
|
3145
3211
|
}
|
|
3146
3212
|
function buildOaAnnouncementBody(args, requireId) {
|
|
@@ -3216,7 +3282,7 @@ async function executeOaLogWrite(client, args, requireId) {
|
|
|
3216
3282
|
moduleName: "日志",
|
|
3217
3283
|
targetPath,
|
|
3218
3284
|
body,
|
|
3219
|
-
data: await client.
|
|
3285
|
+
data: await client.write(targetPath, body)
|
|
3220
3286
|
};
|
|
3221
3287
|
}
|
|
3222
3288
|
async function buildOaLogWriteBody(client, args, requireId) {
|
|
@@ -3233,7 +3299,7 @@ async function buildOaLogWriteBody(client, args, requireId) {
|
|
|
3233
3299
|
if (shouldBuildFields) {
|
|
3234
3300
|
const logId = args.logId ?? args.id;
|
|
3235
3301
|
const targetPath = logId ? `/oaLogTemplateField/field/${logId}` : "/oaLogTemplateField/field";
|
|
3236
|
-
const fieldMetadata = await client.
|
|
3302
|
+
const fieldMetadata = await client.read(targetPath, undefined, buildOaLogFieldQuery(args));
|
|
3237
3303
|
const fields = flattenOaExamineFields(fieldMetadata);
|
|
3238
3304
|
const fieldValues = normalizeFieldValues(fieldValuesInput);
|
|
3239
3305
|
for (const [rawKey, rawValue] of Object.entries(fieldValues)) {
|
|
@@ -3336,7 +3402,7 @@ async function executeCrmDocumentWrite(client, moduleKey, args, requireId) {
|
|
|
3336
3402
|
targetPath,
|
|
3337
3403
|
body,
|
|
3338
3404
|
approvalNotice,
|
|
3339
|
-
data: await client.
|
|
3405
|
+
data: await client.write(targetPath, body)
|
|
3340
3406
|
});
|
|
3341
3407
|
}
|
|
3342
3408
|
function getCrmDocumentWriteDefinition(moduleKey) {
|
|
@@ -3383,7 +3449,7 @@ async function buildStructuredCrmDocumentBody(client, definition, args, requireI
|
|
|
3383
3449
|
}
|
|
3384
3450
|
const recordId = args[definition.primaryKey] ?? args.id ?? args.recordId;
|
|
3385
3451
|
const fieldPath = requireId && !isBlank(recordId) ? `${definition.basePath}/field/${recordId}` : `${definition.basePath}/field`;
|
|
3386
|
-
const fieldMetadata = await client.
|
|
3452
|
+
const fieldMetadata = await client.read(fieldPath, undefined, cleanQuery({ type: args.type }));
|
|
3387
3453
|
const fields = flattenOaExamineFields(fieldMetadata);
|
|
3388
3454
|
if (fields.length === 0 && Object.keys(fieldValues).length > 0) {
|
|
3389
3455
|
throw new Error(`未从 ${fieldPath} 读取到 ${definition.name} 字段,无法自动组装单据字段。`);
|
|
@@ -3721,7 +3787,7 @@ async function buildStructuredOaExamineWriteBody(client, args, examineId) {
|
|
|
3721
3787
|
throw new Error("自动组装 OA 审批自定义字段请提供 categoryId。");
|
|
3722
3788
|
}
|
|
3723
3789
|
const targetPath = `/oaExamineField/queryField/${categoryId}`;
|
|
3724
|
-
const fieldMetadata = await client.
|
|
3790
|
+
const fieldMetadata = await client.read(targetPath, buildOaExamineCreateFieldQuery(args, categoryId));
|
|
3725
3791
|
const fields = flattenOaExamineFields(fieldMetadata);
|
|
3726
3792
|
if (fields.length === 0) {
|
|
3727
3793
|
throw new Error(`未从 ${targetPath} 读取到 OA 审批字段,无法自动组装自定义字段。`);
|
|
@@ -4341,7 +4407,13 @@ function buildModelSaveBody(args) {
|
|
|
4341
4407
|
saveType: args.saveType,
|
|
4342
4408
|
fileId: args.fileId,
|
|
4343
4409
|
aiAnalysis: args.aiAnalysis,
|
|
4344
|
-
member: args.member
|
|
4410
|
+
member: args.member,
|
|
4411
|
+
// 这些字段属于 CrmBusinessSaveBO 顶层,放进 entity 或静默丢弃都会让后端保存链路异常。
|
|
4412
|
+
product: args.product,
|
|
4413
|
+
contactsId: args.contactsId,
|
|
4414
|
+
customerSuperior: args.customerSuperior,
|
|
4415
|
+
contacts: args.contacts,
|
|
4416
|
+
examineFlowData: args.examineFlowData
|
|
4345
4417
|
});
|
|
4346
4418
|
}
|
|
4347
4419
|
function buildFollowupSaveBody(args) {
|
|
@@ -4350,6 +4422,9 @@ function buildFollowupSaveBody(args) {
|
|
|
4350
4422
|
? body.entity
|
|
4351
4423
|
: {};
|
|
4352
4424
|
const entity = { ...sourceEntity };
|
|
4425
|
+
if (args.id !== undefined && entity.id === undefined) {
|
|
4426
|
+
entity.id = args.id;
|
|
4427
|
+
}
|
|
4353
4428
|
if (!Array.isArray(entity.relateDataList)) {
|
|
4354
4429
|
entity.relateDataList = [];
|
|
4355
4430
|
}
|
|
@@ -4358,6 +4433,112 @@ function buildFollowupSaveBody(args) {
|
|
|
4358
4433
|
entity
|
|
4359
4434
|
};
|
|
4360
4435
|
}
|
|
4436
|
+
async function validateBusinessCreate(client, body) {
|
|
4437
|
+
const entity = objectValue(body.entity, "新增商机必须提供 entity 对象。");
|
|
4438
|
+
requireNonBlankText(entity.businessName, "新增商机缺少 entity.businessName。请先补充商机名称。");
|
|
4439
|
+
requireRecordId(entity.customerId, "新增商机缺少 entity.customerId。请先查询并唯一确定客户 ID。");
|
|
4440
|
+
const groups = await loadBusinessStatusGroups(client);
|
|
4441
|
+
const typeId = optionalRecordId(entity.typeId);
|
|
4442
|
+
const statusId = optionalRecordId(entity.statusId);
|
|
4443
|
+
if (!typeId || !statusId) {
|
|
4444
|
+
throw new Error("新增商机缺少合法的 entity.typeId/statusId。请从 crm_get_business_status_groups 的同一状态组中选择,"
|
|
4445
|
+
+ `当前可选值:${formatBusinessStatusGroups(groups)}`);
|
|
4446
|
+
}
|
|
4447
|
+
const group = groups.find((item) => optionalRecordId(item.flowId) === typeId);
|
|
4448
|
+
const setting = Array.isArray(group?.settingList)
|
|
4449
|
+
? group.settingList.find((item) => optionalRecordId(item?.settingId) === statusId)
|
|
4450
|
+
: undefined;
|
|
4451
|
+
if (!group || !setting) {
|
|
4452
|
+
throw new Error(`商机阶段组合无效:typeId=${typeId}, statusId=${statusId}。`
|
|
4453
|
+
+ `typeId 必须是状态组 flowId,statusId 必须来自该组 settingList;当前可选值:${formatBusinessStatusGroups(groups)}`);
|
|
4454
|
+
}
|
|
4455
|
+
return cleanObject({
|
|
4456
|
+
typeId,
|
|
4457
|
+
statusId,
|
|
4458
|
+
flowName: typeof group.flowName === "string" ? group.flowName : undefined,
|
|
4459
|
+
settingName: typeof setting.settingName === "string" ? setting.settingName : undefined
|
|
4460
|
+
});
|
|
4461
|
+
}
|
|
4462
|
+
async function loadBusinessStatusGroups(client) {
|
|
4463
|
+
const data = await client.post("/crmFlow/queryBusinessSetting");
|
|
4464
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
4465
|
+
throw new Error("当前账号没有可用的商机状态组,无法创建商机;请先在 CRM 中启用状态组或检查数据权限。");
|
|
4466
|
+
}
|
|
4467
|
+
return data.filter((item) => Boolean(item) && typeof item === "object" && !Array.isArray(item));
|
|
4468
|
+
}
|
|
4469
|
+
function formatBusinessStatusGroups(groups) {
|
|
4470
|
+
return groups.slice(0, 10).map((group) => {
|
|
4471
|
+
const stages = Array.isArray(group.settingList)
|
|
4472
|
+
? group.settingList.slice(0, 10).map((item) => `${item?.settingName ?? "未命名阶段"}(statusId=${item?.settingId ?? "?"})`).join("、")
|
|
4473
|
+
: "无阶段";
|
|
4474
|
+
return `${group.flowName ?? "未命名状态组"}(typeId=${group.flowId ?? "?"})[${stages}]`;
|
|
4475
|
+
}).join(";");
|
|
4476
|
+
}
|
|
4477
|
+
const FOLLOWUP_TARGETS = new Map([
|
|
4478
|
+
[1, "leads"],
|
|
4479
|
+
[2, "customer"],
|
|
4480
|
+
[3, "contacts"],
|
|
4481
|
+
[4, "product"],
|
|
4482
|
+
[5, "business"],
|
|
4483
|
+
[6, "contract"],
|
|
4484
|
+
[7, "receivables"],
|
|
4485
|
+
[14, "receivablesPlan"],
|
|
4486
|
+
[17, "returnVisit"],
|
|
4487
|
+
[18, "invoice"],
|
|
4488
|
+
[22, "quotation"]
|
|
4489
|
+
]);
|
|
4490
|
+
async function validateAndReadFollowupTarget(client, body, requireActivityId) {
|
|
4491
|
+
const entity = objectValue(body.entity, "跟进记录必须提供 entity 对象。");
|
|
4492
|
+
if (requireActivityId) {
|
|
4493
|
+
requireRecordId(entity.id, "更新跟进记录必须提供 id 或 entity.id。");
|
|
4494
|
+
}
|
|
4495
|
+
requireNonBlankText(entity.content, "跟进记录缺少 entity.content,内容不能为空。");
|
|
4496
|
+
requireNonBlankText(entity.category, "跟进记录缺少 entity.category,跟进方式不能为空。");
|
|
4497
|
+
const activityType = typeof entity.activityType === "number"
|
|
4498
|
+
? entity.activityType
|
|
4499
|
+
: Number(entity.activityType);
|
|
4500
|
+
const moduleKey = FOLLOWUP_TARGETS.get(activityType);
|
|
4501
|
+
if (!moduleKey) {
|
|
4502
|
+
throw new Error("跟进记录 entity.activityType 无效;支持 1线索、2客户、3联系人、4产品、5商机、6合同、"
|
|
4503
|
+
+ "7回款、14回款计划、17回访、18发票、22报价单。");
|
|
4504
|
+
}
|
|
4505
|
+
const targetId = requireRecordId(entity.activityTypeId, "跟进记录缺少 entity.activityTypeId,请先查询并唯一确定被跟进记录 ID。");
|
|
4506
|
+
const definition = getModuleByKey(moduleKey);
|
|
4507
|
+
// 先回读目标,避免无权限、已删除或类型与 ID 不匹配时落到后端空指针兜底。
|
|
4508
|
+
await client.read(`${definition.basePath}/queryById/${targetId}`);
|
|
4509
|
+
return { module: moduleKey, id: targetId, readbackVerified: true };
|
|
4510
|
+
}
|
|
4511
|
+
function objectValue(value, message) {
|
|
4512
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4513
|
+
throw new Error(message);
|
|
4514
|
+
}
|
|
4515
|
+
return value;
|
|
4516
|
+
}
|
|
4517
|
+
function requireNonBlankText(value, message) {
|
|
4518
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
4519
|
+
throw new Error(message);
|
|
4520
|
+
}
|
|
4521
|
+
return value;
|
|
4522
|
+
}
|
|
4523
|
+
function optionalRecordId(value) {
|
|
4524
|
+
if (typeof value === "bigint" && value > 0n) {
|
|
4525
|
+
return value.toString();
|
|
4526
|
+
}
|
|
4527
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value > 0) {
|
|
4528
|
+
return String(value);
|
|
4529
|
+
}
|
|
4530
|
+
if (typeof value === "string" && /^[1-9]\d*$/.test(value.trim())) {
|
|
4531
|
+
return value.trim();
|
|
4532
|
+
}
|
|
4533
|
+
return undefined;
|
|
4534
|
+
}
|
|
4535
|
+
function requireRecordId(value, message) {
|
|
4536
|
+
const id = optionalRecordId(value);
|
|
4537
|
+
if (!id) {
|
|
4538
|
+
throw new Error(message);
|
|
4539
|
+
}
|
|
4540
|
+
return id;
|
|
4541
|
+
}
|
|
4361
4542
|
function cleanQuery(input) {
|
|
4362
4543
|
return cleanObject(input);
|
|
4363
4544
|
}
|