def create_group_relation(node_key1, node1_list, node1_index_name, rel, node_key2, node2_id, node2_index_name, submit_user): node2_id_pinyin = p.get_pinyin(node2_id) node2_id_pinyin = node2_id_pinyin.lower() user_list_string = es_group.get(index=group_name, doc_type=group_type, id=node2_id_pinyin,\ fields=['people']) uid_list = [] uid_list = user_list_string['fields']['people'][0].split('&') uid_list.extend(node1_list) uid_list = [i for i in set(uid_list)] eid_string = '&'.join(uid_list) # print eid_string es_group.update(index=group_name, doc_type=group_type, id=node2_id_pinyin,\ body={'doc':{'people':eid_string, 'people_count':len(uid_list)}}) user_org = search_user_type(uid_list) user_id = user_org[0] org_id = user_org[1] flag = create_rel(node_key1, user_id, node1_index_name, rel, node_key2, node2_id_pinyin, node2_index_name, submit_user) node_key11 = org_primary node11_index_name = org_index_name flag = create_rel(node_key11, org_id, node11_index_name, rel, node_key2, node2_id_pinyin, node2_index_name, submit_user) return flag
def del_u_group_rel(g_name, uid): en_name = p.get_pinyin(g_name) en_name = en_name.lower() s_string = 'START s0 = node:'+group_index_name+'('+group_primary+'="'+en_name+'"),'\ +'s3 = node:'+node_index_name+'('+people_primary+'="'+uid+'") MATCH (s0)-[r:'+group_rel+']-(s3) DELETE r' print s_string graph.run(s_string) user_list_string = es_group.get(index=group_name, doc_type=group_type, id=en_name, fields=['people']) uid_list = user_list_string['fields']['people'][0].split('&') new_uid_list = set(uid_list) - set([uid]) new_uid_list = [i for i in new_uid_list] uid_string = '&'.join(new_uid_list) if len(new_uid_list) == 0: s_string = 'START s0 = node:' + group_index_name + '(' + group_primary + '="' + en_name + '") DELETE s0' graph.run(s_string) es_group.delete(index=group_name, doc_type=group_type, id=en_name) else: es_group.update(index=group_name,doc_type=group_type,id=en_name,\ body={'doc':{'people':uid_string, 'people_count':len(new_uid_list)}}) return '1'
def add_group_file_link(g_name, file_name, operation): new_label = file_name.split('+') en_name = p.get_pinyin(g_name) print en_name group_label = es_group.get(index=group_name, doc_type=group_type, id=en_name,\ fields=['file_link']) print group_label, '------------' try: group_label_list = group_label['fields']['file_link'][0].split('+') except: group_label_list = [] if operation == 'add': group_label_list.extend(new_label) elif operation == 'del': group_label_list = set(group_label_list) - set(new_label) group_label_list = [i for i in set(group_label_list)] group_label_string = '+'.join(group_label_list) es_group.update(index=group_name,doc_type=group_type, id=en_name,\ body={'doc':{'file_link':group_label_string}}) return 1