├── .gitignore ├── README.md ├── yuzi-generator-basic ├── .gitignore ├── generator ├── generator.bat ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── yupi │ │ │ ├── Main.java │ │ │ ├── cli │ │ │ ├── CommandExecutor.java │ │ │ ├── command │ │ │ │ ├── ConfigCommand.java │ │ │ │ ├── GenerateCommand.java │ │ │ │ └── ListCommand.java │ │ │ ├── example │ │ │ │ ├── ASCIIArt.java │ │ │ │ ├── Login.java │ │ │ │ └── SubCommandExample.java │ │ │ └── pattern │ │ │ │ ├── Client.java │ │ │ │ ├── Command.java │ │ │ │ ├── Device.java │ │ │ │ ├── RemoteControl.java │ │ │ │ ├── TurnOffCommand.java │ │ │ │ └── TurnOnCommand.java │ │ │ ├── generator │ │ │ ├── DynamicGenerator.java │ │ │ ├── MainGenerator.java │ │ │ └── StaticGenerator.java │ │ │ └── model │ │ │ └── MainTemplateConfig.java │ └── resources │ │ └── templates │ │ ├── MainTemplate.java.ftl │ │ └── myweb.html.ftl │ └── test │ └── java │ └── FreeMarkerTest.java ├── yuzi-generator-demo-projects ├── acm-template-pro │ ├── .gitignore │ ├── README.md │ └── src │ │ └── com │ │ └── yupi │ │ └── acm │ │ ├── MainTemplate.java │ │ └── MainTemplate.java.ftl ├── acm-template │ ├── .gitignore │ ├── README.md │ └── src │ │ └── com │ │ └── yupi │ │ └── acm │ │ └── MainTemplate.java └── springboot-init │ ├── .gitignore │ ├── Dockerfile │ ├── README.md │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── yupi │ │ └── springbootinit │ │ ├── MainApplication.java │ │ ├── common │ │ ├── BaseResponse.java │ │ ├── DeleteRequest.java │ │ ├── ErrorCode.java │ │ ├── PageRequest.java │ │ └── ResultUtils.java │ │ ├── config │ │ ├── CorsConfig.java │ │ ├── JsonConfig.java │ │ ├── Knife4jConfig.java │ │ └── MyBatisPlusConfig.java │ │ ├── constant │ │ └── UserConstant.java │ │ ├── controller │ │ ├── PostController.java │ │ └── UserController.java │ │ ├── exception │ │ ├── BusinessException.java │ │ ├── GlobalExceptionHandler.java │ │ └── ThrowUtils.java │ │ ├── mapper │ │ ├── PostMapper.java │ │ └── UserMapper.java │ │ ├── model │ │ ├── dto │ │ │ ├── post │ │ │ │ ├── PostAddRequest.java │ │ │ │ ├── PostEsDTO.java │ │ │ │ ├── PostQueryRequest.java │ │ │ │ └── PostUpdateRequest.java │ │ │ └── user │ │ │ │ ├── UserAddRequest.java │ │ │ │ ├── UserLoginRequest.java │ │ │ │ ├── UserQueryRequest.java │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ └── UserUpdateRequest.java │ │ ├── entity │ │ │ ├── Post.java │ │ │ └── User.java │ │ └── enums │ │ │ └── UserRoleEnum.java │ │ └── service │ │ ├── PostService.java │ │ ├── UserService.java │ │ └── impl │ │ ├── PostServiceImpl.java │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mapper │ ├── PostMapper.xml │ └── UserMapper.xml ├── yuzi-generator-maker ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── yupi │ │ │ └── maker │ │ │ ├── Main.java │ │ │ ├── generator │ │ │ ├── JarGenerator.java │ │ │ ├── ScriptGenerator.java │ │ │ ├── file │ │ │ │ ├── DynamicFileGenerator.java │ │ │ │ ├── FileGenerator.java │ │ │ │ └── StaticFileGenerator.java │ │ │ └── main │ │ │ │ ├── GenerateTemplate.java │ │ │ │ ├── MainGenerator.java │ │ │ │ └── ZipGenerator.java │ │ │ ├── meta │ │ │ ├── Meta.java │ │ │ ├── MetaException.java │ │ │ ├── MetaManager.java │ │ │ ├── MetaValidator.java │ │ │ └── enums │ │ │ │ ├── FileGenerateTypeEnum.java │ │ │ │ ├── FileTypeEnum.java │ │ │ │ └── ModelTypeEnum.java │ │ │ └── template │ │ │ ├── FileFilter.java │ │ │ ├── TemplateMaker.java │ │ │ ├── TemplateMakerUtils.java │ │ │ ├── enums │ │ │ ├── FileFilterRangeEnum.java │ │ │ └── FileFilterRuleEnum.java │ │ │ └── model │ │ │ ├── FileFilterConfig.java │ │ │ ├── TemplateMakerConfig.java │ │ │ ├── TemplateMakerFileConfig.java │ │ │ ├── TemplateMakerModelConfig.java │ │ │ └── TemplateMakerOutputConfig.java │ └── resources │ │ ├── examples │ │ └── springboot-init │ │ │ ├── templateMaker.json │ │ │ ├── templateMaker1.json │ │ │ ├── templateMaker2.json │ │ │ ├── templateMaker3.json │ │ │ ├── templateMaker4.json │ │ │ ├── templateMaker5.json │ │ │ ├── templateMaker6.json │ │ │ ├── templateMaker7.json │ │ │ └── templateMaker8.json │ │ ├── meta.json │ │ ├── springboot-init-meta.json │ │ └── templates │ │ ├── README.md.ftl │ │ ├── java │ │ ├── Main.java.ftl │ │ ├── cli │ │ │ ├── CommandExecutor.java.ftl │ │ │ └── command │ │ │ │ ├── ConfigCommand.java.ftl │ │ │ │ ├── GenerateCommand.java.ftl │ │ │ │ ├── JsonGenerateCommand.java.ftl │ │ │ │ └── ListCommand.java.ftl │ │ ├── generator │ │ │ ├── DynamicGenerator.java.ftl │ │ │ ├── MainGenerator.java.ftl │ │ │ └── StaticGenerator.java.ftl │ │ └── model │ │ │ └── DataModel.java.ftl │ │ └── pom.xml.ftl │ └── test │ └── java │ └── com │ └── yupi │ └── maker │ └── template │ └── TemplateMakerTest.java ├── yuzi-generator-web-backend ├── .gitignore ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── Dockerfile ├── README.md ├── doc │ └── swagger.png ├── mvnw ├── mvnw.cmd ├── pom.xml ├── sql │ └── create_table.sql └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── yupi │ │ │ └── web │ │ │ ├── MainApplication.java │ │ │ ├── annotation │ │ │ └── AuthCheck.java │ │ │ ├── aop │ │ │ ├── AuthInterceptor.java │ │ │ └── LogInterceptor.java │ │ │ ├── common │ │ │ ├── BaseResponse.java │ │ │ ├── DeleteRequest.java │ │ │ ├── ErrorCode.java │ │ │ ├── PageRequest.java │ │ │ └── ResultUtils.java │ │ │ ├── config │ │ │ ├── CorsConfig.java │ │ │ ├── CosClientConfig.java │ │ │ ├── JsonConfig.java │ │ │ ├── MyBatisPlusConfig.java │ │ │ └── XxlJobConfig.java │ │ │ ├── constant │ │ │ ├── CommonConstant.java │ │ │ ├── FileConstant.java │ │ │ └── UserConstant.java │ │ │ ├── controller │ │ │ ├── FileController.java │ │ │ ├── GeneratorController.java │ │ │ ├── HealthController.java │ │ │ └── UserController.java │ │ │ ├── exception │ │ │ ├── BusinessException.java │ │ │ ├── GlobalExceptionHandler.java │ │ │ └── ThrowUtils.java │ │ │ ├── job │ │ │ └── ClearCosJobHandler.java │ │ │ ├── manager │ │ │ ├── CacheManager.java │ │ │ └── CosManager.java │ │ │ ├── mapper │ │ │ ├── GeneratorMapper.java │ │ │ └── UserMapper.java │ │ │ ├── model │ │ │ ├── dto │ │ │ │ ├── file │ │ │ │ │ └── UploadFileRequest.java │ │ │ │ ├── generator │ │ │ │ │ ├── GeneratorAddRequest.java │ │ │ │ │ ├── GeneratorCacheRequest.java │ │ │ │ │ ├── GeneratorEditRequest.java │ │ │ │ │ ├── GeneratorMakeRequest.java │ │ │ │ │ ├── GeneratorQueryRequest.java │ │ │ │ │ ├── GeneratorUpdateRequest.java │ │ │ │ │ └── GeneratorUseRequest.java │ │ │ │ └── user │ │ │ │ │ ├── UserAddRequest.java │ │ │ │ │ ├── UserLoginRequest.java │ │ │ │ │ ├── UserQueryRequest.java │ │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ │ ├── UserUpdateMyRequest.java │ │ │ │ │ └── UserUpdateRequest.java │ │ │ ├── entity │ │ │ │ ├── Generator.java │ │ │ │ └── User.java │ │ │ ├── enums │ │ │ │ ├── FileUploadBizEnum.java │ │ │ │ └── UserRoleEnum.java │ │ │ └── vo │ │ │ │ ├── GeneratorVO.java │ │ │ │ ├── LoginUserVO.java │ │ │ │ └── UserVO.java │ │ │ ├── service │ │ │ ├── GeneratorService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ ├── GeneratorServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ │ ├── utils │ │ │ ├── SpringContextUtils.java │ │ │ └── SqlUtils.java │ │ │ └── vertx │ │ │ ├── MainVerticle.java │ │ │ └── VertxManager.java │ └── resources │ │ ├── META-INF │ │ └── additional-spring-configuration-metadata.json │ │ ├── application-prod.yml │ │ ├── application.yml │ │ ├── banner.txt │ │ └── mapper │ │ ├── GeneratorMapper.xml │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── yupi │ └── web │ ├── job │ └── ClearCosJobHandlerTest.java │ ├── manager │ └── CosManagerTest.java │ └── service │ └── GeneratorServiceTest.java └── yuzi-generator-web-frontend ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .prettierignore ├── .prettierrc.js ├── README.md ├── config ├── config.ts ├── defaultSettings.ts ├── proxy.ts └── routes.ts ├── jsconfig.json ├── package.json ├── pnpm-lock.yaml ├── public ├── favicon.ico ├── logo.png ├── pro_icon.svg └── scripts │ └── loading.js ├── src ├── access.ts ├── app.tsx ├── assets │ └── logo.png ├── components │ ├── FileUploader │ │ └── index.tsx │ ├── Footer │ │ └── index.tsx │ ├── HeaderDropdown │ │ └── index.tsx │ ├── PictureUploader │ │ └── index.tsx │ └── RightContent │ │ └── AvatarDropdown.tsx ├── constants │ └── index.ts ├── global.less ├── global.tsx ├── pages │ ├── 404.tsx │ ├── Admin.tsx │ ├── Admin │ │ ├── Generator │ │ │ ├── components │ │ │ │ ├── CreateModal.tsx │ │ │ │ └── UpdateModal.tsx │ │ │ └── index.tsx │ │ └── User │ │ │ ├── components │ │ │ ├── CreateModal.tsx │ │ │ └── UpdateModal.tsx │ │ │ └── index.tsx │ ├── Generator │ │ ├── Add │ │ │ ├── components │ │ │ │ ├── FileConfigForm.tsx │ │ │ │ ├── GeneratorMaker.tsx │ │ │ │ └── ModelConfigForm.tsx │ │ │ └── index.tsx │ │ ├── Detail │ │ │ ├── components │ │ │ │ ├── AuthorInfo.tsx │ │ │ │ ├── FileConfig.tsx │ │ │ │ └── ModelConfig.tsx │ │ │ └── index.tsx │ │ └── Use │ │ │ └── index.tsx │ ├── Index │ │ └── index.tsx │ ├── Test │ │ └── File │ │ │ └── index.tsx │ └── User │ │ ├── Login │ │ └── index.tsx │ │ └── Register │ │ └── index.tsx ├── requestConfig.ts ├── service-worker.js ├── services │ └── backend │ │ ├── fileController.ts │ │ ├── generatorController.ts │ │ ├── index.ts │ │ ├── typings.d.ts │ │ └── userController.ts └── typings.d.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # My Custom 2 | 3 | generated 4 | .idea 5 | .temp 6 | application-local.yml 7 | target 8 | yuzi-generator.iml 9 | 10 | ### Java template 11 | # Compiled class file 12 | *.class 13 | 14 | # Log file 15 | *.log 16 | 17 | # BlueJ files 18 | *.ctxt 19 | 20 | # Mobile Tools for Java (J2ME) 21 | .mtj.tmp/ 22 | 23 | # Package Files # 24 | *.jar 25 | *.war 26 | *.nar 27 | *.ear 28 | *.zip 29 | *.tar.gz 30 | *.rar 31 | 32 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 33 | hs_err_pid* 34 | replay_pid* 35 | 36 | ### JetBrains template 37 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 38 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 39 | 40 | # User-specific stuff 41 | .idea/**/workspace.xml 42 | .idea/**/tasks.xml 43 | .idea/**/usage.statistics.xml 44 | .idea/**/dictionaries 45 | .idea/**/shelf 46 | 47 | # AWS User-specific 48 | .idea/**/aws.xml 49 | 50 | # Generated files 51 | .idea/**/contentModel.xml 52 | 53 | # Sensitive or high-churn files 54 | .idea/**/dataSources/ 55 | .idea/**/dataSources.ids 56 | .idea/**/dataSources.local.xml 57 | .idea/**/sqlDataSources.xml 58 | .idea/**/dynamic.xml 59 | .idea/**/uiDesigner.xml 60 | .idea/**/dbnavigator.xml 61 | 62 | # Gradle 63 | .idea/**/gradle.xml 64 | .idea/**/libraries 65 | 66 | # Gradle and Maven with auto-import 67 | # When using Gradle or Maven with auto-import, you should exclude module files, 68 | # since they will be recreated, and may cause churn. Uncomment if using 69 | # auto-import. 70 | # .idea/artifacts 71 | # .idea/compiler.xml 72 | # .idea/jarRepositories.xml 73 | # .idea/modules.xml 74 | # .idea/*.iml 75 | # .idea/modules 76 | # *.iml 77 | # *.ipr 78 | 79 | # CMake 80 | cmake-build-*/ 81 | 82 | # Mongo Explorer plugin 83 | .idea/**/mongoSettings.xml 84 | 85 | # File-based project format 86 | *.iws 87 | 88 | # IntelliJ 89 | out/ 90 | 91 | # mpeltonen/sbt-idea plugin 92 | .idea_modules/ 93 | 94 | # JIRA plugin 95 | atlassian-ide-plugin.xml 96 | 97 | # Cursive Clojure plugin 98 | .idea/replstate.xml 99 | 100 | # SonarLint plugin 101 | .idea/sonarlint/ 102 | 103 | # Crashlytics plugin (for Android Studio and IntelliJ) 104 | com_crashlytics_export_strings.xml 105 | crashlytics.properties 106 | crashlytics-build.properties 107 | fabric.properties 108 | 109 | # Editor-based Rest Client 110 | .idea/httpRequests 111 | 112 | # Android studio 3.1+ serialized cache file 113 | .idea/caches/build_file_checksums.ser 114 | 115 | -------------------------------------------------------------------------------- /yuzi-generator-basic/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /yuzi-generator-basic/generator: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | java -jar target/yuzi-generator-basic-1.0-SNAPSHOT-jar-with-dependencies.jar "$@" -------------------------------------------------------------------------------- /yuzi-generator-basic/generator.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | java -jar target/yuzi-generator-1.0-SNAPSHOT-jar-with-dependencies.jar %* -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/Main.java: -------------------------------------------------------------------------------- 1 | package com.yupi; 2 | 3 | import com.yupi.cli.CommandExecutor; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | // args = new String[]{"generate", "-l", "-a", "-o"}; 9 | // args = new String[]{"config"}; 10 | // args = new String[]{"list"}; 11 | CommandExecutor commandExecutor = new CommandExecutor(); 12 | commandExecutor.doExecute(args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/CommandExecutor.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli; 2 | 3 | import com.yupi.cli.command.GenerateCommand; 4 | import com.yupi.cli.command.ListCommand; 5 | import com.yupi.cli.command.ConfigCommand; 6 | import picocli.CommandLine; 7 | import picocli.CommandLine.Command; 8 | 9 | /** 10 | * 命令执行器 11 | */ 12 | @Command(name = "yuzi", mixinStandardHelpOptions = true) 13 | public class CommandExecutor implements Runnable { 14 | 15 | private final CommandLine commandLine; 16 | 17 | { 18 | commandLine = new CommandLine(this) 19 | .addSubcommand(new GenerateCommand()) 20 | .addSubcommand(new ConfigCommand()) 21 | .addSubcommand(new ListCommand()); 22 | } 23 | 24 | @Override 25 | public void run() { 26 | // 不输入子命令时,给出友好提示 27 | System.out.println("请输入具体命令,或者输入 --help 查看命令提示"); 28 | } 29 | 30 | /** 31 | * 执行命令 32 | * 33 | * @param args 34 | * @return 35 | */ 36 | public Integer doExecute(String[] args) { 37 | return commandLine.execute(args); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/command/ConfigCommand.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.command; 2 | 3 | import cn.hutool.core.util.ReflectUtil; 4 | import com.yupi.model.MainTemplateConfig; 5 | import picocli.CommandLine.Command; 6 | 7 | import java.lang.reflect.Field; 8 | import java.util.Map; 9 | 10 | @Command(name = "config", description = "查看参数信息", mixinStandardHelpOptions = true) 11 | public class ConfigCommand implements Runnable { 12 | 13 | public void run() { 14 | // 实现 config 命令的逻辑 15 | System.out.println("查看参数信息"); 16 | 17 | // // 获取要打印属性信息的类 18 | // Class myClass = MainTemplateConfig.class; 19 | // // 获取类的所有字段 20 | // Field[] fields = myClass.getDeclaredFields(); 21 | 22 | Field[] fields = ReflectUtil.getFields(MainTemplateConfig.class); 23 | 24 | // 遍历并打印每个字段的信息 25 | for (Field field : fields) { 26 | System.out.println("字段名称:" + field.getName()); 27 | System.out.println("字段类型:" + field.getType()); 28 | // System.out.println("Modifiers: " + java.lang.reflect.Modifier.toString(field.getModifiers())); 29 | System.out.println("---"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/command/GenerateCommand.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.command; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import com.yupi.generator.MainGenerator; 5 | import com.yupi.model.MainTemplateConfig; 6 | import lombok.Data; 7 | import picocli.CommandLine.Command; 8 | import picocli.CommandLine.Option; 9 | 10 | import java.util.concurrent.Callable; 11 | 12 | @Command(name = "generate", description = "生成代码", mixinStandardHelpOptions = true) 13 | @Data 14 | public class GenerateCommand implements Callable { 15 | 16 | @Option(names = {"-l", "--loop"}, arity = "0..1", description = "是否循环", interactive = true, echo = true) 17 | private boolean loop; 18 | 19 | @Option(names = {"-a", "--author"}, arity = "0..1", description = "作者", interactive = true, echo = true) 20 | private String author = "yupi"; 21 | 22 | @Option(names = {"-o", "--outputText"}, arity = "0..1", description = "输出文本", interactive = true, echo = true) 23 | private String outputText = "sum = "; 24 | 25 | public Integer call() throws Exception { 26 | MainTemplateConfig mainTemplateConfig = new MainTemplateConfig(); 27 | BeanUtil.copyProperties(this, mainTemplateConfig); 28 | System.out.println("配置信息:" + mainTemplateConfig); 29 | MainGenerator.doGenerate(mainTemplateConfig); 30 | return 0; 31 | } 32 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/command/ListCommand.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.command; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | import picocli.CommandLine.Command; 5 | 6 | import java.io.File; 7 | import java.util.List; 8 | 9 | @Command(name = "list", description = "查看文件列表", mixinStandardHelpOptions = true) 10 | public class ListCommand implements Runnable { 11 | 12 | public void run() { 13 | String projectPath = System.getProperty("user.dir"); 14 | // 整个项目的根路径 15 | File parentFile = new File(projectPath).getParentFile(); 16 | // 输入路径 17 | String inputPath = new File(parentFile, "yuzi-generator-demo-projects/acm-template").getAbsolutePath(); 18 | List files = FileUtil.loopFiles(inputPath); 19 | for (File file : files) { 20 | System.out.println(file); 21 | } 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/example/ASCIIArt.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.example; 2 | 3 | import picocli.CommandLine; 4 | import picocli.CommandLine.Command; 5 | import picocli.CommandLine.Option; 6 | import picocli.CommandLine.Parameters; 7 | 8 | @Command(name = "ASCIIArt", version = "ASCIIArt 1.0", mixinStandardHelpOptions = true) 9 | public class ASCIIArt implements Runnable { 10 | 11 | @Option(names = { "-s", "--font-size" }, description = "Font size") 12 | int fontSize = 19; 13 | 14 | @Parameters(paramLabel = "", defaultValue = "Hello, picocli", 15 | description = "Words to be translated into ASCII art.") 16 | private String[] words = { "Hello,", "picocli" }; 17 | 18 | @Override 19 | public void run() { 20 | // 自己实现业务逻辑 21 | System.out.println("fontSize = " + fontSize); 22 | System.out.println("words = " + String.join(",", words)); 23 | } 24 | 25 | public static void main(String[] args) { 26 | int exitCode = new CommandLine(new ASCIIArt()).execute(args); 27 | System.exit(exitCode); 28 | } 29 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/example/Login.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.example; 2 | 3 | import picocli.CommandLine; 4 | import picocli.CommandLine.Option; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | public class Login implements Callable { 9 | @Option(names = {"-u", "--user"}, description = "User name") 10 | String user; 11 | 12 | // 设置了 arity 参数,可选交互式 13 | @Option(names = {"-p", "--password"}, arity = "0..1", description = "Passphrase", interactive = true) 14 | String password; 15 | 16 | // 设置了 arity 参数,可选交互式 17 | @Option(names = {"-cp", "--checkPassword"}, arity = "0..1", description = "Check Password", interactive = true) 18 | String checkPassword; 19 | 20 | public Integer call() throws Exception { 21 | System.out.println("password = " + password); 22 | System.out.println("checkPassword = " + checkPassword); 23 | return 0; 24 | } 25 | 26 | public static void main(String[] args) { 27 | new CommandLine(new Login()).execute("-u", "user123", "-p", "123", "-cp", "456"); 28 | } 29 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/example/SubCommandExample.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.example; 2 | 3 | import picocli.CommandLine; 4 | import picocli.CommandLine.Command; 5 | 6 | @Command(name = "main", mixinStandardHelpOptions = true) 7 | public class SubCommandExample implements Runnable { 8 | 9 | @Override 10 | public void run() { 11 | System.out.println("执行主命令"); 12 | } 13 | 14 | @Command(name = "add", description = "增加", mixinStandardHelpOptions = true) 15 | static class AddCommand implements Runnable { 16 | public void run() { 17 | System.out.println("执行增加命令"); 18 | } 19 | } 20 | 21 | @Command(name = "delete", description = "删除", mixinStandardHelpOptions = true) 22 | static class DeleteCommand implements Runnable { 23 | public void run() { 24 | System.out.println("执行删除命令"); 25 | } 26 | } 27 | 28 | @Command(name = "query", description = "查询", mixinStandardHelpOptions = true) 29 | static class QueryCommand implements Runnable { 30 | public void run() { 31 | System.out.println("执行查询命令"); 32 | } 33 | } 34 | 35 | public static void main(String[] args) { 36 | // 执行主命令 37 | String[] myArgs = new String[] { }; 38 | // 查看主命令的帮助手册 39 | // String[] myArgs = new String[] { "--help" }; 40 | // 执行增加命令 41 | // String[] myArgs = new String[] { "add" }; 42 | // 执行增加命令的帮助手册 43 | // String[] myArgs = new String[] { "add", "--help" }; 44 | // 执行不存在的命令,会报错 45 | // String[] myArgs = new String[] { "update" }; 46 | int exitCode = new CommandLine(new SubCommandExample()) 47 | .addSubcommand(new AddCommand()) 48 | .addSubcommand(new DeleteCommand()) 49 | .addSubcommand(new QueryCommand()) 50 | .execute(myArgs); 51 | System.exit(exitCode); 52 | } 53 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/pattern/Client.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.pattern; 2 | 3 | public class Client { 4 | public static void main(String[] args) { 5 | // 创建接收者对象 6 | Device tv = new Device("TV"); 7 | Device stereo = new Device("Stereo"); 8 | 9 | // 创建具体命令对象,可以绑定不同设备 10 | TurnOnCommand turnOn = new TurnOnCommand(tv); 11 | TurnOffCommand turnOff = new TurnOffCommand(stereo); 12 | 13 | // 创建调用者 14 | RemoteControl remote = new RemoteControl(); 15 | 16 | // 执行命令 17 | remote.setCommand(turnOn); 18 | remote.pressButton(); 19 | 20 | remote.setCommand(turnOff); 21 | remote.pressButton(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/pattern/Command.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.pattern; 2 | 3 | public interface Command { 4 | void execute(); 5 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/pattern/Device.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.pattern; 2 | 3 | public class Device { 4 | private String name; 5 | 6 | public Device(String name) { 7 | this.name = name; 8 | } 9 | 10 | public void turnOn() { 11 | System.out.println(name + " 设备打开"); 12 | } 13 | 14 | public void turnOff() { 15 | System.out.println(name + " 设备关闭"); 16 | } 17 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/pattern/RemoteControl.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.pattern; 2 | 3 | public class RemoteControl { 4 | private Command command; 5 | 6 | public void setCommand(Command command) { 7 | this.command = command; 8 | } 9 | 10 | public void pressButton() { 11 | command.execute(); 12 | } 13 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/pattern/TurnOffCommand.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.pattern; 2 | 3 | public class TurnOffCommand implements Command { 4 | private Device device; 5 | 6 | public TurnOffCommand(Device device) { 7 | this.device = device; 8 | } 9 | 10 | public void execute() { 11 | device.turnOff(); 12 | } 13 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/cli/pattern/TurnOnCommand.java: -------------------------------------------------------------------------------- 1 | package com.yupi.cli.pattern; 2 | 3 | public class TurnOnCommand implements Command { 4 | private Device device; 5 | 6 | public TurnOnCommand(Device device) { 7 | this.device = device; 8 | } 9 | 10 | public void execute() { 11 | device.turnOn(); 12 | } 13 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/generator/DynamicGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.generator; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | import com.yupi.model.MainTemplateConfig; 5 | import freemarker.template.Configuration; 6 | import freemarker.template.Template; 7 | import freemarker.template.TemplateException; 8 | 9 | import java.io.File; 10 | import java.io.FileWriter; 11 | import java.io.IOException; 12 | import java.io.Writer; 13 | 14 | /** 15 | * 动态文件生成 16 | */ 17 | public class DynamicGenerator { 18 | 19 | public static void main(String[] args) throws IOException, TemplateException { 20 | String projectPath = System.getProperty("user.dir"); 21 | String inputPath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl"; 22 | String outputPath = projectPath + File.separator + "MainTemplate.java"; 23 | MainTemplateConfig mainTemplateConfig = new MainTemplateConfig(); 24 | mainTemplateConfig.setAuthor("yupi"); 25 | mainTemplateConfig.setLoop(false); 26 | mainTemplateConfig.setOutputText("求和结果:"); 27 | doGenerate(inputPath, outputPath, mainTemplateConfig); 28 | } 29 | 30 | /** 31 | * 生成文件 32 | * 33 | * @param inputPath 模板文件输入路径 34 | * @param outputPath 输出路径 35 | * @param model 数据模型 36 | * @throws IOException 37 | * @throws TemplateException 38 | */ 39 | public static void doGenerate(String inputPath, String outputPath, Object model) throws IOException, TemplateException { 40 | // new 出 Configuration 对象,参数为 FreeMarker 版本号 41 | Configuration configuration = new Configuration(Configuration.VERSION_2_3_32); 42 | 43 | // 指定模板文件所在的路径 44 | File templateDir = new File(inputPath).getParentFile(); 45 | configuration.setDirectoryForTemplateLoading(templateDir); 46 | 47 | // 设置模板文件使用的字符集 48 | configuration.setDefaultEncoding("utf-8"); 49 | 50 | // 创建模板对象,加载指定模板 51 | String templateName = new File(inputPath).getName(); 52 | Template template = configuration.getTemplate(templateName); 53 | 54 | // 创建数据模型 55 | MainTemplateConfig mainTemplateConfig = new MainTemplateConfig(); 56 | mainTemplateConfig.setAuthor("yupi"); 57 | mainTemplateConfig.setLoop(false); 58 | mainTemplateConfig.setOutputText("求和结果:"); 59 | 60 | 61 | // 文件不存在则创建文件和父目录 62 | if (!FileUtil.exist(outputPath)) { 63 | FileUtil.touch(outputPath); 64 | } 65 | 66 | // 生成 67 | Writer out = new FileWriter(outputPath); 68 | template.process(model, out); 69 | 70 | // 生成文件后别忘了关闭哦 71 | out.close(); 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/generator/MainGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.generator; 2 | 3 | import com.yupi.model.MainTemplateConfig; 4 | import freemarker.template.TemplateException; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * 核心生成器 11 | */ 12 | public class MainGenerator { 13 | 14 | /** 15 | * 生成 16 | * 17 | * @param model 数据模型 18 | * @throws TemplateException 19 | * @throws IOException 20 | */ 21 | public static void doGenerate(Object model) throws TemplateException, IOException { 22 | String projectPath = System.getProperty("user.dir"); 23 | // 整个项目的根路径 24 | File parentFile = new File(projectPath).getParentFile(); 25 | // 输入路径 26 | String inputPath = new File(parentFile, "yuzi-generator-demo-projects/acm-template").getAbsolutePath(); 27 | String outputPath = projectPath; 28 | // 生成静态文件 29 | StaticGenerator.copyFilesByRecursive(inputPath, outputPath); 30 | // 生成动态文件 31 | String inputDynamicFilePath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl"; 32 | String outputDynamicFilePath = outputPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java"; 33 | DynamicGenerator.doGenerate(inputDynamicFilePath, outputDynamicFilePath, model); 34 | } 35 | 36 | public static void main(String[] args) throws TemplateException, IOException { 37 | MainTemplateConfig mainTemplateConfig = new MainTemplateConfig(); 38 | mainTemplateConfig.setAuthor("yupi"); 39 | mainTemplateConfig.setLoop(false); 40 | mainTemplateConfig.setOutputText("求和结果:"); 41 | doGenerate(mainTemplateConfig); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/java/com/yupi/model/MainTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 动态模版配置 7 | */ 8 | @Data 9 | public class MainTemplateConfig { 10 | 11 | /** 12 | * 是否生成循环 13 | */ 14 | private boolean loop; 15 | 16 | /** 17 | * 作者注释 18 | */ 19 | private String author = "yupi"; 20 | 21 | /** 22 | * 输出信息 23 | */ 24 | private String outputText = "sum = "; 25 | } 26 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/resources/templates/MainTemplate.java.ftl: -------------------------------------------------------------------------------- 1 | package com.yupi.acm; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * ACM 输入模板(多数之和) 7 | * @author ${author!''} 8 | */ 9 | public class MainTemplate { 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | <#if loop> 14 | while (scanner.hasNext()) { 15 | 16 | // 读取输入元素个数 17 | int n = scanner.nextInt(); 18 | 19 | // 读取数组 20 | int[] arr = new int[n]; 21 | for (int i = 0; i < n; i++) { 22 | arr[i] = scanner.nextInt(); 23 | } 24 | 25 | // 处理问题逻辑,根据需要进行输出 26 | // 示例:计算数组元素的和 27 | int sum = 0; 28 | for (int num : arr) { 29 | sum += num; 30 | } 31 | 32 | System.out.println("${outputText!'sum = '}" + sum); 33 | <#if loop> 34 | } 35 | 36 | scanner.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/main/resources/templates/myweb.html.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 鱼皮官网 5 | 6 | 7 |

欢迎来到鱼皮官网

8 |
    9 | <#-- 循环渲染导航条 --> 10 | <#list menuItems as item> 11 |
  • ${item.label}
  • 12 | 13 |
14 | <#-- 底部版权信息(注释部分,不会被输出)--> 15 |
16 | ${currentYear} 鱼皮官网. All rights reserved. 17 |
18 | 19 | -------------------------------------------------------------------------------- /yuzi-generator-basic/src/test/java/FreeMarkerTest.java: -------------------------------------------------------------------------------- 1 | import freemarker.template.Configuration; 2 | import freemarker.template.Template; 3 | import freemarker.template.TemplateException; 4 | import org.junit.Test; 5 | 6 | import java.io.File; 7 | import java.io.FileWriter; 8 | import java.io.IOException; 9 | import java.io.Writer; 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * FreeMarker 学习测试 17 | */ 18 | public class FreeMarkerTest { 19 | 20 | @Test 21 | public void test() throws IOException, TemplateException { 22 | // new 出 Configuration 对象,参数为 FreeMarker 版本号 23 | Configuration configuration = new Configuration(Configuration.VERSION_2_3_32); 24 | 25 | // 指定模板文件所在的路径 26 | configuration.setDirectoryForTemplateLoading(new File("src/main/resources/templates")); 27 | 28 | // 设置模板文件使用的字符集 29 | configuration.setDefaultEncoding("utf-8"); 30 | 31 | // 创建模板对象,加载指定模板 32 | Template template = configuration.getTemplate("myweb.html.ftl"); 33 | 34 | // 创建数据模型 35 | Map dataModel = new HashMap<>(); 36 | dataModel.put("currentYear", 2023); 37 | List> menuItems = new ArrayList<>(); 38 | Map menuItem1 = new HashMap<>(); 39 | menuItem1.put("url", "https://codefather.cn"); 40 | menuItem1.put("label", "编程导航"); 41 | Map menuItem2 = new HashMap<>(); 42 | menuItem2.put("url", "https://laoyujianli.com"); 43 | menuItem2.put("label", "老鱼简历"); 44 | menuItems.add(menuItem1); 45 | menuItems.add(menuItem2); 46 | dataModel.put("menuItems", menuItems); 47 | 48 | // 生成 49 | Writer out = new FileWriter("myweb.html"); 50 | template.process(dataModel, out); 51 | 52 | // 生成文件后别忘了关闭哦 53 | out.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template-pro/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template-pro/README.md: -------------------------------------------------------------------------------- 1 | # ACM 模板代码 2 | 3 | > 作者:程序员鱼皮 4 | 5 | 提供 ACM 模式的 Java 示例代码 -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template-pro/src/com/yupi/acm/MainTemplate.java: -------------------------------------------------------------------------------- 1 | package com.yupi.acm; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * ACM 输入模板(多数之和) 7 | */ 8 | public class MainTemplate { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | while (scanner.hasNext()) { 13 | // 读取输入元素个数 14 | int n = scanner.nextInt(); 15 | 16 | // 读取数组 17 | int[] arr = new int[n]; 18 | for (int i = 0; i < n; i++) { 19 | arr[i] = scanner.nextInt(); 20 | } 21 | 22 | // 处理问题逻辑,根据需要进行输出 23 | // 示例:计算数组元素的和 24 | int sum = 0; 25 | for (int num : arr) { 26 | sum += num; 27 | } 28 | 29 | System.out.println("Sum: " + sum); 30 | } 31 | 32 | scanner.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template-pro/src/com/yupi/acm/MainTemplate.java.ftl: -------------------------------------------------------------------------------- 1 | package com.yupi.acm; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * ACM 输入模板(多数之和) 7 | * @author ${mainTemplate.author!''} 8 | */ 9 | public class MainTemplate { 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | <#if loop> 14 | while (scanner.hasNext()) { 15 | 16 | // 读取输入元素个数 17 | int n = scanner.nextInt(); 18 | 19 | // 读取数组 20 | int[] arr = new int[n]; 21 | for (int i = 0; i < n; i++) { 22 | arr[i] = scanner.nextInt(); 23 | } 24 | 25 | // 处理问题逻辑,根据需要进行输出 26 | // 示例:计算数组元素的和 27 | int sum = 0; 28 | for (int num : arr) { 29 | sum += num; 30 | } 31 | 32 | System.out.println("${mainTemplate.outputText!'sum = '}" + sum); 33 | <#if loop> 34 | } 35 | 36 | scanner.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template/README.md: -------------------------------------------------------------------------------- 1 | # ACM 模板代码 2 | 3 | > 作者:程序员鱼皮 4 | 5 | 提供 ACM 模式的 Java 示例代码 -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/acm-template/src/com/yupi/acm/MainTemplate.java: -------------------------------------------------------------------------------- 1 | package com.yupi.acm; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * ACM 输入模板(多数之和) 7 | */ 8 | public class MainTemplate { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | while (scanner.hasNext()) { 13 | // 读取输入元素个数 14 | int n = scanner.nextInt(); 15 | 16 | // 读取数组 17 | int[] arr = new int[n]; 18 | for (int i = 0; i < n; i++) { 19 | arr[i] = scanner.nextInt(); 20 | } 21 | 22 | // 处理问题逻辑,根据需要进行输出 23 | // 示例:计算数组元素的和 24 | int sum = 0; 25 | for (int num : arr) { 26 | sum += num; 27 | } 28 | 29 | System.out.println("Sum: " + sum); 30 | } 31 | 32 | scanner.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/Dockerfile: -------------------------------------------------------------------------------- 1 | # Docker 镜像构建 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | FROM maven:3.8.1-jdk-8-slim as builder 5 | 6 | # Copy local code to the container image. 7 | WORKDIR /app 8 | COPY pom.xml . 9 | COPY src ./src 10 | 11 | # Build a release artifact. 12 | RUN mvn package -DskipTests 13 | 14 | # Run the web service on container startup. 15 | CMD ["java","-jar","/app/target/springboot-init-0.0.1-SNAPSHOT.jar","--spring.profiles.active=prod"] -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/README.md: -------------------------------------------------------------------------------- 1 | # SpringBoot 项目初始模板 2 | 3 | > 作者:[程序员鱼皮](https://github.com/liyupi) 4 | > 仅分享于 [编程导航知识星球](https://yupi.icu) 5 | 6 | 基于 Java SpringBoot 的项目初始模板,整合了常用框架和主流业务的示例代码。 7 | 8 | 只需 1 分钟即可完成内容网站的后端!!!大家还可以在此基础上快速开发自己的项目。 9 | 10 | [toc] 11 | 12 | ## 模板特点 13 | 14 | ### 主流框架 & 特性 15 | 16 | - Spring Boot 2.7.x 17 | - Spring MVC 18 | - MyBatis + MyBatis Plus 数据访问(开启分页) 19 | 20 | ### 数据存储 21 | 22 | - MySQL 数据库 23 | - Redis 内存数据库 24 | - Elasticsearch 搜索引擎 25 | 26 | ### 工具类 27 | 28 | - Hutool 工具库 29 | - Lombok 注解 30 | 31 | ### 业务特性 32 | 33 | - Spring Session Redis 分布式登录 34 | - 全局异常处理器 35 | - 自定义错误码 36 | - 封装通用响应类 37 | - Swagger + Knife4j 接口文档 38 | - 全局跨域处理 39 | - 长整数丢失精度解决 40 | 41 | 42 | ## 业务功能 43 | 44 | - 用户登录、注册、注销、更新、检索、权限管理 45 | - 帖子创建、删除、编辑、更新、数据库检索、ES 灵活检索 46 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; 7 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | 10 | /** 11 | * 主类(项目启动入口) 12 | */ 13 | // todo 如需开启 Redis,须移除 exclude 中的内容 14 | @SpringBootApplication(exclude = {RedisAutoConfiguration.class}) 15 | @MapperScan("com.yupi.springbootinit.mapper") 16 | @EnableScheduling 17 | @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) 18 | public class MainApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(MainApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/common/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.common; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 通用返回类 8 | * 9 | * @param 10 | */ 11 | @Data 12 | public class BaseResponse implements Serializable { 13 | 14 | private int code; 15 | 16 | private T data; 17 | 18 | private String message; 19 | 20 | public BaseResponse(int code, T data, String message) { 21 | this.code = code; 22 | this.data = data; 23 | this.message = message; 24 | } 25 | 26 | public BaseResponse(int code, T data) { 27 | this(code, data, ""); 28 | } 29 | 30 | public BaseResponse(ErrorCode errorCode) { 31 | this(errorCode.getCode(), null, errorCode.getMessage()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/common/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.common; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 删除请求 8 | */ 9 | @Data 10 | public class DeleteRequest implements Serializable { 11 | 12 | /** 13 | * id 14 | */ 15 | private Long id; 16 | 17 | private static final long serialVersionUID = 1L; 18 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/common/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.common; 2 | 3 | /** 4 | * 自定义错误码 5 | */ 6 | public enum ErrorCode { 7 | 8 | SUCCESS(0, "ok"), 9 | PARAMS_ERROR(40000, "请求参数错误"), 10 | NOT_LOGIN_ERROR(40100, "未登录"), 11 | NO_AUTH_ERROR(40101, "无权限"), 12 | NOT_FOUND_ERROR(40400, "请求数据不存在"), 13 | FORBIDDEN_ERROR(40300, "禁止访问"), 14 | SYSTEM_ERROR(50000, "系统内部异常"), 15 | OPERATION_ERROR(50001, "操作失败"); 16 | 17 | /** 18 | * 状态码 19 | */ 20 | private final int code; 21 | 22 | /** 23 | * 信息 24 | */ 25 | private final String message; 26 | 27 | ErrorCode(int code, String message) { 28 | this.code = code; 29 | this.message = message; 30 | } 31 | 32 | public int getCode() { 33 | return code; 34 | } 35 | 36 | public String getMessage() { 37 | return message; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/common/PageRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.common; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 分页请求 7 | */ 8 | @Data 9 | public class PageRequest { 10 | 11 | /** 12 | * 当前页号 13 | */ 14 | private long current = 1; 15 | 16 | /** 17 | * 页面大小 18 | */ 19 | private long pageSize = 10; 20 | } 21 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/common/ResultUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.common; 2 | 3 | /** 4 | * 返回工具类 5 | */ 6 | public class ResultUtils { 7 | 8 | /** 9 | * 成功 10 | * 11 | * @param data 12 | * @param 13 | * @return 14 | */ 15 | public static BaseResponse success(T data) { 16 | return new BaseResponse<>(0, data, "ok"); 17 | } 18 | 19 | /** 20 | * 失败 21 | * 22 | * @param errorCode 23 | * @return 24 | */ 25 | public static BaseResponse error(ErrorCode errorCode) { 26 | return new BaseResponse<>(errorCode); 27 | } 28 | 29 | /** 30 | * 失败 31 | * 32 | * @param code 33 | * @param message 34 | * @return 35 | */ 36 | public static BaseResponse error(int code, String message) { 37 | return new BaseResponse(code, null, message); 38 | } 39 | 40 | /** 41 | * 失败 42 | * 43 | * @param errorCode 44 | * @return 45 | */ 46 | public static BaseResponse error(ErrorCode errorCode, String message) { 47 | return new BaseResponse(errorCode.getCode(), null, message); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * 全局跨域配置 9 | */ 10 | @Configuration 11 | public class CorsConfig implements WebMvcConfigurer { 12 | 13 | @Override 14 | public void addCorsMappings(CorsRegistry registry) { 15 | // 覆盖所有请求 16 | registry.addMapping("/**") 17 | // 允许发送 Cookie 18 | .allowCredentials(true) 19 | // 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突) 20 | .allowedOriginPatterns("*") 21 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 22 | .allowedHeaders("*") 23 | .exposedHeaders("*"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/config/JsonConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.jackson.JsonComponent; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 9 | 10 | /** 11 | * Spring MVC Json 配置 12 | */ 13 | @JsonComponent 14 | public class JsonConfig { 15 | 16 | /** 17 | * 添加 Long 转 json 精度丢失的配置 18 | */ 19 | @Bean 20 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 21 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 22 | SimpleModule module = new SimpleModule(); 23 | module.addSerializer(Long.class, ToStringSerializer.instance); 24 | module.addSerializer(Long.TYPE, ToStringSerializer.instance); 25 | objectMapper.registerModule(module); 26 | return objectMapper; 27 | } 28 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/config/Knife4jConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | /** 14 | * Knife4j 接口文档配置 15 | */ 16 | @Configuration 17 | @EnableSwagger2 18 | public class Knife4jConfig { 19 | 20 | @Bean 21 | public Docket defaultApi2() { 22 | return new Docket(DocumentationType.SWAGGER_2) 23 | .apiInfo(new ApiInfoBuilder() 24 | .title("接口文档") 25 | .description("springboot-init") 26 | .version("1.0") 27 | .build()) 28 | .select() 29 | // 指定 Controller 扫描包路径 30 | .apis(RequestHandlerSelectors.basePackage("com.yupi.springbootinit.controller")) 31 | .paths(PathSelectors.any()) 32 | .build(); 33 | } 34 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * MyBatis Plus 配置 12 | * 13 | * @author https://github.com/liyupi 14 | */ 15 | @Configuration 16 | @MapperScan("com.yupi.springbootinit.mapper") 17 | public class MyBatisPlusConfig { 18 | 19 | /** 20 | * 拦截器配置 21 | * 22 | * @return 23 | */ 24 | @Bean 25 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 26 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 27 | // 分页插件 28 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 29 | return interceptor; 30 | } 31 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.constant; 2 | 3 | /** 4 | * 用户常量 5 | */ 6 | public interface UserConstant { 7 | 8 | /** 9 | * 用户登录态键 10 | */ 11 | String USER_LOGIN_STATE = "user_login"; 12 | } 13 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/exception/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.exception; 2 | 3 | import com.yupi.springbootinit.common.ErrorCode; 4 | 5 | /** 6 | * 自定义异常类 7 | */ 8 | public class BusinessException extends RuntimeException { 9 | 10 | /** 11 | * 错误码 12 | */ 13 | private final int code; 14 | 15 | public BusinessException(ErrorCode errorCode) { 16 | super(errorCode.getMessage()); 17 | this.code = errorCode.getCode(); 18 | } 19 | 20 | public BusinessException(ErrorCode errorCode, String message) { 21 | super(message); 22 | this.code = errorCode.getCode(); 23 | } 24 | 25 | public int getCode() { 26 | return code; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.exception; 2 | 3 | import com.yupi.springbootinit.common.BaseResponse; 4 | import com.yupi.springbootinit.common.ErrorCode; 5 | import com.yupi.springbootinit.common.ResultUtils; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.RestControllerAdvice; 9 | 10 | /** 11 | * 全局异常处理器 12 | */ 13 | @RestControllerAdvice 14 | @Slf4j 15 | public class GlobalExceptionHandler { 16 | 17 | @ExceptionHandler(BusinessException.class) 18 | public BaseResponse businessExceptionHandler(BusinessException e) { 19 | log.error("BusinessException", e); 20 | return ResultUtils.error(e.getCode(), e.getMessage()); 21 | } 22 | 23 | @ExceptionHandler(RuntimeException.class) 24 | public BaseResponse runtimeExceptionHandler(RuntimeException e) { 25 | log.error("RuntimeException", e); 26 | return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/exception/ThrowUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.exception; 2 | 3 | import com.yupi.springbootinit.common.ErrorCode; 4 | 5 | /** 6 | * 抛异常工具类 7 | */ 8 | public class ThrowUtils { 9 | 10 | /** 11 | * 条件成立则抛异常 12 | * 13 | * @param condition 14 | * @param runtimeException 15 | */ 16 | public static void throwIf(boolean condition, RuntimeException runtimeException) { 17 | if (condition) { 18 | throw runtimeException; 19 | } 20 | } 21 | 22 | /** 23 | * 条件成立则抛异常 24 | * 25 | * @param condition 26 | * @param errorCode 27 | */ 28 | public static void throwIf(boolean condition, ErrorCode errorCode) { 29 | throwIf(condition, new BusinessException(errorCode)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/mapper/PostMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.springbootinit.model.entity.Post; 5 | 6 | /** 7 | * 帖子数据库操作 8 | */ 9 | public interface PostMapper extends BaseMapper { 10 | 11 | } 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.springbootinit.model.entity.User; 5 | 6 | /** 7 | * 用户数据库操作 8 | */ 9 | public interface UserMapper extends BaseMapper { 10 | 11 | } 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/post/PostAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.post; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import lombok.Data; 6 | 7 | /** 8 | * 创建请求 9 | */ 10 | @Data 11 | public class PostAddRequest implements Serializable { 12 | 13 | /** 14 | * 标题 15 | */ 16 | private String title; 17 | 18 | /** 19 | * 内容 20 | */ 21 | private String content; 22 | 23 | /** 24 | * 标签列表 25 | */ 26 | private List tags; 27 | 28 | private static final long serialVersionUID = 1L; 29 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/post/PostEsDTO.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.post; 2 | 3 | import lombok.Data; 4 | import org.springframework.data.annotation.Id; 5 | import org.springframework.data.elasticsearch.annotations.Field; 6 | import org.springframework.data.elasticsearch.annotations.FieldType; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | /** 13 | * 帖子 ES 包装类 14 | **/ 15 | // todo 取消注释开启 ES(须先配置 ES) 16 | //@Document(indexName = "post") 17 | @Data 18 | public class PostEsDTO implements Serializable { 19 | 20 | private static final String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; 21 | 22 | /** 23 | * id 24 | */ 25 | @Id 26 | private Long id; 27 | 28 | /** 29 | * 标题 30 | */ 31 | private String title; 32 | 33 | /** 34 | * 内容 35 | */ 36 | private String content; 37 | 38 | /** 39 | * 标签列表 40 | */ 41 | private List tags; 42 | 43 | /** 44 | * 创建用户 id 45 | */ 46 | private Long userId; 47 | 48 | /** 49 | * 创建时间 50 | */ 51 | @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN) 52 | private Date createTime; 53 | 54 | /** 55 | * 更新时间 56 | */ 57 | @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN) 58 | private Date updateTime; 59 | 60 | /** 61 | * 是否删除 62 | */ 63 | private Integer isDelete; 64 | 65 | private static final long serialVersionUID = 1L; 66 | } 67 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/post/PostQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.post; 2 | 3 | import com.yupi.springbootinit.common.PageRequest; 4 | import java.io.Serializable; 5 | import java.util.List; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * 查询请求 11 | */ 12 | @EqualsAndHashCode(callSuper = true) 13 | @Data 14 | public class PostQueryRequest extends PageRequest implements Serializable { 15 | 16 | /** 17 | * id 18 | */ 19 | private Long id; 20 | 21 | /** 22 | * id 23 | */ 24 | private Long notId; 25 | 26 | /** 27 | * 搜索词 28 | */ 29 | private String searchText; 30 | 31 | /** 32 | * 标题 33 | */ 34 | private String title; 35 | 36 | /** 37 | * 内容 38 | */ 39 | private String content; 40 | 41 | /** 42 | * 标签列表 43 | */ 44 | private List tags; 45 | 46 | /** 47 | * 至少有一个标签 48 | */ 49 | private List orTags; 50 | 51 | /** 52 | * 创建用户 id 53 | */ 54 | private Long userId; 55 | 56 | private static final long serialVersionUID = 1L; 57 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/post/PostUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.post; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import lombok.Data; 6 | 7 | /** 8 | * 更新请求 9 | */ 10 | @Data 11 | public class PostUpdateRequest implements Serializable { 12 | 13 | /** 14 | * id 15 | */ 16 | private Long id; 17 | 18 | /** 19 | * 标题 20 | */ 21 | private String title; 22 | 23 | /** 24 | * 内容 25 | */ 26 | private String content; 27 | 28 | /** 29 | * 标签列表 30 | */ 31 | private List tags; 32 | 33 | private static final long serialVersionUID = 1L; 34 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/user/UserAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户创建请求 8 | */ 9 | @Data 10 | public class UserAddRequest implements Serializable { 11 | 12 | /** 13 | * 用户昵称 14 | */ 15 | private String userName; 16 | 17 | /** 18 | * 账号 19 | */ 20 | private String userAccount; 21 | 22 | /** 23 | * 用户头像 24 | */ 25 | private String userAvatar; 26 | 27 | /** 28 | * 用户角色: user, admin 29 | */ 30 | private String userRole; 31 | 32 | private static final long serialVersionUID = 1L; 33 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/user/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户登录请求 8 | */ 9 | @Data 10 | public class UserLoginRequest implements Serializable { 11 | 12 | private static final long serialVersionUID = 3191241716373120793L; 13 | 14 | private String userAccount; 15 | 16 | private String userPassword; 17 | } 18 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/user/UserQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.user; 2 | 3 | import com.yupi.springbootinit.common.PageRequest; 4 | import java.io.Serializable; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | /** 9 | * 用户查询请求 10 | */ 11 | @EqualsAndHashCode(callSuper = true) 12 | @Data 13 | public class UserQueryRequest extends PageRequest implements Serializable { 14 | /** 15 | * id 16 | */ 17 | private Long id; 18 | 19 | /** 20 | * 用户昵称 21 | */ 22 | private String userName; 23 | 24 | /** 25 | * 简介 26 | */ 27 | private String userProfile; 28 | 29 | /** 30 | * 用户角色:user/admin/ban 31 | */ 32 | private String userRole; 33 | 34 | private static final long serialVersionUID = 1L; 35 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/user/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户注册请求体 8 | */ 9 | @Data 10 | public class UserRegisterRequest implements Serializable { 11 | 12 | private static final long serialVersionUID = 3191241716373120793L; 13 | 14 | private String userAccount; 15 | 16 | private String userPassword; 17 | 18 | private String checkPassword; 19 | } 20 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户更新请求 8 | */ 9 | @Data 10 | public class UserUpdateRequest implements Serializable { 11 | /** 12 | * id 13 | */ 14 | private Long id; 15 | 16 | /** 17 | * 用户昵称 18 | */ 19 | private String userName; 20 | 21 | /** 22 | * 用户头像 23 | */ 24 | private String userAvatar; 25 | 26 | /** 27 | * 简介 28 | */ 29 | private String userProfile; 30 | 31 | /** 32 | * 用户角色:user/admin/ban 33 | */ 34 | private String userRole; 35 | 36 | private static final long serialVersionUID = 1L; 37 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/entity/Post.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableLogic; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | import lombok.Data; 11 | 12 | /** 13 | * 帖子 14 | */ 15 | @TableName(value = "post") 16 | @Data 17 | public class Post implements Serializable { 18 | 19 | /** 20 | * id 21 | */ 22 | @TableId(type = IdType.ASSIGN_ID) 23 | private Long id; 24 | 25 | /** 26 | * 标题 27 | */ 28 | private String title; 29 | 30 | /** 31 | * 内容 32 | */ 33 | private String content; 34 | 35 | /** 36 | * 标签列表 json 37 | */ 38 | private String tags; 39 | 40 | /** 41 | * 创建用户 id 42 | */ 43 | private Long userId; 44 | 45 | /** 46 | * 创建时间 47 | */ 48 | private Date createTime; 49 | 50 | /** 51 | * 更新时间 52 | */ 53 | private Date updateTime; 54 | 55 | /** 56 | * 是否删除 57 | */ 58 | @TableLogic 59 | private Integer isDelete; 60 | 61 | @TableField(exist = false) 62 | private static final long serialVersionUID = 1L; 63 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableLogic; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | import lombok.Data; 13 | 14 | /** 15 | * 用户 16 | */ 17 | @TableName(value = "user") 18 | @Data 19 | public class User implements Serializable { 20 | 21 | /** 22 | * id 23 | */ 24 | @TableId(type = IdType.ASSIGN_ID) 25 | private Long id; 26 | 27 | /** 28 | * 用户账号 29 | */ 30 | private String userAccount; 31 | 32 | /** 33 | * 用户密码 34 | */ 35 | private String userPassword; 36 | 37 | /** 38 | * 用户昵称 39 | */ 40 | private String userName; 41 | 42 | /** 43 | * 用户头像 44 | */ 45 | private String userAvatar; 46 | 47 | /** 48 | * 用户简介 49 | */ 50 | private String userProfile; 51 | 52 | /** 53 | * 用户角色:user/admin/ban 54 | */ 55 | private String userRole; 56 | 57 | /** 58 | * 创建时间 59 | */ 60 | private Date createTime; 61 | 62 | /** 63 | * 更新时间 64 | */ 65 | private Date updateTime; 66 | 67 | /** 68 | * 是否删除 69 | */ 70 | @TableLogic 71 | private Integer isDelete; 72 | 73 | @TableField(exist = false) 74 | private static final long serialVersionUID = 1L; 75 | } -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/model/enums/UserRoleEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.model.enums; 2 | 3 | /** 4 | * 用户角色枚举 5 | */ 6 | public enum UserRoleEnum { 7 | 8 | USER("用户", "user"), 9 | ADMIN("管理员", "admin"), 10 | BAN("被封号", "ban"); 11 | 12 | private final String text; 13 | 14 | private final String value; 15 | 16 | UserRoleEnum(String text, String value) { 17 | this.text = text; 18 | this.value = value; 19 | } 20 | 21 | public String getValue() { 22 | return value; 23 | } 24 | 25 | public String getText() { 26 | return text; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/service/PostService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.yupi.springbootinit.model.dto.post.PostQueryRequest; 7 | import com.yupi.springbootinit.model.entity.Post; 8 | 9 | /** 10 | * 帖子服务 11 | */ 12 | public interface PostService extends IService { 13 | 14 | /** 15 | * 获取查询条件 16 | * 17 | * @param postQueryRequest 18 | * @return 19 | */ 20 | QueryWrapper getQueryWrapper(PostQueryRequest postQueryRequest); 21 | 22 | /** 23 | * 从 ES 查询 24 | * 25 | * @param postQueryRequest 26 | * @return 27 | */ 28 | Page searchFromEs(PostQueryRequest postQueryRequest); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/java/com/yupi/springbootinit/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.springbootinit.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.yupi.springbootinit.model.dto.user.UserQueryRequest; 6 | import com.yupi.springbootinit.model.entity.User; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | /** 11 | * 用户服务 12 | */ 13 | public interface UserService extends IService { 14 | 15 | /** 16 | * 用户注册 17 | * 18 | * @param userAccount 用户账户 19 | * @param userPassword 用户密码 20 | * @param checkPassword 校验密码 21 | * @return 新用户 id 22 | */ 23 | long userRegister(String userAccount, String userPassword, String checkPassword); 24 | 25 | /** 26 | * 用户登录 27 | * 28 | * @param userAccount 用户账户 29 | * @param userPassword 用户密码 30 | * @param request 31 | * @return 登录用户信息 32 | */ 33 | User userLogin(String userAccount, String userPassword, HttpServletRequest request); 34 | 35 | /** 36 | * 获取当前登录用户 37 | * 38 | * @param request 39 | * @return 40 | */ 41 | User getLoginUser(HttpServletRequest request); 42 | 43 | /** 44 | * 是否为管理员 45 | * 46 | * @param request 47 | * @return 48 | */ 49 | boolean isAdmin(HttpServletRequest request); 50 | 51 | /** 52 | * 是否为管理员 53 | * 54 | * @param user 55 | * @return 56 | */ 57 | boolean isAdmin(User user); 58 | 59 | /** 60 | * 用户注销 61 | * 62 | * @param request 63 | * @return 64 | */ 65 | boolean userLogout(HttpServletRequest request); 66 | 67 | /** 68 | * 获取查询条件 69 | * 70 | * @param userQueryRequest 71 | * @return 72 | */ 73 | QueryWrapper getQueryWrapper(UserQueryRequest userQueryRequest); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 公共配置文件 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | spring: 5 | application: 6 | name: springboot-init 7 | # 默认 dev 环境 8 | profiles: 9 | active: dev 10 | # 支持 swagger3 11 | mvc: 12 | pathmatch: 13 | matching-strategy: ant_path_matcher 14 | # session 配置 15 | session: 16 | # todo 取消注释开启分布式 session(须先配置 Redis) 17 | # store-type: redis 18 | # 30 天过期 19 | timeout: 2592000 20 | # 数据库配置 21 | # todo 需替换配置 22 | datasource: 23 | driver-class-name: com.mysql.cj.jdbc.Driver 24 | url: jdbc:mysql://localhost:3306/my_db 25 | username: root 26 | password: 123456 27 | # Redis 配置 28 | # todo 需替换配置,然后取消注释 29 | # redis: 30 | # database: 1 31 | # host: localhost 32 | # port: 6379 33 | # timeout: 5000 34 | # password: 123456 35 | # Elasticsearch 配置 36 | # todo 需替换配置,然后取消注释 37 | # elasticsearch: 38 | # uris: http://localhost:9200 39 | # username: root 40 | # password: 123456 41 | server: 42 | address: 0.0.0.0 43 | port: 8101 44 | servlet: 45 | context-path: /api 46 | # cookie 30 天过期 47 | session: 48 | cookie: 49 | max-age: 2592000 50 | mybatis-plus: 51 | configuration: 52 | map-underscore-to-camel-case: false 53 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 54 | global-config: 55 | db-config: 56 | logic-delete-field: isDelete # 全局逻辑删除的实体字段名 57 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) 58 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) 59 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/resources/mapper/PostMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | id,title,content,tags,userId, 20 | createTime,updateTime,isDelete 21 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /yuzi-generator-demo-projects/springboot-init/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | id,userName,userAvatar,userProfile, 19 | userRole,createTime,updateTime,isDelete 20 | 21 | 22 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/Main.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker; 2 | 3 | import com.yupi.maker.generator.main.GenerateTemplate; 4 | import com.yupi.maker.generator.main.MainGenerator; 5 | import com.yupi.maker.generator.main.ZipGenerator; 6 | import freemarker.template.TemplateException; 7 | 8 | import java.io.IOException; 9 | 10 | public class Main { 11 | 12 | public static void main(String[] args) throws TemplateException, IOException, InterruptedException { 13 | // GenerateTemplate generateTemplate = new MainGenerator(); 14 | GenerateTemplate generateTemplate = new ZipGenerator(); 15 | generateTemplate.doGenerate(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/generator/JarGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.generator; 2 | 3 | import java.io.*; 4 | import java.util.Map; 5 | 6 | public class JarGenerator { 7 | 8 | public static void doGenerate(String projectDir) throws IOException, InterruptedException { 9 | // 清理之前的构建并打包 10 | // 注意不同操作系统,执行的命令不同 11 | String winMavenCommand = "mvn.cmd clean package -DskipTests=true"; 12 | String otherMavenCommand = "mvn clean package -DskipTests=true"; 13 | String mavenCommand = otherMavenCommand; 14 | 15 | // 这里一定要拆分! 16 | ProcessBuilder processBuilder = new ProcessBuilder(mavenCommand.split(" ")); 17 | processBuilder.directory(new File(projectDir)); 18 | Map environment = processBuilder.environment(); 19 | System.out.println(environment); 20 | Process process = processBuilder.start(); 21 | 22 | // 读取命令的输出 23 | InputStream inputStream = process.getInputStream(); 24 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 25 | String line; 26 | while ((line = reader.readLine()) != null) { 27 | System.out.println(line); 28 | } 29 | 30 | // 等待命令执行完成 31 | int exitCode = process.waitFor(); 32 | System.out.println("命令执行结束,退出码:" + exitCode); 33 | } 34 | 35 | public static void main(String[] args) throws IOException, InterruptedException { 36 | doGenerate("C:\\code\\yuzi-generator\\yuzi-generator-maker\\generated\\acm-template-pro-generator"); 37 | } 38 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/generator/ScriptGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.generator; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.charset.StandardCharsets; 8 | import java.nio.file.Files; 9 | import java.nio.file.Paths; 10 | import java.nio.file.attribute.PosixFilePermission; 11 | import java.nio.file.attribute.PosixFilePermissions; 12 | import java.util.Set; 13 | 14 | public class ScriptGenerator { 15 | 16 | public static void doGenerate(String outputPath, String jarPath) throws IOException { 17 | // 直接写入脚本文件 18 | // linux 19 | StringBuilder sb = new StringBuilder(); 20 | sb.append("#!/bin/bash").append("\n"); 21 | sb.append(String.format("java -jar %s \"$@\"", jarPath)).append("\n"); 22 | FileUtil.writeBytes(sb.toString().getBytes(StandardCharsets.UTF_8), outputPath); 23 | // 添加可执行权限 24 | try { 25 | Set permissions = PosixFilePermissions.fromString("rwxrwxrwx"); 26 | Files.setPosixFilePermissions(Paths.get(outputPath), permissions); 27 | } catch (Exception e) { 28 | 29 | } 30 | 31 | // windows 32 | sb = new StringBuilder(); 33 | sb.append("@echo off").append("\n"); 34 | sb.append(String.format("java -jar %s %%*", jarPath)).append("\n"); 35 | FileUtil.writeBytes(sb.toString().getBytes(StandardCharsets.UTF_8), outputPath + ".bat"); 36 | } 37 | 38 | public static void main(String[] args) throws IOException { 39 | String outputPath = System.getProperty("user.dir") + File.separator + "generator"; 40 | doGenerate(outputPath, ""); 41 | } 42 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/generator/file/FileGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.generator.file; 2 | 3 | import freemarker.template.TemplateException; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | /** 9 | * 核心生成器 10 | */ 11 | public class FileGenerator { 12 | 13 | /** 14 | * 生成 15 | * 16 | * @param model 数据模型 17 | * @throws TemplateException 18 | * @throws IOException 19 | */ 20 | public static void doGenerate(Object model) throws TemplateException, IOException { 21 | String projectPath = System.getProperty("user.dir"); 22 | // 整个项目的根路径 23 | File parentFile = new File(projectPath).getParentFile(); 24 | // 输入路径 25 | String inputPath = new File(parentFile, "yuzi-generator-demo-projects/acm-template").getAbsolutePath(); 26 | String outputPath = projectPath; 27 | // 生成静态文件 28 | StaticFileGenerator.copyFilesByHutool(inputPath, outputPath); 29 | // 生成动态文件 30 | String inputDynamicFilePath = projectPath + File.separator + "src/main/resources/templates/DataModel.java.ftl.ftl"; 31 | String outputDynamicFilePath = outputPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java"; 32 | DynamicFileGenerator.doGenerate(inputDynamicFilePath, outputDynamicFilePath, model); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/generator/file/StaticFileGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.generator.file; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | 5 | /** 6 | * 静态文件生成 7 | */ 8 | public class StaticFileGenerator { 9 | 10 | /** 11 | * 拷贝文件(Hutool 实现,会将输入目录完整拷贝到输出目录下) 12 | * 13 | * @param inputPath 14 | * @param outputPath 15 | */ 16 | public static void copyFilesByHutool(String inputPath, String outputPath) { 17 | FileUtil.copy(inputPath, outputPath, false); 18 | } 19 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/generator/main/MainGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.generator.main; 2 | 3 | /** 4 | * 生成代码生成器 5 | */ 6 | public class MainGenerator extends GenerateTemplate { 7 | 8 | @Override 9 | protected String buildDist(String outputPath, String sourceCopyDestPath, String jarPath, String shellOutputFilePath) { 10 | System.out.println("不要给我输出 dist 啦!"); 11 | return ""; 12 | } 13 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/generator/main/ZipGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.generator.main; 2 | 3 | /** 4 | * 生成代码生成器压缩包 5 | */ 6 | public class ZipGenerator extends GenerateTemplate { 7 | 8 | @Override 9 | protected String buildDist(String outputPath, String sourceCopyDestPath, String jarPath, String shellOutputFilePath) { 10 | String distPath = super.buildDist(outputPath, sourceCopyDestPath, jarPath, shellOutputFilePath); 11 | return super.buildZip(distPath); 12 | } 13 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/meta/Meta.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.meta; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | @NoArgsConstructor 10 | @Data 11 | public class Meta { 12 | 13 | private String name; 14 | private String description; 15 | private String basePackage; 16 | private String version; 17 | private String author; 18 | private String createTime; 19 | private FileConfig fileConfig; 20 | private ModelConfig modelConfig; 21 | 22 | @NoArgsConstructor 23 | @Data 24 | public static class FileConfig implements Serializable { 25 | private String inputRootPath; 26 | private String outputRootPath; 27 | private String sourceRootPath; 28 | private String type; 29 | private List files; 30 | 31 | @NoArgsConstructor 32 | @Data 33 | public static class FileInfo implements Serializable { 34 | private String inputPath; 35 | private String outputPath; 36 | private String type; 37 | private String generateType; 38 | private String condition; 39 | private String groupKey; 40 | private String groupName; 41 | private List files; 42 | } 43 | } 44 | 45 | @NoArgsConstructor 46 | @Data 47 | public static class ModelConfig implements Serializable { 48 | private List models; 49 | 50 | @NoArgsConstructor 51 | @Data 52 | public static class ModelInfo implements Serializable { 53 | private String fieldName; 54 | private String type; 55 | private String description; 56 | private Object defaultValue; 57 | private String abbr; 58 | private String groupKey; 59 | private String groupName; 60 | private List models; 61 | private String condition; 62 | 63 | // 中间参数 64 | // 该分组下所有参数拼接字符串 65 | private String allArgsStr; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/meta/MetaException.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.meta; 2 | 3 | public class MetaException extends RuntimeException { 4 | 5 | public MetaException(String message) { 6 | super(message); 7 | } 8 | 9 | public MetaException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/meta/MetaManager.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.meta; 2 | 3 | import cn.hutool.core.io.resource.ResourceUtil; 4 | import cn.hutool.json.JSONUtil; 5 | 6 | public class MetaManager { 7 | 8 | private static volatile Meta meta; 9 | 10 | private MetaManager() { 11 | // 私有构造函数,防止外部实例化 12 | } 13 | 14 | public static Meta getMetaObject() { 15 | if (meta == null) { 16 | synchronized (MetaManager.class) { 17 | if (meta == null) { 18 | meta = initMeta(); 19 | } 20 | } 21 | } 22 | return meta; 23 | } 24 | 25 | private static Meta initMeta() { 26 | String metaJson = ResourceUtil.readUtf8Str("meta.json"); 27 | // String metaJson = ResourceUtil.readUtf8Str("springboot-init-meta.json"); 28 | Meta newMeta = JSONUtil.toBean(metaJson, Meta.class); 29 | // 校验和处理默认值 30 | MetaValidator.doValidAndFill(newMeta); 31 | return newMeta; 32 | } 33 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/meta/enums/FileGenerateTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.meta.enums; 2 | 3 | /** 4 | * 文件生成类型枚举 5 | */ 6 | public enum FileGenerateTypeEnum { 7 | 8 | DYNAMIC("动态", "dynamic"), 9 | STATIC("静态", "static"); 10 | 11 | private final String text; 12 | 13 | private final String value; 14 | 15 | FileGenerateTypeEnum(String text, String value) { 16 | this.text = text; 17 | this.value = value; 18 | } 19 | 20 | public String getText() { 21 | return text; 22 | } 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/meta/enums/FileTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.meta.enums; 2 | 3 | public enum FileTypeEnum { 4 | 5 | DIR("目录", "dir"), 6 | FILE("文件", "file"), 7 | GROUP("文件组", "group"); 8 | 9 | private final String text; 10 | 11 | private final String value; 12 | 13 | FileTypeEnum(String text, String value) { 14 | this.text = text; 15 | this.value = value; 16 | } 17 | 18 | public String getText() { 19 | return text; 20 | } 21 | 22 | public String getValue() { 23 | return value; 24 | } 25 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/meta/enums/ModelTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.meta.enums; 2 | 3 | /** 4 | * 模型类型枚举 5 | */ 6 | public enum ModelTypeEnum { 7 | 8 | STRING("字符串", "String"), 9 | BOOLEAN("布尔", "boolean"); 10 | 11 | private final String text; 12 | 13 | private final String value; 14 | 15 | ModelTypeEnum(String text, String value) { 16 | this.text = text; 17 | this.value = value; 18 | } 19 | 20 | public String getText() { 21 | return text; 22 | } 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/TemplateMakerUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.yupi.maker.meta.Meta; 5 | 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * 模板制作工具类 12 | */ 13 | public class TemplateMakerUtils { 14 | 15 | /** 16 | * 从未分组文件中移除组内的同名文件 17 | * 18 | * @param fileInfoList 19 | * @return 20 | */ 21 | public static List removeGroupFilesFromRoot(List fileInfoList) { 22 | // 先获取到所有分组 23 | List groupFileInfoList = fileInfoList.stream() 24 | .filter(fileInfo -> StrUtil.isNotBlank(fileInfo.getGroupKey())) 25 | .collect(Collectors.toList()); 26 | 27 | // 获取所有分组内的文件列表 28 | List groupInnerFileInfoList = groupFileInfoList.stream() 29 | .flatMap(fileInfo -> fileInfo.getFiles().stream()) 30 | .collect(Collectors.toList()); 31 | 32 | // 获取所有分组内文件输入路径集合 33 | Set fileInputPathSet = groupInnerFileInfoList.stream() 34 | .map(Meta.FileConfig.FileInfo::getInputPath) 35 | .collect(Collectors.toSet()); 36 | 37 | // 移除所有输入路径在 set 中的外层文件 38 | return fileInfoList.stream() 39 | .filter(fileInfo -> !fileInputPathSet.contains(fileInfo.getInputPath())) 40 | .collect(Collectors.toList()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/enums/FileFilterRangeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.enums; 2 | 3 | import cn.hutool.core.util.ObjectUtil; 4 | import lombok.Getter; 5 | 6 | /** 7 | * 文件过滤范围枚举 8 | */ 9 | @Getter 10 | public enum FileFilterRangeEnum { 11 | 12 | FILE_NAME("文件名称", "fileName"), 13 | FILE_CONTENT("文件内容", "fileContent"); 14 | 15 | private final String text; 16 | 17 | private final String value; 18 | 19 | FileFilterRangeEnum(String text, String value) { 20 | this.text = text; 21 | this.value = value; 22 | } 23 | 24 | /** 25 | * 根据 value 获取枚举 26 | * 27 | * @param value 28 | * @return 29 | */ 30 | public static FileFilterRangeEnum getEnumByValue(String value) { 31 | if (ObjectUtil.isEmpty(value)) { 32 | return null; 33 | } 34 | for (FileFilterRangeEnum anEnum : FileFilterRangeEnum.values()) { 35 | if (anEnum.value.equals(value)) { 36 | return anEnum; 37 | } 38 | } 39 | return null; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/enums/FileFilterRuleEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.enums; 2 | 3 | import cn.hutool.core.util.ObjectUtil; 4 | import lombok.Getter; 5 | 6 | /** 7 | * 文件过滤规则枚举 8 | */ 9 | @Getter 10 | public enum FileFilterRuleEnum { 11 | 12 | CONTAINS("包含", "contains"), 13 | STARTS_WITH("前缀匹配", "startsWith"), 14 | ENDS_WITH("后缀匹配", "endsWith"), 15 | REGEX("正则", "regex"), 16 | EQUALS("相等", "equals"); 17 | 18 | private final String text; 19 | 20 | private final String value; 21 | 22 | FileFilterRuleEnum(String text, String value) { 23 | this.text = text; 24 | this.value = value; 25 | } 26 | 27 | /** 28 | * 根据 value 获取枚举 29 | * 30 | * @param value 31 | * @return 32 | */ 33 | public static FileFilterRuleEnum getEnumByValue(String value) { 34 | if (ObjectUtil.isEmpty(value)) { 35 | return null; 36 | } 37 | for (FileFilterRuleEnum anEnum : FileFilterRuleEnum.values()) { 38 | if (anEnum.value.equals(value)) { 39 | return anEnum; 40 | } 41 | } 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/model/FileFilterConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.model; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * 文件过滤配置 8 | */ 9 | @Data 10 | @Builder 11 | public class FileFilterConfig { 12 | 13 | /** 14 | * 过滤范围 15 | */ 16 | private String range; 17 | 18 | /** 19 | * 过滤规则 20 | */ 21 | private String rule; 22 | 23 | /** 24 | * 过滤值 25 | */ 26 | private String value; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/model/TemplateMakerConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.model; 2 | 3 | import com.yupi.maker.meta.Meta; 4 | import lombok.Data; 5 | 6 | /** 7 | * 模板制作配置 8 | */ 9 | @Data 10 | public class TemplateMakerConfig { 11 | 12 | private Long id; 13 | 14 | private Meta meta = new Meta(); 15 | 16 | private String originProjectPath; 17 | 18 | TemplateMakerFileConfig fileConfig = new TemplateMakerFileConfig(); 19 | 20 | TemplateMakerModelConfig modelConfig = new TemplateMakerModelConfig(); 21 | 22 | TemplateMakerOutputConfig outputConfig = new TemplateMakerOutputConfig(); 23 | } 24 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/model/TemplateMakerFileConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.model; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | public class TemplateMakerFileConfig { 10 | 11 | private List files; 12 | 13 | private FileGroupConfig fileGroupConfig; 14 | 15 | @NoArgsConstructor 16 | @Data 17 | public static class FileInfoConfig { 18 | 19 | private String path; 20 | 21 | private String condition; 22 | 23 | private List filterConfigList; 24 | } 25 | 26 | @Data 27 | public static class FileGroupConfig { 28 | 29 | private String condition; 30 | 31 | private String groupKey; 32 | 33 | private String groupName; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/model/TemplateMakerModelConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.model; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | public class TemplateMakerModelConfig { 10 | 11 | private List models; 12 | 13 | private ModelGroupConfig modelGroupConfig; 14 | 15 | @NoArgsConstructor 16 | @Data 17 | public static class ModelInfoConfig { 18 | 19 | private String fieldName; 20 | 21 | private String type; 22 | 23 | private String description; 24 | 25 | private Object defaultValue; 26 | 27 | private String abbr; 28 | 29 | // 用于替换哪些文本 30 | private String replaceText; 31 | } 32 | 33 | @Data 34 | public static class ModelGroupConfig { 35 | 36 | private String condition; 37 | 38 | private String groupKey; 39 | 40 | private String groupName; 41 | 42 | private String type; 43 | 44 | private String description; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/java/com/yupi/maker/template/model/TemplateMakerOutputConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.maker.template.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class TemplateMakerOutputConfig { 7 | 8 | // 从未分组文件中移除组内的同名文件 9 | private boolean removeGroupFilesFromRoot = true; 10 | } 11 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "meta": { 4 | "name": "springboot-init-generator", 5 | "description": "Spring Boot 模板项目生成器" 6 | }, 7 | "originProjectPath": "../../../yuzi-generator-demo-projects/springboot-init" 8 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "" 7 | } 8 | ] 9 | }, 10 | "modelConfig": { 11 | "models": [ 12 | { 13 | "fieldName": "basePackage", 14 | "type": "String", 15 | "description": "基础包名", 16 | "defaultValue": "com.yupi", 17 | "replaceText": "com.yupi" 18 | } 19 | ] 20 | } 21 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "fileGroupConfig": { 5 | "groupKey": "post", 6 | "groupName": "帖子文件组", 7 | "condition": "needPost" 8 | }, 9 | "files": [ 10 | { 11 | "path": "src/main", 12 | "filterConfigList": [ 13 | { 14 | "range": "fileName", 15 | "rule": "contains", 16 | "value": "Post" 17 | } 18 | ] 19 | } 20 | ] 21 | }, 22 | "modelConfig": { 23 | "models": [ 24 | { 25 | "fieldName": "needPost", 26 | "type": "boolean", 27 | "description": "是否开启帖子功能", 28 | "defaultValue": true 29 | } 30 | ] 31 | } 32 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker3.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "src/main/java/com/yupi/springbootinit/config/CorsConfig.java", 7 | "condition": "needCors" 8 | } 9 | ] 10 | }, 11 | "modelConfig": { 12 | "models": [ 13 | { 14 | "fieldName": "needCors", 15 | "type": "boolean", 16 | "description": "是否开启跨域功能", 17 | "defaultValue": true 18 | } 19 | ] 20 | } 21 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker4.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "src/main/java/com/yupi/springbootinit/config/Knife4jConfig.java", 7 | "condition": "needDocs" 8 | } 9 | ] 10 | }, 11 | "modelConfig": { 12 | "models": [ 13 | { 14 | "fieldName": "needDocs", 15 | "type": "boolean", 16 | "description": "是否开启接口文档功能", 17 | "defaultValue": true 18 | } 19 | ] 20 | } 21 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker5.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "src/main/java/com/yupi/springbootinit/config/Knife4jConfig.java", 7 | "condition": "needDocs" 8 | } 9 | ] 10 | }, 11 | "modelConfig": { 12 | "modelGroupConfig": { 13 | "groupKey": "docsConfig", 14 | "groupName": "接口文档配置", 15 | "type": "DocsConfig", 16 | "description": "用于生成接口文档配置", 17 | "condition": "needDocs" 18 | }, 19 | "models": [ 20 | { 21 | "fieldName": "title", 22 | "type": "String", 23 | "description": "接口文档标题", 24 | "defaultValue": "接口文档", 25 | "replaceText": "接口文档" 26 | }, 27 | { 28 | "fieldName": "description", 29 | "type": "String", 30 | "description": "接口文档描述", 31 | "defaultValue": "springboot-init", 32 | "replaceText": "springboot-init" 33 | }, 34 | { 35 | "fieldName": "version", 36 | "type": "String", 37 | "description": "接口文档版本", 38 | "defaultValue": "1.0", 39 | "replaceText": "1.0" 40 | } 41 | ] 42 | } 43 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker6.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "src/main/resources/application.yml" 7 | } 8 | ] 9 | }, 10 | "modelConfig": { 11 | "modelGroupConfig": { 12 | "groupKey": "mysqlConfig", 13 | "groupName": "MySQL数据库配置", 14 | "type": "MysqlConfig", 15 | "description": "用于生成MySQL数据库配置" 16 | }, 17 | "models": [ 18 | { 19 | "fieldName": "url", 20 | "type": "String", 21 | "description": "地址", 22 | "defaultValue": "jdbc:mysql://localhost:3306/my_db", 23 | "replaceText": "jdbc:mysql://localhost:3306/my_db" 24 | }, 25 | { 26 | "fieldName": "username", 27 | "type": "String", 28 | "description": "用户名", 29 | "defaultValue": "root", 30 | "replaceText": "root" 31 | }, 32 | { 33 | "fieldName": "password", 34 | "type": "String", 35 | "description": "密码", 36 | "defaultValue": "123456", 37 | "replaceText": "123456" 38 | } 39 | ] 40 | } 41 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker7.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "src/main/resources/application.yml" 7 | }, 8 | { 9 | "path": "src/main/java/com/yupi/springbootinit/MainApplication.java" 10 | }, 11 | { 12 | "path": "pom.xml" 13 | } 14 | ] 15 | }, 16 | "modelConfig": { 17 | "models": [ 18 | { 19 | "fieldName": "needRedis", 20 | "type": "boolean", 21 | "description": "是否开启Redis功能", 22 | "defaultValue": true 23 | } 24 | ] 25 | } 26 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/examples/springboot-init/templateMaker8.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "fileConfig": { 4 | "files": [ 5 | { 6 | "path": "src/main/java/com/yupi/springbootinit/model/dto/post/PostEsDTO.java", 7 | "condition": "needPost && needEs" 8 | } 9 | ] 10 | }, 11 | "modelConfig": { 12 | "models": [ 13 | { 14 | "fieldName": "needEs", 15 | "type": "boolean", 16 | "description": "是否开启ES功能", 17 | "defaultValue": true 18 | } 19 | ] 20 | } 21 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "acm-template-pro-generator", 3 | "description": "ACM 示例模板生成器", 4 | "basePackage": "com.yupi", 5 | "version": "1.0", 6 | "author": "yupi", 7 | "createTime": "2023-11-22", 8 | "fileConfig": { 9 | "inputRootPath": ".source/acm-template-pro", 10 | "outputRootPath": "generated", 11 | "sourceRootPath": "C:/code/yuzi-generator/yuzi-generator-demo-projects/acm-template-pro", 12 | "type": "dir", 13 | "files": [ 14 | { 15 | "groupKey": "git", 16 | "groupName": "开源", 17 | "type": "group", 18 | "condition": "needGit", 19 | "files": [ 20 | { 21 | "inputPath": ".gitignore", 22 | "outputPath": ".gitignore", 23 | "type": "file", 24 | "generateType": "static" 25 | }, 26 | { 27 | "inputPath": "README.md", 28 | "outputPath": "README.md", 29 | "type": "file", 30 | "generateType": "static" 31 | } 32 | ] 33 | }, 34 | { 35 | "inputPath": "src/com/yupi/acm/MainTemplate.java.ftl", 36 | "outputPath": "src/com/yupi/acm/MainTemplate.java", 37 | "type": "file", 38 | "generateType": "dynamic" 39 | } 40 | ] 41 | }, 42 | "modelConfig": { 43 | "models": [ 44 | { 45 | "fieldName": "needGit", 46 | "type": "boolean", 47 | "description": "是否生成 .gitignore 文件", 48 | "defaultValue": true 49 | }, 50 | { 51 | "fieldName": "loop", 52 | "type": "boolean", 53 | "description": "是否生成循环", 54 | "defaultValue": false, 55 | "abbr": "l" 56 | }, 57 | { 58 | "groupKey": "mainTemplate", 59 | "groupName": "核心模板", 60 | "type": "MainTemplate", 61 | "description": "用于生成核心模板文件", 62 | "condition": "loop", 63 | "models": [ 64 | { 65 | "fieldName": "author", 66 | "type": "String", 67 | "description": "作者注释", 68 | "defaultValue": "yupi", 69 | "abbr": "a" 70 | }, 71 | { 72 | "fieldName": "outputText", 73 | "type": "String", 74 | "description": "输出信息", 75 | "defaultValue": "sum = ", 76 | "abbr": "o" 77 | } 78 | ] 79 | } 80 | ] 81 | } 82 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/README.md.ftl: -------------------------------------------------------------------------------- 1 | # ${name} 2 | 3 | > ${description} 4 | > 5 | > 作者:${author} 6 | > 7 | > 基于 [程序员鱼皮](https://yuyuanweb.feishu.cn/wiki/Abldw5WkjidySxkKxU2cQdAtnah) 的 [鱼籽代码生成器项目](https://github.com/liyupi/yuzi-generator) 制作,感谢您的使用! 8 | 9 | 可以通过命令行交互式输入的方式动态生成想要的项目代码 10 | 11 | ## 使用说明 12 | 13 | 执行项目根目录下的脚本文件: 14 | 15 | ``` 16 | generator <命令> <选项参数> 17 | ``` 18 | 19 | 示例命令: 20 | 21 | ``` 22 | generator generate <#list modelConfig.models as modelInfo>-${modelInfo.abbr} 23 | ``` 24 | 25 | ## 参数说明 26 | 27 | <#list modelConfig.models as modelInfo> 28 | ${modelInfo?index + 1})${modelInfo.fieldName} 29 | 30 | 类型:${modelInfo.type} 31 | 32 | 描述:${modelInfo.description} 33 | 34 | 默认值:${modelInfo.defaultValue?c} 35 | 36 | 缩写: -${modelInfo.abbr} 37 | 38 | 39 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/Main.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}; 2 | 3 | import ${basePackage}.cli.CommandExecutor; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | CommandExecutor commandExecutor = new CommandExecutor(); 9 | commandExecutor.doExecute(args); 10 | } 11 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/cli/CommandExecutor.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.cli; 2 | 3 | import ${basePackage}.cli.command.GenerateCommand; 4 | import ${basePackage}.cli.command.JsonGenerateCommand; 5 | import ${basePackage}.cli.command.ListCommand; 6 | import ${basePackage}.cli.command.ConfigCommand; 7 | import picocli.CommandLine; 8 | import picocli.CommandLine.Command; 9 | 10 | /** 11 | * 命令执行器 12 | */ 13 | @Command(name = "${name}", mixinStandardHelpOptions = true) 14 | public class CommandExecutor implements Runnable { 15 | 16 | private final CommandLine commandLine; 17 | 18 | { 19 | commandLine = new CommandLine(this) 20 | .addSubcommand(new GenerateCommand()) 21 | .addSubcommand(new ConfigCommand()) 22 | .addSubcommand(new ListCommand()) 23 | .addSubcommand(new JsonGenerateCommand()); 24 | } 25 | 26 | @Override 27 | public void run() { 28 | // 不输入子命令时,给出友好提示 29 | System.out.println("请输入具体命令,或者输入 --help 查看命令提示"); 30 | } 31 | 32 | /** 33 | * 执行命令 34 | * 35 | * @param args 36 | * @return 37 | */ 38 | public Integer doExecute(String[] args) { 39 | return commandLine.execute(args); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/cli/command/ConfigCommand.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.cli.command; 2 | 3 | import cn.hutool.core.util.ReflectUtil; 4 | import ${basePackage}.model.DataModel; 5 | import picocli.CommandLine.Command; 6 | 7 | import java.lang.reflect.Field; 8 | 9 | @Command(name = "config", description = "查看参数信息", mixinStandardHelpOptions = true) 10 | public class ConfigCommand implements Runnable { 11 | 12 | public void run() { 13 | // 实现 config 命令的逻辑 14 | System.out.println("查看参数信息"); 15 | 16 | Field[] fields = ReflectUtil.getFields(DataModel.class); 17 | 18 | // 遍历并打印每个字段的信息 19 | for (Field field : fields) { 20 | System.out.println("字段名称:" + field.getName()); 21 | System.out.println("字段类型:" + field.getType()); 22 | System.out.println("---"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/cli/command/JsonGenerateCommand.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.cli.command; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | import cn.hutool.json.JSONUtil; 5 | import ${basePackage}.generator.MainGenerator; 6 | import ${basePackage}.model.DataModel; 7 | import lombok.Data; 8 | import picocli.CommandLine.Command; 9 | import picocli.CommandLine.Option; 10 | 11 | import java.util.concurrent.Callable; 12 | 13 | /** 14 | * 读取 json 文件生成代码 15 | */ 16 | @Command(name = "json-generate", description = "读取 json 文件生成代码", mixinStandardHelpOptions = true) 17 | @Data 18 | public class JsonGenerateCommand implements Callable { 19 | 20 | @Option(names = {"-f", "--file"}, arity = "0..1", description = "json 文件路径", interactive = true, echo = true) 21 | private String filePath; 22 | 23 | public Integer call() throws Exception { 24 | // 读取 json 文件,转换为数据模型 25 | String jsonStr = FileUtil.readUtf8String(filePath); 26 | DataModel dataModel = JSONUtil.toBean(jsonStr, DataModel.class); 27 | MainGenerator.doGenerate(dataModel); 28 | return 0; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/cli/command/ListCommand.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.cli.command; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | import picocli.CommandLine.Command; 5 | 6 | import java.io.File; 7 | import java.util.List; 8 | 9 | @Command(name = "list", description = "查看文件列表", mixinStandardHelpOptions = true) 10 | public class ListCommand implements Runnable { 11 | 12 | public void run() { 13 | // 输入路径 14 | String inputPath = "${fileConfig.inputRootPath}"; 15 | List files = FileUtil.loopFiles(inputPath); 16 | for (File file : files) { 17 | System.out.println(file); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/generator/DynamicGenerator.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.generator; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | import freemarker.template.Configuration; 5 | import freemarker.template.Template; 6 | import freemarker.template.TemplateException; 7 | 8 | import java.io.File; 9 | import java.io.FileWriter; 10 | import java.io.IOException; 11 | import java.io.Writer; 12 | 13 | /** 14 | * 动态文件生成 15 | */ 16 | public class DynamicGenerator { 17 | 18 | /** 19 | * 生成文件 20 | * 21 | * @param inputPath 模板文件输入路径 22 | * @param outputPath 输出路径 23 | * @param model 数据模型 24 | * @throws IOException 25 | * @throws TemplateException 26 | */ 27 | public static void doGenerate(String inputPath, String outputPath, Object model) throws IOException, TemplateException { 28 | // new 出 Configuration 对象,参数为 FreeMarker 版本号 29 | Configuration configuration = new Configuration(Configuration.VERSION_2_3_32); 30 | 31 | // 指定模板文件所在的路径 32 | File templateDir = new File(inputPath).getParentFile(); 33 | configuration.setDirectoryForTemplateLoading(templateDir); 34 | 35 | // 设置模板文件使用的字符集 36 | configuration.setDefaultEncoding("utf-8"); 37 | 38 | // 创建模板对象,加载指定模板 39 | String templateName = new File(inputPath).getName(); 40 | Template template = configuration.getTemplate(templateName); 41 | 42 | // 文件不存在则创建文件和父目录 43 | if (!FileUtil.exist(outputPath)) { 44 | FileUtil.touch(outputPath); 45 | } 46 | 47 | // 生成 48 | Writer out = new FileWriter(outputPath); 49 | template.process(model, out); 50 | 51 | // 生成文件后别忘了关闭哦 52 | out.close(); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/generator/MainGenerator.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.generator; 2 | 3 | import com.yupi.model.DataModel; 4 | import freemarker.template.TemplateException; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | <#macro generateFile indent fileInfo> 10 | ${indent}inputPath = new File(inputRootPath, "${fileInfo.inputPath}").getAbsolutePath(); 11 | ${indent}outputPath = new File(outputRootPath, "${fileInfo.outputPath}").getAbsolutePath(); 12 | <#if fileInfo.generateType == "static"> 13 | ${indent}StaticGenerator.copyFilesByHutool(inputPath, outputPath); 14 | <#else> 15 | ${indent}DynamicGenerator.doGenerate(inputPath, outputPath, model); 16 | 17 | 18 | 19 | /** 20 | * 核心生成器 21 | */ 22 | public class MainGenerator { 23 | 24 | /** 25 | * 生成 26 | * 27 | * @param model 数据模型 28 | * @throws TemplateException 29 | * @throws IOException 30 | */ 31 | public static void doGenerate(DataModel model) throws TemplateException, IOException { 32 | String inputRootPath = "${fileConfig.inputRootPath}"; 33 | String outputRootPath = "${fileConfig.outputRootPath}"; 34 | 35 | String inputPath; 36 | String outputPath; 37 | 38 | <#-- 获取模型变量 --> 39 | <#list modelConfig.models as modelInfo> 40 | <#-- 有分组 --> 41 | <#if modelInfo.groupKey??> 42 | <#list modelInfo.models as subModelInfo> 43 | ${subModelInfo.type} ${subModelInfo.fieldName} = model.${modelInfo.groupKey}.${subModelInfo.fieldName}; 44 | 45 | <#else> 46 | ${modelInfo.type} ${modelInfo.fieldName} = model.${modelInfo.fieldName}; 47 | 48 | 49 | 50 | <#list fileConfig.files as fileInfo> 51 | <#if fileInfo.groupKey??> 52 | // groupKey = ${fileInfo.groupKey} 53 | <#if fileInfo.condition??> 54 | if (${fileInfo.condition}) { 55 | <#list fileInfo.files as fileInfo> 56 | <@generateFile fileInfo=fileInfo indent=" " /> 57 | 58 | } 59 | <#else> 60 | <#list fileInfo.files as fileInfo> 61 | <@generateFile fileInfo=fileInfo indent=" " /> 62 | 63 | 64 | <#else> 65 | <#if fileInfo.condition??> 66 | if(${fileInfo.condition}) { 67 | <@generateFile fileInfo=fileInfo indent=" " /> 68 | } 69 | <#else> 70 | <@generateFile fileInfo=fileInfo indent=" " /> 71 | 72 | 73 | 74 | } 75 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/generator/StaticGenerator.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.generator; 2 | 3 | import cn.hutool.core.io.FileUtil; 4 | 5 | /** 6 | * 静态文件生成 7 | */ 8 | public class StaticGenerator { 9 | 10 | /** 11 | * 拷贝文件(Hutool 实现,会将输入目录完整拷贝到输出目录下) 12 | * 13 | * @param inputPath 14 | * @param outputPath 15 | */ 16 | public static void copyFilesByHutool(String inputPath, String outputPath) { 17 | FileUtil.copy(inputPath, outputPath, false); 18 | } 19 | } -------------------------------------------------------------------------------- /yuzi-generator-maker/src/main/resources/templates/java/model/DataModel.java.ftl: -------------------------------------------------------------------------------- 1 | package ${basePackage}.model; 2 | 3 | import lombok.Data; 4 | 5 | <#macro generateModel indent modelInfo> 6 | <#if modelInfo.description??> 7 | ${indent}/** 8 | ${indent} * ${modelInfo.description} 9 | ${indent} */ 10 | 11 | ${indent}public ${modelInfo.type} ${modelInfo.fieldName}<#if modelInfo.defaultValue??> = ${modelInfo.defaultValue?c}; 12 | 13 | 14 | /** 15 | * 数据模型 16 | */ 17 | @Data 18 | public class DataModel { 19 | <#list modelConfig.models as modelInfo> 20 | 21 | <#-- 有分组 --> 22 | <#if modelInfo.groupKey??> 23 | /** 24 | * ${modelInfo.groupName} 25 | */ 26 | public ${modelInfo.type} ${modelInfo.groupKey} = new ${modelInfo.type}(); 27 | 28 | /** 29 | * ${modelInfo.description} 30 | */ 31 | @Data 32 | public static class ${modelInfo.type} { 33 | <#list modelInfo.models as modelInfo> 34 | <@generateModel indent=" " modelInfo=modelInfo /> 35 | 36 | } 37 | 38 | <#else> 39 | <#-- 无分组 --> 40 | <@generateModel indent=" " modelInfo=modelInfo /> 41 | 42 | 43 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/Dockerfile: -------------------------------------------------------------------------------- 1 | # Docker 镜像构建 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | FROM maven:3.8.1-jdk-8-slim as builder 5 | 6 | # Copy local code to the container image. 7 | WORKDIR /app 8 | COPY pom.xml . 9 | COPY src ./src 10 | 11 | # Build a release artifact. 12 | RUN mvn package -DskipTests 13 | 14 | # Run the web service on container startup. 15 | CMD ["java","-jar","/app/target/yuzi-generator-web-backend-0.0.1-SNAPSHOT.jar","--spring.profiles.active=prod"] -------------------------------------------------------------------------------- /yuzi-generator-web-backend/doc/swagger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyupi/yuzi-generator/a2a0edb2cbbb6a869196b6b8a85e6ad30bbb635c/yuzi-generator-web-backend/doc/swagger.png -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; 7 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | 10 | /** 11 | * 主类(项目启动入口) 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @SpringBootApplication 17 | @MapperScan("com.yupi.web.mapper") 18 | @EnableScheduling 19 | @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) 20 | public class MainApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(MainApplication.class, args); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/annotation/AuthCheck.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 权限校验 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface AuthCheck { 17 | 18 | /** 19 | * 必须有某个角色 20 | * 21 | * @return 22 | */ 23 | String mustRole() default ""; 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/aop/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.aop; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.aspectj.lang.ProceedingJoinPoint; 6 | import org.aspectj.lang.annotation.Around; 7 | import org.aspectj.lang.annotation.Aspect; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.util.StopWatch; 10 | import org.springframework.web.context.request.RequestAttributes; 11 | import org.springframework.web.context.request.RequestContextHolder; 12 | import org.springframework.web.context.request.ServletRequestAttributes; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | import java.util.UUID; 16 | 17 | /** 18 | * 请求响应日志 AOP 19 | * 20 | * @author 程序员鱼皮 21 | * @from 编程导航知识星球 22 | **/ 23 | @Aspect 24 | @Component 25 | @Slf4j 26 | public class LogInterceptor { 27 | 28 | /** 29 | * 执行拦截 30 | */ 31 | @Around("execution(* com.yupi.web.controller.*.*(..))") 32 | public Object doInterceptor(ProceedingJoinPoint point) throws Throwable { 33 | // 计时 34 | StopWatch stopWatch = new StopWatch(); 35 | stopWatch.start(); 36 | // 获取请求路径 37 | RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); 38 | HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); 39 | // 生成请求唯一 id 40 | String requestId = UUID.randomUUID().toString(); 41 | String url = httpServletRequest.getRequestURI(); 42 | // 获取请求参数 43 | Object[] args = point.getArgs(); 44 | String reqParam = "[" + StringUtils.join(args, ", ") + "]"; 45 | // 输出请求日志 46 | log.info("request start,id: {}, path: {}, ip: {}, params: {}", requestId, url, 47 | httpServletRequest.getRemoteHost(), reqParam); 48 | // 执行原方法 49 | Object result = point.proceed(); 50 | // 输出响应日志 51 | stopWatch.stop(); 52 | long totalTimeMillis = stopWatch.getTotalTimeMillis(); 53 | log.info("request end, id: {}, cost: {}ms", requestId, totalTimeMillis); 54 | return result; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/common/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.common; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 通用返回类 9 | * 10 | * @param 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class BaseResponse implements Serializable { 16 | 17 | private int code; 18 | 19 | private T data; 20 | 21 | private String message; 22 | 23 | public BaseResponse(int code, T data, String message) { 24 | this.code = code; 25 | this.data = data; 26 | this.message = message; 27 | } 28 | 29 | public BaseResponse(int code, T data) { 30 | this(code, data, ""); 31 | } 32 | 33 | public BaseResponse(ErrorCode errorCode) { 34 | this(errorCode.getCode(), null, errorCode.getMessage()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/common/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.common; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 删除请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class DeleteRequest implements Serializable { 15 | 16 | /** 17 | * id 18 | */ 19 | private Long id; 20 | 21 | private static final long serialVersionUID = 1L; 22 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/common/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.common; 2 | 3 | /** 4 | * 自定义错误码 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public enum ErrorCode { 10 | 11 | SUCCESS(0, "ok"), 12 | PARAMS_ERROR(40000, "请求参数错误"), 13 | NOT_LOGIN_ERROR(40100, "未登录"), 14 | NO_AUTH_ERROR(40101, "无权限"), 15 | NOT_FOUND_ERROR(40400, "请求数据不存在"), 16 | FORBIDDEN_ERROR(40300, "禁止访问"), 17 | SYSTEM_ERROR(50000, "系统内部异常"), 18 | OPERATION_ERROR(50001, "操作失败"); 19 | 20 | /** 21 | * 状态码 22 | */ 23 | private final int code; 24 | 25 | /** 26 | * 信息 27 | */ 28 | private final String message; 29 | 30 | ErrorCode(int code, String message) { 31 | this.code = code; 32 | this.message = message; 33 | } 34 | 35 | public int getCode() { 36 | return code; 37 | } 38 | 39 | public String getMessage() { 40 | return message; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/common/PageRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.common; 2 | 3 | import com.yupi.web.constant.CommonConstant; 4 | import lombok.Data; 5 | 6 | /** 7 | * 分页请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class PageRequest { 14 | 15 | /** 16 | * 当前页号 17 | */ 18 | private int current = 1; 19 | 20 | /** 21 | * 页面大小 22 | */ 23 | private int pageSize = 10; 24 | 25 | /** 26 | * 排序字段 27 | */ 28 | private String sortField; 29 | 30 | /** 31 | * 排序顺序(默认升序) 32 | */ 33 | private String sortOrder = CommonConstant.SORT_ORDER_ASC; 34 | } 35 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/common/ResultUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.common; 2 | 3 | /** 4 | * 返回工具类 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public class ResultUtils { 10 | 11 | /** 12 | * 成功 13 | * 14 | * @param data 15 | * @param 16 | * @return 17 | */ 18 | public static BaseResponse success(T data) { 19 | return new BaseResponse<>(0, data, "ok"); 20 | } 21 | 22 | /** 23 | * 失败 24 | * 25 | * @param errorCode 26 | * @return 27 | */ 28 | public static BaseResponse error(ErrorCode errorCode) { 29 | return new BaseResponse<>(errorCode); 30 | } 31 | 32 | /** 33 | * 失败 34 | * 35 | * @param code 36 | * @param message 37 | * @return 38 | */ 39 | public static BaseResponse error(int code, String message) { 40 | return new BaseResponse(code, null, message); 41 | } 42 | 43 | /** 44 | * 失败 45 | * 46 | * @param errorCode 47 | * @return 48 | */ 49 | public static BaseResponse error(ErrorCode errorCode, String message) { 50 | return new BaseResponse(errorCode.getCode(), null, message); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * 全局跨域配置 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Configuration 14 | public class CorsConfig implements WebMvcConfigurer { 15 | 16 | @Override 17 | public void addCorsMappings(CorsRegistry registry) { 18 | // 覆盖所有请求 19 | registry.addMapping("/**") 20 | // 允许发送 Cookie 21 | .allowCredentials(true) 22 | // 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突) 23 | .allowedOriginPatterns("*") 24 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 25 | .allowedHeaders("*") 26 | .exposedHeaders("*"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/config/CosClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.config; 2 | 3 | import com.qcloud.cos.COSClient; 4 | import com.qcloud.cos.ClientConfig; 5 | import com.qcloud.cos.auth.BasicCOSCredentials; 6 | import com.qcloud.cos.auth.COSCredentials; 7 | import com.qcloud.cos.region.Region; 8 | import lombok.Data; 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | /** 14 | * 腾讯云对象存储客户端 15 | * 16 | * @author 程序员鱼皮 17 | * @from 编程导航知识星球 18 | */ 19 | @Configuration 20 | @ConfigurationProperties(prefix = "cos.client") 21 | @Data 22 | public class CosClientConfig { 23 | 24 | /** 25 | * accessKey 26 | */ 27 | private String accessKey; 28 | 29 | /** 30 | * secretKey 31 | */ 32 | private String secretKey; 33 | 34 | /** 35 | * 区域 36 | */ 37 | private String region; 38 | 39 | /** 40 | * 桶名 41 | */ 42 | private String bucket; 43 | 44 | @Bean 45 | public COSClient cosClient() { 46 | // 初始化用户身份信息(secretId, secretKey) 47 | COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey); 48 | // 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224 49 | ClientConfig clientConfig = new ClientConfig(new Region(region)); 50 | // 生成cos客户端 51 | return new COSClient(cred, clientConfig); 52 | } 53 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/config/JsonConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.jackson.JsonComponent; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 9 | 10 | /** 11 | * Spring MVC Json 配置 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @JsonComponent 17 | public class JsonConfig { 18 | 19 | /** 20 | * 添加 Long 转 json 精度丢失的配置 21 | */ 22 | @Bean 23 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 24 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 25 | SimpleModule module = new SimpleModule(); 26 | module.addSerializer(Long.class, ToStringSerializer.instance); 27 | module.addSerializer(Long.TYPE, ToStringSerializer.instance); 28 | objectMapper.registerModule(module); 29 | return objectMapper; 30 | } 31 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * MyBatis Plus 配置 12 | * 13 | * @author https://github.com/liyupi 14 | */ 15 | @Configuration 16 | @MapperScan("com.yupi.web.mapper") 17 | public class MyBatisPlusConfig { 18 | 19 | /** 20 | * 拦截器配置 21 | * 22 | * @return 23 | */ 24 | @Bean 25 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 26 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 27 | // 分页插件 28 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 29 | return interceptor; 30 | } 31 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/config/XxlJobConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.config; 2 | 3 | import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * xxl-job config 11 | */ 12 | @Configuration 13 | @Slf4j 14 | public class XxlJobConfig { 15 | 16 | @Value("${xxl.job.admin.addresses}") 17 | private String adminAddresses; 18 | 19 | @Value("${xxl.job.accessToken}") 20 | private String accessToken; 21 | 22 | @Value("${xxl.job.executor.appname}") 23 | private String appname; 24 | 25 | @Value("${xxl.job.executor.address}") 26 | private String address; 27 | 28 | @Value("${xxl.job.executor.ip}") 29 | private String ip; 30 | 31 | @Value("${xxl.job.executor.port}") 32 | private int port; 33 | 34 | @Value("${xxl.job.executor.logpath}") 35 | private String logPath; 36 | 37 | @Value("${xxl.job.executor.logretentiondays}") 38 | private int logRetentionDays; 39 | 40 | 41 | @Bean 42 | public XxlJobSpringExecutor xxlJobExecutor() { 43 | log.info(">>>>>>>>>>> xxl-job config init."); 44 | XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); 45 | xxlJobSpringExecutor.setAdminAddresses(adminAddresses); 46 | xxlJobSpringExecutor.setAppname(appname); 47 | xxlJobSpringExecutor.setAddress(address); 48 | xxlJobSpringExecutor.setIp(ip); 49 | xxlJobSpringExecutor.setPort(port); 50 | xxlJobSpringExecutor.setAccessToken(accessToken); 51 | xxlJobSpringExecutor.setLogPath(logPath); 52 | xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); 53 | 54 | return xxlJobSpringExecutor; 55 | } 56 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.constant; 2 | 3 | /** 4 | * 通用常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public interface CommonConstant { 10 | 11 | /** 12 | * 升序 13 | */ 14 | String SORT_ORDER_ASC = "ascend"; 15 | 16 | /** 17 | * 降序 18 | */ 19 | String SORT_ORDER_DESC = " descend"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/constant/FileConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.constant; 2 | 3 | /** 4 | * 文件常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public interface FileConstant { 10 | 11 | /** 12 | * COS 访问地址 13 | * todo 需替换配置 14 | */ 15 | String COS_HOST = "https://yupi.icu"; 16 | } 17 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.constant; 2 | 3 | /** 4 | * 用户常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public interface UserConstant { 10 | 11 | /** 12 | * 用户登录态键 13 | */ 14 | String USER_LOGIN_STATE = "user_login"; 15 | 16 | // region 权限 17 | 18 | /** 19 | * 默认角色 20 | */ 21 | String DEFAULT_ROLE = "user"; 22 | 23 | /** 24 | * 管理员角色 25 | */ 26 | String ADMIN_ROLE = "admin"; 27 | 28 | /** 29 | * 被封号 30 | */ 31 | String BAN_ROLE = "ban"; 32 | 33 | // endregion 34 | } 35 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/controller/HealthController.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * 健康检查 10 | */ 11 | @RestController 12 | @RequestMapping("/health") 13 | @Slf4j 14 | public class HealthController { 15 | 16 | @GetMapping 17 | public String healthCheck() { 18 | return "ok"; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/exception/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.exception; 2 | 3 | import com.yupi.web.common.ErrorCode; 4 | 5 | /** 6 | * 自定义异常类 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class BusinessException extends RuntimeException { 12 | 13 | /** 14 | * 错误码 15 | */ 16 | private final int code; 17 | 18 | public BusinessException(int code, String message) { 19 | super(message); 20 | this.code = code; 21 | } 22 | 23 | public BusinessException(ErrorCode errorCode) { 24 | super(errorCode.getMessage()); 25 | this.code = errorCode.getCode(); 26 | } 27 | 28 | public BusinessException(ErrorCode errorCode, String message) { 29 | super(message); 30 | this.code = errorCode.getCode(); 31 | } 32 | 33 | public int getCode() { 34 | return code; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.exception; 2 | 3 | import com.yupi.web.common.BaseResponse; 4 | import com.yupi.web.common.ErrorCode; 5 | import com.yupi.web.common.ResultUtils; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.RestControllerAdvice; 9 | 10 | /** 11 | * 全局异常处理器 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @RestControllerAdvice 17 | @Slf4j 18 | public class GlobalExceptionHandler { 19 | 20 | @ExceptionHandler(BusinessException.class) 21 | public BaseResponse businessExceptionHandler(BusinessException e) { 22 | log.error("BusinessException", e); 23 | return ResultUtils.error(e.getCode(), e.getMessage()); 24 | } 25 | 26 | @ExceptionHandler(RuntimeException.class) 27 | public BaseResponse runtimeExceptionHandler(RuntimeException e) { 28 | log.error("RuntimeException", e); 29 | return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/exception/ThrowUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.exception; 2 | 3 | import com.yupi.web.common.ErrorCode; 4 | 5 | /** 6 | * 抛异常工具类 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class ThrowUtils { 12 | 13 | /** 14 | * 条件成立则抛异常 15 | * 16 | * @param condition 17 | * @param runtimeException 18 | */ 19 | public static void throwIf(boolean condition, RuntimeException runtimeException) { 20 | if (condition) { 21 | throw runtimeException; 22 | } 23 | } 24 | 25 | /** 26 | * 条件成立则抛异常 27 | * 28 | * @param condition 29 | * @param errorCode 30 | */ 31 | public static void throwIf(boolean condition, ErrorCode errorCode) { 32 | throwIf(condition, new BusinessException(errorCode)); 33 | } 34 | 35 | /** 36 | * 条件成立则抛异常 37 | * 38 | * @param condition 39 | * @param errorCode 40 | * @param message 41 | */ 42 | public static void throwIf(boolean condition, ErrorCode errorCode, String message) { 43 | throwIf(condition, new BusinessException(errorCode, message)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/job/ClearCosJobHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.job; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.xxl.job.core.handler.annotation.XxlJob; 5 | import com.yupi.web.manager.CosManager; 6 | import com.yupi.web.mapper.GeneratorMapper; 7 | import com.yupi.web.model.entity.Generator; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.List; 13 | import java.util.stream.Collectors; 14 | 15 | @Component 16 | @Slf4j 17 | public class ClearCosJobHandler { 18 | 19 | @Resource 20 | private CosManager cosManager; 21 | 22 | @Resource 23 | private GeneratorMapper generatorMapper; 24 | 25 | /** 26 | * 每天执行 27 | * 28 | * @throws Exception 29 | */ 30 | @XxlJob("clearCosJobHandler") 31 | public void clearCosJobHandler() throws Exception { 32 | log.info("clearCosJobHandler start"); 33 | // 编写业务逻辑 34 | // 1. 包括用户上传的模板制作文件(generator_make_template) 35 | cosManager.deleteDir("/generator_make_template/"); 36 | 37 | // 2. 已删除的代码生成器对应的产物包文件(generator_dist)。 38 | List generatorList = generatorMapper.listDeletedGenerator(); 39 | List keyList = generatorList.stream().map(Generator::getDistPath) 40 | .filter(StrUtil::isNotBlank) 41 | // 移除 '/' 前缀 42 | .map(distPath -> distPath.substring(1)) 43 | .collect(Collectors.toList()); 44 | 45 | cosManager.deleteObjects(keyList); 46 | log.info("clearCosJobHandler end"); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/manager/CacheManager.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.manager; 2 | 3 | import com.github.benmanes.caffeine.cache.Cache; 4 | import com.github.benmanes.caffeine.cache.Caffeine; 5 | import org.springframework.data.redis.core.RedisTemplate; 6 | import org.springframework.data.redis.serializer.StringRedisSerializer; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | /** 13 | * 多级缓存 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | */ 18 | @Component 19 | public class CacheManager { 20 | 21 | @Resource 22 | private RedisTemplate redisTemplate; 23 | 24 | /** 25 | * 本地缓存 26 | */ 27 | Cache localCache = Caffeine.newBuilder() 28 | .expireAfterWrite(100, TimeUnit.MINUTES) 29 | .maximumSize(10_000) 30 | .build(); 31 | 32 | /** 33 | * 写入缓存 34 | * 35 | * @param key 36 | * @param value 37 | */ 38 | public void put(String key, Object value) { 39 | localCache.put(key, value); 40 | redisTemplate.opsForValue().set(key, value, 100, TimeUnit.MINUTES); 41 | } 42 | 43 | /** 44 | * 读缓存 45 | * 46 | * @param key 47 | * @return 48 | */ 49 | public Object get(String key) { 50 | // 先从本地缓存中获取 51 | Object value = localCache.getIfPresent(key); 52 | if (value != null) { 53 | return value; 54 | } 55 | 56 | // 本地缓存未命中,尝试从 Redis 获取 57 | value = redisTemplate.opsForValue().get(key); 58 | if (value != null) { 59 | // 将 redis 的值写入到本地缓存 60 | localCache.put(key, value); 61 | } 62 | 63 | return value; 64 | } 65 | 66 | /** 67 | * 一处缓存 68 | * 69 | * @param key 70 | */ 71 | public void delete(String key) { 72 | localCache.invalidate(key); 73 | redisTemplate.delete(key); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/mapper/GeneratorMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.web.model.entity.Generator; 5 | import org.apache.ibatis.annotations.Select; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author 李鱼皮 11 | * @description 针对表【generator(代码生成器)】的数据库操作Mapper 12 | * @createDate 2023-12-27 20:49:39 13 | * @Entity com.yupi.web.model.entity.Generator 14 | */ 15 | public interface GeneratorMapper extends BaseMapper { 16 | @Select("SELECT id, distPath FROM generator WHERE isDelete = 1") 17 | List listDeletedGenerator(); 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.web.model.entity.User; 5 | 6 | /** 7 | * 用户数据库操作 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | public interface UserMapper extends BaseMapper { 13 | 14 | } 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/file/UploadFileRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.file; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 文件上传请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UploadFileRequest implements Serializable { 15 | 16 | /** 17 | * 业务 18 | */ 19 | private String biz; 20 | 21 | private static final long serialVersionUID = 1L; 22 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import com.yupi.maker.meta.Meta; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | /** 10 | * 创建请求 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @Data 16 | public class GeneratorAddRequest implements Serializable { 17 | 18 | /** 19 | * 名称 20 | */ 21 | private String name; 22 | 23 | /** 24 | * 描述 25 | */ 26 | private String description; 27 | 28 | /** 29 | * 基础包 30 | */ 31 | private String basePackage; 32 | 33 | /** 34 | * 版本 35 | */ 36 | private String version; 37 | 38 | /** 39 | * 作者 40 | */ 41 | private String author; 42 | 43 | /** 44 | * 标签列表(json 数组) 45 | */ 46 | private List tags; 47 | 48 | /** 49 | * 图片 50 | */ 51 | private String picture; 52 | 53 | /** 54 | * 文件配置(json字符串) 55 | */ 56 | private Meta.FileConfig fileConfig; 57 | 58 | /** 59 | * 模型配置(json字符串) 60 | */ 61 | private Meta.ModelConfig modelConfig; 62 | 63 | /** 64 | * 代码生成器产物路径 65 | */ 66 | private String distPath; 67 | 68 | /** 69 | * 状态 70 | */ 71 | private Integer status; 72 | 73 | private static final long serialVersionUID = 1L; 74 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorCacheRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 缓存代码生成器请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class GeneratorCacheRequest implements Serializable { 15 | 16 | /** 17 | * 生成器的 id 18 | */ 19 | private Long id; 20 | 21 | private static final long serialVersionUID = 1L; 22 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorEditRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import com.yupi.maker.meta.Meta; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | /** 10 | * 编辑请求 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @Data 16 | public class GeneratorEditRequest implements Serializable { 17 | 18 | /** 19 | * id 20 | */ 21 | private Long id; 22 | 23 | /** 24 | * 名称 25 | */ 26 | private String name; 27 | 28 | /** 29 | * 描述 30 | */ 31 | private String description; 32 | 33 | /** 34 | * 基础包 35 | */ 36 | private String basePackage; 37 | 38 | /** 39 | * 版本 40 | */ 41 | private String version; 42 | 43 | /** 44 | * 作者 45 | */ 46 | private String author; 47 | 48 | /** 49 | * 标签列表(json 数组) 50 | */ 51 | private List tags; 52 | 53 | /** 54 | * 图片 55 | */ 56 | private String picture; 57 | 58 | /** 59 | * 文件配置(json字符串) 60 | */ 61 | private Meta.FileConfig fileConfig; 62 | 63 | /** 64 | * 模型配置(json字符串) 65 | */ 66 | private Meta.ModelConfig modelConfig; 67 | 68 | /** 69 | * 代码生成器产物路径 70 | */ 71 | private String distPath; 72 | 73 | private static final long serialVersionUID = 1L; 74 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorMakeRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import com.yupi.maker.meta.Meta; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 制作代码生成器请求 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class GeneratorMakeRequest implements Serializable { 16 | 17 | /** 18 | * 元信息 19 | */ 20 | private Meta meta; 21 | 22 | /** 23 | * 模板文件压缩包路径 24 | */ 25 | private String zipFilePath; 26 | 27 | private static final long serialVersionUID = 1L; 28 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import com.yupi.web.common.PageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | /** 11 | * 查询请求 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @EqualsAndHashCode(callSuper = true) 17 | @Data 18 | public class GeneratorQueryRequest extends PageRequest implements Serializable { 19 | 20 | /** 21 | * id 22 | */ 23 | private Long id; 24 | 25 | /** 26 | * id 27 | */ 28 | private Long notId; 29 | 30 | /** 31 | * 搜索词 32 | */ 33 | private String searchText; 34 | 35 | /** 36 | * 标签列表 37 | */ 38 | private List tags; 39 | 40 | /** 41 | * 至少有一个标签 42 | */ 43 | private List orTags; 44 | 45 | /** 46 | * 创建用户 id 47 | */ 48 | private Long userId; 49 | 50 | /** 51 | * 名称 52 | */ 53 | private String name; 54 | 55 | /** 56 | * 描述 57 | */ 58 | private String description; 59 | 60 | /** 61 | * 基础包 62 | */ 63 | private String basePackage; 64 | 65 | /** 66 | * 版本 67 | */ 68 | private String version; 69 | 70 | /** 71 | * 作者 72 | */ 73 | private String author; 74 | 75 | 76 | /** 77 | * 代码生成器产物路径 78 | */ 79 | private String distPath; 80 | 81 | /** 82 | * 状态 83 | */ 84 | private Integer status; 85 | 86 | private static final long serialVersionUID = 1L; 87 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import com.yupi.maker.meta.Meta; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | /** 10 | * 更新请求 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @Data 16 | public class GeneratorUpdateRequest implements Serializable { 17 | 18 | /** 19 | * id 20 | */ 21 | private Long id; 22 | 23 | /** 24 | * 名称 25 | */ 26 | private String name; 27 | 28 | /** 29 | * 描述 30 | */ 31 | private String description; 32 | 33 | /** 34 | * 基础包 35 | */ 36 | private String basePackage; 37 | 38 | /** 39 | * 版本 40 | */ 41 | private String version; 42 | 43 | /** 44 | * 作者 45 | */ 46 | private String author; 47 | 48 | /** 49 | * 标签列表(json 数组) 50 | */ 51 | private List tags; 52 | 53 | /** 54 | * 图片 55 | */ 56 | private String picture; 57 | 58 | /** 59 | * 文件配置(json字符串) 60 | */ 61 | private Meta.FileConfig fileConfig; 62 | 63 | /** 64 | * 模型配置(json字符串) 65 | */ 66 | private Meta.ModelConfig modelConfig; 67 | 68 | /** 69 | * 代码生成器产物路径 70 | */ 71 | private String distPath; 72 | 73 | /** 74 | * 状态 75 | */ 76 | private Integer status; 77 | 78 | private static final long serialVersionUID = 1L; 79 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/generator/GeneratorUseRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.generator; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Map; 7 | 8 | /** 9 | * 使用代码生成器请求 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class GeneratorUseRequest implements Serializable { 16 | 17 | /** 18 | * 生成器的 id 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 数据模型 24 | */ 25 | private Map dataModel; 26 | 27 | private static final long serialVersionUID = 1L; 28 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/user/UserAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户创建请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UserAddRequest implements Serializable { 15 | 16 | /** 17 | * 用户昵称 18 | */ 19 | private String userName; 20 | 21 | /** 22 | * 账号 23 | */ 24 | private String userAccount; 25 | 26 | /** 27 | * 用户头像 28 | */ 29 | private String userAvatar; 30 | 31 | /** 32 | * 用户角色: user, admin 33 | */ 34 | private String userRole; 35 | 36 | private static final long serialVersionUID = 1L; 37 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/user/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户登录请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UserLoginRequest implements Serializable { 15 | 16 | private static final long serialVersionUID = 3191241716373120793L; 17 | 18 | private String userAccount; 19 | 20 | private String userPassword; 21 | } 22 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/user/UserQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.user; 2 | 3 | import com.yupi.web.common.PageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * 用户查询请求 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @EqualsAndHashCode(callSuper = true) 16 | @Data 17 | public class UserQueryRequest extends PageRequest implements Serializable { 18 | /** 19 | * id 20 | */ 21 | private Long id; 22 | 23 | /** 24 | * 用户昵称 25 | */ 26 | private String userName; 27 | 28 | /** 29 | * 简介 30 | */ 31 | private String userProfile; 32 | 33 | /** 34 | * 用户角色:user/admin/ban 35 | */ 36 | private String userRole; 37 | 38 | private static final long serialVersionUID = 1L; 39 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/user/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户注册请求体 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UserRegisterRequest implements Serializable { 15 | 16 | private static final long serialVersionUID = 3191241716373120793L; 17 | 18 | private String userAccount; 19 | 20 | private String userPassword; 21 | 22 | private String checkPassword; 23 | } 24 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/user/UserUpdateMyRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户更新个人信息请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UserUpdateMyRequest implements Serializable { 15 | 16 | /** 17 | * 用户昵称 18 | */ 19 | private String userName; 20 | 21 | /** 22 | * 用户头像 23 | */ 24 | private String userAvatar; 25 | 26 | /** 27 | * 简介 28 | */ 29 | private String userProfile; 30 | 31 | private static final long serialVersionUID = 1L; 32 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/dto/user/UserUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户更新请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UserUpdateRequest implements Serializable { 15 | /** 16 | * id 17 | */ 18 | private Long id; 19 | 20 | /** 21 | * 用户昵称 22 | */ 23 | private String userName; 24 | 25 | /** 26 | * 用户头像 27 | */ 28 | private String userAvatar; 29 | 30 | /** 31 | * 简介 32 | */ 33 | private String userProfile; 34 | 35 | /** 36 | * 用户角色:user/admin/ban 37 | */ 38 | private String userRole; 39 | 40 | private static final long serialVersionUID = 1L; 41 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/entity/Generator.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * 代码生成器 11 | * 12 | * @TableName generator 13 | */ 14 | @TableName(value = "generator") 15 | @Data 16 | public class Generator implements Serializable { 17 | /** 18 | * id 19 | */ 20 | @TableId(type = IdType.AUTO) 21 | private Long id; 22 | 23 | /** 24 | * 名称 25 | */ 26 | private String name; 27 | 28 | /** 29 | * 描述 30 | */ 31 | private String description; 32 | 33 | /** 34 | * 基础包 35 | */ 36 | private String basePackage; 37 | 38 | /** 39 | * 版本 40 | */ 41 | private String version; 42 | 43 | /** 44 | * 作者 45 | */ 46 | private String author; 47 | 48 | /** 49 | * 标签列表(json 数组) 50 | */ 51 | private String tags; 52 | 53 | /** 54 | * 图片 55 | */ 56 | private String picture; 57 | 58 | /** 59 | * 文件配置(json字符串) 60 | */ 61 | private String fileConfig; 62 | 63 | /** 64 | * 模型配置(json字符串) 65 | */ 66 | private String modelConfig; 67 | 68 | /** 69 | * 代码生成器产物路径 70 | */ 71 | private String distPath; 72 | 73 | /** 74 | * 状态 75 | */ 76 | private Integer status; 77 | 78 | /** 79 | * 创建用户 id 80 | */ 81 | private Long userId; 82 | 83 | /** 84 | * 创建时间 85 | */ 86 | private Date createTime; 87 | 88 | /** 89 | * 更新时间 90 | */ 91 | private Date updateTime; 92 | 93 | /** 94 | * 是否删除 95 | */ 96 | @TableLogic 97 | private Integer isDelete; 98 | 99 | @TableField(exist = false) 100 | private static final long serialVersionUID = 1L; 101 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * 用户 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @TableName(value = "user") 16 | @Data 17 | public class User implements Serializable { 18 | 19 | /** 20 | * id 21 | */ 22 | @TableId(type = IdType.ASSIGN_ID) 23 | private Long id; 24 | 25 | /** 26 | * 用户账号 27 | */ 28 | private String userAccount; 29 | 30 | /** 31 | * 用户密码 32 | */ 33 | private String userPassword; 34 | 35 | /** 36 | * 用户昵称 37 | */ 38 | private String userName; 39 | 40 | /** 41 | * 用户头像 42 | */ 43 | private String userAvatar; 44 | 45 | /** 46 | * 用户简介 47 | */ 48 | private String userProfile; 49 | 50 | /** 51 | * 用户角色:user/admin/ban 52 | */ 53 | private String userRole; 54 | 55 | /** 56 | * 创建时间 57 | */ 58 | private Date createTime; 59 | 60 | /** 61 | * 更新时间 62 | */ 63 | private Date updateTime; 64 | 65 | /** 66 | * 是否删除 67 | */ 68 | @TableLogic 69 | private Integer isDelete; 70 | 71 | @TableField(exist = false) 72 | private static final long serialVersionUID = 1L; 73 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/enums/FileUploadBizEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.enums; 2 | 3 | import org.apache.commons.lang3.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * 文件上传业务类型枚举 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | public enum FileUploadBizEnum { 16 | 17 | USER_AVATAR("用户头像", "user_avatar"), 18 | GENERATOR_PICTURE("生成器图片", "generator_picture"), 19 | GENERATOR_DIST("生成器产物包", "generator_dist"), 20 | GENERATOR_MAKE_TEMPLATE("生成器制作模板文件", "generator_make_template"); 21 | 22 | 23 | private final String text; 24 | 25 | private final String value; 26 | 27 | FileUploadBizEnum(String text, String value) { 28 | this.text = text; 29 | this.value = value; 30 | } 31 | 32 | /** 33 | * 获取值列表 34 | * 35 | * @return 36 | */ 37 | public static List getValues() { 38 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 39 | } 40 | 41 | /** 42 | * 根据 value 获取枚举 43 | * 44 | * @param value 45 | * @return 46 | */ 47 | public static FileUploadBizEnum getEnumByValue(String value) { 48 | if (ObjectUtils.isEmpty(value)) { 49 | return null; 50 | } 51 | for (FileUploadBizEnum anEnum : FileUploadBizEnum.values()) { 52 | if (anEnum.value.equals(value)) { 53 | return anEnum; 54 | } 55 | } 56 | return null; 57 | } 58 | 59 | public String getValue() { 60 | return value; 61 | } 62 | 63 | public String getText() { 64 | return text; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/enums/UserRoleEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.enums; 2 | 3 | import org.apache.commons.lang3.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * 用户角色枚举 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | public enum UserRoleEnum { 16 | 17 | USER("用户", "user"), 18 | ADMIN("管理员", "admin"), 19 | BAN("被封号", "ban"); 20 | 21 | private final String text; 22 | 23 | private final String value; 24 | 25 | UserRoleEnum(String text, String value) { 26 | this.text = text; 27 | this.value = value; 28 | } 29 | 30 | /** 31 | * 获取值列表 32 | * 33 | * @return 34 | */ 35 | public static List getValues() { 36 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 37 | } 38 | 39 | /** 40 | * 根据 value 获取枚举 41 | * 42 | * @param value 43 | * @return 44 | */ 45 | public static UserRoleEnum getEnumByValue(String value) { 46 | if (ObjectUtils.isEmpty(value)) { 47 | return null; 48 | } 49 | for (UserRoleEnum anEnum : UserRoleEnum.values()) { 50 | if (anEnum.value.equals(value)) { 51 | return anEnum; 52 | } 53 | } 54 | return null; 55 | } 56 | 57 | public String getValue() { 58 | return value; 59 | } 60 | 61 | public String getText() { 62 | return text; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/vo/LoginUserVO.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | /** 9 | * 已登录用户视图(脱敏) 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | **/ 14 | @Data 15 | public class LoginUserVO implements Serializable { 16 | 17 | /** 18 | * 用户 id 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 用户昵称 24 | */ 25 | private String userName; 26 | 27 | /** 28 | * 用户头像 29 | */ 30 | private String userAvatar; 31 | 32 | /** 33 | * 用户简介 34 | */ 35 | private String userProfile; 36 | 37 | /** 38 | * 用户角色:user/admin/ban 39 | */ 40 | private String userRole; 41 | 42 | /** 43 | * 创建时间 44 | */ 45 | private Date createTime; 46 | 47 | /** 48 | * 更新时间 49 | */ 50 | private Date updateTime; 51 | 52 | private static final long serialVersionUID = 1L; 53 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/model/vo/UserVO.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.model.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | /** 9 | * 用户视图(脱敏) 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class UserVO implements Serializable { 16 | 17 | /** 18 | * id 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 用户昵称 24 | */ 25 | private String userName; 26 | 27 | /** 28 | * 用户头像 29 | */ 30 | private String userAvatar; 31 | 32 | /** 33 | * 用户简介 34 | */ 35 | private String userProfile; 36 | 37 | /** 38 | * 用户角色:user/admin/ban 39 | */ 40 | private String userRole; 41 | 42 | /** 43 | * 创建时间 44 | */ 45 | private Date createTime; 46 | 47 | private static final long serialVersionUID = 1L; 48 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/service/GeneratorService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.yupi.web.model.dto.generator.GeneratorQueryRequest; 7 | import com.yupi.web.model.entity.Generator; 8 | import com.yupi.web.model.vo.GeneratorVO; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | 12 | /** 13 | * 帖子服务 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | */ 18 | public interface GeneratorService extends IService { 19 | 20 | /** 21 | * 校验 22 | * 23 | * @param generator 24 | * @param add 25 | */ 26 | void validGenerator(Generator generator, boolean add); 27 | 28 | /** 29 | * 获取查询条件 30 | * 31 | * @param generatorQueryRequest 32 | * @return 33 | */ 34 | QueryWrapper getQueryWrapper(GeneratorQueryRequest generatorQueryRequest); 35 | 36 | /** 37 | * 获取帖子封装 38 | * 39 | * @param generator 40 | * @param request 41 | * @return 42 | */ 43 | GeneratorVO getGeneratorVO(Generator generator, HttpServletRequest request); 44 | 45 | /** 46 | * 分页获取帖子封装 47 | * 48 | * @param generatorPage 49 | * @param request 50 | * @return 51 | */ 52 | Page getGeneratorVOPage(Page generatorPage, HttpServletRequest request); 53 | } 54 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/utils/SpringContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.utils; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import org.springframework.beans.BeansException; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.ApplicationContextAware; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Spring 上下文获取工具 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @Component 16 | public class SpringContextUtils implements ApplicationContextAware { 17 | 18 | private static ApplicationContext applicationContext; 19 | 20 | @Override 21 | public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException { 22 | SpringContextUtils.applicationContext = applicationContext; 23 | } 24 | 25 | /** 26 | * 通过名称获取 Bean 27 | * 28 | * @param beanName 29 | * @return 30 | */ 31 | public static Object getBean(String beanName) { 32 | return applicationContext.getBean(beanName); 33 | } 34 | 35 | /** 36 | * 通过 class 获取 Bean 37 | * 38 | * @param beanClass 39 | * @param 40 | * @return 41 | */ 42 | public static T getBean(Class beanClass) { 43 | return applicationContext.getBean(beanClass); 44 | } 45 | 46 | /** 47 | * 通过名称和类型获取 Bean 48 | * 49 | * @param beanName 50 | * @param beanClass 51 | * @param 52 | * @return 53 | */ 54 | public static T getBean(String beanName, Class beanClass) { 55 | return applicationContext.getBean(beanName, beanClass); 56 | } 57 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/utils/SqlUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.utils; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | /** 6 | * SQL 工具 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class SqlUtils { 12 | 13 | /** 14 | * 校验排序字段是否合法(防止 SQL 注入) 15 | * 16 | * @param sortField 17 | * @return 18 | */ 19 | public static boolean validSortField(String sortField) { 20 | if (StringUtils.isBlank(sortField)) { 21 | return false; 22 | } 23 | return !StringUtils.containsAny(sortField, "=", "(", ")", " "); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/java/com/yupi/web/vertx/VertxManager.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.vertx; 2 | 3 | import com.yupi.web.manager.CacheManager; 4 | import io.vertx.core.Verticle; 5 | import io.vertx.core.Vertx; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.annotation.PostConstruct; 9 | import javax.annotation.Resource; 10 | 11 | @Component 12 | public class VertxManager { 13 | 14 | @Resource 15 | private CacheManager cacheManager; 16 | 17 | @PostConstruct 18 | public void init() { 19 | Vertx vertx = Vertx.vertx(); 20 | Verticle myVerticle = new MainVerticle(cacheManager); 21 | vertx.deployVerticle(myVerticle); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "cos.client.accessKey", 5 | "type": "java.lang.String", 6 | "description": "Description for cos.client.accessKey." 7 | }, 8 | { 9 | "name": "cos.client.secretKey", 10 | "type": "java.lang.String", 11 | "description": "Description for cos.client.secretKey." 12 | }, 13 | { 14 | "name": "cos.client.region", 15 | "type": "java.lang.String", 16 | "description": "Description for cos.client.region." 17 | }, 18 | { 19 | "name": "cos.client.bucket", 20 | "type": "java.lang.String", 21 | "description": "Description for cos.client.bucket." 22 | }, 23 | { 24 | "name": "wx.open.appId", 25 | "type": "java.lang.String", 26 | "description": "Description for wx.open.appId." 27 | }, 28 | { 29 | "name": "wx.open.appSecret", 30 | "type": "java.lang.String", 31 | "description": "Description for wx.open.appSecret." 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | # 线上配置文件 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | server: 5 | port: 8101 6 | spring: 7 | # 数据库配置 8 | # todo 需替换配置 9 | datasource: 10 | driver-class-name: com.mysql.cj.jdbc.Driver 11 | url: jdbc:mysql://localhost:3306/my_db 12 | username: root 13 | password: 123456 14 | # Redis 配置 15 | # todo 需替换配置 16 | redis: 17 | database: 1 18 | host: localhost 19 | port: 6379 20 | timeout: 5000 21 | password: 123456 22 | mybatis-plus: 23 | configuration: 24 | # 生产环境关闭日志 25 | log-impl: '' 26 | # 接口文档配置 27 | knife4j: 28 | basic: 29 | enable: true 30 | username: root 31 | password: 123456 -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | by 程序员鱼皮:https://github.com/liyupi 2 | 可能是最好的编程学习圈子:https://yupi.icu 3 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/resources/mapper/GeneratorMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | id 28 | ,name,description, 29 | basePackage,version,author, 30 | tags,picture,fileConfig, 31 | modelConfig,distPath,status, 32 | userId,createTime,updateTime, 33 | isDelete 34 | 35 | 36 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id 21 | , 22 | userName,userAvatar,userProfile, 23 | userRole,createTime,updateTime,isDelete 24 | 25 | 26 | -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/test/java/com/yupi/web/job/ClearCosJobHandlerTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.job; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import javax.annotation.Resource; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | @SpringBootTest 11 | class ClearCosJobHandlerTest { 12 | 13 | @Resource 14 | private ClearCosJobHandler clearCosJobHandler; 15 | 16 | @Test 17 | void clearCosJobHandler() throws Exception { 18 | clearCosJobHandler.clearCosJobHandler(); 19 | } 20 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/test/java/com/yupi/web/manager/CosManagerTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.manager; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import javax.annotation.Resource; 7 | import java.util.Arrays; 8 | 9 | @SpringBootTest 10 | class CosManagerTest { 11 | 12 | @Resource 13 | private CosManager cosManager; 14 | 15 | @Test 16 | void deleteObject() { 17 | cosManager.deleteObject("/test/logo.png"); 18 | } 19 | 20 | @Test 21 | void deleteObjects() { 22 | cosManager.deleteObjects(Arrays.asList("test/test1.png", "test/test2.png")); 23 | } 24 | 25 | @Test 26 | void deleteDir() { 27 | cosManager.deleteDir("/test/"); 28 | } 29 | } -------------------------------------------------------------------------------- /yuzi-generator-web-backend/src/test/java/com/yupi/web/service/GeneratorServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.web.service; 2 | 3 | import com.yupi.web.model.entity.Generator; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * 批量插入数据(仅单次执行) 11 | */ 12 | // 取消注释才能启动 13 | //@SpringBootTest 14 | class GeneratorServiceTest { 15 | 16 | @Resource 17 | private GeneratorService generatorService; 18 | 19 | @Test 20 | public void testInsert() { 21 | Generator generator = generatorService.getById(18L); 22 | for (int i = 0; i < 100000; i++) { 23 | generator.setId(null); 24 | generatorService.save(generator); 25 | } 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [Makefile] 16 | indent_style = tab 17 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/.eslintignore: -------------------------------------------------------------------------------- 1 | /lambda/ 2 | /scripts 3 | /config 4 | .history 5 | public 6 | dist 7 | .umi 8 | mock -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [require.resolve('@umijs/lint/dist/config/eslint')], 3 | globals: { 4 | page: true, 5 | REACT_APP_ENV: true, 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | **/node_modules 5 | # roadhog-api-doc ignore 6 | /src/utils/request-temp.js 7 | _roadhog-api-doc 8 | 9 | # production 10 | /dist 11 | 12 | # misc 13 | .DS_Store 14 | npm-debug.log* 15 | yarn-error.log 16 | 17 | /coverage 18 | .idea 19 | yarn.lock 20 | package-lock.json 21 | *bak 22 | .vscode 23 | 24 | 25 | # visual studio code 26 | .history 27 | *.log 28 | functions/* 29 | .temp/** 30 | 31 | # umi 32 | .umi 33 | .umi-production 34 | .umi-test 35 | 36 | # screenshot 37 | screenshot 38 | .firebase 39 | .eslintcache 40 | 41 | build 42 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/.prettierignore: -------------------------------------------------------------------------------- 1 | **/*.svg 2 | .umi 3 | .umi-production 4 | /dist 5 | .dockerignore 6 | .DS_Store 7 | .eslintignore 8 | *.png 9 | *.toml 10 | docker 11 | .editorconfig 12 | Dockerfile* 13 | .gitignore 14 | .prettierignore 15 | LICENSE 16 | .eslintcache 17 | *.lock 18 | yarn-error.log 19 | .history 20 | CNAME 21 | /build 22 | /public 23 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | singleQuote: true, 3 | trailingComma: 'all', 4 | printWidth: 100, 5 | proseWrap: 'never', 6 | endOfLine: 'lf', 7 | overrides: [ 8 | { 9 | files: '.prettierrc', 10 | options: { 11 | parser: 'json', 12 | }, 13 | }, 14 | { 15 | files: 'document.ejs', 16 | options: { 17 | parser: 'html', 18 | }, 19 | }, 20 | ], 21 | }; 22 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/README.md: -------------------------------------------------------------------------------- 1 | # 鱼籽代码生成 2 | 3 | > 基于 Ant Design Pro 二次开发,更简单易用 4 | 5 | 6 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/config/defaultSettings.ts: -------------------------------------------------------------------------------- 1 | import { ProLayoutProps } from '@ant-design/pro-components'; 2 | 3 | /** 4 | * 默认设置 5 | */ 6 | const Settings: ProLayoutProps & { 7 | pwa?: boolean; 8 | logo?: string; 9 | } = { 10 | navTheme: 'light', 11 | colorPrimary: '#2F54EB', 12 | layout: 'top', 13 | contentWidth: 'Fixed', 14 | fixedHeader: false, 15 | fixSiderbar: true, 16 | colorWeak: false, 17 | title: '鱼籽代码生成', 18 | pwa: true, 19 | iconfontUrl: '', 20 | token: { 21 | // 参见ts声明,demo 见文档,通过token 修改样式 22 | //https://procomponents.ant.design/components/layout#%E9%80%9A%E8%BF%87-token-%E4%BF%AE%E6%94%B9%E6%A0%B7%E5%BC%8F 23 | }, 24 | }; 25 | 26 | export default Settings; 27 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/config/proxy.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @name 代理的配置 3 | * @see 在生产环境 代理是无法生效的,所以这里没有生产环境的配置 4 | * ------------------------------- 5 | * The agent cannot take effect in the production environment 6 | * so there is no configuration of the production environment 7 | * For details, please see 8 | * https://pro.ant.design/docs/deploy 9 | * 10 | * @doc https://umijs.org/docs/guides/proxy 11 | */ 12 | export default { 13 | // 如果需要自定义本地开发服务器 请取消注释按需调整 14 | // dev: { 15 | // // localhost:8000/api/** -> https://preview.pro.ant.design/api/** 16 | // '/api/': { 17 | // // 要代理的地址 18 | // target: 'https://preview.pro.ant.design', 19 | // // 配置了这个可以从 http 代理到 https 20 | // // 依赖 origin 的功能可能需要这个,比如 cookie 21 | // changeOrigin: true, 22 | // }, 23 | // }, 24 | 25 | /** 26 | * @name 详细的代理配置 27 | * @doc https://github.com/chimurai/http-proxy-middleware 28 | */ 29 | test: { 30 | // localhost:8000/api/** -> https://preview.pro.ant.design/api/** 31 | '/api/': { 32 | target: 'https://proapi.azurewebsites.net', 33 | changeOrigin: true, 34 | pathRewrite: { '^': '' }, 35 | }, 36 | }, 37 | pre: { 38 | '/api/': { 39 | target: 'your pre url', 40 | changeOrigin: true, 41 | pathRewrite: { '^': '' }, 42 | }, 43 | }, 44 | }; 45 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/config/routes.ts: -------------------------------------------------------------------------------- 1 | export default [ 2 | { 3 | path: '/user', 4 | layout: false, 5 | routes: [ 6 | { path: '/user/login', component: './User/Login' }, 7 | { path: '/user/register', component: './User/Register' } 8 | ] 9 | }, 10 | { path: '/', icon: 'home', component: './Index', name: "主页" }, 11 | { 12 | path: '/generator/add', 13 | icon: 'plus', 14 | component: './Generator/Add', 15 | name: '创建生成器', 16 | }, 17 | { 18 | path: '/generator/update', 19 | icon: 'plus', 20 | component: './Generator/Add', 21 | name: '修改生成器', 22 | hideInMenu: true, 23 | }, 24 | { 25 | path: '/generator/use/:id', 26 | icon: 'home', 27 | component: './Generator/Use', 28 | name: '使用生成器', 29 | hideInMenu: true, 30 | }, 31 | { 32 | path: '/generator/detail/:id', 33 | icon: 'home', 34 | component: './Generator/Detail', 35 | name: '生成器详情', 36 | hideInMenu: true, 37 | }, 38 | { 39 | path: '/test/file', 40 | icon: 'home', 41 | component: './Test/File', 42 | name: '文件上传下载测试', 43 | hideInMenu: true, 44 | }, 45 | { 46 | path: '/admin', 47 | icon: 'crown', 48 | name: "管理页", 49 | access: 'canAdmin', 50 | routes: [ 51 | { path: '/admin', redirect: '/admin/user' }, 52 | { icon: 'table', path: '/admin/user', component: './Admin/User', name: "用户管理" }, 53 | { icon: 'tools', path: '/admin/generator', component: './Admin/Generator', name: "生成器管理" }, 54 | ], 55 | }, 56 | { path: '/', redirect: '/welcome' }, 57 | { path: '*', layout: false, component: './404' }, 58 | ]; 59 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "jsx": "react-jsx", 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "baseUrl": ".", 7 | "paths": { 8 | "@/*": ["./src/*"] 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyupi/yuzi-generator/a2a0edb2cbbb6a869196b6b8a85e6ad30bbb635c/yuzi-generator-web-frontend/public/favicon.ico -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyupi/yuzi-generator/a2a0edb2cbbb6a869196b6b8a85e6ad30bbb635c/yuzi-generator-web-frontend/public/logo.png -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/public/pro_icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/src/access.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @see https://umijs.org/zh-CN/plugins/plugin-access 3 | * */ 4 | export default function access(initialState: { currentUser?: API.LoginUserVO } | undefined) { 5 | const { currentUser } = initialState ?? {}; 6 | return { 7 | canUser: currentUser, 8 | canAdmin: currentUser && currentUser.userRole === 'admin', 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /yuzi-generator-web-frontend/src/app.tsx: -------------------------------------------------------------------------------- 1 | import logo from '@/assets/logo.png'; 2 | import Footer from '@/components/Footer'; 3 | import { getLoginUserUsingGet } from '@/services/backend/userController'; 4 | import type { RunTimeLayoutConfig } from '@umijs/max'; 5 | import { history } from '@umijs/max'; 6 | import defaultSettings from '../config/defaultSettings'; 7 | import { AvatarDropdown } from './components/RightContent/AvatarDropdown'; 8 | import { requestConfig } from './requestConfig'; 9 | 10 | const loginPath = '/user/login'; 11 | 12 | /** 13 | * @see https://umijs.org/zh-CN/plugins/plugin-initial-state 14 | * */ 15 | export async function getInitialState(): Promise { 16 | const initialState: InitialState = { 17 | currentUser: undefined, 18 | }; 19 | // 如果不是登录页面,执行 20 | const { location } = history; 21 | if (location.pathname !== loginPath) { 22 | try { 23 | const res = await getLoginUserUsingGet(); 24 | initialState.currentUser = res.data; 25 | } catch (error: any) { 26 | // 如果未登录 27 | } 28 | 29 | // 模拟登录用户 30 | // const mockUser: API.LoginUserVO = { 31 | // userAvatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png', 32 | // userName: 'yupi', 33 | // userRole: 'admin', 34 | // }; 35 | // initialState.currentUser = mockUser; 36 | } 37 | return initialState; 38 | } 39 | 40 | // ProLayout 支持的api https://procomponents.ant.design/components/layout 41 | // @ts-ignore 42 | export const layout: RunTimeLayoutConfig = ({ initialState }) => { 43 | return { 44 | logo, 45 | avatarProps: { 46 | render: () => { 47 | return ; 48 | }, 49 | }, 50 | waterMarkProps: { 51 | content: initialState?.currentUser?.userName, 52 | }, 53 | footerRender: () =>