From 7fc844b27c22d85b4736366da5e0a431af6ec135 Mon Sep 17 00:00:00 2001 From: maxmon <541182180@qq.com> Date: Tue, 11 Apr 2023 23:30:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=93=E5=AD=98=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/app/api/v1/anno.py | 40 +++++++++++++++++++++++++++------------- be/app/api/v1/files.py | 7 ++++++- be/app/libs/tools.py | 2 ++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/be/app/api/v1/anno.py b/be/app/api/v1/anno.py index 76511ce..7f6baf2 100644 --- a/be/app/api/v1/anno.py +++ b/be/app/api/v1/anno.py @@ -11,6 +11,28 @@ from ...libs.tools import read_file, write_json, read_json_file, make_dir api = RedPrint('anno') +waiting_list_dic = {} + +def create_anno_2_file(project_name, anno_cont, all_anno=None): + + anno_output_path = ANNO_OUTPUT_PATH.format(project_name) + + # 判断路径是否存在 + if not os.path.exists(anno_output_path): + write_json(anno_output_path, [anno_cont]) + else: + output_anno = OutputAnno() + output_anno.all_anno = read_json_file(anno_output_path) + output_anno.add_anno(anno_cont) + + write_json(anno_output_path, output_anno.all_anno) + + waiting_list_dic[project_name] = waiting_list_dic[project_name][1:] + if len(waiting_list_dic[project_name]) > 0: + create_anno_2_file(project_name, waiting_list_dic[project_name][0], all_anno) + return True + return True + @@ -29,19 +51,11 @@ def create_anno(): anno_cont.annoDetails = anno_details anno_cont.isAnno = True - anno_output_path = ANNO_OUTPUT_PATH.format(project_name) - - # 判断路径是否存在 - if not os.path.exists(anno_output_path): - write_json(anno_output_path, [anno_cont]) - ret_info.errCode = 0 - else: - output_anno = OutputAnno() - output_anno.all_anno = read_json_file(anno_output_path) - output_anno.add_anno(anno_cont) - - write_json(anno_output_path, output_anno.all_anno) - ret_info.errCode = 0 + if project_name not in waiting_list_dic: + waiting_list_dic[project_name] = [] + waiting_list_dic[project_name].append(anno_cont) + if (len(waiting_list_dic[project_name]) == 1): # 自己位于第一个才处理,其他在第一个结束时处理 + create_anno_2_file(project_name, waiting_list_dic[project_name][0]) except Exception as e: print(e) diff --git a/be/app/api/v1/files.py b/be/app/api/v1/files.py index 363d596..a3fb119 100644 --- a/be/app/api/v1/files.py +++ b/be/app/api/v1/files.py @@ -30,6 +30,8 @@ def query_file(): file_names.remove('anno.json') anno_output_path = ANNO_OUTPUT_PATH.format(project_name) + if not os.path.exists(anno_output_path): + open(anno_output_path, 'w', encoding='utf-8').write('[]').close() # 判断路径是否存在 if not os.path.exists(anno_output_path): @@ -116,7 +118,10 @@ def get_json(): project_file_list = get_project_file(project_path) anno_data_set = set() download_json = [] - anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json') + anno_file_path = PROJECT_PATH.format(project_name) + '/anno.json' + if not os.path.exists(anno_file_path): + open(anno_file_path, 'w', encoding='utf-8').write('[]').close() + anno_data = read_json_file(anno_file_path) for item in anno_data: item_dict = {} item_dict['file'] = item['fileName'] diff --git a/be/app/libs/tools.py b/be/app/libs/tools.py index 6c48dab..342280e 100644 --- a/be/app/libs/tools.py +++ b/be/app/libs/tools.py @@ -22,9 +22,11 @@ def make_dir(path): if not folder: os.mkdir(path) +json_cache_dic = {} # 将json数据写入.json文件 def write_json(json_file_path, data): + json_cache_dic[json_file_path] = data with open(json_file_path, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, default=lambda o: o.__dict__)