ZeusAutoCode code generation tool (open source)

ZeusAutoCode code generation tool

1. Introduction

Zeus code generator is an automatic code generation tool designed to quickly generate basic CRUD codes. On this basis, it also provides some advanced functions to achieve flexible configuration and generate scalable code.

The backend is implemented based on springboot, freemarker, mybatisplus

The front end adopts vue3, elementplus, electron technology

ZEUS official website

Client online download

Back-end Gitee warehouse address | Front-end Gitee warehouse address

Back-end GitHub warehouse address | Front-end GitHub warehouse address

Advantage

1. 项目结构可视化,文件树、文件图形化的模板编辑,操作模板更加直观、简洁。
2. 使用Freemarker作为模板引擎,模板中支持Freemarker所有语法,系统提供强大的内置字典。模板操作更加灵活。
3. Zeus可以作为作为mysql、oracle客户端,直接连接内网数据库。
4. 脚本管理。取代Jenkins,轻量化快速更新打包项目。网页查看项目日志等功能。
5. 方便团队开发项目,统一代码风格,规范化代码接口。

The client supports multiple openings. Multiple clients can be opened on the same computer. You can log in to the accounts of administrators and ordinary users separately, and administrators can modify the content of the template. Normal user generated code.

2. Quick use

  1. download apps

    Client online download

  2. The client has two users by default

    管理员 admin/admin
    普通用户 test/123456
    

    Log in to the administrator account, in the project management section, you can view the project, enter the project management to view the existing templates.
    Code generation is to dynamically generate code reversely from the database based on these templates

  3. Create a new configuration
    Log in to a common user account

    Create a new configuration information in the configuration management, see 6.2 Ordinary user new configuration for details

  4. generate code

    Select configuration in the code retrieval center, select the table to generate codes, and refer to 6.3 Ordinary User Generated Codes for details

  5. you're done

    Open the configuration management file path of our configuration, you will see the generated code

3. Role Description

administrator

团队技术leader,负责创建项目、组建项目人员、创建模板、管理用户、版本更新、脚本管理(更新打包)。

general user

普通开发人员,(前端后端都可以)通过配置中心配置项目路径和数据库地址。在取码中心快速生成代码、注入项目中

4. Description of shortcut keys

Shortcut keys are only valid on the client side

1. Switch background interface

Shortcut key CTRL I

The zeus code generator client can dynamically switch the background interface address of the request

2. Open the console

Shortcut keys CTRL ALT I

Zeus code generator client, you can open the browser console to view interface information

5. Function description

1. Project Management (Administrator)

  1. A project is a fundamental unit in zeus. It can be a front-end project or a back-end project.
  2. Code generation is based on the project, in addition to the project has its own name, description, public and other attributes. Also has the advanced function [data dictionary] (more flexible generation template).
  3. If the project is not a public project, you can form your own development team and join developers. Only developers can see the corresponding project.
  4. The project also includes space trees and templates. The space tree is the directory structure of the project, which has two forms of files and folders.
  5. The file corresponds to the template, and the corresponding code is generated according to the code in the template.

1. Project Description

Projects are defined by administrators and can be in any form, such as front-end projects or back-end projects. They have attributes such as project name, project description, public or not, and creation attributes. If it is a non-public project, you can create a team of personnel for the project, and designated personnel can see this project.

2. Data dictionary

The data dictionary is an advanced configuration of the template. Divided into built-in dictionaries and custom dictionaries

1. Built-in dictionary

The built-in dictionary is a built-in dictionary in the system. In the template, the user can directly use the dictionary value to obtain the corresponding data.

The data source of the built-in dictionary is the database connection configured by ordinary users in the configuration center, and then the table selected in the code retrieval center. (table name, description, field list)

Users can complete basic single-table CRUD operations by using the built-in dictionary in the template

Level 1 dictionary secondary dictionary Dictionary definition example
${table_name} null table name model_user
${tableDesc} null table description user table
${TableName} null Table name initial letter uppercase camel case ModelUser
${tableName} null Table name initial lowercase camel case modelUser
${FiledList} filed_name field name user_name
${FiledList} filedDesc field description user name
${FiledList} FILEDNAME Capitalize the first letter of the field name in camel case UserName
${FiledList} filedName The first letter of the field name is lowercase camel case userName
${FiledList} isKey Whether primary key Y/N
${FiledList} nullable Is it non-empty Y/N
${FiledList} filedLen field length (number) 20
${FiledList} scale precision (number) 2
${FiledList} defaultValue Defaults
${FiledList} realType real field type varchar
${FiledList} javaType Field type to JAVA type String
${FiledList} xmlType Field type to XML type VARCHAR

Built-in dictionary conversion rules

Field type to XML type rules Field type to JAVA type rules
varchar ==> VARCHAR varchar ==> String
char ==> VARCHAR double ==> Double
text ==> LONGVARCHAR char ==> String
tinyint ==> TINYINT text ==> String
bigint ==> BIGINT int ==> Integer
int ==> INTEGER tinyint ==> Integer
numeric ==> DOUBLE bigint ==> Long
decimal ==> FLOAT numeric ==> Double
date ==> DATE decimal ==> Float
datetime ==> TIMESTAMP date ==> Date
datetime ==> TIMESTAMP
2. Custom dictionary

Custom dictionaries are divided into three types: strings, arrays, and property lists.

Administrators can define a project's built-in dictionaries within a project. Use built-in dictionaries in templates. Similar to declaring a slot. Users can flexibly assign values ​​to slots when generating code. Dynamically generate the code you want.

Classification Function
string Declare a custom dictionary of string type, which is mainly used to pass fixed strings to templates. such as package name
array Declare an array dictionary, which is commonly used to control the addition, deletion, modification and query functions in the background, or the front-end, button display, addition, deletion, modification and query functions
property list The property list is a filter on the FiledList in the built-in dictionary. Can be used for front-end query conditions, list data, edit data dynamics

3. Spatial tree

The space tree is the directory structure of the project. The space tree is composed of files and folders. The files are Freemarker templates.

Users dynamically generate code with this directory structure into the project by building their own project space tree.

The root node of the space tree is the root directory of the project. Corresponds to the configuration in the background project project directory of ordinary users [Configuration Center].

1. Create a new space tree
  1. Select the root node of the project and right click to create a new file or folder.

  2. Then, click on the folder "right click" to modify the folder, or add folders and files under the folder

  3. Click on the file and fill in the corresponding template information on the right

  4. 填充好模板后,点击右上角提交代码按钮。即可保存模板

在这里插入图片描述

空间树目录要和实际项目目录保持一致

2. 空间树示例

在这里插入图片描述

2. 用户管理(管理员)

管理员可以通过用户管理功能创建系统用户

3. 版本更新(管理员)

管理员可以通过版本更新实现客户端的快速更新迭代

版本更新分为线上更新和线下更新两种模式。

实现方式:

通过判断当前版本的版本号(数据库存储)和客户端的版本号(package.json的version属性)是否一致,如果不一致,就拉取最新的版本,下载到本地。重启客户端,完成客户端升级

1. 线下更新

1. 修改前端代码中的package.json中的version属性。
2. 前端代码打包 yarn run package:prod
3. 通过对前端代码进行打包,找到D:\workspace\workspace-zeus\zeus-view\dist_electron\win-ia32-unpacked\resources\app.asar文件。对此文件进行压缩,压缩成zip包,
4. 在【版本更新】处新建一个版本,版本号和version的版本号一致。上传刚才压缩的zip包
5. 重启客户端,自动拉去最新版本,完成更新

2. 线上更新

1. 修改前端代码中的package.json中的version属性。
2. 提交代码到git上
3. 执行【脚本管理】的 ‘生成器前端打包’脚本
4. 在【版本更新】处新建一个版本,版本号和version的版本号一致。选择线上。url固定填 http://39.101.173.227/zeus/app.zip
5. 重启客户端,自动拉去最新版本,完成更新

3. 前端更新脚本示例

脚本文件 viewcode.sh

#!/bin/bash
#auth eric
#date 2021-07-14
#*********脚本入参#*********
appname=code
#Git源码位置
gitsrc=/home/egn/GitSpace/zeus-view
#Nginx位置
nginxsrc=/usr/local/nginx/html/zeus/
#*********脚本入参#*********
cd $gitsrc && git pull origin master && yarn run build:prod
mv -f $gitsrc/dist_electron/win-unpacked/resources/app.asar $nginxsrc
rm -rf $nginxsrc/*.zip
echo '删除历史包'
cd $nginxsrc
zip app.zip app.asar
echo '发布成功'

参考这个脚本,也可以做其他前端项目的自动打包

4. 后台更新脚本示例

脚本文件 code.sh

#!/bin/bash
#auth eric
#date 2021-07-14
#*********脚本入参#*********
appname=code
#Git源码位置
gitsrc=/home/egn/GitSpace/zeus-server
#Docker脚本位置
dockersrc=/home/egn/DockerBuilder/$appname
#*********脚本入参#*********
cd $gitsrc && git pull origin master && mvn install -DskipTests
if [ $? -eq 0 ]; 
then
    echo "maven build success "
else 
    echo -e '\033[31m[ error ] gradle build faild \033[0m' && exit 1
fi
\cp -f $gitsrc/target/*.jar $dockersrc
echo '第二步:查看是否有镜像'
cd $dockersrc
imageresult=$(docker images |grep  $appname | wc -l)
if [ $imageresult -eq 0 ]; 
then
  echo "不存在镜像,需要重新初始化鏡像";
  docker build -t $appname .
  docker run -d --name $appname -p 8003:8003 --restart always $appname
else
  conid=$(docker ps |grep  $appname |awk '{print $1}')
  docker cp *.jar $conid:/$appname.jar
  docker restart $conid
  if [ $? -eq 0 ]; 
  then
    echo "发布成功!"
  else 
    echo -e '\033[31m[ error ] 发布失败 \033[0m' && exit 1
  fi
fi

参考此脚本,同理可以做后台项目自动打包部署

5. 前后端脚本基础环境搭建

https://blog.csdn.net/qq_35921773/article/details/121694667

4. 脚本管理(管理员)

脚本管理核心是远程连接linux服务器,执行linux命令

用户可以通过该功能实现项目的远程打包、查看日志、服务重启……等操作

5. 网页库(管理员)

网页库是让用户快捷跳转项目常用网址的一个功能。管理员可以通过网页库新建该项目的所有网址,例如Gitlab、禅道、测试环境地址、原型地址……

6. 配置中心(普通用户)

普通用户在配置中心可以根据自己已有的项目,新建该项目的配置信息。

配置信息主要包含:选择项目、项目目录、配置名称、配置描述、数据库连接信息这些属性

用户可见的项目: 公开项目和私有项目用户在项目成员中
数据库连接信息: 客户端作为数据库连接工具,就像是Navicat一样获取当前数据的所有表。可以连接内网数据库
项目目录:生成的代码注入的目录。一般为项目根目录

7. 取码中心(普通用户)

注意:

使用zeus客户端生成代码会强制覆盖本地代码。所以在生成代码前,可以先通过配置详情功能选择要生成的文件

1. 操作步骤

  1. 选择用户在配置中心新建的配置数据
  2. 选择配置数据库加载而来的数据表
  3. 打开【配置详情】页面。可以动态勾选要生成的模板,以及动态填充自定义字典内容。
  4. 点击生成按钮,代码自动注入到 配置中心的用户自建的配置目录中

2. 高级配置

(前端待完善)

配置详情页面

数组类型字典,复选框勾选

属性列表型字典,表格复选框勾选

8. 网页库(普通用户)

用户通过管理员分配的网页库可见权限,点击网页直接打开浏览器跳转到对应的网址

六、使用手册

Tips: 客户端可以多开,可以同时打开两个客户端,一个登录管理员,一个登录普通用户。管理员实时编辑模板,普通用户实时生成代码。

1. 管理员新建项目

管理员可以通过新增按钮创建项目,也可以直接通过复制操作,完全拷贝一个项目

在这里插入图片描述

在项目中构建自己的空间树、和模板。详情参考功能说明中的空间树介绍

2. 普通用户新建配置

普通用户在【配置管理】菜单中,新建配置

  1. 选择项目
  2. 设置项目所在的本地目录
  3. 填写数据库连接信息
  4. 测试数据库连接
  5. 保存配置

在这里插入图片描述

3. 普通用户生成代码

  1. 用户打开【取码中心】功能
  2. 选择我们在配置中心新建的配置
  3. 选择根据配置信息加载的表
  4. 点击生成代码

在这里插入图片描述

4. 高级配置

在这里插入图片描述

5. 模板语法

主要参考已有模板,Freemarker的所有语法都支持。

这里列举下常见语法

  1. 遍历数组

    <#list FiledList as field>
    	private ${field.javaType} ${field.filedName};
    </#list>
    
  2. 字符串转数组

    <#assign function_list=FunctionList?split(",") >
    <#list function_list as function>
       <#if (function == 'findPage')>
       </#if>
    </#list>   
    
  3. 遍历数组获取下标

    <#list FiledList as column>
    	<#if (column_index>0)>
    	<#if (column.javaType== 'String')>
    		if(StringUtils.isNotEmpty(body.getParameter().get${FiledList[0].FILEDNAME}())) queryWrapper.like("${column.filed_name}", body.getParameter().get${FiledList[0].FILEDNAME}());
    	</#if>
    	<#if (column.javaType== 'Integer' || column.javaType== 'Double' || column.javaType== 'Float' || column.javaType== 'Long')>
    		if(body.getParameter().get${FiledList[0].FILEDNAME}() != null) queryWrapper.eq("${column.filed_name}", body.getParameter().get${FiledList[0].FILEDNAME}());
    	</#if>
    	</#if>
    </#list>
    

七、常见问题

1. 取码中心生成代码失败

通过管理员登录系统,进入脚本管理,运行查看代码生成器日志脚本,查看模板报错信息。

2. 取码中心生成无反应

  1. zeus客户端软件权限

    1. 桌面选择zeus客户端的logo
    2. 右键》属性》打开文件所在位置》找到zeus.exe 以管理员权限运行
    3. 桌面zeus快捷方式,右键》属性》高级》勾选 以管理员身份运行
    
  2. 切换【配置中心】代码。后台项目目录

    尽量不要选C盘的,C盘权限不足会导致代码无法注入。

  3. 查看日志排查问题

    接口问题排查

    在客户端使用快捷键CTRL ALT I 可以打开控制台,查看生成代码接口,是否返回正常,如果是接口错误,大概率是模板错误

    客户端问题排查

    1. 桌面选择zeus客户端的logo
    2. 右键》属性》打开文件所在位置
    3. 复制当前路径
    4. 使用管理员方式打开CMD,输入刚才输入的路径cd进去
    5. 执行zeus.exe
    6. 查看客户端日志
    

Guess you like

Origin blog.csdn.net/qq_35921773/article/details/129832612