//  [python]
def read_zip(self,zip_file_path,create_user):
    # 导入流程：
    # 1、解压zip压缩包文件到temp文件夹
    # 2、遍历temp文件夹内的解压后的.md文件
    # 3、读取.md文件的文本内容
    # 4、如果里面匹配到相对路径的静态文件，从指定文件夹里面读取
    # 5、上传图片，写入数据库，修改.md文件里面的url路径

    # 新建一个临时文件夹，用于存放解压的文件
    self.temp_dir = zip_file_path[:-3]
    os.mkdir(self.temp_dir)
    # 解压 zip 文件到指定临时文件夹
    shutil.unpack_archive(zip_file_path, extract_dir=self.temp_dir)

    # 处理文件夹和文件名的中文乱码
    for root, dirs, files in os.walk(self.temp_dir):
        for dir in dirs:
            try:
                new_dir = dir.encode('cp437').decode('gbk')
            except:
                new_dir = dir.encode('utf-8').decode('utf-8')
            # print(new_dir)
            os.rename(os.path.join(root, dir), os.path.join(root, new_dir))

        for file in files:
            try:
                new_file = file.encode('cp437').decode('gbk')
            except:
                new_file = file.encode('utf-8').decode('utf-8')
            # print(root, new_file)
            os.rename(os.path.join(root, file), os.path.join(root, new_file))

    # 读取yaml文件
    try:
        with open(os.path.join(self.temp_dir ,'mrdoc.yaml'),'r',encoding='utf-8') as yaml_file:
            yaml_str = yaml.safe_load(yaml_file.read())
            project_name = yaml_str['project_name'] \
                if 'project_name' in yaml_str.keys() else zip_file_path[:-4].split('/')[-1]
            project_desc = yaml_str['project_desc'] if 'project_desc' in yaml_str.keys() else ''
            project_role = yaml_str['project_role'] if 'project_role' in yaml_str.keys() else 1
            editor_mode = yaml_str['editor_mode'] if 'editor_mode' in yaml_str.keys() else 1
            project_toc = yaml_str['toc']
            toc_item_list = []
            for toc in project_toc:
                # print(toc)
                item = {
                    'name': toc['name'],
                    'file': toc['file'],
                    'parent': 0,
                }
                toc_item_list.append(item)
                if 'children' in toc.keys():
                    for b in toc['children']:
                        item = {
                            'name': b['name'],
                            'file': b['file'],
                            'parent': toc['name']
                        }
                        toc_item_list.append(item)
                        if 'children' in b.keys():
                            for c in b['children']:
                                item = {
                                    'name': c['name'],
                                    'file': c['file'],
                                    'parent': b['name']
                                }
                                toc_item_list.append(item)


    except:
        logger.error(_("未发现yaml文件"))
        project_name = zip_file_path[:-4].split('/')[-1]
        project_desc = ''
        project_role = 1
        editor_mode = 1
        project_toc = False

    # 开启事务
    with transaction.atomic():
        save_id = transaction.savepoint()
        try:
            # 新建文集
            project = Project.objects.create(
                name=project_name,
                intro=project_desc,
                role=project_role,
                create_user=create_user
            )
            if project_toc is False:
                # 遍历临时文件夹中的所有文件和文件夹
                for f in os.listdir(self.temp_dir):
                    # 获取 .md 文件
                    if f.endswith('.md'):
                        # print(f)
                        # 读取 .md 文件文本内容
                        with open(os.path.join(self.temp_dir,f),'r',encoding='utf-8') as md_file:
                            md_content = md_file.read()
                            md_content = self.operat_md_media(md_content,create_user)
                            # 新建文档
                            doc = Doc.objects.create(
                                name = f[:-3],
                                pre_content = md_content,
                                top_doc = project.id,
                                status = 0,
                                editor_mode = editor_mode,
                                create_user = create_user
                            )
            else:
                for i in toc_item_list:
                    with open(os.path.join(self.temp_dir,i['file']),'r',encoding='utf-8') as md_file:
                        md_content = md_file.read()
                        md_content = self.operat_md_media(md_content, create_user)
                        # 新建文档
                        doc = Doc.objects.create(
                            name=i['name'],
                            pre_content=md_content,
                            top_doc=project.id,
                            parent_doc = (Doc.objects.get(top_doc=project.id,name=i['parent'])).id \
                                if i['parent'] != 0 else 0,
                            status=0,
                            editor_mode=editor_mode,
                            create_user=create_user
                        )
        except:
            logger.exception(_("解析导入文件异常"))
            # 回滚事务
            transaction.savepoint_rollback(save_id)

        transaction.savepoint_commit(save_id)
    try:
        shutil.rmtree(self.temp_dir)
        os.remove(zip_file_path)
        return project.id
    except:
        logger.exception(_("删除临时文件异常"))
        return None