批量生成时序图、类图

时序图在线工具地址WebSequenceDiagrams - Draw sequence diagrams online in seconds


类图在线工具地址PlantUML Web Server

1. 时序图使用示例

时序图代码:

title 计划类别
participant 用户            as 1
participant CategoryController  as 2
participant CategoryService     as 3
participant CategoryDao         as 4
1 -> 2: 创建计划类别
2 -> 3: CreateCategory(CreateCategoryRequestParam param)
3 -> 4: InsertCategory(CategoryDto dto)
4 --> 3: 
3 --> 2: 
2 --> 1:
1 -> 2: 创建计划类别
2 -> 3: UpdateCategory(UpdateCategoryRequestParam param)
3 -> 4: UpdateCategory(CategoryDto dto)
4 --> 3: 
3 --> 2: 
2 --> 1:
1 -> 2: 删除计划类别
2 -> 3: DeleteCategory(DeleteCategoryRequestParam param)
3 -> 4: DeleteCategoryById(String id)
4 --> 3: 
3 --> 2: 
2 --> 1:
1 -> 2: 查询计划类别
2 -> 3: QueryCategory(QueryCategoryRequestParam param)
3 -> 4: QueryCategoryByParam(QueryCategory dto)
4 --> 3: 
3 --> 2: 
2 --> 1:

生成的时序图示例:

2. 类图使用示例

类图代码:

abstract class CategoryDao {
    +String insertBIZ(CategoryDto dto)
    +void updateBIZ(CategoryDto dto)
    +void deleteBIZById(String id)
    +List<CategoryDto> queryBIZByParam(QueryCategoryDto dto)
}
class CategoryService {
    +createBIZ(CreateCategoryRequest param)
    +updateBIZ(UpdateCategoryRequest param)
    +deleteBIZ(DeleteCategoryRequest param)
    +queryBIZ(QueryCategoryRequest param)
}
class CategoryController {
    +handleCreateBIZ()
    +handleUpdateBIZ()
    +handleDeleteBIZ()
    +handleQueryBIZ()
}
CategoryService ..> CategoryDao: uses
CategoryController ..> CategoryService: uses

生成类图示例:

3. python批量生成类图,时序图

时序图代码模板:

title title_
participant 用户            as 1
participant BIZ_Controller  as 2
participant BIZ_Service     as 3
participant BIZ_Dao         as 4
1 -> 2: 创建title_
2 -> 3: CreateBIZ_(CreateBIZ_RequestParam param)
3 -> 4: InsertBIZ_(BIZ_Dto dto)
4 --> 3: 
3 --> 2: 
2 --> 1:
1 -> 2: 创建title_
2 -> 3: UpdateBIZ_(UpdateBIZ_RequestParam param)
3 -> 4: UpdateBIZ_(BIZ_Dto dto)
4 --> 3: 
3 --> 2: 
2 --> 1:
1 -> 2: 删除title_
2 -> 3: DeleteBIZ_(DeleteBIZ_RequestParam param)
3 -> 4: DeleteBIZ_ById(String id)
4 --> 3: 
3 --> 2: 
2 --> 1:
1 -> 2: 查询title_
2 -> 3: QueryBIZ_(QueryBIZ_RequestParam param)
3 -> 4: QueryBIZ_ByParam(QueryBIZ_ dto)
4 --> 3: 
3 --> 2: 
2 --> 1:

类图模板:

abstract class BIZ_Dao {
    +String insertBIZ(BIZ_Dto dto)
    +void updateBIZ(BIZ_Dto dto)
    +void deleteBIZById(String id)
    +List<BIZ_Dto> queryBIZByParam(QueryBIZ_Dto dto)
}
class BIZ_Service {
    +createBIZ(CreateBIZ_Request param)
    +updateBIZ(UpdateBIZ_Request param)
    +deleteBIZ(DeleteBIZ_Request param)
    +queryBIZ(QueryBIZ_Request param)
}
class BIZ_Controller {
    +handleCreateBIZ()
    +handleUpdateBIZ()
    +handleDeleteBIZ()
    +handleQueryBIZ()
}
BIZ_Service ..> BIZ_Dao: uses
BIZ_Controller ..> BIZ_Service: uses

两个模板中:

        TITLE_ 表示业务名称,

        BIZ_ 表示业务编码(即生成的视图层,业务层,数据层的统一命名空间)

python脚本如下:

import pandas as pd

sht_str = ("title TITLE_\n" +
           "participant 用户            as 1\n" +
           "participant BIZ_Controller  as 2\n" +
           "participant BIZ_Service     as 3\n" +
           "participant BIZ_Dao         as 4\n" +
           "1 -> 2: 创建TITLE_\n" +
           "2 -> 3: CreateBIZ_(CreateBIZ_RequestParam param)\n" +
           "3 -> 4: InsertBIZ_(BIZ_Dto dto)\n" +
           "4 --> 3: \n" +
           "3 --> 2: \n" +
           "2 --> 1:\n" +
           "1 -> 2: 创建TITLE_\n" +
           "2 -> 3: UpdateBIZ_(UpdateBIZ_RequestParam param)\n" +
           "3 -> 4: UpdateBIZ_(BIZ_Dto dto)\n" +
           "4 --> 3: \n" +
           "3 --> 2: \n" +
           "2 --> 1:\n" +
           "1 -> 2: 删除TITLE_\n" +
           "2 -> 3: DeleteBIZ_(DeleteBIZ_RequestParam param)\n" +
           "3 -> 4: DeleteBIZ_ById(String id)\n" +
           "4 --> 3: \n" +
           "3 --> 2: \n" +
           "2 --> 1:\n" +
           "1 -> 2: 查询TITLE_\n" +
           "2 -> 3: QueryBIZ_(QueryBIZ_RequestParam param)\n" +
           "3 -> 4: QueryBIZ_ByParam(QueryBIZ_ dto)\n" +
           "4 --> 3: \n" +
           "3 --> 2: \n" +
           "2 --> 1:\n"
           )
lt_str = (
        "abstract class BIZ_Dao {\n" +
        "    +String insertBIZ(BIZ_Dto dto)\n" +
        "    +void updateBIZ(BIZ_Dto dto)\n" +
        "    +void deleteBIZById(String id)\n" +
        "    +List<BIZ_Dto> queryBIZByParam(QueryBIZ_Dto dto)\n" +
        "}\n" +
        "class BIZ_Service {\n" +
        "    +createBIZ(CreateBIZ_Request param)\n" +
        "    +updateBIZ(UpdateBIZ_Request param)\n" +
        "    +deleteBIZ(DeleteBIZ_Request param)\n" +
        "    +queryBIZ(QueryBIZ_Request param)\n" +
        "}\n" +
        "class BIZ_Controller {\n" +
        "    +handleCreateBIZ()\n" +
        "    +handleUpdateBIZ()\n" +
        "    +handleDeleteBIZ()\n" +
        "    +handleQueryBIZ()\n" +
        "}\n" +
        "BIZ_Service ..> BIZ_Dao: uses\n" +
        "BIZ_Controller ..> BIZ_Service: uses\n"
)


def modify_row(row):
    TITLE_ = row['TITLE_']
    BIZ_ = row['BIZ_']
    if not BIZ_.strip():
        return (sht_str, lt_str)
    sht = sht_str.replace("TITLE_", TITLE_).replace("BIZ_", BIZ_).replace('"', '')
    lt = lt_str.replace("TITLE_", TITLE_).replace("BIZ_", BIZ_).replace('"', '')
    return sht, lt
    
# 读取Excel文件
df = pd.read_excel('tem_old.xlsx')
df[['时序图', '类图']] = df.apply(modify_row, axis=1, result_type='expand').apply(pd.Series)
df.to_excel('modified_file.xlsx', index=False)

        使用脚本读取脚本同一目录下的‘tem_old.xlsx’文件,读取excel文件信息,分别生成时序图和类图的代码。

其中:

sht_str 为上述时序图统一模板。

lt_str 为上述类图模板

modify_row() 方法,解析excle文件,'TITLE_' 列和'BIZ_'列,填充'时序图', '类图'两列。

脚本目录如下:

其中 tem_old.xlsx 中数据结构如下:

(第一列作为excel模板标题复制进去)

TITLE_

BIZ_

时序图

类图

计划类别

Category

计划

Plan

宣传计划

AdvocacyPlan

其中结果集 modified_file.xlsx中数据结构如下:

TITLE_

BIZ_

时序图

类图

计划类别

Category

title 计划类别
participant 用户 as 1
participant CategoryController as 2
participant CategoryService as 3
participant CategoryDao as 4
1 -> 2: 创建计划类别
2 -> 3: CreateCategory(CreateCategoryRequestParam param)
3 -> 4: InsertCategory(CategoryDto dto)
4 --> 3:
3 --> 2:
2 --> 1:
1 -> 2: 创建计划类别
2 -> 3: UpdateCategory(UpdateCategoryRequestParam param)
3 -> 4: UpdateCategory(CategoryDto dto)
4 --> 3:
3 --> 2:
2 --> 1:
1 -> 2: 删除计划类别
2 -> 3: DeleteCategory(DeleteCategoryRequestParam param)
3 -> 4: DeleteCategoryById(String id)
4 --> 3:
3 --> 2:
2 --> 1:
1 -> 2: 查询计划类别
2 -> 3: QueryCategory(QueryCategoryRequestParam param)
3 -> 4: QueryCategoryByParam(QueryCategory dto)
4 --> 3:
3 --> 2:
2 --> 1:

abstract class CategoryDao {
+String insertBIZ(CategoryDto dto)
+void updateBIZ(CategoryDto dto)
+void deleteBIZById(String id)
+List<CategoryDto> queryBIZByParam(QueryCategoryDto dto)
}
class CategoryService {
+createBIZ(CreateCategoryRequest param)
+updateBIZ(UpdateCategoryRequest param)
+deleteBIZ(DeleteCategoryRequest param)
+queryBIZ(QueryCategoryRequest param)
}
class CategoryController {
+handleCreateBIZ()
+handleUpdateBIZ()
+handleDeleteBIZ()
+handleQueryBIZ()
}
CategoryService ..> CategoryDao: uses
CategoryController ..> CategoryService: uses
 

示例: 根据【计划类别】这一行生成的时序图、类图。

时序图【WebSequenceDiagrams - Draw sequence diagrams online in seconds】:

类图【PlantUML Web Server】:

  • 23
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值