| | |
| | | |
| | | |
| | | async def create_menu_sync(db): |
| | | json_file_path = "env_conf/menu_conf.json" |
| | | json_file_path = "env_conf/menu_conf.json.template" |
| | | with open(json_file_path, 'r', encoding='utf-8') as file: |
| | | json_data = json.load(file).get("data", []) |
| | | for menu in json_data: |
| | | menu['dialog'].clear() |
| | | # for menu in json_data: |
| | | # menu['dialog'].clear() |
| | | dialogs = db.query(DialogModel).all() |
| | | |
| | | dialog_dict = {} |
| | | for dialog in dialogs: |
| | | if dialog.name not in dialog_dict: |
| | | dialog_dict[dialog.name] = [] |
| | | dialog_dict[dialog.name].append(dialog) |
| | | |
| | | for menu in json_data: |
| | | if menu['title'] in dialog_dict: |
| | | for dialog in dialog_dict[menu['title']]: |
| | | new_dialog_item = { |
| | | dialog_dict[dialog.name].append({ |
| | | 'id': dialog.id, |
| | | 'chat_id': dialog.id, |
| | | 'chat_type': '', |
| | | 'agentType': dialog.dialog_type |
| | | } |
| | | menu['dialog'].append(new_dialog_item) |
| | | }) |
| | | |
| | | for menu in json_data: |
| | | # if menu['title'] in dialog_dict: |
| | | # for dialog in dialog_dict[menu['title']]: |
| | | # new_dialog_item = { |
| | | # 'id': dialog.id, |
| | | # 'chat_id': dialog.id, |
| | | # 'chat_type': '', |
| | | # 'agentType': dialog.dialog_type |
| | | # } |
| | | menu['dialog']= dialog_dict.get(menu['title'], []) |
| | | json_data = {"data": json_data} |
| | | new_file_name = f"menu_conf.json.template" |
| | | new_file_path = os.path.join(os.path.dirname(json_file_path), new_file_name) |