weaver-work-cli 0.1.45 → 0.1.46
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/dist/chunks/{attachment-content-CE3GMWTS.js → attachment-content-MCXQBD6N.js} +3 -3
- package/dist/chunks/{chunk-VIMCY4DI.js → chunk-4RWS2YYL.js} +2 -2
- package/dist/chunks/{chunk-4EXOIQDI.js → chunk-6AXKWFKG.js} +4 -14
- package/dist/chunks/{chunk-JWWTI63L.js → chunk-6V5ZPKHV.js} +2 -8
- package/dist/chunks/{chunk-3ZMAQQ3W.js → chunk-76H3IKH6.js} +39 -26
- package/dist/chunks/{chunk-LGKWL4OH.js → chunk-AD46OMQK.js} +86 -25
- package/dist/chunks/{chunk-3WBIQLMB.js → chunk-GSZTA43P.js} +2 -2
- package/dist/chunks/{chunk-OAE3AZBQ.js → chunk-IP4CWQCF.js} +6 -6
- package/dist/chunks/{chunk-77YP6I52.js → chunk-IRMIEDXN.js} +1 -1
- package/dist/chunks/{chunk-T4MWQAQB.js → chunk-JFAWZX53.js} +128 -9
- package/dist/chunks/{chunk-DGMYACGJ.js → chunk-OXHHJWNC.js} +1 -1
- package/dist/chunks/{chunk-LXFVWZLM.js → chunk-PSOMGA3U.js} +3 -3
- package/dist/chunks/{chunk-LRCPNDZA.js → chunk-UFIFZ4YC.js} +10 -8
- package/dist/chunks/{conflict-IYJETSGT.js → conflict-H7EHQXYY.js} +2 -2
- package/dist/chunks/{create-flow-7JLC7UID.js → create-flow-VRVJEOBX.js} +6 -6
- package/dist/chunks/{ehr-MYRDCHZ4.js → ehr-SH2LM3NK.js} +528 -40
- package/dist/chunks/{env-3MBHAWBL.js → env-66FPSJDV.js} +2 -2
- package/dist/chunks/{factory-TZEVU4DU.js → factory-UH2TZBVA.js} +1 -1
- package/dist/chunks/{group-chat-KL3HFKRM.js → group-chat-CAKMMV7K.js} +3 -3
- package/dist/chunks/{lazy-dispatch-UH6HGK2I.js → lazy-dispatch-DD6ULZ3I.js} +1 -1
- package/dist/chunks/{meeting-C67EHQ4Z.js → meeting-VTBFW4HI.js} +10 -10
- package/dist/chunks/{recruit-stage-AHY5QAMF.js → recruit-stage-CAKZTUA7.js} +917 -85
- package/dist/chunks/{registry-XPWPGHYE.js → registry-JVQBLFQ5.js} +10 -10
- package/dist/chunks/{room-recommend-CNWE5WQK.js → room-recommend-5U55FMXZ.js} +4 -4
- package/dist/chunks/{schedule-YYNYBQIE.js → schedule-IDETODCA.js} +4 -4
- package/dist/cmd/action.js +14 -10
- package/dist/index.js +5 -5
- package/dist/shortcuts/ehr/host.js +2 -2
- package/dist/shortcuts/ehr/index.js +14 -3
- package/dist/shortcuts/ehr/manifest.js +5 -1
- package/dist/shortcuts/ehr/operations/recruit-candidate-import.js +40 -10
- package/dist/shortcuts/ehr/operations/recruit-interview-overview.js +258 -0
- package/dist/shortcuts/ehr/operations/recruit-position.js +10 -8
- package/dist/shortcuts/ehr/operations/recruit-stats.js +14 -1
- package/dist/shortcuts/ehr/operations/recruit-tag.js +173 -0
- package/dist/shortcuts/ehr/operations/recruit-write.js +137 -18
- package/dist/shortcuts/ehr/operations/recruit.js +180 -8
- package/dist/shortcuts/ehr/operations/registry.js +4 -0
- package/dist/shortcuts/ehr/operations.js +24 -0
- package/dist/shortcuts/ehr/recruit-stage/batch-store.js +78 -0
- package/dist/shortcuts/ehr/recruit-stage/context.js +231 -0
- package/dist/shortcuts/ehr/recruit-stage/continuation.js +74 -0
- package/dist/shortcuts/ehr/recruit-stage/errors.js +65 -0
- package/dist/shortcuts/ehr/recruit-stage/fs-scan.js +165 -0
- package/dist/shortcuts/ehr/recruit-stage/host.js +109 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/interview-arrange.js +1049 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/interview-feedback.js +295 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/jd-create.js +961 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/list.js +431 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/registry.js +50 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/resume-import.js +1647 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/search.js +158 -0
- package/dist/shortcuts/ehr/recruit-stage/operations/types.js +34 -0
- package/dist/shortcuts/ehr/recruit-stage/runtime.js +31 -0
- package/dist/shortcuts/ehr/recruit-stage/school-tiers.json +318 -0
- package/dist/shortcuts/ehr/recruit-stage/shared.js +805 -0
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +93 -18
- package/dist/shortcuts/meeting/operations/eb/factory.js +5 -8
- package/dist/shortcuts/meeting/operations/eb/room-recommend.js +2 -13
- package/dist/shortcuts/meeting/operations/invitation.js +27 -4
- package/dist/shortcuts/recruit-stage/batch-store.js +78 -0
- package/dist/shortcuts/recruit-stage/fs-scan.js +165 -0
- package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +277 -20
- package/dist/shortcuts/recruit-stage/operations/interview-feedback.js +31 -7
- package/dist/shortcuts/recruit-stage/operations/jd-create.js +106 -16
- package/dist/shortcuts/recruit-stage/operations/registry.js +12 -0
- package/dist/shortcuts/recruit-stage/operations/resume-import.js +273 -6
- package/dist/shortcuts/recruit-stage/operations/types.js +9 -0
- package/dist/shortcuts/recruit-stage/shared.js +60 -6
- package/package.json +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-compare-report-template.html +2 -2
- package/skills/weaver-e10-jucailin/SKILL.md +12 -3
- package/skills/weaver-e10-jucailin/archive/LEGACY-README.md +18 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-SKILL.md +239 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-openai.yaml +131 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-position-templates.md +221 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-arrange-interview.md +334 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-capability-check.md +127 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-check-install.md +65 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-detail-process.md +63 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-edit-interview-feedback.md +142 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-jd-create.md +114 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-jd-template.md +56 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-list-candidate.md +101 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-list-interview.md +148 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-match-candidates.md +77 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-output-links.md +72 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-resolve-creator.md +69 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-resolve-metadata.md +241 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-resume-import.md +457 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-resume-parse.md +128 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-search-candidate.md +146 -0
- package/skills/weaver-e10-jucailin/archive/LEGACY-recruit-urge-feedback.md +69 -0
- package/skills/weaver-e10-jucailin/lib/recruit-xiaoe-file.mjs +192 -0
- package/skills/weaver-e10-jucailin/lib/xiaoe-session.mjs +66 -0
- package/skills/weaver-e10-jucailin/references/recruit-create.md +19 -93
- package/skills/weaver-e10-jucailin/references/recruit-interview-overview.md +64 -0
- package/skills/weaver-e10-jucailin/references/recruit-read.md +63 -1
- package/skills/weaver-e10-jucailin/references/recruit-screening-to-interview-sop.md +95 -0
- package/skills/weaver-e10-jucailin/references/recruit-stage-ops.md +89 -0
- package/skills/weaver-e10-jucailin/references/recruit-tag.md +81 -0
- package/skills/weaver-e10-jucailin/references/recruit-write.md +53 -9
- package/skills/weaver-e10-meeting/SKILL.md +48 -4
- package/skills/weaver-e10-meeting/references/meeting-eb.md +1 -1
- package/skills/weaver-e10-recruit-stage/SKILL.md +8 -5
- package/skills/weaver-e10-recruit-stage/agents/openai.yaml +16 -6
- package/skills/weaver-e10-recruit-stage/lib/recruit-xiaoe-file.mjs +5 -1
- package/skills/weaver-e10-recruit-stage/references/position-templates.md +20 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +21 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +4 -0
|
@@ -0,0 +1,961 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* recruit-stage.jd.create.* —— 生成职位 JD / 创建职位(写操作,自 recruit-generate-jd.mjs 1:1 移植)
|
|
3
|
+
*
|
|
4
|
+
* 链路:① saveFormData(职位管理 uf_rcrt_position_manage) → ② addPosition?formDataId 提交生成职位
|
|
5
|
+
*
|
|
6
|
+
* 三种操作:
|
|
7
|
+
* .prepare 只出确认摘要(不写库),签发 continuation(写操作红线:先确认后落库)
|
|
8
|
+
* .apply 用户确认后执行(confirm:true + continuation + 摘要指纹比对)
|
|
9
|
+
* .prefill 预填模式(人工保存):输出新建页 URL + WeFormSDK 注入脚本,不落库
|
|
10
|
+
*
|
|
11
|
+
* 字段 id 全部经环境缓存 fields[objId] 运行时取,不写死。
|
|
12
|
+
* 多行文本字段(position_duty/work_request)走 dataText;单行文本(position_name)走 content;
|
|
13
|
+
* 关联类字段(demand/status/recruit_flow)走 dataOptions。
|
|
14
|
+
*
|
|
15
|
+
* sets 覆盖("贴合 JD 型"):AI 读 JD 后按字段语义传值,按字段取值类别自动解析 optionId:
|
|
16
|
+
* 数值型→content;人员型→按姓名解析 userId;枚举型→ds/options;字典引用型→数据字典;
|
|
17
|
+
* 关联表单型 work_location→「办公地点」解析;其它→content。
|
|
18
|
+
*
|
|
19
|
+
* 默认值策略(跨环境运行时解析、不写死 id):状态=招聘中;流程=环境默认启用流程;
|
|
20
|
+
* 人数=1、薪酬月数=12;薪酬类型=月薪、招聘方式=社会招聘;
|
|
21
|
+
* 招聘负责人/用人经理=当前登录用户;工作地点=「办公地点」列表里启用状态的默认详细地址;
|
|
22
|
+
* 其余关联表单型取环境内已有职位记录的值("默认值=系统现成值")。
|
|
23
|
+
* ⚠️ 工作地点**不参与继承**:历史职位曾带出 detail_location 为「1」的脏地点。
|
|
24
|
+
*/
|
|
25
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
26
|
+
import { readFileSync } from 'node:fs';
|
|
27
|
+
import { resolve as resolvePath, dirname } from 'node:path';
|
|
28
|
+
import { fileURLToPath } from 'node:url';
|
|
29
|
+
import { rsSuccess, schemaOf } from './types.js';
|
|
30
|
+
import { rsFail, rsValidationError, rsConfirmationError } from '../errors.js';
|
|
31
|
+
import { objIdOf, formIdOf, saveFormData, getDsOptions, getFormDataRecord, resolvePersonId, findMenuNode, resolveCurrentUser, buildCardUrl, buildListUrl, randHex32, dsOptionsSnapshot, restoreDsOptions, invalidateEnvCache, verifySubmitted, expectedFields, probeCreatePermission, } from '../shared.js';
|
|
32
|
+
const SCHEMA_ID_STR = { type: 'string', description: '18 位记录 id(字符串)' };
|
|
33
|
+
// 职位管理表单字段 dataKey(缓存 fields 里取;不写死 fieldId)
|
|
34
|
+
const DATAKEYS_TEXT = ['position_name'];
|
|
35
|
+
const DATAKEYS_MTEXT = ['position_duty', 'work_request'];
|
|
36
|
+
// 必填字段默认值策略
|
|
37
|
+
const DEF_TEXT = { recruit_count: '1', number_of_pay_months: '12' };
|
|
38
|
+
const DEF_OPTION = { salary_type: '月薪', recruit_type: '社会招聘' };
|
|
39
|
+
const DEF_CURRENT_USER = ['recr_principal', 'employ_manager'];
|
|
40
|
+
// 🔴 薪资(salary_min / salary_max)必须继承,不能留空:这两个字段是**职位表单必填项**,
|
|
41
|
+
// 不传会导致后端必填校验失败、建职位直接报错(2026-11-06 实测:移除继承后 willSubmit 无薪资字段)。
|
|
42
|
+
// 但历史薪资确实可能是脏数据(实测抓到 300 元月薪),因此不静默使用:
|
|
43
|
+
// 通过 summary.inheritedFromRef 暴露继承值,并对明显偏低的值追加 inheritedSalaryWarnings 提示。
|
|
44
|
+
// 🔴 2026-11-07 实测修正:以下字段**不再从参考职位继承**——
|
|
45
|
+
// · job_category(职位序列):每个职位各不相同,继承会把上一个职位的「销售」带到新职位,
|
|
46
|
+
// 该错误已由职位卡片页坐实(「核验1107-JD-B」JD 写的是后端接口开发,落库职位序列却是「销售」);
|
|
47
|
+
// · salary_min / salary_max(薪酬区间):继承会把历史脏值「0.00」写成新职位的正式薪酬,
|
|
48
|
+
// 同样已在卡片页坐实(最低/最高薪酬均为 0.00)。
|
|
49
|
+
// 自用 EB 包 ebdf_field 实测这三个字段 required 均未开启,留空不会阻断保存;
|
|
50
|
+
// 用户需要就显式传 jobCategory / salaryMin / salaryMax,不再用脏值填坑。
|
|
51
|
+
const DEF_FROM_REF = [
|
|
52
|
+
'position_nature', 'education', 'work_years',
|
|
53
|
+
];
|
|
54
|
+
const DEF_STATUS = '招聘中';
|
|
55
|
+
// 默认办公地点用「详细地址名称」声明,不写死记录 id:运行时到「办公地点」列表
|
|
56
|
+
// 按「启用」状态 + 详细地址精确匹配取 id。历史职位继承会把内容写成「1」的脏地点带进新职位
|
|
57
|
+
// (2026-11-06 实测:某在册地点 detail_location 就是 "1" 且状态为启用),故 work_location 已从
|
|
58
|
+
// DEF_FROM_REF 移除,改由本默认地点解析;匹配不到则不写该字段并点名,不臆造 id。
|
|
59
|
+
const DEFAULT_WORK_LOCATION = '浦江镇三鲁公路3419号泛微软件园';
|
|
60
|
+
// sets 覆盖解析:字段取值类别
|
|
61
|
+
const NUM_KEYS = new Set(['recruit_count', 'number_of_pay_months', 'salary_min', 'salary_max', 'internship_duration', 'working_days']);
|
|
62
|
+
const PERSON_KEYS = new Set(['recr_principal', 'recr_helper', 'employ_manager', 'interviewer']);
|
|
63
|
+
const OPTION_KEYS = new Set(['salary_type', 'recruit_type', 'status']);
|
|
64
|
+
const DICT_KEYS = new Set(['position_nature', 'job_category', 'education', 'work_years']);
|
|
65
|
+
const MTEXT_KEYS = new Set(['position_duty', 'work_request']);
|
|
66
|
+
function fingerprint(value) {
|
|
67
|
+
return createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
68
|
+
}
|
|
69
|
+
function detailValueId(d) {
|
|
70
|
+
if (!d)
|
|
71
|
+
return '';
|
|
72
|
+
if (d.dataOptions && d.dataOptions[0])
|
|
73
|
+
return String(d.dataOptions[0].optionId || '');
|
|
74
|
+
if (d.dataText)
|
|
75
|
+
return String(d.dataText.content || '');
|
|
76
|
+
if (d.content !== undefined)
|
|
77
|
+
return String(d.content);
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
function dictGroupOf(cache, valueId) {
|
|
81
|
+
const row = (cache.dict?.raw || []).find((x) => String(x.option_id) === String(valueId));
|
|
82
|
+
return row ? String(row.dict_type) : '';
|
|
83
|
+
}
|
|
84
|
+
function dictIdByName(cache, name, group) {
|
|
85
|
+
const rows = (cache.dict?.raw || []).filter((x) => x.selection_name === name && (!group || String(x.dict_type) === group));
|
|
86
|
+
return rows.length ? String(rows[0].option_id) : '';
|
|
87
|
+
}
|
|
88
|
+
// 取环境内一条「字段较全」的职位记录的全部字段(ret: { fid: detail }),保证引用有效
|
|
89
|
+
async function fetchRefByFid(ctx) {
|
|
90
|
+
const { host, cache } = ctx;
|
|
91
|
+
const objId = objIdOf(cache, 'position_manage');
|
|
92
|
+
const formId = formIdOf(cache, 'position_manage');
|
|
93
|
+
const posMenu = cache.lists?.position || null;
|
|
94
|
+
if (!posMenu)
|
|
95
|
+
return {};
|
|
96
|
+
const body = {
|
|
97
|
+
current: 1, pageSize: 20, tableuid: randHex32(),
|
|
98
|
+
listId: posMenu.listId, searchParamData: { searchType: '3', type: 'and' },
|
|
99
|
+
terminal: 'PC', browser: 'Chrome', requiredMatch: 1, mapResult: 1,
|
|
100
|
+
recheckQuery: 1, isFollow: 0, isShareToMe: 0, filterCondition: {},
|
|
101
|
+
cusMenuId: posMenu.cusMenuId, urlPageTitle: '招聘职位', menuName: '招聘职位',
|
|
102
|
+
};
|
|
103
|
+
const r = await host.request({
|
|
104
|
+
path: `/api/ebuilder/form/list/getListDatas?passid=${objId}&cid=${objId}`,
|
|
105
|
+
body, headers: { ebBusinessId: posMenu.listId },
|
|
106
|
+
});
|
|
107
|
+
const rows = r?.data?.data || [];
|
|
108
|
+
const ref = rows.find((x) => x.form_data_id && x.position_nature);
|
|
109
|
+
if (!ref)
|
|
110
|
+
return {};
|
|
111
|
+
const rec = await getFormDataRecord(host, formId, String(ref.form_data_id), objId);
|
|
112
|
+
const byFid = {};
|
|
113
|
+
for (const d of rec.dataDetails || []) {
|
|
114
|
+
const f = String(d.fieldId || d.formField?.id || '');
|
|
115
|
+
if (f)
|
|
116
|
+
byFid[f] = d;
|
|
117
|
+
}
|
|
118
|
+
return byFid;
|
|
119
|
+
}
|
|
120
|
+
// ref 记录 detail → 提交 detail(保留 dataOptions/dataText/content 形态)
|
|
121
|
+
function refToSubmit(d) {
|
|
122
|
+
const o = { formField: { id: String(d.fieldId || d.formField?.id) } };
|
|
123
|
+
if (d.dataOptions)
|
|
124
|
+
o.dataOptions = d.dataOptions;
|
|
125
|
+
else if (d.dataText)
|
|
126
|
+
o.dataText = d.dataText;
|
|
127
|
+
else if (d.content !== undefined && d.content !== '')
|
|
128
|
+
o.content = d.content;
|
|
129
|
+
else if (d.value !== undefined && d.value !== '')
|
|
130
|
+
o.dataText = { content: String(d.value) };
|
|
131
|
+
else
|
|
132
|
+
return null;
|
|
133
|
+
return o;
|
|
134
|
+
}
|
|
135
|
+
// 工作地点的「办公地点」菜单定位:三级来源,不依赖 cache.menus
|
|
136
|
+
// 实测(2026-11-05):本环境环境缓存**没有 menus 字段**(只有 forms/lists/fields/dict 等),
|
|
137
|
+
// 原实现直接读 cache.menus → 拿到 undefined → findMenuNode 返回 null → resolveWorkLocation 恒为 null
|
|
138
|
+
// → work_location 每次进 setSkipped(连完整地址都写不进去)。改为:
|
|
139
|
+
// ① cache.lists.all_search(与面试数字人菜单解析同一模式,已在用)
|
|
140
|
+
// ② cache.menus(若某环境确实有)
|
|
141
|
+
// ③ allMenus 接口兜底(resolvePositionNewUrl 已在用,同一写法)
|
|
142
|
+
const WORK_PLACE_NAMES = ['办公地点', '工作地点'];
|
|
143
|
+
async function findWorkPlaceMenu(ctx) {
|
|
144
|
+
const { host, appId, cache } = ctx;
|
|
145
|
+
const ok = (m) => m && m.listId;
|
|
146
|
+
// ① all_search
|
|
147
|
+
const allSearch = ((cache.lists || {}).all_search || []);
|
|
148
|
+
const hit1 = allSearch.find((m) => ok(m) && WORK_PLACE_NAMES.some((n) => String(m.menuName || '').includes(n)));
|
|
149
|
+
if (hit1)
|
|
150
|
+
return { listId: String(hit1.listId), cusMenuId: String(hit1.cusMenuId || ''), menuName: String(hit1.menuName || '') };
|
|
151
|
+
// ② cache.menus(可能不存在)
|
|
152
|
+
const hit2 = findMenuNode(cache.menus || [], WORK_PLACE_NAMES, (m) => ok(m));
|
|
153
|
+
if (hit2)
|
|
154
|
+
return { listId: String(hit2.listId), cusMenuId: String(hit2.cusMenuId || ''), menuName: String(hit2.menuName || '') };
|
|
155
|
+
// ③ allMenus 接口
|
|
156
|
+
try {
|
|
157
|
+
const r = await host.request({ path: `/api/cusapp/app/allMenus?isFront=1&appId=${appId}&terminalType=PC`, method: 'GET' });
|
|
158
|
+
const flat = [];
|
|
159
|
+
(function walk(ns) { for (const n of (ns || []))
|
|
160
|
+
if (n && typeof n === 'object') {
|
|
161
|
+
flat.push(n);
|
|
162
|
+
walk(n.children || n.childs);
|
|
163
|
+
} })(r?.data?.cusAppMenus || r?.data);
|
|
164
|
+
const hit3 = findMenuNode(flat, WORK_PLACE_NAMES, (m) => ok(m));
|
|
165
|
+
if (hit3)
|
|
166
|
+
return { listId: String(hit3.listId), cusMenuId: String(hit3.cusMenuId || ''), menuName: String(hit3.menuName || '') };
|
|
167
|
+
}
|
|
168
|
+
catch { /* 接口不可用则放弃 */ }
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
// 仅进程内 memo(不落盘):同一 CLI 进程内 prepare/apply 及多个 set 复用一次列表请求。
|
|
172
|
+
// 记录 id / 启用状态 optionId 一律运行时从列表解析,跨环境不缓存、不写死。
|
|
173
|
+
const workPlaceMemo = new Map();
|
|
174
|
+
function stripHtml(s) {
|
|
175
|
+
return String(s ?? '').replace(/<[^>]*>/g, '').trim();
|
|
176
|
+
}
|
|
177
|
+
function parseSpans(raw) {
|
|
178
|
+
try {
|
|
179
|
+
const v = Array.isArray(raw) ? raw : JSON.parse(String(raw || '[]'));
|
|
180
|
+
return Array.isArray(v) ? v : [];
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** 「启用」判定:只读服务端翻译后的文本,不写死 optionId(跨环境 optionId 会变)。 */
|
|
187
|
+
function isEnabledText(s) {
|
|
188
|
+
const t = stripHtml(s);
|
|
189
|
+
return t.includes('启用') && !t.includes('禁用');
|
|
190
|
+
}
|
|
191
|
+
/** 拉取「办公地点」列表,按 place_status=启用 过滤;状态信息缺失时返回原始行并标记未过滤。 */
|
|
192
|
+
async function loadWorkPlaces(ctx) {
|
|
193
|
+
const { host, appId } = ctx;
|
|
194
|
+
const menu = await findWorkPlaceMenu(ctx);
|
|
195
|
+
if (!menu)
|
|
196
|
+
return { rows: [], statusFiltered: false };
|
|
197
|
+
const key = appId + '|' + menu.listId;
|
|
198
|
+
const cached = workPlaceMemo.get(key);
|
|
199
|
+
if (cached)
|
|
200
|
+
return cached;
|
|
201
|
+
const [tagObjId] = await Promise.all([
|
|
202
|
+
host
|
|
203
|
+
.request({ path: `/api/ebuilder/form/obj/getObjsByTag?appId=${appId}&tag=uf_rcrt_work_place`, method: 'GET' })
|
|
204
|
+
.then((t) => (Array.isArray(t?.data) && t.data[0] ? String(t.data[0].id || '') : ''))
|
|
205
|
+
.catch(() => ''),
|
|
206
|
+
]);
|
|
207
|
+
const pObj = tagObjId || String(menu.objId || '');
|
|
208
|
+
if (!pObj)
|
|
209
|
+
return { rows: [], statusFiltered: false };
|
|
210
|
+
const pageSize = 200;
|
|
211
|
+
const rawRows = [];
|
|
212
|
+
const dispRows = [];
|
|
213
|
+
for (let page = 1; page <= 5; page++) {
|
|
214
|
+
const body = {
|
|
215
|
+
current: page, pageSize, tableuid: randHex32(),
|
|
216
|
+
listId: menu.listId, searchParamData: { searchType: '3', type: 'and' },
|
|
217
|
+
terminal: 'PC', browser: 'Chrome', requiredMatch: 1, mapResult: 1,
|
|
218
|
+
recheckQuery: 1, isFollow: 0, isShareToMe: 0, filterCondition: {},
|
|
219
|
+
cusMenuId: menu.cusMenuId, urlPageTitle: menu.menuName, menuName: menu.menuName,
|
|
220
|
+
};
|
|
221
|
+
const r = await host.request({
|
|
222
|
+
path: `/api/ebuilder/form/list/getListDatas?passid=${pObj}&cid=${pObj}`,
|
|
223
|
+
body, headers: { ebBusinessId: menu.listId },
|
|
224
|
+
});
|
|
225
|
+
const batch = (r?.data?.data || r?.data?.displayData || []);
|
|
226
|
+
rawRows.push(...batch);
|
|
227
|
+
dispRows.push(...(r?.data?.displayData || []));
|
|
228
|
+
if (batch.length < pageSize)
|
|
229
|
+
break; // 服务端 total/hasMore 不可信,唯一可靠判据是分页本身
|
|
230
|
+
}
|
|
231
|
+
// 从 displayData 学「启用」对应的 optionId 集合与行 id 集合(两种形态都兼容)
|
|
232
|
+
const enabledStatusIds = new Set();
|
|
233
|
+
const enabledRowIds = new Set();
|
|
234
|
+
for (const d of dispRows) {
|
|
235
|
+
const rid = String(d?.form_data_id || d?.id || '');
|
|
236
|
+
if (isEnabledText(d?.place_status) && rid)
|
|
237
|
+
enabledRowIds.add(rid);
|
|
238
|
+
for (const s of parseSpans(d?.place_statusSpan)) {
|
|
239
|
+
if (isEnabledText(s?.name) && s?.id)
|
|
240
|
+
enabledStatusIds.add(String(s.id));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const statusFiltered = enabledRowIds.size > 0 || enabledStatusIds.size > 0;
|
|
244
|
+
const rows = rawRows
|
|
245
|
+
.filter((x) => !statusFiltered
|
|
246
|
+
|| enabledRowIds.has(String(x?.form_data_id || x?.id || ''))
|
|
247
|
+
|| enabledStatusIds.has(String(x?.place_status || '')))
|
|
248
|
+
.map((x) => ({
|
|
249
|
+
id: String(x?.form_data_id || x?.id || ''),
|
|
250
|
+
name: String(x?.name || ''),
|
|
251
|
+
detail: String(x?.detail_location || ''),
|
|
252
|
+
area: String(x?.area_text || ''),
|
|
253
|
+
city: String(x?.city || ''),
|
|
254
|
+
}))
|
|
255
|
+
.filter((x) => !!x.id);
|
|
256
|
+
const out = { rows, statusFiltered };
|
|
257
|
+
workPlaceMemo.set(key, out);
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
/** 精确匹配优先;包含匹配要求地址文本足够长且非纯数字,避免把内容写成「1」的脏地点选中。 */
|
|
261
|
+
function matchWorkPlace(rows, value) {
|
|
262
|
+
const v = String(value).trim();
|
|
263
|
+
if (!v || !rows.length)
|
|
264
|
+
return null;
|
|
265
|
+
const exact = rows.find((r) => r.detail === v) || rows.find((r) => r.name === v);
|
|
266
|
+
if (exact)
|
|
267
|
+
return exact;
|
|
268
|
+
const valid = (s) => s.length >= 4 && !/^\d+$/.test(s);
|
|
269
|
+
return rows.find((r) => (r.detail.includes(v) && valid(r.detail))
|
|
270
|
+
|| (r.name.includes(v) && valid(r.name))
|
|
271
|
+
|| (r.area.includes(v) && valid(r.area))
|
|
272
|
+
|| (v.includes(r.detail) && valid(r.detail))) || null;
|
|
273
|
+
}
|
|
274
|
+
// 工作地点:按名称/详细地址/城市解析「办公地点」记录 id(只在启用记录中匹配)
|
|
275
|
+
async function resolveWorkLocation(ctx, value) {
|
|
276
|
+
if (!String(value).trim())
|
|
277
|
+
return null;
|
|
278
|
+
const { rows } = await loadWorkPlaces(ctx);
|
|
279
|
+
const hit = matchWorkPlace(rows, value);
|
|
280
|
+
return hit ? { id: hit.id, name: hit.detail || hit.name || String(value) } : null;
|
|
281
|
+
}
|
|
282
|
+
/** 默认办公地点:按声明的详细地址在启用列表中精确解析 id,解析不到返回 null(不写、不继承)。 */
|
|
283
|
+
async function resolveDefaultWorkLocation(ctx) {
|
|
284
|
+
return resolveWorkLocation(ctx, DEFAULT_WORK_LOCATION);
|
|
285
|
+
}
|
|
286
|
+
// 解析 sets key=value → 提交 detail(按字段取值类别;解析不到返回 null)
|
|
287
|
+
async function resolveSetValue(ctx, key, value, refByFid) {
|
|
288
|
+
const { host, appId, cache } = ctx;
|
|
289
|
+
const objId = objIdOf(cache, 'position_manage');
|
|
290
|
+
const id = (cache.fields[objId] || {})[key];
|
|
291
|
+
if (!id)
|
|
292
|
+
return null;
|
|
293
|
+
if (NUM_KEYS.has(key)) {
|
|
294
|
+
// 薪资字段单位是「千元」(页面 15.00 = 15K,与字段 ID 交叉验证);用户/Agent 传的是「元」。
|
|
295
|
+
// 只对**显式输入**换算;从已有职位继承的值本来就是千元,绝不能再除一次。
|
|
296
|
+
if (key === 'salary_min' || key === 'salary_max') {
|
|
297
|
+
const n = Number(String(value).replace(/,/g, ''));
|
|
298
|
+
if (Number.isFinite(n) && n > 0) {
|
|
299
|
+
const k = n / 1000;
|
|
300
|
+
return { formField: { id }, content: String(Number.isInteger(k) ? k : Number(k.toFixed(3))) };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return { formField: { id }, content: String(value) };
|
|
304
|
+
}
|
|
305
|
+
if (MTEXT_KEYS.has(key))
|
|
306
|
+
return { formField: { id }, dataText: { content: String(value) } };
|
|
307
|
+
if (key === 'position_name')
|
|
308
|
+
return { formField: { id }, content: String(value) };
|
|
309
|
+
if (PERSON_KEYS.has(key)) {
|
|
310
|
+
const uid = await resolvePersonId(host, id, value);
|
|
311
|
+
return uid ? { formField: { id }, dataOptions: [{ optionId: String(uid), content: value }] } : null;
|
|
312
|
+
}
|
|
313
|
+
if (OPTION_KEYS.has(key)) {
|
|
314
|
+
const m = await getDsOptions(host, objId, id);
|
|
315
|
+
const oid = m[value];
|
|
316
|
+
return oid ? { formField: { id }, dataOptions: [{ optionId: String(oid), content: value }] } : null;
|
|
317
|
+
}
|
|
318
|
+
if (DICT_KEYS.has(key)) {
|
|
319
|
+
const group = dictGroupOf(cache, detailValueId(refByFid[String(id)]));
|
|
320
|
+
const did = dictIdByName(cache, value, group) || dictIdByName(cache, value, '');
|
|
321
|
+
return did ? { formField: { id }, dataOptions: [{ optionId: String(did), content: value }] } : null;
|
|
322
|
+
}
|
|
323
|
+
if (key === 'work_location') {
|
|
324
|
+
const loc = await resolveWorkLocation(ctx, value);
|
|
325
|
+
return loc ? { formField: { id }, dataOptions: [{ optionId: loc.id, content: loc.name }] } : null;
|
|
326
|
+
}
|
|
327
|
+
return { formField: { id }, content: String(value) };
|
|
328
|
+
}
|
|
329
|
+
// ── 预填(人工保存)模式:dataDetails → WeFormSDK.changeFieldValue 的 (mark, info) ──
|
|
330
|
+
function toPrefillFields(dataDetails, fields) {
|
|
331
|
+
const inv = {};
|
|
332
|
+
for (const [k, v] of Object.entries(fields))
|
|
333
|
+
inv[String(v)] = k;
|
|
334
|
+
const personFids = new Set(Object.keys(fields).filter((k) => PERSON_KEYS.has(k)).map((k) => String(fields[k])));
|
|
335
|
+
const out = [];
|
|
336
|
+
for (const d of dataDetails) {
|
|
337
|
+
const fid = String(d.formField.id);
|
|
338
|
+
let info = null;
|
|
339
|
+
if (d.dataOptions)
|
|
340
|
+
info = { specialObj: d.dataOptions.map((o) => ({ id: String(o.optionId), name: o.content, ...(personFids.has(fid) ? { type: 'user' } : {}) })) };
|
|
341
|
+
else if (d.dataText)
|
|
342
|
+
info = { value: String(d.dataText.content) };
|
|
343
|
+
else if (d.content !== undefined)
|
|
344
|
+
info = { value: String(d.content) };
|
|
345
|
+
if (info)
|
|
346
|
+
out.push({ mark: 'field' + fid, info, label: inv[fid] || fid });
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
350
|
+
// 职位管理「新建页」URL:从 allMenus 解析职位列表菜单(别名匹配,跨环境不写死)
|
|
351
|
+
async function resolvePositionNewUrl(ctx) {
|
|
352
|
+
const { host, appId, baseUrl, cache } = ctx;
|
|
353
|
+
const cached = cache.menus?.find?.((m) => m.combinationId && m.id && m.pageId && ['招聘职位', '职位列表', '职位管理'].some((n) => (m.menuName || '').includes(n)));
|
|
354
|
+
let node = cached || null;
|
|
355
|
+
if (!node) {
|
|
356
|
+
const r = await host.request({ path: `/api/cusapp/app/allMenus?isFront=1&appId=${appId}&terminalType=PC`, method: 'GET' });
|
|
357
|
+
const flat = [];
|
|
358
|
+
(function walk(ns) { for (const n of (ns || []))
|
|
359
|
+
if (n && typeof n === 'object') {
|
|
360
|
+
flat.push(n);
|
|
361
|
+
walk(n.children || n.childs);
|
|
362
|
+
} })(r?.data?.cusAppMenus || r?.data);
|
|
363
|
+
node = findMenuNode(flat, ['招聘职位', '职位列表', '职位管理'], (n) => n.combinationId && n.id && n.pageId);
|
|
364
|
+
}
|
|
365
|
+
if (!node)
|
|
366
|
+
return null;
|
|
367
|
+
return `${baseUrl}/ebdapp/view/${appId}/combination/${node.combinationId}-${node.id}/search/${node.pageId}?terminal=PC&cusMenuId=${node.id}`;
|
|
368
|
+
}
|
|
369
|
+
// 招聘首页(PAGE 型)URL
|
|
370
|
+
async function resolveHomePageUrl(ctx) {
|
|
371
|
+
const { host, appId, baseUrl } = ctx;
|
|
372
|
+
const r = await host.request({ path: `/api/cusapp/app/allMenus?isFront=1&appId=${appId}&terminalType=PC`, method: 'GET' });
|
|
373
|
+
const flat = [];
|
|
374
|
+
(function walk(ns) { for (const n of (ns || []))
|
|
375
|
+
if (n && typeof n === 'object') {
|
|
376
|
+
flat.push(n);
|
|
377
|
+
walk(n.children || n.childs);
|
|
378
|
+
} })(r?.data?.cusAppMenus || r?.data);
|
|
379
|
+
const node = findMenuNode(flat, ['招聘首页', '招聘主页'], (n) => n.pageType === 'PAGE' && n.pageId && n.id)
|
|
380
|
+
|| flat.find((n) => n.pageType === 'PAGE' && String(n.menuName || '').includes('首页'));
|
|
381
|
+
if (!node || !node.pageId || !node.id)
|
|
382
|
+
return null;
|
|
383
|
+
return `${baseUrl}/ebdapp/view/${appId}/PAGE/${node.pageId}-${node.id}?terminal=PC&cusMenuId=${node.id}&appId_${node.pageId}=${appId}`;
|
|
384
|
+
}
|
|
385
|
+
// 参考同类职位:抓最近一页职位列表(displayData 已是服务端翻译后的可读文本),按关键词客户端过滤
|
|
386
|
+
// 取前 5 条,再逐条拉记录详情取薪酬与职责/要求正文。供 AI 在确认摘要里给出「最近同类职位参考」。
|
|
387
|
+
const REF_DETAIL_KEYS = ['salary_type', 'salary_min', 'salary_max', 'number_of_pay_months', 'education',
|
|
388
|
+
'work_years', 'recruit_count', 'recruit_type', 'position_nature', 'work_location', 'department', 'sub_company'];
|
|
389
|
+
const REF_TEXT_KEYS = ['position_duty', 'work_request'];
|
|
390
|
+
async function fetchRecentReferences(ctx, jd, keyword) {
|
|
391
|
+
const { host, cache } = ctx;
|
|
392
|
+
const listParam = cache.lists?.position || null;
|
|
393
|
+
if (!listParam?.listId)
|
|
394
|
+
return { available: false, reason: '环境缓存缺少职位列表参数', items: [] };
|
|
395
|
+
const r = await host.request({
|
|
396
|
+
path: '/api/ebuilder/form/list/getListDatas?passid=' + jd.objId + '&cid=' + jd.objId,
|
|
397
|
+
body: {
|
|
398
|
+
current: 1, pageSize: 30, tableuid: randHex32(), listId: listParam.listId,
|
|
399
|
+
searchParamData: { searchType: '3', type: 'and' },
|
|
400
|
+
terminal: 'PC', browser: 'Chrome', requiredMatch: 1, mapResult: 1, recheckQuery: 1,
|
|
401
|
+
isFollow: 0, isShareToMe: 0, filterCondition: {},
|
|
402
|
+
cusMenuId: listParam.cusMenuId, urlPageTitle: listParam.menuName, menuName: listParam.menuName,
|
|
403
|
+
},
|
|
404
|
+
headers: { ebBusinessId: listParam.listId },
|
|
405
|
+
});
|
|
406
|
+
const rows = r?.data?.displayData || r?.data?.data || [];
|
|
407
|
+
const kw = String(keyword || '').trim();
|
|
408
|
+
const tokens = [...new Set(kw.split(/[^A-Za-z0-9\u4e00-\u9fff]+/).concat(kw).map((t) => t.trim()).filter((t) => t.length >= 2))];
|
|
409
|
+
const match = (row) => {
|
|
410
|
+
if (!tokens.length)
|
|
411
|
+
return true;
|
|
412
|
+
const name = String(row.position_name || row.name || '');
|
|
413
|
+
const hay = name + ' ' + Object.values(row.displayData || {}).map(String).join(' ');
|
|
414
|
+
return tokens.some((t) => hay.toUpperCase().includes(t.toUpperCase()));
|
|
415
|
+
};
|
|
416
|
+
const fields = cache.fields[jd.objId] || {};
|
|
417
|
+
const rev = {};
|
|
418
|
+
for (const [k, v] of Object.entries(fields))
|
|
419
|
+
rev[String(v)] = k;
|
|
420
|
+
const picked = [];
|
|
421
|
+
for (const row of rows) {
|
|
422
|
+
if (!match(row) || picked.length >= 5)
|
|
423
|
+
continue;
|
|
424
|
+
const dataId = String(row.form_data_id || row.id || '');
|
|
425
|
+
if (!dataId || dataId === String(jd.dataId || ''))
|
|
426
|
+
continue;
|
|
427
|
+
const item = {
|
|
428
|
+
职位: String(row.position_name || row.name || '').trim(),
|
|
429
|
+
状态: String(row.status || row.data_status_value || '').trim(),
|
|
430
|
+
创建时间: String(row.create_time || '').trim(),
|
|
431
|
+
};
|
|
432
|
+
try {
|
|
433
|
+
const rec = await getFormDataRecord(host, jd.formId, dataId, jd.objId, '');
|
|
434
|
+
for (const d of rec.dataDetails || []) {
|
|
435
|
+
const dk = rev[String(d.fieldId ?? d.formField?.id)] || '';
|
|
436
|
+
if (!dk)
|
|
437
|
+
continue;
|
|
438
|
+
let v = '';
|
|
439
|
+
if (Array.isArray(d.dataOptions) && d.dataOptions.length)
|
|
440
|
+
v = d.dataOptions.map((o) => o?.content || '').join(',');
|
|
441
|
+
else if (d.dataText?.content)
|
|
442
|
+
v = String(d.dataText.content);
|
|
443
|
+
else if (d.content !== undefined && d.content !== '')
|
|
444
|
+
v = String(d.content);
|
|
445
|
+
if (v === '')
|
|
446
|
+
continue;
|
|
447
|
+
if (REF_DETAIL_KEYS.includes(dk))
|
|
448
|
+
item[dk] = v.slice(0, 60);
|
|
449
|
+
else if (REF_TEXT_KEYS.includes(dk))
|
|
450
|
+
item[dk] = v.replace(/\s+/g, ' ').slice(0, 150);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
catch { /* 单条详情失败不影响其余参考 */ }
|
|
454
|
+
if (Object.keys(item).length > 3)
|
|
455
|
+
picked.push(item);
|
|
456
|
+
}
|
|
457
|
+
return { available: true, keyword: kw, scanned: rows.length, items: picked };
|
|
458
|
+
}
|
|
459
|
+
async function buildJd(opts) {
|
|
460
|
+
const { ctx, positionName, duty, requestText, demandId, demandName, sets } = opts;
|
|
461
|
+
const { host, appId, cache } = ctx;
|
|
462
|
+
const objId = objIdOf(cache, 'position_manage');
|
|
463
|
+
const formId = formIdOf(cache, 'position_manage');
|
|
464
|
+
const fields = cache.fields[objId] || {};
|
|
465
|
+
const fid = (k) => fields[k];
|
|
466
|
+
for (const k of DATAKEYS_TEXT)
|
|
467
|
+
if (!fid(k))
|
|
468
|
+
throw rsFail('职位管理缺少字段 ' + k + '(ds/fields 解析不到)');
|
|
469
|
+
for (const k of DATAKEYS_MTEXT)
|
|
470
|
+
if (!fid(k))
|
|
471
|
+
throw rsFail('职位管理缺少字段 ' + k + '(ds/fields 解析不到)');
|
|
472
|
+
// 并行预取:refByFid(sets 解析依赖它)与 currentUser(仅第⑤步用,与 sets 无依赖)
|
|
473
|
+
// 同时发出,避免过去「先等 refByFid → 再逐 set 串行 → 最后才取 currentUser」的多余 RTT。
|
|
474
|
+
const currentUserPromise = resolveCurrentUser(host)
|
|
475
|
+
.catch(() => null);
|
|
476
|
+
const refByFid = await fetchRefByFid(ctx);
|
|
477
|
+
const map = new Map();
|
|
478
|
+
const put = (d) => { if (d && d.formField && d.formField.id)
|
|
479
|
+
map.set(String(d.formField.id), d); };
|
|
480
|
+
const hasKey = (k) => { const id = fid(k); return !!(id && map.has(String(id))); };
|
|
481
|
+
// ① 用户提供的核心字段
|
|
482
|
+
put({ formField: { id: fid('position_name') }, content: positionName });
|
|
483
|
+
if (duty)
|
|
484
|
+
put({ formField: { id: fid('position_duty') }, dataText: { content: duty } });
|
|
485
|
+
if (requestText)
|
|
486
|
+
put({ formField: { id: fid('work_request') }, dataText: { content: requestText } });
|
|
487
|
+
if (demandId) {
|
|
488
|
+
if (!fid('demand'))
|
|
489
|
+
throw rsFail('职位管理缺少字段 demand(ds/fields 解析不到,关联需求无法设置)');
|
|
490
|
+
put({ formField: { id: fid('demand') }, dataOptions: [{ optionId: String(demandId), content: demandName || String(demandId) }] });
|
|
491
|
+
}
|
|
492
|
+
// ② sets 覆盖(AI 依 JD 指定;优先于自动默认值)
|
|
493
|
+
// 各项之间互不依赖(都只读 refByFid 与字典缓存),因此并行解析:
|
|
494
|
+
// 原实现逐个 await,6 个 set 就要串 6 次 RTT(含 work_location 内部 2~3 次请求),是 prepare 的主要串行瓶颈。
|
|
495
|
+
// 仍按原顺序 put,保证同一 key 多次出现时「后者覆盖前者」的语义不变。
|
|
496
|
+
const appliedSets = [];
|
|
497
|
+
const skippedSets = [];
|
|
498
|
+
const resolvedSets = await Promise.all(sets.map(async ([k, v]) => ({ k, v, d: await resolveSetValue(ctx, k, v, refByFid).catch(() => null) })));
|
|
499
|
+
for (const { k, v, d } of resolvedSets) {
|
|
500
|
+
if (d) {
|
|
501
|
+
put(d);
|
|
502
|
+
appliedSets.push(k + '=' + v);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
skippedSets.push(k + '=' + v);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
// ③ 默认值:招聘状态 = 招聘中
|
|
509
|
+
if (!hasKey('status')) {
|
|
510
|
+
if (!fid('status'))
|
|
511
|
+
throw rsFail('职位管理缺少字段 status(ds/fields 解析不到)');
|
|
512
|
+
const statusMap = await getDsOptions(host, objId, fid('status'));
|
|
513
|
+
const statusId = statusMap[DEF_STATUS];
|
|
514
|
+
if (!statusId)
|
|
515
|
+
throw rsFail('职位管理「招聘状态」未解析到「' + DEF_STATUS + '」选项(ds/options 返回为空)');
|
|
516
|
+
put({ formField: { id: fid('status') }, dataOptions: [{ optionId: String(statusId), content: DEF_STATUS }] });
|
|
517
|
+
}
|
|
518
|
+
// ④ 默认值:招聘流程 = 环境默认启用的流程
|
|
519
|
+
const defFlow = cache.defaultRecruitFlow;
|
|
520
|
+
if (!hasKey('recruit_flow') && fid('recruit_flow') && defFlow && defFlow.id) {
|
|
521
|
+
put({ formField: { id: fid('recruit_flow') }, dataOptions: [{ optionId: String(defFlow.id), content: defFlow.name }] });
|
|
522
|
+
}
|
|
523
|
+
// ⑤ 人员型默认 = 当前登录用户
|
|
524
|
+
const filled = [];
|
|
525
|
+
let currentUser = null;
|
|
526
|
+
if (DEF_CURRENT_USER.some((k) => fid(k) && !hasKey(k))) {
|
|
527
|
+
currentUser = await currentUserPromise;
|
|
528
|
+
if (currentUser && currentUser.id) {
|
|
529
|
+
for (const k of DEF_CURRENT_USER) {
|
|
530
|
+
if (fid(k) && !hasKey(k)) {
|
|
531
|
+
put({ formField: { id: fid(k) }, dataOptions: [{ optionId: String(currentUser.id), content: currentUser.name }] });
|
|
532
|
+
filled.push(k);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
// ⑥ 其余必填字段默认值
|
|
538
|
+
for (const [k, v] of Object.entries(DEF_TEXT)) {
|
|
539
|
+
if (fid(k) && !hasKey(k)) {
|
|
540
|
+
put({ formField: { id: fid(k) }, content: v });
|
|
541
|
+
filled.push(k);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
for (const [k, name] of Object.entries(DEF_OPTION)) {
|
|
545
|
+
if (fid(k) && !hasKey(k)) {
|
|
546
|
+
const m = await getDsOptions(host, objId, fid(k));
|
|
547
|
+
const oid = m[name];
|
|
548
|
+
if (oid) {
|
|
549
|
+
put({ formField: { id: fid(k) }, dataOptions: [{ optionId: String(oid), content: name }] });
|
|
550
|
+
filled.push(k);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
// 其余必填字段默认值:从「环境内最近一条职位记录」继承
|
|
555
|
+
// ⚠️ 继承来源可能是脏数据(实测本环境 836 条职位中「蓝堡舟山普陀区蓝堡」占 35 条),
|
|
556
|
+
// 因此逐个字段记录 inheritedFromRef,在确认摘要里明示,避免用户以为是自己指定的值。
|
|
557
|
+
const inheritedFromRef = [];
|
|
558
|
+
for (const k of DEF_FROM_REF) {
|
|
559
|
+
const id = fid(k);
|
|
560
|
+
if (id && !map.has(String(id)) && refByFid[String(id)]) {
|
|
561
|
+
const d = refToSubmit(refByFid[String(id)]);
|
|
562
|
+
if (d) {
|
|
563
|
+
put(d);
|
|
564
|
+
filled.push(k);
|
|
565
|
+
inheritedFromRef.push({ field: k, value: detailValueId(refByFid[String(id)]) });
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
// 继承来的薪资若明显偏低(历史脏数据,实测出现过 300 元月薪),额外点名提示。
|
|
570
|
+
// 不阻断提交(薪资是必填项,阻断等于无法建档),但要求 Agent 在确认摘要里明确提示用户核对。
|
|
571
|
+
const inheritedSalaryWarnings = [];
|
|
572
|
+
for (const key of ['salary_min', 'salary_max']) {
|
|
573
|
+
const hit = inheritedFromRef.find((x) => x.field === key);
|
|
574
|
+
if (!hit)
|
|
575
|
+
continue;
|
|
576
|
+
const num = Number(String(hit.value).replace(/[^\d.]/g, ''));
|
|
577
|
+
// 继承值单位也是千元:18 = 18K 正常;低于 1(<1000元)或高于 100(>10万/月)才算异常
|
|
578
|
+
if (hit.value && Number.isFinite(num) && (num < 1 || num > 100)) {
|
|
579
|
+
inheritedSalaryWarnings.push(key + ' 继承值「' + hit.value + '」(千元)明显异常,请人工核对后再提交');
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
// ⑦ 工作地点默认值:不再从历史职位继承(实测会把 detail_location 为「1」的脏地点带进新职位),
|
|
583
|
+
// 改为在「办公地点」列表按「启用」状态 + 详细地址精确解析;解析不到则不写并点名。
|
|
584
|
+
let workLocationDefault = null;
|
|
585
|
+
let workLocationWarning = null;
|
|
586
|
+
if (!hasKey('work_location') && fid('work_location')) {
|
|
587
|
+
const loc = await resolveDefaultWorkLocation(ctx).catch(() => null);
|
|
588
|
+
if (loc) {
|
|
589
|
+
put({ formField: { id: fid('work_location') }, dataOptions: [{ optionId: loc.id, content: loc.name }] });
|
|
590
|
+
filled.push('work_location');
|
|
591
|
+
workLocationDefault = loc.name;
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
workLocationWarning = `未在「办公地点」列表找到启用状态的默认地点「${DEFAULT_WORK_LOCATION}」,本次不写 work_location;请用 sets 指定`;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
const inv = {};
|
|
598
|
+
for (const [k, v] of Object.entries(fields))
|
|
599
|
+
inv[String(v)] = k;
|
|
600
|
+
const requiredDefaultsFilled = [...map.keys()].map((f) => inv[f] || f).filter((k) => filled.includes(k));
|
|
601
|
+
return {
|
|
602
|
+
objId, formId, appId, dataDetails: [...map.values()],
|
|
603
|
+
summary: {
|
|
604
|
+
action: '生成职位JD(创建职位)',
|
|
605
|
+
positionName,
|
|
606
|
+
dutyLen: (duty || '').length,
|
|
607
|
+
requestLen: (requestText || '').length,
|
|
608
|
+
demand: demandId ? (demandName || demandId) : '(未关联需求)',
|
|
609
|
+
status: DEF_STATUS,
|
|
610
|
+
// 解析不到环境默认流程时不写该字段,表单自身默认值生效;文案按实际行为表述,避免误导。
|
|
611
|
+
recruitFlow: (defFlow && defFlow.id) ? defFlow.name : '(沿用表单默认值)',
|
|
612
|
+
currentUser: currentUser ? currentUser.name : null,
|
|
613
|
+
setApplied: appliedSets,
|
|
614
|
+
setSkipped: skippedSets,
|
|
615
|
+
// 明示哪些字段值继承自「环境内最近一条职位记录」——这些不是用户指定的,可能来自脏数据,
|
|
616
|
+
// 必须在确认摘要里人工核对(工作地点不参与继承,见 workLocationDefault)
|
|
617
|
+
inheritedFromRef: inheritedFromRef.length ? inheritedFromRef : undefined,
|
|
618
|
+
inheritedSalaryWarnings: inheritedSalaryWarnings.length ? inheritedSalaryWarnings : undefined,
|
|
619
|
+
inheritedNote: inheritedFromRef.length
|
|
620
|
+
? '以上字段未指定,值继承自环境内最近一条职位记录,可能含历史脏数据,请核对后再提交(工作地点不参与继承)'
|
|
621
|
+
: undefined,
|
|
622
|
+
workLocationDefault: workLocationDefault || undefined,
|
|
623
|
+
workLocationWarning: workLocationWarning || undefined,
|
|
624
|
+
requiredDefaultsFilled,
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function setsOf(args) {
|
|
629
|
+
const raw = args.sets;
|
|
630
|
+
if (Array.isArray(raw)) {
|
|
631
|
+
return raw.map((item) => {
|
|
632
|
+
if (typeof item === 'string') {
|
|
633
|
+
const j = item.indexOf('=');
|
|
634
|
+
if (j <= 0)
|
|
635
|
+
throw rsValidationError('set_invalid', `sets 项必须是 "字段=值" 形式:${item}`);
|
|
636
|
+
return [item.slice(0, j).trim().replace(/-/g, '_'), item.slice(j + 1)];
|
|
637
|
+
}
|
|
638
|
+
if (item && typeof item === 'object' && item.key !== undefined) {
|
|
639
|
+
return [String(item.key).trim().replace(/-/g, '_'), String(item.value ?? '')];
|
|
640
|
+
}
|
|
641
|
+
throw rsValidationError('set_invalid', 'sets 项必须是字符串 "字段=值" 或 {key,value} 对象');
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
return [];
|
|
645
|
+
}
|
|
646
|
+
async function prepare(args, env) {
|
|
647
|
+
const host = env.host;
|
|
648
|
+
const session = await host.getSession();
|
|
649
|
+
const ctx = { host, baseUrl: session.baseUrl.replace(/\/+$/, ''), appId: '', cache: await env.recruitContext() };
|
|
650
|
+
ctx.appId = ctx.cache.appId;
|
|
651
|
+
const perm = await probeCreatePermission(ctx.host, objIdOf(ctx.cache, 'position_manage'));
|
|
652
|
+
if (perm === 'denied')
|
|
653
|
+
throw rsFail('当前账号没有「职位管理」表单的创建权限,已阻断(未写入任何数据)');
|
|
654
|
+
const positionName = String(args.positionName || '').trim();
|
|
655
|
+
if (!positionName)
|
|
656
|
+
throw rsValidationError('position_name_required', 'positionName 必填');
|
|
657
|
+
const jd = await buildJd({
|
|
658
|
+
ctx, positionName,
|
|
659
|
+
duty: args.positionDuty ? String(args.positionDuty) : undefined,
|
|
660
|
+
requestText: args.workRequest ? String(args.workRequest) : undefined,
|
|
661
|
+
demandId: args.demandId ? String(args.demandId) : undefined,
|
|
662
|
+
demandName: args.demandName ? String(args.demandName) : undefined,
|
|
663
|
+
sets: setsOf(args),
|
|
664
|
+
});
|
|
665
|
+
// 参考检索默认关闭:环境职位数据重复严重(实测 836 条中「舟山民宿管家」30 条)且列表层
|
|
666
|
+
// 无薪资/学历字段,参考价值低于请求成本。需要时显式传 referenceKeyword 才执行;
|
|
667
|
+
// 岗位范式改由 references/recruit-stage/position-templates.md 提供(零请求)。
|
|
668
|
+
const refs = args.referenceKeyword
|
|
669
|
+
? await fetchRecentReferences(ctx, jd, String(args.referenceKeyword))
|
|
670
|
+
.catch((e) => ({ available: false, reason: e.message, items: [] }))
|
|
671
|
+
: {
|
|
672
|
+
available: false,
|
|
673
|
+
skipped: true,
|
|
674
|
+
reason: '未显式指定 referenceKeyword,已跳过同类职位参考检索;请改用 references/recruit-stage/position-templates.md 的岗位范式补齐 positionDuty / workRequest(该文件未覆盖的职位族须由用户提供)',
|
|
675
|
+
items: [],
|
|
676
|
+
};
|
|
677
|
+
// fingerprint 必须基于完整 dataDetails(apply 阶段比对同一口径),回执里才做瘦身。
|
|
678
|
+
const willSubmit = { formId: jd.formId, objId: jd.objId, dataDetails: jd.dataDetails };
|
|
679
|
+
const fp = fingerprint(willSubmit);
|
|
680
|
+
const continuation = await env.continuation.issue({ operation: 'ehr.recruit.stage.jd.create.apply', fingerprint: fp,
|
|
681
|
+
enumMaps: await dsOptionsSnapshot(),
|
|
682
|
+
// 🔴 2026-11-07 修复:协议文档写「apply 带 confirm + continuation」,但 apply 原来只从 args 取
|
|
683
|
+
// positionName/positionDuty/...,Agent 少传 positionName 就直接报 position_name_required。
|
|
684
|
+
// 现把 prepare 用过的业务参数一并签进 continuation;apply 显式传的仍优先。
|
|
685
|
+
argsSnapshot: {
|
|
686
|
+
positionName: String(args.positionName || ''),
|
|
687
|
+
positionDuty: args.positionDuty ? String(args.positionDuty) : undefined,
|
|
688
|
+
workRequest: args.workRequest ? String(args.workRequest) : undefined,
|
|
689
|
+
demandId: args.demandId ? String(args.demandId) : undefined,
|
|
690
|
+
demandName: args.demandName ? String(args.demandName) : undefined,
|
|
691
|
+
} });
|
|
692
|
+
// 回执体积控制:continuation 与 fingerprint 放在返回体最前,避免大输出被截断时 Agent 取不到它们
|
|
693
|
+
// 而重复调用 prepare(实测多花 10.7s)。
|
|
694
|
+
// 🔴 2026-11-07 修正(D1):此前 willSubmit 只列字段名、不给 fieldId 与取值,Agent 无法自检
|
|
695
|
+
// 「准备写进表单的到底是什么值」,只能盲确认。现在改为逐字段 {key, fieldId, value},
|
|
696
|
+
// 并把单值截到 60 字符控制体积;指纹仍基于完整 dataDetails,不受裁剪影响。
|
|
697
|
+
const invFieldKeys = {};
|
|
698
|
+
for (const [k, v] of Object.entries(ctx.cache.fields[jd.objId] || {}))
|
|
699
|
+
invFieldKeys[String(v)] = k;
|
|
700
|
+
// dataDetails 三种取值载体必须在摘要里都覆盖到,否则会显示成 null 误导 Agent:
|
|
701
|
+
// 单行文本 / 数字 → content;多行文本(职位职责 / 任职要求)→ dataText.content;
|
|
702
|
+
// 选项 / 关联字段 → dataOptions[0]。
|
|
703
|
+
const briefValue = (d) => {
|
|
704
|
+
let raw;
|
|
705
|
+
if (d?.dataText && d.dataText.content !== undefined && d.dataText.content !== null)
|
|
706
|
+
raw = d.dataText.content;
|
|
707
|
+
else if (d?.content !== undefined && d?.content !== null)
|
|
708
|
+
raw = d.content;
|
|
709
|
+
else if (Array.isArray(d?.dataOptions) && d.dataOptions.length)
|
|
710
|
+
raw = d.dataOptions[0]?.content ?? d.dataOptions[0]?.id;
|
|
711
|
+
if (typeof raw === 'string')
|
|
712
|
+
return raw.length > 60 ? raw.slice(0, 60) + '…' : raw;
|
|
713
|
+
return raw === undefined ? null : raw;
|
|
714
|
+
};
|
|
715
|
+
// 🔴 2026-11-07 修复(缺陷 B):prepare 的 preview 此前恒为空对象 {}。
|
|
716
|
+
// 协议约定 preview 是「给用户看的确认摘要」,为空等于确认链形同虚设(用户看不到要提交什么)。
|
|
717
|
+
// 现在用 summary + 正文摘要拼出 preview;bodyPreview 不截成 60 字(那是 willSubmit 的体积控制口径),
|
|
718
|
+
// 摘要给 100 字以便用户判断 JD 是否可用。
|
|
719
|
+
const fieldTextOf = (name) => {
|
|
720
|
+
const fid = String((ctx.cache.fields[jd.objId] || {})[name] || '');
|
|
721
|
+
if (!fid)
|
|
722
|
+
return '';
|
|
723
|
+
const d = willSubmit.dataDetails.find((x) => String(x?.formField?.id) === fid);
|
|
724
|
+
const raw = d?.dataText?.content ?? d?.content;
|
|
725
|
+
return typeof raw === 'string' ? raw : '';
|
|
726
|
+
};
|
|
727
|
+
const clip = (s, n) => (s.length > n ? s.slice(0, n) + '…' : s);
|
|
728
|
+
const dutyText = fieldTextOf('position_duty');
|
|
729
|
+
const requestText = fieldTextOf('work_request');
|
|
730
|
+
// 🔴 2026-11-07 修复(缺陷 A 配套):正文为空时不再静默成功。
|
|
731
|
+
// 实测「技术研发」这类泛称会产出 dutyLen=0 / requestLen=0 的空 JD,但 ok=true,
|
|
732
|
+
// 上层看起来像"没反应"。这里显式给 warning,把责任明确回给调用方(补正文或查模板)。
|
|
733
|
+
const missingBody = jd.summary.dutyLen === 0 || jd.summary.requestLen === 0;
|
|
734
|
+
const jdWarning = missingBody
|
|
735
|
+
? `JD 正文不完整(职责 ${jd.summary.dutyLen} 字 / 任职要求 ${jd.summary.requestLen} 字)。请补 positionDuty / workRequest 后重新 prepare,或按 references/recruit-stage/position-templates.md 对应职位族补齐;以当前内容 apply 会创建一条没有职责与要求的职位记录。`
|
|
736
|
+
: undefined;
|
|
737
|
+
const preview = {
|
|
738
|
+
action: jd.summary.action,
|
|
739
|
+
positionName: jd.summary.positionName,
|
|
740
|
+
positionDuty: dutyText ? clip(dutyText, 100) : '(空,见 warning)',
|
|
741
|
+
workRequest: requestText ? clip(requestText, 100) : '(空,见 warning)',
|
|
742
|
+
demand: jd.summary.demand,
|
|
743
|
+
status: jd.summary.status,
|
|
744
|
+
recruitFlow: jd.summary.recruitFlow,
|
|
745
|
+
currentUser: jd.summary.currentUser,
|
|
746
|
+
setApplied: jd.summary.setApplied,
|
|
747
|
+
setSkipped: jd.summary.setSkipped,
|
|
748
|
+
inheritedFromRef: jd.summary.inheritedFromRef,
|
|
749
|
+
inheritedSalaryWarnings: jd.summary.inheritedSalaryWarnings,
|
|
750
|
+
inheritedNote: jd.summary.inheritedNote,
|
|
751
|
+
workLocationDefault: jd.summary.workLocationDefault,
|
|
752
|
+
workLocationWarning: jd.summary.workLocationWarning,
|
|
753
|
+
requiredDefaultsFilled: jd.summary.requiredDefaultsFilled,
|
|
754
|
+
fieldCount: willSubmit.dataDetails.length,
|
|
755
|
+
warning: jdWarning,
|
|
756
|
+
};
|
|
757
|
+
return rsSuccess('ehr.recruit.stage.jd.create.prepare', {
|
|
758
|
+
mode: 'prepare',
|
|
759
|
+
continuation,
|
|
760
|
+
fingerprint: fp,
|
|
761
|
+
...jd.summary,
|
|
762
|
+
preview,
|
|
763
|
+
jdWarning,
|
|
764
|
+
recentReferences: refs.items,
|
|
765
|
+
recentReferencesNote: refs.skipped
|
|
766
|
+
? refs.reason
|
|
767
|
+
: refs.available
|
|
768
|
+
? `已按「${refs.keyword}」在当前环境职位列表中检索(扫描 ${refs.scanned} 条,命中 ${refs.items.length} 条)——请对标这些同类职位的薪酬/人数/要求给出推荐值,一并放进确认摘要,不要逐字段询问用户`
|
|
769
|
+
: ('参考检索不可用:' + (refs.reason || '')),
|
|
770
|
+
willSubmit: {
|
|
771
|
+
formId: willSubmit.formId,
|
|
772
|
+
objId: willSubmit.objId,
|
|
773
|
+
fieldCount: willSubmit.dataDetails.length,
|
|
774
|
+
fields: willSubmit.dataDetails.map((d) => {
|
|
775
|
+
const fid = String(d?.formField?.id || '');
|
|
776
|
+
return { key: invFieldKeys[fid] || fid, fieldId: fid, value: briefValue(d) };
|
|
777
|
+
}),
|
|
778
|
+
},
|
|
779
|
+
}, {
|
|
780
|
+
continuation,
|
|
781
|
+
fingerprint: fp,
|
|
782
|
+
confirmHint: '用户明确确认后,携带 confirm:true 与本 continuation 调用 recruit-stage.jd.create.apply',
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
async function apply(args, env) {
|
|
786
|
+
if (args.confirm !== true)
|
|
787
|
+
throw rsConfirmationError('ehr.recruit.stage.jd.create.apply', { hint: '写操作必须显式 confirm:true' });
|
|
788
|
+
if (!args.continuation)
|
|
789
|
+
throw rsValidationError('continuation_required', '缺少 continuation(来自 prepare 的 meta)');
|
|
790
|
+
const payload = await env.continuation.verify(String(args.continuation), 'ehr.recruit.stage.jd.create.apply');
|
|
791
|
+
restoreDsOptions(payload.enumMaps);
|
|
792
|
+
// 🔴 2026-11-07 修复:把 prepare 快照里的业务参数补回 args(显式传的优先),
|
|
793
|
+
// 使 apply 只带 confirm + continuation 也能执行,与协议文档一致。
|
|
794
|
+
const merged = { ...(payload.argsSnapshot || {}), ...args };
|
|
795
|
+
const host = env.host;
|
|
796
|
+
const session = await host.getSession();
|
|
797
|
+
const ctx = { host, baseUrl: session.baseUrl.replace(/\/+$/, ''), appId: '', cache: await env.recruitContext() };
|
|
798
|
+
ctx.appId = ctx.cache.appId;
|
|
799
|
+
const positionName = String(merged.positionName || '').trim();
|
|
800
|
+
if (!positionName)
|
|
801
|
+
throw rsValidationError('position_name_required', 'positionName 必填');
|
|
802
|
+
const jd = await buildJd({
|
|
803
|
+
ctx, positionName,
|
|
804
|
+
duty: merged.positionDuty ? String(merged.positionDuty) : undefined,
|
|
805
|
+
requestText: merged.workRequest ? String(merged.workRequest) : undefined,
|
|
806
|
+
demandId: merged.demandId ? String(merged.demandId) : undefined,
|
|
807
|
+
demandName: merged.demandName ? String(merged.demandName) : undefined,
|
|
808
|
+
sets: setsOf(merged),
|
|
809
|
+
});
|
|
810
|
+
const willSubmit = { formId: jd.formId, objId: jd.objId, dataDetails: jd.dataDetails };
|
|
811
|
+
if (payload.fingerprint !== fingerprint(willSubmit)) {
|
|
812
|
+
throw rsValidationError('fingerprint_mismatch', '待提交内容与 prepare 确认摘要不一致(字段值已变化),请重新 prepare 确认后再 apply');
|
|
813
|
+
}
|
|
814
|
+
// ① 保存职位管理表单 → ② addPosition 提交生成职位
|
|
815
|
+
const formDataId = await saveFormData(host, {
|
|
816
|
+
appId: jd.appId, formId: jd.formId, objId: jd.objId,
|
|
817
|
+
name: '职位管理-' + positionName, dataDetails: jd.dataDetails,
|
|
818
|
+
});
|
|
819
|
+
const r2 = await host.request({ path: '/api/recruit/position/v2/addPosition?formDataId=' + formDataId, method: 'POST' });
|
|
820
|
+
const data = r2?.data || {};
|
|
821
|
+
const positionPostId = data.positionPostId;
|
|
822
|
+
const checkRpa = data.checkRpa;
|
|
823
|
+
const rpaValidMsg = data.rpaValidMsg || null;
|
|
824
|
+
// 页面真实响应:外层 status=true、data.status=false(业务子状态,不是失败)、fail=false、
|
|
825
|
+
// successMsg=操作成功,且可能没有 positionPostId。旧逻辑强依赖 positionPostId 会把成功误判为 failed。
|
|
826
|
+
// 🔴 2026-11-07 实测修正:`fail:false` 的真实语义是「没有失败」,旧写法 `r2?.fail !== false`
|
|
827
|
+
// 把「明确返回 fail:false」判成失败,于是职位已建成却返回 result=failed(ok:true)。
|
|
828
|
+
// 只有 `fail === true` 才算失败。
|
|
829
|
+
const okByResponse = r2?.status !== false && r2?.fail !== true && data.fail !== true;
|
|
830
|
+
// 第三层门禁:写完回查记录与关键字段,作为最终判定(接口语义不一致时以落库为准)
|
|
831
|
+
// 🔴 2026-11-07 扩展:此前只回查 position_name/status/salary/work_location(实测 checked 恒为 3),
|
|
832
|
+
// 正文两个最容易被静默丢弃的字段(position_duty / work_request)不在核对范围——写没写进去摘要看不出来。
|
|
833
|
+
// 现把这两个多行文本也纳入严格比对(二者载体是 dataText,与单行文本不同,漏掉就会一直"假绿")。
|
|
834
|
+
const verification = await verifySubmitted({
|
|
835
|
+
host, formId: jd.formId, objId: jd.objId, dataId: formDataId,
|
|
836
|
+
expected: expectedFields(jd.dataDetails, ctx.cache.fields[jd.objId] || {}, ['position_name', 'position_duty', 'work_request', 'status', 'salary_min', 'salary_max', 'work_location'], ['position_name', 'status'], ['salary_min', 'salary_max', 'work_location']),
|
|
837
|
+
});
|
|
838
|
+
if (verification.mismatches.length)
|
|
839
|
+
invalidateEnvCache(ctx.baseUrl, ctx.appId);
|
|
840
|
+
const recordOk = verification.unavailable ? okByResponse : verification.mismatches.length === 0;
|
|
841
|
+
const created = okByResponse && recordOk;
|
|
842
|
+
const result = !created ? 'failed' : (verification.mismatches.length ? 'partial' : 'success');
|
|
843
|
+
// 列表链接只打开列表;详情单页由 viewLink 单独给出,两者不再合并成一个「列表+滑出详情」地址。
|
|
844
|
+
const listUrl = buildListUrl(ctx.baseUrl, (ctx.cache.lists?.position?.listId) || '');
|
|
845
|
+
const cardUrl = buildCardUrl(ctx.baseUrl, jd.objId, formDataId);
|
|
846
|
+
return rsSuccess('ehr.recruit.stage.jd.create.apply', {
|
|
847
|
+
mode: 'apply',
|
|
848
|
+
result,
|
|
849
|
+
formDataId,
|
|
850
|
+
positionPostId: positionPostId || null,
|
|
851
|
+
rpaChecked: checkRpa === undefined ? null : !!checkRpa,
|
|
852
|
+
rpaValidMsg,
|
|
853
|
+
verification: { checked: verification.checked, mismatches: verification.mismatches, unavailable: verification.unavailable || null },
|
|
854
|
+
verifyWarnings: verification.mismatches.map((m) => '落库回查不一致:' + m.label + ' 期望 ' + m.expected + ',实际 ' + m.actual),
|
|
855
|
+
positionListUrl: listUrl,
|
|
856
|
+
positionCardUrl: cardUrl,
|
|
857
|
+
positionListLocateUrl: listUrl,
|
|
858
|
+
// 产物链接(Agent 原样搬运成 Markdown 链接,按顺序:详情在前、列表在后)
|
|
859
|
+
viewLink: cardUrl ? `[查看 ${jd.summary.positionName || '新建职位'} 职位详情](${cardUrl})` : null,
|
|
860
|
+
listLocateLink: listUrl ? `[打开职位列表](${listUrl})` : null,
|
|
861
|
+
agentNote: '查看入口 = 两个 Markdown 链接:① viewLink 职位详情单页 ② listLocateLink 职位列表(只打开列表,不打开详情)。按顺序原样搬运,不要包 browsertool 标签;缺哪个只给另一个。链接只是查看入口,重复点击不会重复创建。',
|
|
862
|
+
...jd.summary,
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
async function prefill(args, env) {
|
|
866
|
+
const host = env.host;
|
|
867
|
+
const session = await host.getSession();
|
|
868
|
+
const ctx = { host, baseUrl: session.baseUrl.replace(/\/+$/, ''), appId: '', cache: await env.recruitContext() };
|
|
869
|
+
ctx.appId = ctx.cache.appId;
|
|
870
|
+
const positionName = String(args.positionName || '').trim();
|
|
871
|
+
if (!positionName)
|
|
872
|
+
throw rsValidationError('position_name_required', 'positionName 必填');
|
|
873
|
+
const jd = await buildJd({
|
|
874
|
+
ctx, positionName,
|
|
875
|
+
duty: args.positionDuty ? String(args.positionDuty) : undefined,
|
|
876
|
+
requestText: args.workRequest ? String(args.workRequest) : undefined,
|
|
877
|
+
demandId: args.demandId ? String(args.demandId) : undefined,
|
|
878
|
+
demandName: args.demandName ? String(args.demandName) : undefined,
|
|
879
|
+
sets: setsOf(args),
|
|
880
|
+
});
|
|
881
|
+
const fields = toPrefillFields(jd.dataDetails, ctx.cache.fields[jd.objId] || {});
|
|
882
|
+
const listUrl = await resolvePositionNewUrl(ctx);
|
|
883
|
+
const homeUrl = await resolveHomePageUrl(ctx);
|
|
884
|
+
const jsExpr = `(() => { const W = window.WeFormSDK; const i = W && W.getWeFormInstance('ebuilderform', '${jd.formId}');`
|
|
885
|
+
+ ` if (!i) return 'no-form-instance(请先打开职位管理新建表单)'; const fields = ${JSON.stringify(fields)};`
|
|
886
|
+
+ ` let ok = 0, fail = []; for (const f of fields) { try { i.changeFieldValue(f.mark, f.info); ok++; } catch (e) { fail.push(f.label); } }`
|
|
887
|
+
+ ` return 'prefilled ' + ok + '/' + fields.length + (fail.length ? ' fail=' + fail.join(',') : ''); })()`;
|
|
888
|
+
return rsSuccess('ehr.recruit.stage.jd.create.prefill', {
|
|
889
|
+
mode: 'prefill',
|
|
890
|
+
...jd.summary,
|
|
891
|
+
formId: jd.formId,
|
|
892
|
+
fields,
|
|
893
|
+
jsExpr,
|
|
894
|
+
openMethods: {
|
|
895
|
+
homeFullscreen: { url: homeUrl, openAction: '点「快速入口 → 创建职位」打开表单,再点表单右上角「放大」按钮 → 全屏单页' },
|
|
896
|
+
listDialog: { url: listUrl, openAction: '点击页面上的「新建」' },
|
|
897
|
+
},
|
|
898
|
+
steps: [
|
|
899
|
+
'1) 浏览器打开 openMethods.homeFullscreen.url(或 listDialog.url),需已登录该环境',
|
|
900
|
+
'2) 打开新建表单:B = 首页点「创建职位」+ 点表单右上「放大」(全屏单页);A = 列表点「新建」(弹窗)',
|
|
901
|
+
'3) 在页面上下文执行 jsExpr(如 browser-skill: bsk evaluate "<jsExpr>")→ 返回 prefilled N/N 即完成',
|
|
902
|
+
'4) 由操作者核对内容后自行点「保存/保存并发布」;本模式不写任何数据',
|
|
903
|
+
],
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
const baseInput = {
|
|
907
|
+
positionName: { type: 'string', description: '职位名称(必填)' },
|
|
908
|
+
positionDuty: { type: 'string', description: '职位职责/JD 正文(多行文本)' },
|
|
909
|
+
workRequest: { type: 'string', description: '任职要求(多行文本)' },
|
|
910
|
+
demandId: { ...SCHEMA_ID_STR, description: '关联招聘需求 id(可选)' },
|
|
911
|
+
demandName: { type: 'string', description: '关联招聘需求名称(可选,仅展示)' },
|
|
912
|
+
sets: {
|
|
913
|
+
type: 'array', maxItems: 30,
|
|
914
|
+
items: { oneOf: [{ type: 'string' }, { type: 'object', properties: { key: { type: 'string' }, value: { type: 'string' } } }] },
|
|
915
|
+
description: 'AI 依 JD 指定的字段值("字段dataKey=值" 或 {key,value})',
|
|
916
|
+
},
|
|
917
|
+
referenceKeyword: { type: 'string', description: '同类职位参考检索关键词(默认用职位名)' },
|
|
918
|
+
};
|
|
919
|
+
export const jdCreateOperations = [
|
|
920
|
+
{
|
|
921
|
+
name: 'ehr.recruit.stage.jd.create.prepare',
|
|
922
|
+
resource: 'recruit.jd',
|
|
923
|
+
method: 'prepare',
|
|
924
|
+
action: 'jd.create.prepare',
|
|
925
|
+
summary: '生成职位确认摘要:解析职位表单字段、套用默认值(状态/流程/负责人/关联字段取环境现成值)、检索最近同类职位参考,不写入任何数据',
|
|
926
|
+
capability: 'recruit.jd.create',
|
|
927
|
+
risk: 'write',
|
|
928
|
+
requiresConfirmation: true,
|
|
929
|
+
inputSchema: schemaOf(baseInput, { required: ['positionName'] }),
|
|
930
|
+
handler: prepare,
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
name: 'ehr.recruit.stage.jd.create.apply',
|
|
934
|
+
resource: 'recruit.jd',
|
|
935
|
+
method: 'apply',
|
|
936
|
+
action: 'jd.create.apply',
|
|
937
|
+
summary: '用户确认后创建职位:saveFormData(职位管理)→ addPosition 生成职位,与页面「保存」等价;返回职位详情与列表定位双链接',
|
|
938
|
+
capability: 'recruit.jd.create',
|
|
939
|
+
risk: 'write',
|
|
940
|
+
requiresConfirmation: true,
|
|
941
|
+
inputSchema: schemaOf({ ...baseInput, confirm: { type: 'boolean', description: '必须显式 true' }, continuation: { type: 'string', description: 'prepare 返回的 continuation' } }, { required: ['positionName', 'confirm', 'continuation'] }),
|
|
942
|
+
handler: apply,
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
name: 'ehr.recruit.stage.jd.create.prefill',
|
|
946
|
+
resource: 'recruit.jd',
|
|
947
|
+
method: 'prefill',
|
|
948
|
+
action: 'jd.create.prefill',
|
|
949
|
+
summary: '预填模式(人工保存):输出打开职位新建页的 URL + WeFormSDK 注入 jsExpr,不落库,由操作者核对后自行保存',
|
|
950
|
+
capability: 'recruit.jd.create',
|
|
951
|
+
risk: 'read',
|
|
952
|
+
inputSchema: schemaOf(baseInput, { required: ['positionName'] }),
|
|
953
|
+
handler: prefill,
|
|
954
|
+
},
|
|
955
|
+
];
|
|
956
|
+
// 保留引用避免 tree-shake 误删(readFileSync/fileURLToPath 供 school-tiers 等后续扩展使用)
|
|
957
|
+
void readFileSync;
|
|
958
|
+
void resolvePath;
|
|
959
|
+
void dirname;
|
|
960
|
+
void fileURLToPath;
|
|
961
|
+
void randomBytes;
|