开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
开源项目 > 程序开发 > 代码生成器 &&
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
31 Star 259 Fork 131

小螺旋丸/codeMan

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
标签 (2)
master
v2.35
v2.33
master
分支 (1)
标签 (2)
master
v2.35
v2.33
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
标签 (2)
master
v2.35
v2.33
codeMan
/
src
/
main
/
java
/
util
/
CodeWriterUtil.java
codeMan
/
src
/
main
/
java
/
util
/
CodeWriterUtil.java
CodeWriterUtil.java 50.67 KB
一键复制 编辑 原始数据 按行查看 历史
zhangruixuann 提交于 2022年04月10日 21:08 +08:00 . feat:SpringCloud完善
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
package util;
import constant.ChildWindowConstant;
import constant.CodeConstant;
import constant.CodeFtlConstant;
import constant.Constant;
import constant.FreeMarkerConfig;
import constant.MenuLevel;
import entity.DataSourceModel;
import entity.DatabaseModel;
import entity.EntityFieldModel;
import entity.MakeEntityModel;
import entity.Parameters;
import entity.TableConditionModel;
import entity.TableFiledModel;
import entity.TableNameAndType;
import entity.TablesQueryModel;
import entity.cmnSys.CmSysMenu;
import freemarker.template.Template;
import javax.swing.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @ClassName CodeWriterUtil
* @Author zrx
* @Date 2020年8月4日 11:54
*/
public class CodeWriterUtil {
private static Template getTemplate(String ftlStr) throws IOException {
Template template = FreeMarkerConfig.configuration.getTemplate(ftlStr);
template.setEncoding(StandardCharsets.UTF_8.name());
return template;
}
// 首字母大写 驼峰
public static String captureName(String name) {
StringBuilder result = new StringBuilder();
if (name.contains(".")) {
String[] nameArr = name.split("\\.");
for (String str : nameArr) {
if (str.length() > 1) {
result.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
} else {
result.append(str.substring(0, 1).toUpperCase());
}
}
} else if (name.contains("_")) {
String[] nameArr = name.split("_");
for (String str : nameArr) {
if (str.length() > 1) {
result.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
} else {
result.append(str.substring(0, 1).toUpperCase());
}
}
} else if (name.contains("-")) {
String[] nameArr = name.split("-");
for (String str : nameArr) {
if (str.length() > 1) {
result.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
} else {
result.append(str.substring(0, 1).toUpperCase());
}
}
} else {
if (name.length() > 1) {
result = new StringBuilder(name.substring(0, 1).toUpperCase() + name.substring(1));
} else {
result = new StringBuilder(name.substring(0, 1).toUpperCase());
}
}
return result.toString();
}
// 首字母小写
public static String firstLower(String name) {
String result;
if (name.length() > 1) {
result = name.substring(0, 1).toLowerCase() + name.substring(1);
} else {
result = name.substring(0, 1).toLowerCase();
}
return result;
}
/**
* 登录用户设置
*
* @param loginModel
* @param root
*/
public static void setLonginUser(String loginModel, Map<String, Object> root) {
if ("静态用户".equals(loginModel)) {
String condition = "";
if (ChildWindowConstant.user1.size() != 0) {
condition += "(\"" + ChildWindowConstant.user1.get(0) + "\"" + ".equals(user.getUserName()) && " + "\""
+ ChildWindowConstant.user1.get(1) + "\"" + ".equals(user.getPassword()))" + " || ";
}
if (ChildWindowConstant.user2.size() != 0) {
condition += "(\"" + ChildWindowConstant.user2.get(0) + "\"" + ".equals(user.getUserName()) && " + "\""
+ ChildWindowConstant.user2.get(1) + "\"" + ".equals(user.getPassword()))" + " || ";
}
if (ChildWindowConstant.user3.size() != 0) {
condition += "(\"" + ChildWindowConstant.user3.get(0) + "\"" + ".equals(user.getUserName()) && " + "\""
+ ChildWindowConstant.user3.get(1) + "\"" + ".equals(user.getPassword()))" + " || ";
}
condition = condition.substring(0, condition.lastIndexOf("|") - 2);
root.put(CodeConstant.USER_CONDITION, condition);
root.put(CodeConstant.USER_NAME_FILED, "userName");
root.put(CodeConstant.USER_PWD_FILED, "password");
} else if ("动态用户".equals(loginModel)) {
root.put(CodeConstant.USER_TABLE, ChildWindowConstant.dynamicUserList.get(0));
root.put(CodeConstant.USER_NAME_FILED, ChildWindowConstant.dynamicUserList.get(1));
root.put(CodeConstant.USER_PWD_FILED, ChildWindowConstant.dynamicUserList.get(2));
}
}
/**
* 自定义实体
*
* @throws Exception
*/
public static void getMakeEntity(String outPathVal, String entityDir, Map<String, Object> root) throws Exception {
// 自定义实体
if (ChildWindowConstant.makeEntityModelMap.size() == 0) {
return;
}
// 输出流
for (Map.Entry<String, List<MakeEntityModel>> entry : ChildWindowConstant.makeEntityModelMap.entrySet()) {
String makeEntityName = entry.getKey();
List<MakeEntityModel> makeEntityModels = entry.getValue();
for (MakeEntityModel makeEntityModel : makeEntityModels) {
if ("List".equals(makeEntityModel.getServiceType())) {
root.put(CodeConstant.HAS_LIST, 1);
break;
}
}
root.put(CodeConstant.MAKE_ENTITY_NAME, makeEntityName);
root.put(CodeConstant.MAKE_ENTITY_MODELS, makeEntityModels);
root.put(CodeConstant.MAKE_ENTITY_NAME_CN, ChildWindowConstant.makeEntityEngAndCn.get(makeEntityName));
makCodeByTel(getTemplate(CodeFtlConstant.MAKE_ENTITY_FTL), outPathVal, entityDir, captureName(makeEntityName) + ".java", root);
root.remove(CodeConstant.HAS_LIST);
}
}
/**
* springboot用到的文件 yml 启动类等
*
* @throws Exception
*/
public static void getSpringbootCommon(boolean cloudModel, String loginModel, boolean isAuthority, String outPathVal, String projectNameVal, String cloudSysEngName, String resourcesDir, String mainApplicationDir,
String captureProjectNameVal, String mainApplicationTestDir, String mvcConfigDir, Map<String, Object> root,
String frameWorkVal) throws Exception {
// 自定义实体
if (!"springBoot".equals(frameWorkVal)) {
return;
}
makCodeByTel(getTemplate(CodeFtlConstant.APPLICATION_YML_FTL), outPathVal, resourcesDir, "application.yml", root);
makCodeByTel(getTemplate(CodeFtlConstant.MAIN_APPLICATION_FTL), outPathVal, mainApplicationDir, captureProjectNameVal + "Application.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.MAIN_APPLICATION_TEST_FTL), outPathVal, mainApplicationTestDir, captureProjectNameVal + "ApplicationTests.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.MVC_CONFIG_FTL), outPathVal, cloudModel ? getSysCommonDir(projectNameVal, cloudSysEngName, mvcConfigDir) : mvcConfigDir, "MvcConfig.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.TRANSACTION_ADVICE_CONFIG_FTL), outPathVal, cloudModel ? getSerDir(projectNameVal, cloudSysEngName, mvcConfigDir) : mvcConfigDir, "TransactionAdviceConfig.java", root);
if ((!"静态用户".equals(loginModel) || isAuthority) && cloudModel) {
makCodeByTel(getTemplate(CodeFtlConstant.TRANSACTION_ADVICE_CONFIG_FTL), outPathVal, getSerSystemDir(projectNameVal, cloudSysEngName, mvcConfigDir), "TransactionAdviceConfig.java", root);
}
}
/**
* springMVC用到的文件
*
* @throws Exception
*/
public static void getSpringMvcCommon(String outPathVal, String resourcesDir, String projectNameVal, String htmlDir,
String settingsDir, String mvcConfigDir, Map<String, Object> root, String frameWorkVal) throws Exception {
// 自定义实体
if (!"ssm".equals(frameWorkVal)) {
return;
}
String metaInfDir = FreeOutUtil.setProjectName(Constant.FREE_OUT_PATH_METAINF_MVC, projectNameVal);
makCodeByTel(getTemplate(CodeFtlConstant.MVC_INTERCEPTOR_FTL), outPathVal, mvcConfigDir, "MVCInterceptor.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.MVC_JDBC_PROPERTIES_FTL), outPathVal, resourcesDir, "jdbc.properties", root);
makCodeByTel(getTemplate(CodeFtlConstant.MVC_SPRING_MVC_FTL), outPathVal, resourcesDir, "spring-mvc.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.MVC_SPRING_MYBATIS_FTL), outPathVal, resourcesDir, "spring-mybatis.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.WEB_XML_FTL), outPathVal, htmlDir, "web.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.ORG_ECLIPSE_COMPONENT_FTL), outPathVal, settingsDir, "org.eclipse.wst.common.component", root);
makCodeByTel(getTemplate(CodeFtlConstant.MANIFESTMF_FTL), outPathVal, metaInfDir, "MANIFEST.MF", root);
}
/**
* 动态用户生成的文件(用户名密码需要连接数据库查询的情况)
*
* @throws Exception
*/
public static void getDynamicUser(String outPathVal, String sqlMapperDir, String serviceDir, String serviceImplDir, String daoDir, String loginModel, Map<String, Object> root) throws Exception {
// 自定义实体
if (!"动态用户".equals(loginModel)) {
return;
}
makCodeByTel(getTemplate(CodeFtlConstant.USER_MAPPER_FTL), outPathVal, sqlMapperDir, "loginMapper.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.IUSER_SERVICE_FTL), outPathVal, serviceDir, "LoginService.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.USER_SERVICE_FTL), outPathVal, serviceImplDir, "LoginServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.IUSER_DAO_FTL), outPathVal, daoDir, "LoginDao.java", root);
}
/**
* 动态生成core包下的注解
*
* @throws Exception
*/
public static void getCoreAnnotation(String outPathVal, String coreAnnotationDir, Map<String, Object> root) throws Exception {
makCodeByTel(getTemplate(CodeFtlConstant.LOGIN_REQUIRED_FTL), outPathVal, coreAnnotationDir, "LoginRequired.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.NO_PACK_FTL), outPathVal, coreAnnotationDir, "NoPack.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.RECORD_LOG_FTL), outPathVal, coreAnnotationDir, "RecordLog.java", root);
}
/**
* 动态生成core包下的响应体类
*
* @throws Exception
*/
public static void getCoreResponse(String outPathVal, String coreDir, Map<String, Object> root) throws Exception {
makCodeByTel(getTemplate(CodeFtlConstant.RESPONSE_RESULT_FTL), outPathVal, coreDir, "ResponseResult.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.RESPONSE_STATUS_FTL), outPathVal, coreDir, "ResponseStatus.java", root);
}
/**
* 动态生成core包下的exception类
*
* @throws Exception
*/
public static void getCoreException(String outPathVal, String coreExceptionDir, Map<String, Object> root) throws Exception {
makCodeByTel(getTemplate(CodeFtlConstant.BUSINESS_EXCEPTION_FTL), outPathVal, coreExceptionDir, "BusinessException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.FORBIDDEN_EXCEPTION_FTL), outPathVal, coreExceptionDir, "ForbiddenException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.HTTP_CLIENT_CONNECTION_EXCEPTION_FTL), outPathVal, coreExceptionDir, "HttpClientConnectionException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.HTTP_CLIENT_EXCEPTION_FTL), outPathVal, coreExceptionDir, "HttpClientException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.ILLEGAL_PARAMETER_EXCEPTION_FTL), outPathVal, coreExceptionDir, "IllegalParameterException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.INTERNAL_SERVER_ERROR_EXCEPTION_FTL), outPathVal, coreExceptionDir, "InternalServerErrorException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.NOT_AUTHORIZED_EXCEPTION_FTL), outPathVal, coreExceptionDir, "NotAuthorizedException.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.NOT_FOUND_EXCEPTION_FTL), outPathVal, coreExceptionDir, "NotFoundException.java", root);
}
/**
* 公共代码的生成
*
* @throws Exception
*/
public static void getCommonCode(boolean isRedisSingleLogin, boolean cloudModel, String outPathVal, String projectDir, String initDir, String coreAnnotationDir, String utilDir, String themeVal,
String htmlDir, String webClientHtmlPath, String daoDir, String resourcesDir, String sqlMapperDir,
String controllerDir, String mvcConfigDir, String entityDir, String staticDir,
String webClientJsConfigPath, boolean authority, Map<String, Object> root) throws Exception {
boolean ifSwagger = "是".equals(ChildWindowConstant.commonParametersModel.getIfUseSwagger());
makCodeByTel(getTemplate(CodeFtlConstant.POM_FTL), outPathVal, projectDir, "pom.xml", root);
if (!cloudModel) {
makCodeByTel(getTemplate(CodeFtlConstant.CLASSPATH_FTL), outPathVal, projectDir, ".classpath", root);
makCodeByTel(getTemplate(CodeFtlConstant.PROJECT_FTL), outPathVal, projectDir, ".project", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.CASTUTIL_FTL), outPathVal, utilDir, "CastUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.SESSION_UTIL_FTL), outPathVal, utilDir, "SessionUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.EXTERNAL_FIELD_FTL), outPathVal, coreAnnotationDir, "ExternalField.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.SINGLETON_OBJECT), outPathVal, utilDir, "SingletonObject.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.STRING_UTIL), outPathVal, utilDir, "StringUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.BUSINESS_INITIALIZER), outPathVal, initDir, "BusinessInitializer.java", root);
if (isRedisSingleLogin) {
makCodeByTel(getTemplate(CodeFtlConstant.REDIS_CACHE_UTIL), outPathVal, utilDir, "RedisCacheUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.REDIS_CONFIG), outPathVal, mvcConfigDir, "RedisConfig.java", root);
}
// homehtml的输出流
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.HOME_FTL), outPathVal, htmlDir, "home.html", root);
} else {
makCodeByTel(getTemplate(CodeFtlConstant.HOME_FTL), outPathVal, webClientHtmlPath, "home.html", root);
}
// welcomehtml的输出流
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.WELCOME_FTL), outPathVal, htmlDir, "welcome.html", root);
} else {
makCodeByTel(getTemplate(CodeFtlConstant.WELCOME_FTL), outPathVal, webClientHtmlPath, "welcome.html", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.IBASE_DAO_FTL), outPathVal, daoDir, "BaseDao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.EXCEL_UTIL_FTL), outPathVal, utilDir, "ExcelUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.LOGBACK_FTL), outPathVal, resourcesDir, "logback.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.MYBATIS_CONFIG_FTL), outPathVal, sqlMapperDir, "mybatis-config.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.USER_CONTROLLER_FTL), outPathVal, controllerDir, "LoginController.java", root);
// loginHtml的输出流
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.LOGIN_HTML_FTL), outPathVal, htmlDir, "login.html", root);
} else {
makCodeByTel(getTemplate(CodeFtlConstant.LOGIN_HTML_FTL), outPathVal, webClientHtmlPath, "login.html", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.USER_FTL), outPathVal, entityDir, authority ? "CmSysUserEntity.java" : "User.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.ALL_EXCEPTION_HANDLER_FTL), outPathVal, mvcConfigDir, "AllExceptionHandler.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CORS_CONFIG_FTL), outPathVal, mvcConfigDir, "CorsConfig.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.LOG_AOP_ASPECT_FTL), outPathVal, mvcConfigDir, "LogAopAspect.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.LOGGER_UTIL_FTL), outPathVal, utilDir, "LoggerUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.PAGE_UTIL_FTL), outPathVal, utilDir, "PageUtil.java", root);
if (ifSwagger) {
makCodeByTel(getTemplate(CodeFtlConstant.SWAGGER_CONFIG_FTL), outPathVal, mvcConfigDir, "SwaggerConfig.java", root);
}
// 根据主题的不同生成的路径不同
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.CONFIG_JS_FTL), outPathVal, staticDir + "js/", "config.js", root);
} else {
makCodeByTel(getTemplate(CodeFtlConstant.CONFIG_JS_FTL), outPathVal, webClientJsConfigPath, "config.js", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.COMMON_ENTITY_FTL), outPathVal, entityDir, "CommonEntity.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.PAGE_DATA_FTL), outPathVal, entityDir, "PageData.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.JACKSON_CONFIG_FTL), outPathVal, mvcConfigDir, "JacksonConfig.java", root);
}
/**
* 单表相关代码生成
*
* @throws Exception
*/
public static void getSingleTableCode(String projectNameVal, boolean cloudModel, boolean mutiDataSource, String outPathVal, String ifJavaBean, String entityDir, String daoDir,
String serviceDir, String serviceImplDir, String controllerDir, String sqlMapperDir, String themeVal,
String htmlDir, String webClientHtmlPath, String[] tableNameArr, String dataBaseTypeVal,
Map<String, Object> root) throws Exception {
if (mutiDataSource) {
//如果配置了多数据源
for (Map.Entry<String, DataSourceModel> modelEntry : ChildWindowConstant.dataSourceModelMap.entrySet()) {
String dataSource = modelEntry.getKey();
DataSourceModel sourceModel = modelEntry.getValue();
String modelTableName = sourceModel.getTableName();
tableNameArr = modelTableName.split("#");
//当前数据源
root.put(CodeConstant.CURRENT_DATA_SOURCE_NAME, dataSource);
root.put(CodeConstant.DATA_BASE_TYPE, sourceModel.getDataBaseTypeVal());
makeSingleTableCode(projectNameVal, cloudModel, outPathVal, ifJavaBean, entityDir, daoDir, serviceDir, serviceImplDir, controllerDir, sqlMapperDir, themeVal, htmlDir, webClientHtmlPath, tableNameArr, sourceModel.getDataBaseTypeVal(),
root, sourceModel.getCurrentTableNameAndTypes(), sourceModel.getPrimaryKeyListMap(), sourceModel.getCurrentTableCnNameMap(), sourceModel.getAllColumnMsgMap(),
sourceModel.getColumnMsgMap(), sourceModel.getUpdateColumnMsgMap(), sourceModel.getQueryColumnMsgMap());
}
//恢复type
root.put(CodeConstant.DATA_BASE_TYPE, dataBaseTypeVal);
} else {
makeSingleTableCode(projectNameVal, cloudModel, outPathVal, ifJavaBean, entityDir, daoDir, serviceDir, serviceImplDir, controllerDir, sqlMapperDir, themeVal, htmlDir, webClientHtmlPath, tableNameArr, dataBaseTypeVal,
root, ChildWindowConstant.currentTableNameAndTypes, ChildWindowConstant.primaryKeyListMap, ChildWindowConstant.currentTableCnNameMap, ChildWindowConstant.allColumnMsgMap,
ChildWindowConstant.columnMsgMap, ChildWindowConstant.updateColumnMsgMap, ChildWindowConstant.queryColumnMsgMap);
}
}
/**
* 生成单表代码
*/
private static void makeSingleTableCode(String projectNameVal, boolean cloudModel, String outPathVal, String ifJavaBean, String entityDir, String daoDir,
String serviceDir, String serviceImplDir, String controllerDir, String sqlMapperDir, String themeVal,
String htmlDir, String webClientHtmlPath, String[] tableNameArr, String dataBaseTypeVal,
Map<String, Object> root, Map<String, List<TableNameAndType>> currentTableNameAndTypes,
Map<String, List<String>> primaryKeyListMap, Map<String, String> currentTableCnNameMap, Map<String, List<DatabaseModel>> allColumnMsgMap,
Map<String, List<DatabaseModel>> columnMsgMap, Map<String, List<DatabaseModel>> updateColumnMsgMap, Map<String, List<DatabaseModel>> queryColumnMsgMap) throws Exception {
for (String currentTableName : tableNameArr) {
root.put(CodeConstant.REAL_TABLE_NAME, currentTableName);
String captureurrentTableName = CodeWriterUtil.captureName(currentTableName);
// 如果是JavaBean配置
if ("JavaBean".equals(ifJavaBean)) {
// bean的名称
root.put(CodeConstant.ENTITY_NAME, captureurrentTableName + "Entity");
List<TableNameAndType> tableNameAndTypes = currentTableNameAndTypes.get(currentTableName);
root.put(CodeConstant.ENTITY_NAME_AND_TYPES, tableNameAndTypes);
}
root.put(CodeConstant.IDAO_NAME, captureurrentTableName + "Dao");
root.put(CodeConstant.ISERVICE_NAME, captureurrentTableName + "Service");
root.put(CodeConstant.SERVICE_NAME, captureurrentTableName + "ServiceImpl");
root.put(CodeConstant.CONTROLLER_NAME, captureurrentTableName + "Controller");
root.put(CodeConstant.CONTROLLER_PREFIX,
captureurrentTableName.length() > 1
? captureurrentTableName.substring(0, 1).toLowerCase() + captureurrentTableName.substring(1)
: captureurrentTableName.substring(0, 1).toLowerCase());
root.put(CodeConstant.TABLE_NAME, captureurrentTableName);
List<String> primaryKeyList = primaryKeyListMap.get(currentTableName);
String currentTableCnName = currentTableCnNameMap.get(currentTableName);
// root.put(CodeConstant.primaryKeyList, primaryKeyList);
root.put(CodeConstant.CURRENT_TABLE_CN_NAME, currentTableCnName);
// 因为主键必须设置 所以所有的条件不可能为0
List<DatabaseModel> allColumnList = allColumnMsgMap.get(currentTableName);
List<DatabaseModel> sortAllColumnList = new ArrayList<>(allColumnList);
if ("mysql".equals(dataBaseTypeVal)) {
sortAllColumnList.sort((o1, o2) -> {
if (o1.getWhereNo().compareTo(o2.getWhereNo()) == 0) {
return 0;
} else if (o2.getWhereNo().compareTo(o1.getWhereNo()) > 0) {
return -1;
} else {
return 1;
}
});
} else if ("oracle".equals(dataBaseTypeVal)) {
sortAllColumnList.sort((o1, o2) -> {
if (o1.getWhereNo().compareTo(o2.getWhereNo()) == 0) {
return 0;
} else if (o2.getWhereNo().compareTo(o1.getWhereNo()) > 0) {
return 1;
} else {
return -1;
}
});
}
// sql条件排序使用
root.put(CodeConstant.COLUMN_LIST, sortAllColumnList);
// 页面显示使用
List<DatabaseModel> selectColumnList = columnMsgMap.get(currentTableName);
selectColumnList.sort((o1, o2) -> {
if (o1.getShowNo().compareTo(o2.getShowNo()) == 0) {
return 0;
} else if (o2.getShowNo().compareTo(o1.getShowNo()) > 0) {
return -1;
} else {
return 1;
}
});
// 如果查询的个数为0 则默认查全部
if (selectColumnList.size() == 0) {
selectColumnList.addAll(allColumnList);
root.put(CodeConstant.SELECT_COLUMN_LIST, allColumnList);
} else {
// 设置的查询字段列表
root.put(CodeConstant.SELECT_COLUMN_LIST, selectColumnList);
}
List<DatabaseModel> updateColumnList = updateColumnMsgMap.get(currentTableName);
// 如果没有配置更新,以初始展示的项目为准
if (updateColumnList.size() == 0) {
updateColumnList.addAll(selectColumnList);
root.put(CodeConstant.UPDATE_COLUMN_LIST, selectColumnList);
} else {
root.put(CodeConstant.UPDATE_COLUMN_LIST, updateColumnList);
}
List<DatabaseModel> queryColumnList = queryColumnMsgMap.get(currentTableName);
// 如果没有配置更新,以初始展示的项目为准
if (queryColumnList.size() == 0) {
root.put(CodeConstant.QUERY_COLUMN_LIST, selectColumnList);
} else {
root.put(CodeConstant.QUERY_COLUMN_LIST, queryColumnList);
}
List<DatabaseModel> primaryKeyModelList = new ArrayList<>();
for (String primaryKey : primaryKeyList) {
DatabaseModel model = new DatabaseModel();
model.setColumnsEng(primaryKey);
// 设置sqlParamColumnEng
model.setSqlParamColumnEng(DataUtils.getSqlParam(primaryKey));
primaryKeyModelList.add(model);
}
// 遍历主键的模型list,判断在selectColumnList中存不存在,如不存在,加入
List<DatabaseModel> selectColumnListMapper = new ArrayList<>(selectColumnList);
for (DatabaseModel model : primaryKeyModelList) {
// 如果没有,添加
if (!selectColumnListMapper.contains(model)) {
selectColumnListMapper.add(model);
}
/*
* if (updateColumnList.contains(model)) { updateColumnList.remove(model); }
*/
}
root.put(CodeConstant.PRIMARY_KEY_MODEL_LIST, primaryKeyModelList);
root.put(CodeConstant.SELECT_COLUMN_LIST_MAPPER, selectColumnListMapper);
// 实体类输出
if ("JavaBean".equals(ifJavaBean)) {
makCodeByTel(getTemplate(CodeFtlConstant.ENTITY_FTL), outPathVal, entityDir, captureurrentTableName + "Entity.java", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.DAO_FTL), outPathVal, daoDir, captureurrentTableName + "Dao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.ISERVICE_FTL), outPathVal, serviceDir, captureurrentTableName + "Service.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.SERVICE_FTL), outPathVal, serviceImplDir, captureurrentTableName + "ServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CONTROLLER_FTL), outPathVal, controllerDir, captureurrentTableName + "Controller.java", root);
if (cloudModel) {
//生成feign
makCodeByTel(getTemplate(CodeFtlConstant.FEIGN_SERVICE_CLIENT), outPathVal, Constant.CLOUD_FEIGN_CLIENT.replaceFirst(Constant.PROJECT_NAME, projectNameVal), captureurrentTableName + "Client.java", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.SQL_MAPPER_FTL), outPathVal, sqlMapperDir, CodeWriterUtil.firstLower(captureurrentTableName) + "Mapper.xml", root);
// 当前表html的输出文件
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.HTML_FTL), outPathVal, htmlDir + currentTableName + "/", "list.html", root);
// 前后端分离主题
} else {
makCodeByTel(getTemplate(CodeFtlConstant.HTML_FTL), outPathVal, webClientHtmlPath + currentTableName + "/", "list.html", root);
}
}
}
/**
* 多表相关代码生成
*
* @throws Exception
*/
public static void getMutiTableCode(String dataBaseTypeVal, boolean mutiDataSource, String outPathVal, String sqlMapperDir, String serviceDir,
String serviceImplDir, String daoDir, String controllerDir, String themeVal, String entityDir, String htmlDir,
String webClientHtmlPath, Map<String, Object> root) throws Exception {
if (mutiDataSource) {
//如果配置了多数据源模式生成
for (Map.Entry<String, DataSourceModel> modelEntry : ChildWindowConstant.dataSourceModelMap.entrySet()) {
String dataSource = modelEntry.getKey();
DataSourceModel sourceModel = modelEntry.getValue();
//当前数据源
root.put(CodeConstant.CURRENT_DATA_SOURCE_NAME, dataSource);
root.put(CodeConstant.DATA_BASE_TYPE, sourceModel.getDataBaseTypeVal());
makeMutiTableCode(outPathVal, sqlMapperDir, serviceDir, serviceImplDir, daoDir, controllerDir, themeVal, entityDir, htmlDir, webClientHtmlPath, root, sourceModel.getTablesQueryMap(), sourceModel.getTablesQueryEndAndCnMap());
}
//恢复type
root.put(CodeConstant.DATA_BASE_TYPE, dataBaseTypeVal);
} else {
makeMutiTableCode(outPathVal, sqlMapperDir, serviceDir, serviceImplDir, daoDir, controllerDir, themeVal, entityDir, htmlDir, webClientHtmlPath, root, ChildWindowConstant.tablesQueryMap, ChildWindowConstant.tablesQueryEndAndCnMap);
}
}
/**
* 生成多表的代码
*/
private static void makeMutiTableCode(String outPathVal, String sqlMapperDir, String serviceDir,
String serviceImplDir, String daoDir, String controllerDir, String themeVal, String entityDir, String htmlDir,
String webClientHtmlPath, Map<String, Object> root, Map<String, Map<String, TablesQueryModel>> tablesQueryMap, Map<String, String> tablesQueryEndAndCnMap) throws Exception {
// 多表配置生成文件
for (Map.Entry<String, Map<String, TablesQueryModel>> methodEntry : tablesQueryMap.entrySet()) {
// 当前模块英文名
String currentMutiEng = methodEntry.getKey();
// 当前模块中文名
String currentMutiCn = tablesQueryEndAndCnMap.get(currentMutiEng);
root.put(CodeConstant.CURRENT_MUTI_ENG, currentMutiEng);
String capCurrentMutiEng = CodeWriterUtil.captureName(currentMutiEng);
root.put(CodeConstant.CAP_CURRENT_MUTI_ENG, capCurrentMutiEng);
root.put(CodeConstant.CURRENT_MUTI_CN, currentMutiCn);
Map<String, TablesQueryModel> methodMap = methodEntry.getValue();
// 方法的map
root.put(CodeConstant.CURRENT_METHOD_MAP, methodMap);
//生成java代码
makCodeByTel(getTemplate(CodeFtlConstant.MUTI_TABLE_SQL_MAPPER_FTL), outPathVal, sqlMapperDir, CodeWriterUtil.firstLower(capCurrentMutiEng) + "MutiSqlMapper.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.IMUTI_TABLE_DAO_FTL), outPathVal, daoDir, capCurrentMutiEng + "MutiDao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.IMUTI_TABLE_SERVICE_FTL), outPathVal, serviceDir, capCurrentMutiEng + "MutiService.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.MUTI_TABLE_SERVICE_FTL), outPathVal, serviceImplDir, capCurrentMutiEng + "MutiServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.MUTI_TABLE_CONTROLLER_FTL), outPathVal, controllerDir, capCurrentMutiEng + "MutiController.java", root);
// 遍历当前模块的所有方法 一个方法对应一个entity和一个html
for (Map.Entry<String, TablesQueryModel> method : methodMap.entrySet()) {
// 当前方法名
String methodName = method.getKey();
TablesQueryModel tablesQueryModel = method.getValue();
// 当前方法中文名
String methodNameCn = tablesQueryModel.getMethodName_cn();
// 当前方法实体名 首字母大写
String entityName = CodeWriterUtil.captureName(tablesQueryModel.getEntityName());
// 当前方法实体中文名
String entityNameCn = tablesQueryModel.getEntityName_cn();
List<TableFiledModel> tableFiledModels = tablesQueryModel.getTableFiledModels();
List<TableConditionModel> tableConditionModels = tablesQueryModel.getTableConditionModels();
// entity的集合
List<EntityFieldModel> entityFieldList = new ArrayList<>();
for (TableFiledModel model : tableFiledModels) {
EntityFieldModel entityFieldModel = new EntityFieldModel();
entityFieldModel.setFieldName(model.getAnotherFiledName());
entityFieldModel.setFieldName_cn(model.getFiledText_cn());
entityFieldModel.setFieldType(model.getFiledType());
entityFieldModel.setCompareText("");
entityFieldList.add(entityFieldModel);
}
for (TableConditionModel model : tableConditionModels) {
EntityFieldModel entityFieldModel = new EntityFieldModel();
entityFieldModel.setFieldName(model.getAnotherTableName() + "_" + model.getFiled_eng());
entityFieldModel.setFieldName_cn(model.getFiled_cn());
entityFieldModel.setFieldType(model.getServiceType());
entityFieldModel.setCompareText(model.getCompareText());
if (!entityFieldList.contains(entityFieldModel) && "".equals(model.getUnchangeValue())) {
entityFieldList.add(entityFieldModel);
}
}
root.put(CodeConstant.CURRENT_MUTI_METHOD_ENG, methodName);
root.put(CodeConstant.CURRENT_MUTI_METHOD_CN, methodNameCn);
root.put(CodeConstant.CURRENT_MUTI_ENTITY_NAME, entityName + "Muti");
root.put(CodeConstant.CURRENT_MUTI_ENTITY_NAME_CN, entityNameCn);
root.put(CodeConstant.TABLE_FILED_MODELS, tableFiledModels);
root.put(CodeConstant.TABLE_CONDITION_MODELS, tableConditionModels);
root.put(CodeConstant.ENTITY_FILED_MODELS, entityFieldList);
// 一个方法一个html
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.MUTI_TABLE_HTML_FTL), outPathVal, htmlDir + currentMutiEng + "Muti/", methodName + "List.html", root);
} else {
makCodeByTel(getTemplate(CodeFtlConstant.MUTI_TABLE_HTML_FTL), outPathVal, webClientHtmlPath + currentMutiEng + "Muti/", methodName + "List.html", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.MUTI_TABLE_ENTITY_FTL), outPathVal, entityDir, entityName + "Muti.java", root);
}
}
}
/**
* 生成setting文件夹下的代码(eclipse用户使用)
*/
public static void getSettingCode(Map<String, Object> root, boolean cloudModel, String outPathVal, String frameWorkVal, String settingsDir) {
if (isNotALL(root) || cloudModel) {
return;
}
try {
String realSettingDir = FreeOutUtil.checkAndMakeDir(outPathVal + settingsDir);
File mvcSettingsZip = new File(Constant.mvcSettingsZip);
File settingsZip = new File(Constant.settingsZip);
if ("ssm".equals(frameWorkVal)) {
if (!mvcSettingsZip.exists()) {
mvcSettingsZip = HttpDownloadUtil.downloadFile(Constant.downMvcSettingsZipNet, Constant.modelFiles);
}
ZipUtils.unZip(mvcSettingsZip, realSettingDir, Constant.ZIP_PWD);
}
if ("springBoot".equals(frameWorkVal)) {
if (!settingsZip.exists()) {
settingsZip = HttpDownloadUtil.downloadFile(Constant.downSettingsZipNet, Constant.modelFiles);
}
ZipUtils.unZip(settingsZip, realSettingDir, Constant.ZIP_PWD);
}
} catch (Exception e) {
throw new RuntimeException("生成配置文件setting时出错!可能是网络问题导致的,请重试!");
}
}
/**
* 生成static文件夹下的代码
*/
public static void getStaticCode(Map<String, Object> root, String outPathVal, String themeVal, String staticDir, String webClientPath) {
if (isNotALL(root)) {
return;
}
try {
if (CodeConstant.OLD_THEME.equals(themeVal)) {
String realStaticDir = FreeOutUtil.checkAndMakeDir(outPathVal + staticDir);
File staticZip = new File(Constant.staticZip);
ZipUtils.unZip(staticZip, realStaticDir, Constant.ZIP_PWD);
// 如果是前后端分离响应式项目
} else if (CodeConstant.H_ADMIN_THEME.equals(themeVal)) {
String realWebClientPath = FreeOutUtil.checkAndMakeDir(outPathVal + webClientPath);
File webClientZip = new File(Constant.webClientZip);
ZipUtils.unZip(webClientZip, realWebClientPath, Constant.ZIP_PWD);
}
} catch (Exception e) {
throw new RuntimeException("生成静态资源文件时出错!可能是网络问题导致的,请重试!");
}
}
/**
* 生成ojdbc的lib文件夹
*/
public static void getOjdbcCode(boolean cloudModel, boolean mutiDataSource, Map<String, Object> root, String outPathVal, String frameWorkVal, String dataBaseTypeVal,
String projectNameVal) {
if (isNotALL(root)) {
return;
}
// 如果是oracle,sqlserver或者多数据源模式,需要添加ojdbc支持
if ("oracle".equals(dataBaseTypeVal) || "sqlserver".equals(dataBaseTypeVal) || mutiDataSource || cloudModel) {
// 下载lib.zip文件到项目路径下 oracle sqlserver 的驱动
String libDir = null;
if ("ssm".equals(frameWorkVal)) {
libDir = FreeOutUtil.setProjectName(Constant.FREE_OUT_PATH_LIB_MVC, projectNameVal);
}
if ("springBoot".equals(frameWorkVal)) {
if (cloudModel) {
libDir = Constant.CLOUD_SYS_PARENT + "lib" + File.separator;
} else {
libDir = FreeOutUtil.setProjectName(Constant.FREE_OUT_PATH_LIB, projectNameVal);
}
}
try {
String realLibDir = FreeOutUtil.checkAndMakeDir(outPathVal + libDir);
File libZip = new File(Constant.libZip);
if (!libZip.exists()) {
libZip = HttpDownloadUtil.downloadFile(Constant.downLibZipNet, Constant.modelFiles);
}
ZipUtils.unZip(libZip, realLibDir, Constant.ZIP_PWD);
} catch (Exception e) {
throw new RuntimeException("生成lib文件夹时出错!可能是网络问题导致的,请重试!");
}
}
}
/**
* 生成权限相关代码
*
* @param outPathVal
* @param utilDir
* @param themeVal
* @param htmlDir
* @param webClientHtmlPath
* @param daoDir
* @param sqlMapperDir
* @param controllerDir
* @param entityDir
* @param constantDir
* @param root
*/
public static void makeAuthCode(String outPathVal, String utilDir, String themeVal, String htmlDir, String webClientHtmlPath, String daoDir, String sqlMapperDir, String controllerDir, String serviceDir, String serviceImplDir, String entityDir, String constantDir, String coreAnnotationDir, String coreValidatesDir, String dtoDir, Map<String, Object> root) throws Exception {
makCodeByTel(getTemplate(CodeFtlConstant.MOVE_TYPE_FTL), outPathVal, constantDir, "MoveType.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.YES_OR_NO_FTL), outPathVal, constantDir, "YesOrNo.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_BUTTON_CONTROLLER_FTL), outPathVal, controllerDir, "CmSysButtonController.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_CONTROLLER_FTL), outPathVal, controllerDir, "CmSysMenuController.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_CONTROLLER_FTL), outPathVal, controllerDir, "CmSysRoleController.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_CONTROLLER_FTL), outPathVal, controllerDir, "CmSysUserController.java", root);
//makCodeByTel(getTemplate(CodeFtlConstant.EXTERNAL_FIELD_FTL), outPathVal, coreAnnotationDir, "ExternalField.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.ADD_FTL), outPathVal, coreValidatesDir, "Add.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.UPDATE_FTL), outPathVal, coreValidatesDir, "Update.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_BUTTON_DAO_FTL), outPathVal, daoDir, "CmSysButtonDao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_DAO_FTL), outPathVal, daoDir, "CmSysMenuDao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_DAO_FTL), outPathVal, daoDir, "CmSysRoleDao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_DAO_FTL), outPathVal, daoDir, "CmSysUserDao.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.NODE_MOVE_DTO_FTL), outPathVal, dtoDir, "NodeMoveDto.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_BUTTON_ENTITY_FTL), outPathVal, entityDir, "CmSysButtonEntity.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_ENTITY_FTL), outPathVal, entityDir, "CmSysMenuEntity.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_BUTTON_ENTITY_FTL), outPathVal, entityDir, "CmSysRoleButtonEntity.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_ENTITY_FTL), outPathVal, entityDir, "CmSysRoleEntity.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_MENU_ENTITY_FTL), outPathVal, entityDir, "CmSysRoleMenuEntity.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_BUTTON_MAPPER_FTL), outPathVal, sqlMapperDir, "cmSysButtonMapper.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_MAPPER_FTL), outPathVal, sqlMapperDir, "cmSysMenuMapper.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_MAPPER_FTL), outPathVal, sqlMapperDir, "cmSysRoleMapper.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_MAPPER_FTL), outPathVal, sqlMapperDir, "cmSysUserMapper.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_BUTTON_SERVICE_FTL), outPathVal, serviceDir, "CmSysButtonService.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_SERVICE_FTL), outPathVal, serviceDir, "CmSysMenuService.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_SERVICE_FTL), outPathVal, serviceDir, "CmSysRoleService.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_SERVICE_FTL), outPathVal, serviceDir, "CmSysUserService.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_BUTTON_SERVICE_IMPL_FTL), outPathVal, serviceImplDir, "CmSysButtonServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_SERVICE_IMPL_FTL), outPathVal, serviceImplDir, "CmSysMenuServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_SERVICE_IMPL_FTL), outPathVal, serviceImplDir, "CmSysRoleServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_SERVICE_IMPL_FTL), outPathVal, serviceImplDir, "CmSysUserServiceImpl.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.MD5_UTIL_FTL), outPathVal, utilDir, "Md5Util.java", root);
//makCodeByTel(getTemplate(CodeFtlConstant.SESSION_UTIL_FTL), outPathVal, utilDir, "SessionUtil.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.SNOWFLAKE_ID_WORKER_FTL), outPathVal, utilDir, "SnowflakeIdWorker.java", root);
if (CodeConstant.OLD_THEME.equals(themeVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_HTML_FTL), outPathVal, htmlDir + "cmSysMenu/", "list.html", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_HTML_FTL), outPathVal, htmlDir + "cmSysRole/", "list.html", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_HTML_FTL), outPathVal, htmlDir + "cmSysUser/", "list.html", root);
} else {
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_MENU_HTML_FTL), outPathVal, webClientHtmlPath + "cmSysMenu/", "list.html", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_ROLE_HTML_FTL), outPathVal, webClientHtmlPath + "cmSysRole/", "list.html", root);
makCodeByTel(getTemplate(CodeFtlConstant.CM_SYS_USER_HTML_FTL), outPathVal, webClientHtmlPath + "cmSysUser/", "list.html", root);
}
}
/**
* 多数据源代码生成
*
* @param frameWorkVal
*/
public static void getMutiSourceCode(String outPathVal, String mutidatasourceDir, String frameWorkVal, Map<String, Object> root) throws Exception {
makCodeByTel(getTemplate(CodeFtlConstant.DATA_SOURCE_TYPE), outPathVal, mutidatasourceDir, "DataSourceType.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.DB_TYPE), outPathVal, mutidatasourceDir, "DBType.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.DYNAMIC_DATA_SOURCE), outPathVal, mutidatasourceDir, "DynamicDataSource.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.DYNAMIC_DATA_SOURCE_ASPECT), outPathVal, mutidatasourceDir, "DynamicDataSourceAspect.java", root);
if ("springBoot".equals(frameWorkVal)) {
makCodeByTel(getTemplate(CodeFtlConstant.DYNAMIC_DATA_SOURCE_CONFIG), outPathVal, mutidatasourceDir, "DynamicDataSourceConfig.java", root);
}
makCodeByTel(getTemplate(CodeFtlConstant.DYNAMIC_DATA_SOURCE_HOLDER), outPathVal, mutidatasourceDir, "DynamicDataSourceHolder.java", root);
}
/**
* cloud 模式下生成公共代码
*
* @param outPathVal
*/
public static void makeCloudCommon(String outPathVal, Parameters parameters, Map<String, Object> root) throws Exception {
parameters.getCloudServices().add(parameters.getProjectNameVal());
root.put(CodeConstant.CLOUD_SERVICES, parameters.getCloudServices());
//父工程pom
makCodeByTel(getTemplate(CodeFtlConstant.SYS_PARENT_POM_XML), outPathVal, Constant.CLOUD_SYS_PARENT, "pom.xml", root);
if (CodeConstant.EUREKA.equals(parameters.getCloudRegiseterCenter())) {
//eureka
makCodeByTel(getTemplate(CodeFtlConstant.SYS_EUREKA_POM_XML), outPathVal, Constant.SYS_EUREKA, "pom.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.SYS_EUREKA_YML), outPathVal, Constant.CLOUD_SYS_EUREKA_RESOURCES, "application.yml", root);
makCodeByTel(getTemplate(CodeFtlConstant.EUREKA_SERVER), outPathVal, Constant.CLOUD_SYS_EUREKA, "EurekaServer.java", root);
}
if (CodeConstant.ZUUL.equals(parameters.getCloudNeteWork())) {
//zuul
makCodeByTel(getTemplate(CodeFtlConstant.SYS_ZUUL_POM_XML), outPathVal, Constant.SYS_ZUUL, "pom.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.CLOUD_ZUUL), outPathVal, Constant.CLOUD_SYS_ZUUL, "CloudZuul.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CLOUD_ZUUL_FILTER), outPathVal, Constant.CLOUD_SYS_ZUUL_CONFIG, "CloudZuulFilter.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.ZUUL_CORS_CONFIG), outPathVal, Constant.CLOUD_SYS_ZUUL_CONFIG, "CorsConfig.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.ZUUL_REST_TEMPLATE_CONFIG), outPathVal, Constant.CLOUD_SYS_ZUUL_CONFIG, "RestTemplateConfig.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.CLOUD_ZUUL_YML), outPathVal, Constant.CLOUD_SYS_ZUUL_RESOURCES, "application.yml", root);
} else if (CodeConstant.GATEWAY.equals(parameters.getCloudNeteWork())) {
//gateway
makCodeByTel(getTemplate(CodeFtlConstant.SYS_GATEWAY_POM_XML), outPathVal, Constant.SYS_GATEWAY, "pom.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.GATEWAY_APPLICATION), outPathVal, Constant.CLOUD_SYS_GATEWAY, "GatewayApplication.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.GATEWAY_AUTHORIZE_FILTER), outPathVal, Constant.CLOUD_SYS_GATEWAY, "AuthorizeFilter.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.GATEWAY_YML), outPathVal, Constant.CLOUD_SYS_GATEWAY_RESOURCES, "application.yml", root);
}
//sys-common
makCodeByTel(getTemplate(CodeFtlConstant.SYS_COMMON_POM_XML), outPathVal, Constant.CLOUD_SYS_COMMON, "pom.xml", root);
//service-system
makCodeByTel(getTemplate(CodeFtlConstant.SERVICE_SYSTEM_POM_XML), outPathVal, Constant.CLOUD_SERVICE_SYSTEM, "pom.xml", root);
makCodeByTel(getTemplate(CodeFtlConstant.SERVICE_SYSTEM_APP), outPathVal, FreeOutUtil.setProjectName(Constant.CLOUD_SERVICE_SYSTEM_MAIN, parameters.getCloudSysEngName()), "SystemApplication.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.SERVICE_SYSTEM_YML), outPathVal, Constant.CLOUD_SERVICE_SYSTEM_RESOURCES, "application.yml", root);
//feign
makCodeByTel(getTemplate(CodeFtlConstant.FEIGN_CONFIGURATION), outPathVal, Constant.CLOUD_FEIGN_CONFIG, "DefaultFeignConfiguration.java", root);
makCodeByTel(getTemplate(CodeFtlConstant.FEIGN_POM_XML), outPathVal, Constant.CLOUD_FEIGN_BASE, "pom.xml", root);
}
/**
* 根据模板生成代码文件
*/
private static void makCodeByTel(Template template, String outPathVal, String dir, String fileName, Map<String, Object> root) throws Exception {
//如果都不满足生成条件
if (isNotALL(root) && !isController(template, root) && !isService(template, root) && !isDao(template, root) && !isEntity(template, root) && !isView(template, root)) {
return;
}
if (!isCloudModelPass(template, dir, root)) {
return;
}
if (!isCoverPass(outPathVal + dir + fileName, root)) {
return;
}
Writer out = new OutputStreamWriter(
new FileOutputStream(
FreeOutUtil.checkAndMakeDir(outPathVal + dir) + fileName),
StandardCharsets.UTF_8);
template.process(root, out);
out.flush();
out.close();
}
public static String getSysCommonDir(String projectNameVal, String cloudSysEngName, String dir) {
return dir.replaceFirst(projectNameVal, "sys-common")
.replaceFirst(projectNameVal, cloudSysEngName);
}
public static String getSerSystemDir(String projectNameVal, String cloudSysEngName, String dir) {
return dir.replaceFirst(projectNameVal, "service-system")
.replaceFirst(projectNameVal, cloudSysEngName);
}
public static String getSerDir(String projectNameVal, String cloudSysEngName, String dir) {
return dir.replaceFirst(projectNameVal, "service-" + projectNameVal)
.replaceFirst(projectNameVal, cloudSysEngName)
.replaceFirst(projectNameVal, cloudSysEngName).replaceFirst(cloudSysEngName, projectNameVal);
}
/**
* 是否只生成微服务
*
* @return
*/
private static boolean isCoverPass(String filePath, Map<String, Object> root) {
boolean isCoverExist = (boolean) root.get(CodeConstant.IS_COVER_EXIST_FILE);
if (isCoverExist) {
return true;
}
return !new File(filePath).exists();
}
/**
* 是否只生成微服务
*
* @return
*/
private static boolean isCloudModelPass(Template template, String dir, Map<String, Object> root) {
boolean isCloudModel = (boolean) root.get(CodeConstant.IS_CLOUD_MODEL);
boolean isOnlyCloudModel = (boolean) root.get(CodeConstant.IS_ONLY_CLOUD_MODEL);
if (isCloudModel && isOnlyCloudModel) {
if (dir.contains("sys-gateway") || dir.contains("sys-zuul") || dir.contains("sys-common") || dir.contains("sys-feign-api")) {
String templateName = template.getName();
return templateName.contains(CodeFtlConstant.HTML_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_HTML_FTL)
|| templateName.contains(CodeFtlConstant.ENTITY_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_ENTITY_FTL)
|| templateName.contains(CodeFtlConstant.MAKE_ENTITY_FTL) || templateName.contains(CodeFtlConstant.COMMON_ENTITY_FTL)
|| templateName.contains(CodeFtlConstant.FEIGN_SERVICE_CLIENT);
}
return !dir.contains("sys-") && !dir.contains("service-system");
}
return true;
}
/**
* 是否生全部
*
* @return
*/
private static boolean isNotALL(Map<String, Object> root) {
boolean isController = (boolean) root.get(CodeConstant.IS_CONTROLLER);
boolean isService = (boolean) root.get(CodeConstant.IS_SERVICE);
boolean isDao = (boolean) root.get(CodeConstant.IS_DAO);
boolean isEntity = (boolean) root.get(CodeConstant.IS_ENTITY);
boolean isView = (boolean) root.get(CodeConstant.IS_VIEW);
//有一个选了等于没有全选
return isController || isService || isDao || isEntity || isView;
}
/**
* 是否生controller
*
* @return
*/
private static boolean isController(Template template, Map<String, Object> root) {
String templateName = template.getName();
boolean isController = (boolean) root.get(CodeConstant.IS_CONTROLLER);
return isController && (templateName.contains(CodeFtlConstant.CONTROLLER_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_CONTROLLER_FTL));
}
/**
* 是否生service
*
* @return
*/
private static boolean isService(Template template, Map<String, Object> root) {
String templateName = template.getName();
boolean isService = (boolean) root.get(CodeConstant.IS_SERVICE);
return isService && (templateName.contains(CodeFtlConstant.SERVICE_FTL) || templateName.contains(CodeFtlConstant.ISERVICE_FTL) || templateName.contains(CodeFtlConstant.IMUTI_TABLE_SERVICE_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_SERVICE_FTL));
}
/**
* 是否生service
*
* @return
*/
private static boolean isDao(Template template, Map<String, Object> root) {
String templateName = template.getName();
boolean isDao = (boolean) root.get(CodeConstant.IS_DAO);
return isDao && (templateName.contains(CodeFtlConstant.DAO_FTL) || templateName.contains(CodeFtlConstant.IMUTI_TABLE_DAO_FTL) || templateName.contains(CodeFtlConstant.SQL_MAPPER_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_SQL_MAPPER_FTL));
}
/**
* 是否生entity
*
* @return
*/
private static boolean isEntity(Template template, Map<String, Object> root) {
String templateName = template.getName();
boolean isEntity = (boolean) root.get(CodeConstant.IS_ENTITY);
return isEntity && (templateName.contains(CodeFtlConstant.ENTITY_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_ENTITY_FTL) || templateName.contains(CodeFtlConstant.MAKE_ENTITY_FTL) || templateName.contains(CodeFtlConstant.COMMON_ENTITY_FTL));
}
/**
* 是否生view
*
* @return
*/
private static boolean isView(Template template, Map<String, Object> root) {
String templateName = template.getName();
boolean isView = (boolean) root.get(CodeConstant.IS_VIEW);
return isView && (templateName.contains(CodeFtlConstant.HTML_FTL) || templateName.contains(CodeFtlConstant.MUTI_TABLE_HTML_FTL));
}
/**
* 判断当前操作系统
*/
public static String getSystemType() {
String osName = System.getProperty("os.name");
if (osName.startsWith(Constant.MAC_OS)) {
return Constant.MAC_OS;
} else if (osName.startsWith("Windows")) {
return Constant.WINDOWS;
} else {
return null;
}
}
/**
* 特殊字符过滤
*
* @param str
* @return
*/
public static String spStrFilter(String str) {
// 清除掉所有特殊字符
String regEx = "[-`~!@#$%^&*()+=|{}':;,\\[\\].<>/?!\...()—【】‘;:""’。,、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
String trim = m.replaceAll("").trim();
if ("src".contains(trim) || "main".contains(trim)
|| "java".contains(trim) || "service".contains(trim)
|| "system".contains(trim) || "sys".contains(trim) || "common".contains(trim)) {
return "";
}
return trim;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

代码生成器源码,可一键生成controller,service,dao,实体类,单表、多表的sql语句,日志处理、事务支持等,同时可以生成dubbo和springCloud脚手架方便开发微服务项目,能在很大程度上提高开发效率,节约开发时间。代码生成完毕后即为一个前台到后台的完整项目。目前后台支持SSM/SpringBoot,数据库支持mysql/postgresql/oracle,前台样式使用BootStrap,js支持jquery/vue,导入eclipse/idea便可运行,可根据需求自由扩展!
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版 (2)

全部

开源评估指数源自 OSS-Compass 评估体系,评估体系围绕以下三个维度对项目展开评估:

1. 开源生态

  • 生产力:来评估开源项目输出软件制品和开源价值的能力。
  • 创新力:用于评估开源软件及其生态系统的多样化程度。
  • 稳健性:用于评估开源项目面对多变的发展环境,抵御内外干扰并自我恢复的能力。

2. 协作、人、软件

  • 协作:代表了开源开发行为中协作的程度和深度。
  • 人:观察开源项目核心人员在开源项目中的影响力,并通过第三方视角考察用户和开发者对开源项目的评价。
  • 软件:从开源项目对外输出的制品评估其价值最终落脚点。也是开源评估最"古老"的主流方向之一"开源软件" 的具体表现。

3. 评估模型

    基于"开源生态"与"协作、人、软件"的维度,找到与该目标直接或间接相关的可量化指标,对开源项目健康与生态进行量化评估,最终形成开源评估指数。

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/zrxjava/codeMan.git
git@gitee.com:zrxjava/codeMan.git
zrxjava
codeMan
codeMan
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /