Code reverse generation sequence diagram class diagram - Visual_Paradigm practice

Table of contents

foreword

1. Introduction to Visual_Paradigm

1. Introduction to the main interface

 2. Function introduction

2. Code-based sequence diagram generation

1. Create a new VP project

 2. Reverse generation of sequence diagram

Three, VP class diagram generation

1. Generate the main entrance

 4. Data ER model generation

1, SQL script

2. ER reverse generation

 Summarize


foreword

        I don't know if the R&D partners will encounter such a demand in their daily work. Due to some objective factors, our project has reached the end of the development stage, and project acceptance is required, but some design work at the beginning of the project has not yet been carried out, such as the sequence diagram, class diagram, and database model required in the detailed design stage. ER diagram and so on. At this point, of course we can choose to start from scratch, after all, it's just a UML diagram, right? It only needs to add some workload, as long as you give it time, it will definitely be realized, so the R&D students started some blah blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah. Another is based on existing results, such as code, are there any tools or methods that can reversely generate UML diagrams such as sequence diagrams and class diagrams based on code?

        This article will take you to solve this pain point, and recommend a UML shortcut generation software that can be used in daily work. To help you quickly generate documents, the blog will take the Java language as an example, focusing on how to perform retrospective sequence diagrams and class diagrams based on Visual_paradigm, and introduce the rapid construction of ER models based on SQL scripts. It not only provides a solution for the initial project design documents in the later stage of the project, but also helps junior programmers deeply understand the execution logic and call sequence of the code from the perspective of UML, which is an excellent way to read and understand the source code. If it is helpful to you, welcome to leave a message in the comment area for exchange. The writing is hasty, and at the same time limited by my experience, some of the opinions are inappropriate. Please criticize and correct.

1. Introduction to Visual_Paradigm

        Visual_Paradigm (VP for short) is an enterprise-level design tool that includes system modeling, diagramming, team collaboration, and many other functions. Based on Javadevelopment, open source, and cross-platform, it provides platform clients such as Windows, Linux, and so on. The background is very deep. The first version was released in 2002. It belongs to an old modeling brand. In the early stage, it only had modeling functions, but it has been continuously upgraded and updated in recent years. The positioning is not only limited. And also vigorously develop online drawing, drawing currently needs to go over the wall to access.MacVPUMLOnline

        This software is a commercial software, which can be tried directly for personal use. It has all the basic functions, but the advanced functions have a certain impact. Here, the Visual_Paradigm_CE_17_0_20230201_Win64.exe version is used.

1. Introduction to the main interface

        If you find that your software has expired during the program startup process, it doesn’t matter, just click the button in the red box in the picture below to continue using it, and friends who have enough money can also apply for payment.

 2. Function introduction

        In fact, we are not going to give a complete introduction to the functions of VP here. After installing the software, you can familiarize yourself with it and understand it through trial. Here is only a brief introduction, so that readers can have a simple understanding.

 

UX: Mainly used for user use design, such as mobile or PC page design, to help users better explain how to use the system, and can be compared with Axure. (You are welcome to inquire about the difference between UX and CX)

CX: Customer experience, or CX, covers a wider net and encompasses all interactions a customer has with every aspect of a business – including specific products within a brand or specific services they bring. In this way, CX can envelope the user experience. Several businesses hire CX designers to analyze and assess how customers feel about their brand as a whole and improve how customers interact with them. CX takes into account what customers think of an organization's advertising strategy, brand reputation, customer service, pricing, delivery methods, product availability, and the general sales process. You can find out more in this Getting Started Guide to Customer Experience (CX).

System Design: It mainly covers all aspects of UML, all graphics. For example, use case diagrams, class diagrams, sequence diagrams, state diagrams, activity diagrams, component diagrams, etc., the basic commonly used UML design diagrams are completed here.

Business Design: Mainly provide the design and implementation of main business flow charts.

Data Visualization: data visualization, here also provides various types of charts to achieve visual analysis of data. Can benchmark Echarts, DataV's data visualization products.

2. Code-based sequence diagram generation

        The sample code used here takes Ruoyi as an example, and the development language is mainly JAVA. Other programming languages ​​are not involved yet, but should be supported. About Ruoyi will not be described in detail here, there is a more detailed introduction on the open source website.

1. Create a new VP project

        In order to centrally manage the generated map information, we create a new project in the VP software. In the main interface of VP, click the project tab page, click the Add button, and the Add page will appear. After filling in the relevant information, the project creation is completed.

 After the information is entered, click Create Blank Project to complete. You can see the vp project directory in the directory tree on the left.

 2. Reverse generation of sequence diagram

        Use the program code function in the tool Tab page, select the last drop-down menu, Instant Reverse Java to Sequence Diagram.

 In the following interface, select the code directory where the sequence diagram needs to be generated. Taking Ruoyi as an example, the src.java directory is selected here

 After confirming, click Next to enter the method selection interface, select the method to be generated, and click Finish.

         After clicking Finish, you can see the following sequence diagram, isn't it very convenient?

 The following is the source code of edit, which is convenient for everyone to compare. The code of Controller is still simple. Let's take a look at the business logic code of Servcie.

/**
* 修改菜单
*/
@RequiresPermissions("system:menu:edit")
@GetMapping("/edit/{menuId}")
public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap)
{
     mmap.put("menu", menuService.selectMenuById(menuId));
     return prefix + "/edit";
}

/**
* 修改保存菜单信息
* 
* @param menu 菜单信息
* @return 结果
*/
@Override
public int updateMenu(Menu menu)
{
   menu.setUpdateBy(ShiroUtils.getLoginName());
   return menuMapper.updateMenu(menu);
}

Three, VP class diagram generation

        In fact, VP can not only realize the generation of sequence diagrams, but also support the generation of class diagrams. Also take Ruoyi's code as an example.

1. Generate the main entrance

        In the left menu of the VP project, select the directory to be generated. Here, the Menu package is generated as an example.

 Right-click the reverse engineering "menu" to add a class diagram to enter the generation interface.

 4. Data ER model generation

        In the process of program design, the ER model of relational database is also a very important model, and ER model modeling and expression are also required. How to generate models based on existing SQL statements? VP also provides such a rapid generation capability.

1, SQL script

        The SQL script here uses the demo SQL that comes with Ruoyi. The main script (section) looks like this:

- ----------------------------
-- 1、部门表
-- ----------------------------
drop table if exists sys_dept;
create table sys_dept (
  dept_id           bigint(20)      not null auto_increment    comment '部门id',
  parent_id         bigint(20)      default 0                  comment '父部门id',
  ancestors         varchar(50)     default ''                 comment '祖级列表',
  dept_name         varchar(30)     default ''                 comment '部门名称',
  order_num         int(4)          default 0                  comment '显示顺序',
  leader            varchar(20)     default null               comment '负责人',
  phone             varchar(11)     default null               comment '联系电话',
  email             varchar(50)     default null               comment '邮箱',
  status            char(1)         default '0'                comment '部门状态(0正常 1停用)',
  del_flag          char(1)         default '0'                comment '删除标志(0代表存在 2代表删除)',
  create_by         varchar(64)     default ''                 comment '创建者',
  create_time 	    datetime                                   comment '创建时间',
  update_by         varchar(64)     default ''                 comment '更新者',
  update_time       datetime                                   comment '更新时间',
  primary key (dept_id)
) engine=innodb auto_increment=200 comment = '部门表';

-- ----------------------------
-- 初始化-部门表数据
-- ----------------------------
insert into sys_dept values(100,  0,   '0',          '若依科技',   0, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(101,  100, '0,100',      '深圳总公司', 1, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(102,  100, '0,100',      '长沙分公司', 2, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(103,  101, '0,100,101',  '研发部门',   1, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(104,  101, '0,100,101',  '市场部门',   2, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(105,  101, '0,100,101',  '测试部门',   3, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(106,  101, '0,100,101',  '财务部门',   4, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(107,  101, '0,100,101',  '运维部门',   5, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(108,  102, '0,100,102',  '市场部门',   1, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);
insert into sys_dept values(109,  102, '0,100,102',  '财务部门',   2, '若依', '15888888888', '[email protected]', '0', '0', 'admin', sysdate(), '', null);


-- ----------------------------
-- 2、用户信息表
-- ----------------------------
drop table if exists sys_user;
create table sys_user (
  user_id           bigint(20)      not null auto_increment    comment '用户ID',
  dept_id           bigint(20)      default null               comment '部门ID',
  login_name        varchar(30)     not null                   comment '登录账号',
  user_name         varchar(30)     default ''                 comment '用户昵称',
  user_type         varchar(2)      default '00'               comment '用户类型(00系统用户 01注册用户)',
  email             varchar(50)     default ''                 comment '用户邮箱',
  phonenumber       varchar(11)     default ''                 comment '手机号码',
  sex               char(1)         default '0'                comment '用户性别(0男 1女 2未知)',
  avatar            varchar(100)    default ''                 comment '头像路径',
  password          varchar(50)     default ''                 comment '密码',
  salt              varchar(20)     default ''                 comment '盐加密',
  status            char(1)         default '0'                comment '帐号状态(0正常 1停用)',
  del_flag          char(1)         default '0'                comment '删除标志(0代表存在 2代表删除)',
  login_ip          varchar(128)    default ''                 comment '最后登录IP',
  login_date        datetime                                   comment '最后登录时间',
  pwd_update_date   datetime                                   comment '密码最后更新时间',
  create_by         varchar(64)     default ''                 comment '创建者',
  create_time       datetime                                   comment '创建时间',
  update_by         varchar(64)     default ''                 comment '更新者',
  update_time       datetime                                   comment '更新时间',
  remark            varchar(500)    default null               comment '备注',
  primary key (user_id)
) engine=innodb auto_increment=100 comment = '用户信息表';

2. ER reverse generation

        On the Tab page, select DB, DDL reverse engineering drop-down menu.

         After selecting the sql to be generated, you need to pay attention to setting the database version and encoding information, especially the encoding information. If the encoding setting is incorrect, the model may not be generated or there may be garbled characters.

 

        After clicking the OK button, the ER model of the entire database will be generated on the main page, isn't it very convenient?

 Summarize

        The above is the main content of this article. This article mainly explains in detail a UML quick generation software tool to help the rapid generation of documents. Taking Java language as an example, it focuses on how to perform retrospective sequence diagrams and class diagrams based on Visual_paradigm and ER models based on SQL scripts. An introduction to quick builds.

Guess you like

Origin blog.csdn.net/yelangkingwuzuhu/article/details/132187163