参照型存的是字符串,关联型存的是id
这个wiki介绍的是将字符串类型存储的字段改为存储id类型的字段,以及对应数据刷新云函数
1. 找到对应代码项及数据来源
比如我们以上海建工为例:将执业资格子集下面的字段刷新(以资格名称为例),1. 对应找到需要刷新的代码项 2. 确定刷新数据来源于哪个model 下的哪个字段
如下我们可以确认:1. model: employee_dynamic_subset_zyzgt 下 zhiyezige_name 字段 2. 代码项 执业资格名称 category_id:78
Image Added
Image Added
复制云函数代码,修改对应model和刷新字段以及代码项类id
信息 |
---|
|
class CalculateCompanyAge(object): page_size = 500 api = 'hcm.model.list' update_model = "employee_dynamic_subset_zyzgt" update_field = "zhiyezige_name" update_category = 78 get_count_param = {"model": update_model, "page_index": 1, "page_size": 1} flush_param = {"model": "CommonBasicItem", "filter_dict": {"category_id": update_category}, "page_index": 1, "page_size": 100000} extra_property = { "fields": [ {"field": [update_field], "key": update_field} ] }
def execute(self, param): flush_map = {} count = CustomerUtil.call_open_api(self.api, self.get_count_param)['count'] flush_list = CustomerUtil.call_open_api(self.api, self.flush_param)['list'] for _item in flush_list: flush_map[_item.get('name')] = _item.get('id') for data_item in self.get_data_with_pagination(count): for data in data_item: edit_id = data['id'] zhiyezige_name = data.get(self.update_field) if zhiyezige_name: if zhiyezige_name in flush_map: flush_id = flush_map[zhiyezige_name] l = CustomerUtil.call_open_api('hcm.model.edit', {"id_": edit_id, "model": self.update_model, "info": {self.update_field: flush_id}})
def get_data_with_pagination(self, count): for page_index in range(1, int(count / self.page_size) + 2): data_list = CustomerUtil.call_open_api("hcm.model.list", param={"model": self.update_model, "extra_property": self.extra_property, "page_index": page_index, "page_size": self.page_size})[ 'list'] yield data_list
def test(self, param): return self.execute(param) |
你更新其他子集其他字段只需要替换三个地方:1.update_model 更新的子集model 2. update_field 刷新字段 3 。代码项类update_category
即可