一般校验器要配置在待入职和人员信息管理
例如:配置教育经历最多只能有一条'是否最高学历'、'是否最高学位'、'是否全日制最高学历'、'是否全日制最高学位'!
这种我们如果单独配置在人员信息管理中,待入职没配置,那么人员从待入职到人员信息管理就可能因为校验不满足导致人员信息生效不过去。所以我们配置就要配置完整,才能保证所有数据来源都是正确的,即在待入职和人员信息管理中都配上校验。
以下以教育经历配置为例:
1.点击新增,切换元数据,切换到不带场景的model.json(即EmployeeEducation.json),添加以下配置
- checker:固定写法
- name:云函数的名字(注意不要有特殊符号,可以使用下划线“_”)
- key:json文件唯一key值,保证当前json文件中不重复即可
- tips:校验不通过时的提示信息(平台暂时只能支持在这里设置提示)
{
"validators": [{
"checker": "DynamicChecker",
"name": "EmployeeEducation",
"key": "is_highest_validator",
"tips": "教育经历最多只能有一条'是否最高学历'、'是否最高学位'、'是否全日制最高学历'、'是否全日制最高学位'!"
}]
}
配置完成时效果图:

2.添加云函数(系统设置——扩展管理——云函数管理)
类型选择:“校验器”
名称:DataChecker_xxx(xxx为前面json文件中配置的name,此处应为DataChecker_EmployeeEducation)
描述:添加描述信息
启用:是
配置完成时效果图:

打开配置好的云函数,复制以下代码并根据实际情况进行修改(必须确认修改项为☆☆☆标识; 禁止修改项为★★★标识,其他的有代码能力的可以修改,否则勿动!!!)
class UniquenessChecker(DynamicCheckBase):
"""
云函数校验器示例,在对象新增,修改时会校验
"""
def check(self, info):
# ☆☆☆model:为校验的模型名,可根据实际情况修改☆☆☆
model = "EmployeeEducation"
employee_id = info['employee_id']
info_list = CustomerUtil.call_open_api('hcm.model.list', {
"model": model,
"filter_dict": {
"employee_id": employee_id
},
"page_index": 1,
"page_size": 200,
"extra_property": {"sorts": []}
})['list']
# ☆☆☆校验项,根据实际情况修改(请配置校验字段的key以及该字段值为“是”和“否”的实际存储值)☆☆☆
# ☆☆☆以下示例为校验多项字段的配置,如只校验单一字段,请去掉多余字段☆☆☆
check_item_dict_list = [
{
"key": "is_highest", # 是否最高学历的key
"yes_flag": 1, # 是否最高学历为“是”
"no_flag": 0 # 是否最高学历“否”
},
{
"key": "is_highest_deg", # 是否最高学位的key
"yes_flag": "1", # 是否最高学位为“是”
"no_flag": "0" # 是否最高学位“否”
},
{
"key": "full_highest_edu", # 是否全日制最高学历的key
"yes_flag": 1, # 是否全日制最高学历为“是”
"no_flag": 0 # 是否全日制最高学历“否”
},
{
"key": "full_highest_deg", # 是否全日制最高学位的key
"yes_flag": 1, # 是否全日制最高学位为“是”
"no_flag": 0 # 是否全日制最高学位“否”
}
]
total_result = self.total_check(info, info_list, check_item_dict_list)
return {"success": total_result}
# ★★★无需修改★★★
def total_check(self, info, info_list, check_item_dict_list):
for item in check_item_dict_list:
key = item['key']
yes_flag = item['yes_flag']
no_flag = item['no_flag']
item_result = self.item_check(info, info_list, key, yes_flag, no_flag)
if not item_result:
return False
return True
# ★★★无需修改★★★
def item_check(self, info, info_list, key, yes_flag, no_flag):
list_id = info.get('id')
flag = info.get(key)
if len(info_list) == 0:
return True
else:
id_list = [item['id'] for item in info_list]
# 如果id列表不包含表单的id(新增)
if list_id not in id_list:
for item in info_list:
if item[key] == yes_flag and flag == yes_flag:
return False
return True
# 如果id列表中包含表单的id(修改)
else:
if flag == no_flag:
return True
else:
for item in info_list:
if item['id'] == list_id:
continue
if item[key] == yes_flag and flag == yes_flag:
return False
return True
附:查看实际存储值(yes_flag、no_flag)的方法(字段强烈推荐使用布尔型,就不用这么麻烦的来看实际存储值,布尔型的yes_flag为True,no_flag为False)
1.枚举项为Mask里面的key,注意是否有引号(如果mask里面key是"1",那么函数里面就是"1";如果mask里面key是1,那么函数里面就是1)

2.接口hcm.model.list中查看(界面F12查看控制台,点击右上角刷新,控制台选择NetWork查看hcm.model.list接口,查看右侧Preview数据项即可)
