开源 企业版 高校版 私有云 模力方舟 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
/
DataUtils.java
codeMan
/
src
/
main
/
java
/
util
/
DataUtils.java
DataUtils.java 47.68 KB
一键复制 编辑 原始数据 按行查看 历史
zhangruixuann 提交于 2022年04月08日 23:21 +08:00 . feat:集成redis单点登录,集成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 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
package util;
import constant.ChildWindowConstant;
import constant.CodeConstant;
import constant.MenuLevel;
import entity.DataSourceModel;
import entity.Parameters;
import entity.TablesQueryModel;
import entity.cmnSys.CmSysButton;
import entity.cmnSys.CmSysMenu;
import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DataUtils {
/**
* 已经存在的表
*/
private static final List<String> EXIST_TABLES = new ArrayList<>(10);
/**
* @param columnsEng
*/
public static String getSqlParam(String columnsEng) {
String sqlParamColumEng = "";
if (columnsEng.contains(".")) {
columnsEng = columnsEng.toLowerCase();
String[] nameArr = columnsEng.split("\\.");
sqlParamColumEng = makeSqlParam(nameArr);
} else if (columnsEng.contains("_")) {
columnsEng = columnsEng.toLowerCase();
String[] nameArr = columnsEng.split("_");
sqlParamColumEng = makeSqlParam(nameArr);
} else if (columnsEng.contains("-")) {
columnsEng = columnsEng.toLowerCase();
String[] nameArr = columnsEng.split("-");
sqlParamColumEng = makeSqlParam(nameArr);
} else {
if (columnsEng.matches("^[A-Z|0-9A-Z]+$")) {
sqlParamColumEng = columnsEng.toLowerCase();
} else {
if (columnsEng.length() > 2) {
sqlParamColumEng = columnsEng.substring(0, 2).toLowerCase() + columnsEng.substring(2);
} else {
sqlParamColumEng = columnsEng.toLowerCase();
}
}
}
return sqlParamColumEng;
}
private static String makeSqlParam(String[] nameArr) {
StringBuilder sqlParamColumEng = new StringBuilder();
for (int j = 0; j < nameArr.length; j++) {
if (j == 0) {
sqlParamColumEng.append(nameArr[j]);
} else if (nameArr[j].length() > 1) {
sqlParamColumEng.append(nameArr[j].substring(0, 1).toUpperCase()).append(nameArr[j].substring(1));
} else {
sqlParamColumEng.append(nameArr[j].toUpperCase());
}
}
if (sqlParamColumEng.length() > 2) {
sqlParamColumEng = new StringBuilder(sqlParamColumEng.substring(0, 2).toLowerCase() + sqlParamColumEng.substring(2));
} else {
sqlParamColumEng = new StringBuilder(sqlParamColumEng.toString().toLowerCase());
}
return sqlParamColumEng.toString();
}
/**
* 生成权限管理需要的表并初始化数据
*
* @param parameters 参数
*/
public static void makeAuth(Parameters parameters) {
//清空表
EXIST_TABLES.clear();
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
if (parameters.isCloudModel()) {
//如果是cloudModel模式,数据源需要换为系统服务数据源
Parameters cloudSysDsName = parameters.getCloudSysDsParam();
connection = DBUtils.getConnection(cloudSysDsName);
} else {
connection = DBUtils.getConnection(parameters);
}
assert connection != null;
statement = connection.createStatement();
if (CodeConstant.MYSQL.equals(parameters.getDataBaseTypeVal())) {
//cm_sys_user
createTable("cm_sys_user", statement,
"select count(*) from information_schema.tables t where t.table_schema ='" + parameters.getDataBaseNameVal() + "' and t.table_name ='cm_sys_user'",
"CREATE TABLE `cm_sys_user` (\n" +
" `user_id` bigint(20) NOT NULL,\n" +
" `role_id` bigint(20) DEFAULT NULL,\n" +
" `username` varchar(30) DEFAULT NULL,\n" +
" `password` varchar(100) DEFAULT NULL,\n" +
" `create_time` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
" `update_time` datetime DEFAULT NULL,\n" +
" `create_user_id` bigint(20) DEFAULT NULL,\n" +
" `update_user_id` bigint(20) DEFAULT NULL,\n" +
" PRIMARY KEY (`user_id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
//cm_sys_menu
createTable("cm_sys_menu", statement,
"select count(*) from information_schema.tables t where t.table_schema ='" + parameters.getDataBaseNameVal() + "' and t.table_name ='cm_sys_menu'",
"CREATE TABLE `cm_sys_menu` (\n" +
" `menu_id` bigint(20) NOT NULL,\n" +
" `parent_id` bigint(20) DEFAULT NULL,\n" +
" `order_no` bigint(20) DEFAULT NULL,\n" +
" `menu_name` varchar(30) DEFAULT NULL,\n" +
" `menu_icon` varchar(30) DEFAULT NULL,\n" +
" `url_address` varchar(100) DEFAULT NULL,\n" +
" `can_del` int(1) DEFAULT NULL,\n" +
" `create_time` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
" `update_time` datetime DEFAULT NULL,\n" +
" `create_user_id` bigint(20) DEFAULT NULL,\n" +
" `update_user_id` bigint(20) DEFAULT NULL,\n" +
" PRIMARY KEY (`menu_id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
//cm_sys_role
createTable("cm_sys_role", statement,
"select count(*) from information_schema.tables t where t.table_schema ='" + parameters.getDataBaseNameVal() + "' and t.table_name ='cm_sys_role'",
"CREATE TABLE `cm_sys_role` (\n" +
" `role_id` bigint(20) NOT NULL,\n" +
" `role_name` varchar(30) DEFAULT NULL,\n" +
" `create_time` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
" `update_time` datetime DEFAULT NULL,\n" +
" `create_user_id` bigint(20) DEFAULT NULL,\n" +
" `update_user_id` bigint(20) DEFAULT NULL,\n" +
" PRIMARY KEY (`role_id`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
//cm_sys_button
createTable("cm_sys_button", statement,
"select count(*) from information_schema.tables t where t.table_schema ='" + parameters.getDataBaseNameVal() + "' and t.table_name ='cm_sys_button'",
"CREATE TABLE `cm_sys_button` (\n" +
" `button_id` bigint(20) NOT NULL,\n" +
" `menu_id` bigint(20) NOT NULL,\n" +
" `button_name` varchar(30) DEFAULT NULL,\n" +
" `module_tag_id` varchar(30) DEFAULT NULL,\n" +
" `create_time` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
" `update_time` datetime DEFAULT NULL,\n" +
" `create_user_id` bigint(20) DEFAULT NULL,\n" +
" `update_user_id` bigint(20) DEFAULT NULL,\n" +
" PRIMARY KEY (`button_id`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
//cm_sys_role_menu
createTable("cm_sys_role_menu", statement,
"select count(*) from information_schema.tables t where t.table_schema ='" + parameters.getDataBaseNameVal() + "' and t.table_name ='cm_sys_role_menu'",
"CREATE TABLE `cm_sys_role_menu` (\n" +
" `role_menu_id` bigint(20) NOT NULL,\n" +
" `role_id` bigint(20) DEFAULT NULL,\n" +
" `menu_id` bigint(20) DEFAULT NULL,\n" +
" `create_time` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
" `update_time` datetime DEFAULT NULL,\n" +
" `create_user_id` bigint(20) DEFAULT NULL,\n" +
" `update_user_id` bigint(20) DEFAULT NULL,\n" +
" PRIMARY KEY (`role_menu_id`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
//cm_sys_role_button
createTable("cm_sys_role_button", statement,
"select count(*) from information_schema.tables t where t.table_schema ='" + parameters.getDataBaseNameVal() + "' and t.table_name ='cm_sys_role_button'",
"CREATE TABLE `cm_sys_role_button` (\n" +
" `role_button_id` bigint(20) NOT NULL,\n" +
" `role_id` bigint(20) DEFAULT NULL,\n" +
" `button_id` bigint(20) DEFAULT NULL,\n" +
" `menu_id` bigint(20) DEFAULT NULL,\n" +
" `create_time` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
" `update_time` datetime DEFAULT NULL,\n" +
" `create_user_id` bigint(20) DEFAULT NULL,\n" +
" `update_user_id` bigint(20) DEFAULT NULL,\n" +
" PRIMARY KEY (`role_button_id`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
} else if (CodeConstant.ORACLE.equals(parameters.getDataBaseTypeVal())) {
//cm_sys_user
createTable("cm_sys_user", statement,
"select count(*) from user_tables where table_name=upper('cm_sys_user')",
"CREATE TABLE \"CM_SYS_USER\" \n" +
" (\t\"USER_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"ROLE_ID\" NUMBER(20,0), \n" +
"\t\"USERNAME\" NVARCHAR2(30), \n" +
"\t\"PASSWORD\" NVARCHAR2(100), \n" +
"\t\"CREATE_TIME\" DATE, \n" +
"\t\"UPDATE_TIME\" DATE, \n" +
"\t\"CREATE_USER_ID\" NUMBER(20,0), \n" +
"\t\"UPDATE_USER_ID\" NUMBER(20,0), \n" +
"\t PRIMARY KEY (\"USER_ID\"))");
//cm_sys_menu
createTable("cm_sys_menu", statement,
"select count(*) from user_tables where table_name=upper('cm_sys_menu')",
"CREATE TABLE \"CM_SYS_MENU\" \n" +
" (\t\"MENU_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"PARENT_ID\" NUMBER(20,0), \n" +
"\t\"ORDER_NO\" NUMBER(20,0), \n" +
"\t\"MENU_NAME\" NVARCHAR2(30), \n" +
"\t\"MENU_ICON\" NVARCHAR2(30), \n" +
"\t\"URL_ADDRESS\" NVARCHAR2(100), \n" +
"\t\"CAN_DEL\" NUMBER(1,0), \n" +
"\t\"CREATE_TIME\" DATE, \n" +
"\t\"UPDATE_TIME\" DATE, \n" +
"\t\"CREATE_USER_ID\" NUMBER(20,0), \n" +
"\t\"UPDATE_USER_ID\" NUMBER(20,0), \n" +
"\t PRIMARY KEY (\"MENU_ID\"))");
//cm_sys_role
createTable("cm_sys_role", statement,
"select count(*) from user_tables where table_name=upper('cm_sys_role')",
"CREATE TABLE \"CM_SYS_ROLE\" \n" +
" (\t\"ROLE_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"ROLE_NAME\" NVARCHAR2(30), \n" +
"\t\"CREATE_TIME\" DATE, \n" +
"\t\"UPDATE_TIME\" DATE, \n" +
"\t\"CREATE_USER_ID\" NUMBER(20,0), \n" +
"\t\"UPDATE_USER_ID\" NUMBER(20,0), \n" +
"\t PRIMARY KEY (\"ROLE_ID\"))");
//cm_sys_button
createTable("cm_sys_button", statement,
"select count(*) from user_tables where table_name=upper('cm_sys_button')",
"CREATE TABLE \"CM_SYS_BUTTON\" \n" +
" (\t\"BUTTON_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"MENU_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"BUTTON_NAME\" NVARCHAR2(30), \n" +
"\t\"MODULE_TAG_ID\" NVARCHAR2(30), \n" +
"\t\"CREATE_TIME\" DATE, \n" +
"\t\"UPDATE_TIME\" DATE, \n" +
"\t\"CREATE_USER_ID\" NUMBER(20,0), \n" +
"\t\"UPDATE_USER_ID\" NUMBER(20,0), \n" +
"\t PRIMARY KEY (\"BUTTON_ID\"))");
//cm_sys_role_menu
createTable("cm_sys_role_menu", statement,
"select count(*) from user_tables where table_name=upper('cm_sys_role_menu')",
"CREATE TABLE \"CM_SYS_ROLE_MENU\" \n" +
" (\t\"ROLE_MENU_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"ROLE_ID\" NUMBER(20,0), \n" +
"\t\"MENU_ID\" NUMBER(20,0), \n" +
"\t\"CREATE_TIME\" DATE, \n" +
"\t\"UPDATE_TIME\" DATE, \n" +
"\t\"CREATE_USER_ID\" NUMBER(20,0), \n" +
"\t\"UPDATE_USER_ID\" NUMBER(20,0), \n" +
"\t PRIMARY KEY (\"ROLE_MENU_ID\"))");
//cm_sys_role_button
createTable("cm_sys_role_button", statement,
"select count(*) from user_tables where table_name=upper('cm_sys_role_button')",
"CREATE TABLE \"CM_SYS_ROLE_BUTTON\" \n" +
" (\t\"ROLE_BUTTON_ID\" NUMBER(20,0) NOT NULL ENABLE, \n" +
"\t\"ROLE_ID\" NUMBER(20,0), \n" +
"\t\"BUTTON_ID\" NUMBER(20,0), \n" +
"\t\"MENU_ID\" NUMBER(20,0), \n" +
"\t\"CREATE_TIME\" DATE, \n" +
"\t\"UPDATE_TIME\" DATE, \n" +
"\t\"CREATE_USER_ID\" NUMBER(20,0), \n" +
"\t\"UPDATE_USER_ID\" NUMBER(20,0), \n" +
"\t PRIMARY KEY (\"ROLE_BUTTON_ID\"))");
} else if (CodeConstant.POSTGRESQL.equals(parameters.getDataBaseTypeVal())) {
rs = statement.executeQuery("select count(*) FROM information_schema.schemata WHERE schema_name = 'public';");
rs.next();
int count = rs.getInt(1);
//如果没查到,证明没有这个表,创建public模式
if (count == 0) {
statement.executeUpdate("create schema public");
}
//cm_sys_user
createTable("cm_sys_user", statement,
"select count(*) from information_schema.tables where table_schema='public' AND table_name='cm_sys_user'",
"CREATE TABLE \"public\".\"cm_sys_user\" (\n" +
" \"user_id\" int8 NOT NULL,\n" +
" \"role_id\" int8,\n" +
" \"username\" varchar(30) COLLATE \"pg_catalog\".\"default\",\n" +
" \"password\" varchar(100) COLLATE \"pg_catalog\".\"default\",\n" +
" \"create_time\" timestamp(6),\n" +
" \"update_time\" timestamp(6),\n" +
" \"create_user_id\" int8,\n" +
" \"update_user_id\" int8,\n" +
" CONSTRAINT \"cm_sys_user_pkey\" PRIMARY KEY (\"user_id\")\n" +
")");
//cm_sys_menu
createTable("cm_sys_menu", statement,
"select count(*) from information_schema.tables where table_schema='public' AND table_name='cm_sys_menu'",
"CREATE TABLE \"public\".\"cm_sys_menu\" (\n" +
" \"menu_id\" int8 NOT NULL,\n" +
" \"parent_id\" int8,\n" +
" \"order_no\" int8,\n" +
" \"menu_name\" varchar(30) COLLATE \"pg_catalog\".\"default\",\n" +
" \"menu_icon\" varchar(30) COLLATE \"pg_catalog\".\"default\",\n" +
" \"url_address\" varchar(100) COLLATE \"pg_catalog\".\"default\",\n" +
" \"can_del\" int8,\n" +
" \"create_time\" timestamp(6),\n" +
" \"update_time\" timestamp(6),\n" +
" \"create_user_id\" int8,\n" +
" \"update_user_id\" int8,\n" +
" CONSTRAINT \"cm_sys_menu_pkey\" PRIMARY KEY (\"menu_id\")\n" +
")");
//cm_sys_role
createTable("cm_sys_role", statement,
"select count(*) from information_schema.tables where table_schema='public' AND table_name='cm_sys_role'",
"CREATE TABLE \"public\".\"cm_sys_role\" (\n" +
" \"role_id\" int8 NOT NULL,\n" +
" \"role_name\" varchar(30) COLLATE \"pg_catalog\".\"default\",\n" +
" \"create_time\" timestamp(6),\n" +
" \"update_time\" timestamp(6),\n" +
" \"create_user_id\" int8,\n" +
" \"update_user_id\" int8,\n" +
" CONSTRAINT \"cm_sys_role_pkey\" PRIMARY KEY (\"role_id\")\n" +
")");
//cm_sys_button
createTable("cm_sys_button", statement,
"select count(*) from information_schema.tables where table_schema='public' AND table_name='cm_sys_button'",
"CREATE TABLE \"public\".\"cm_sys_button\" (\n" +
" \"button_id\" int8 NOT NULL,\n" +
" \"menu_id\" int8 NOT NULL,\n" +
" \"button_name\" varchar(30) COLLATE \"pg_catalog\".\"default\",\n" +
" \"module_tag_id\" varchar(30) COLLATE \"pg_catalog\".\"default\",\n" +
" \"create_time\" timestamp(6),\n" +
" \"update_time\" timestamp(6),\n" +
" \"create_user_id\" int8,\n" +
" \"update_user_id\" int8,\n" +
" CONSTRAINT \"cm_sys_button_pkey\" PRIMARY KEY (\"button_id\")\n" +
")");
//cm_sys_role_menu
createTable("cm_sys_role_menu", statement,
"select count(*) from information_schema.tables where table_schema='public' AND table_name='cm_sys_role_menu'",
"CREATE TABLE \"public\".\"cm_sys_role_menu\" (\n" +
" \"role_menu_id\" int8 NOT NULL,\n" +
" \"role_id\" int8,\n" +
" \"menu_id\" int8,\n" +
" \"create_time\" timestamp(6),\n" +
" \"update_time\" timestamp(6),\n" +
" \"create_user_id\" int8,\n" +
" \"update_user_id\" int8,\n" +
" CONSTRAINT \"cm_sys_role_menu_pkey\" PRIMARY KEY (\"role_menu_id\")\n" +
")");
//cm_sys_role_button
createTable("cm_sys_role_button", statement,
"select count(*) from information_schema.tables where table_schema='public' AND table_name='cm_sys_role_button'",
"CREATE TABLE \"public\".\"cm_sys_role_button\" (\n" +
" \"role_button_id\" int8 NOT NULL,\n" +
" \"role_id\" int8,\n" +
" \"button_id\" int8,\n" +
" \"menu_id\" int8,\n" +
" \"create_time\" timestamp(6),\n" +
" \"update_time\" timestamp(6),\n" +
" \"create_user_id\" int8,\n" +
" \"update_user_id\" int8,\n" +
" CONSTRAINT \"cm_sys_role_button_pkey\" PRIMARY KEY (\"role_button_id\")\n" +
")");
} else if (CodeConstant.SQL_SERVER.equals(parameters.getDataBaseTypeVal())) {
//cm_sys_user
createTable("cm_sys_user", statement,
"select count(*) from sysobjects where name='cm_sys_user'",
"CREATE TABLE [dbo].[cm_sys_user] (\n" +
" [user_id] bigint NOT NULL,\n" +
" [role_id] bigint NULL,\n" +
" [username] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [password] nvarchar(100) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [create_time] datetime NULL,\n" +
" [update_time] datetime NULL,\n" +
" [create_user_id] bigint NULL,\n" +
" [update_user_id] bigint NULL,\n" +
" CONSTRAINT [PK__cm_sys_u__B9BE370FFE3BA845] PRIMARY KEY CLUSTERED ([user_id]))\n"
);
//cm_sys_menu
createTable("cm_sys_menu", statement,
"select count(*) from sysobjects where name='cm_sys_menu'",
"CREATE TABLE [dbo].[cm_sys_menu] (\n" +
" [menu_id] bigint NOT NULL,\n" +
" [parent_id] bigint NULL,\n" +
" [order_no] bigint NULL,\n" +
" [menu_name] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [menu_icon] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [url_address] nvarchar(100) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [can_del] int NULL,\n" +
" [create_time] datetime NULL,\n" +
" [update_time] datetime NULL,\n" +
" [create_user_id] bigint NULL,\n" +
" [update_user_id] bigint NULL,\n" +
" CONSTRAINT [PK__cm_sys_m__4CA0FADCF6ED6F9D] PRIMARY KEY CLUSTERED ([menu_id]))\n"
);
//cm_sys_role
createTable("cm_sys_role", statement,
"select count(*) from sysobjects where name='cm_sys_role'",
"CREATE TABLE [dbo].[cm_sys_role] (\n" +
" [role_id] bigint NOT NULL,\n" +
" [role_name] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [create_time] datetime NULL,\n" +
" [update_time] datetime NULL,\n" +
" [create_user_id] bigint NULL,\n" +
" [update_user_id] bigint NULL,\n" +
" CONSTRAINT [PK__cm_sys_r__760965CC910C7522] PRIMARY KEY CLUSTERED ([role_id]))\n"
);
//cm_sys_button
createTable("cm_sys_button", statement,
"select count(*) from sysobjects where name='cm_sys_button'",
"CREATE TABLE [dbo].[cm_sys_button] (\n" +
" [button_id] bigint NOT NULL,\n" +
" [menu_id] bigint NOT NULL,\n" +
" [button_name] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [module_tag_id] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL,\n" +
" [create_time] datetime NULL,\n" +
" [update_time] datetime NULL,\n" +
" [create_user_id] bigint NULL,\n" +
" [update_user_id] bigint NULL,\n" +
" CONSTRAINT [PK__cm_sys_b__D288541B2D707289] PRIMARY KEY CLUSTERED ([button_id]))\n"
);
//cm_sys_role_menu
createTable("cm_sys_role_menu", statement,
"select count(*) from sysobjects where name='cm_sys_role_menu'",
"CREATE TABLE [dbo].[cm_sys_role_menu] (\n" +
" [role_menu_id] bigint NOT NULL,\n" +
" [role_id] bigint NULL,\n" +
" [menu_id] bigint NULL,\n" +
" [create_time] datetime NULL,\n" +
" [update_time] datetime NULL,\n" +
" [create_user_id] bigint NULL,\n" +
" [update_user_id] bigint NULL,\n" +
" CONSTRAINT [PK__cm_sys_r__7101AE8A33410FC5] PRIMARY KEY CLUSTERED ([role_menu_id]))\n"
);
//cm_sys_role_button
createTable("cm_sys_role_button", statement,
"select count(*) from sysobjects where name='cm_sys_role_button'",
"CREATE TABLE [dbo].[cm_sys_role_button] (\n" +
" [role_button_id] bigint NOT NULL,\n" +
" [role_id] bigint NULL,\n" +
" [button_id] bigint NULL,\n" +
" [menu_id] bigint NULL,\n" +
" [create_time] datetime NULL,\n" +
" [update_time] datetime NULL,\n" +
" [create_user_id] bigint NULL,\n" +
" [update_user_id] bigint NULL,\n" +
" CONSTRAINT [PK__cm_sys_r__C9997DED28C833C2] PRIMARY KEY CLUSTERED ([role_button_id]))\n");
}
//生成数据
authDataInit(connection, parameters);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "权限管理建表时出错:" + e.getMessage(), "错误",
JOptionPane.ERROR_MESSAGE);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException ignored) {
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException ignored) {
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException ignored) {
}
}
}
}
private static void createTable(String tableName, Statement statement, String countSql, String createSql) {
try {
ResultSet rs = statement.executeQuery(countSql);
rs.next();
int count = rs.getInt(1);
//如果没查到,证明没有这个表,创建
if (count == 0) {
statement.executeUpdate(createSql);
//如果有这个表,提示用户需不需要创建
} else {
int ifGo = JOptionPane.showConfirmDialog(null,
"您的数据库中已存在" + tableName + "表" + CodeConstant.NEW_LINE
+ "是否需要重建表(重建会删除已有表以及表中数据)?",
"提示", JOptionPane.YES_NO_OPTION);
if (ifGo == 0) {
statement.executeUpdate("DROP TABLE " + tableName);
statement.executeUpdate(createSql);
//重新建表了,移除
EXIST_TABLES.remove(tableName);
} else {
//没有建表,添加
EXIST_TABLES.add(tableName);
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "权限管理建表时出错:" + e.getMessage(), "错误",
JOptionPane.ERROR_MESSAGE);
}
}
/**
* 初始化权限管理表的数据
*
* @param connection
*/
private static void authDataInit(Connection connection, Parameters parameters) {
PreparedStatement pst;
try {
if (!EXIST_TABLES.contains("cm_sys_user")) {
//初始化cm_sys_user表
pst = connection.prepareStatement("INSERT INTO cm_sys_user(user_id,role_id,username,password,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 1);
pst.setLong(2, 1);
pst.setString(3, "admin");
//前台需要传md5加密后的密码,后台再次加密后比对
pst.setString(4, Md5Util.digest(Md5Util.digest("123456")));
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
}
if (!EXIST_TABLES.contains("cm_sys_role")) {
//初始化cm_sys_role表
pst = connection.prepareStatement("INSERT INTO cm_sys_role(role_id,role_name,create_time,create_user_id) VALUES(?,?,?,?)");
pst.setLong(1, 1);
pst.setString(2, "超级管理员");
pst.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
pst.setLong(4, 1);
pst.executeUpdate();
pst.close();
}
if (!EXIST_TABLES.contains("cm_sys_menu")) {
//初始化cm_sys_menu表
//创建系统管理,用户管理,菜单管理,角色管理四个基本菜单
pst = connection.prepareStatement("INSERT INTO cm_sys_menu(menu_id,parent_id,order_no,menu_name,menu_icon,url_address,can_del,create_time,create_user_id) VALUES(?,?,?,?,?,?,?,?,?)");
pst.setLong(1, 562076320075694080L);
pst.setLong(2, 0L);
pst.setLong(3, 562076320075694080L);
pst.setString(4, "系统管理");
pst.setString(5, CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "icon icon-chart" : "fa fa fa-bar-chart-o");
pst.setString(6, "");
pst.setInt(7, 0);
pst.setTimestamp(8, new Timestamp(System.currentTimeMillis()));
pst.setLong(9, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_menu(menu_id,parent_id,order_no,menu_name,menu_icon,url_address,can_del,create_time,create_user_id) VALUES(?,?,?,?,?,?,?,?,?)");
pst.setLong(1, 562076608706723840L);
pst.setLong(2, 562076320075694080L);
pst.setLong(3, 562076608706723840L);
pst.setString(4, "用户管理");
pst.setString(5, "");
pst.setString(6, CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "cm_sys_user/list" : "cmSysUser/list.html");
pst.setInt(7, 0);
pst.setTimestamp(8, new Timestamp(System.currentTimeMillis()));
pst.setLong(9, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_menu(menu_id,parent_id,order_no,menu_name,menu_icon,url_address,can_del,create_time,create_user_id) VALUES(?,?,?,?,?,?,?,?,?)");
pst.setLong(1, 562076608706723852L);
pst.setLong(2, 562076320075694080L);
pst.setLong(3, 562076608706723852L);
pst.setString(4, "菜单管理");
pst.setString(5, "");
pst.setString(6, CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "cm_sys_menu/list" : "cmSysMenu/list.html");
pst.setInt(7, 0);
pst.setTimestamp(8, new Timestamp(System.currentTimeMillis()));
pst.setLong(9, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_menu(menu_id,parent_id,order_no,menu_name,menu_icon,url_address,can_del,create_time,create_user_id) VALUES(?,?,?,?,?,?,?,?,?)");
pst.setLong(1, 582393341447278592L);
pst.setLong(2, 562076320075694080L);
pst.setLong(3, 582393341447278592L);
pst.setString(4, "角色管理");
pst.setString(5, "");
pst.setString(6, CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "cm_sys_role/list" : "cmSysRole/list.html");
pst.setInt(7, 0);
pst.setTimestamp(8, new Timestamp(System.currentTimeMillis()));
pst.setLong(9, 1);
pst.executeUpdate();
pst.close();
}
if (!EXIST_TABLES.contains("cm_sys_role_menu")) {
//初始化cm_sys_role_menu表
pst = connection.prepareStatement("INSERT INTO cm_sys_role_menu(role_menu_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?)");
pst.setLong(1, 583197571498196992L);
pst.setLong(2, 1);
pst.setLong(3, 562076320075694080L);
pst.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
pst.setLong(5, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_menu(role_menu_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?)");
pst.setLong(1, 583197571506585600L);
pst.setLong(2, 1);
pst.setLong(3, 562076608706723840L);
pst.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
pst.setLong(5, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_menu(role_menu_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?)");
pst.setLong(1, 583197571523362816L);
pst.setLong(2, 1);
pst.setLong(3, 562076608706723852L);
pst.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
pst.setLong(5, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_menu(role_menu_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?)");
pst.setLong(1, 583197571552722944L);
pst.setLong(2, 1);
pst.setLong(3, 582393341447278592L);
pst.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
pst.setLong(5, 1);
pst.executeUpdate();
pst.close();
}
if (!EXIST_TABLES.contains("cm_sys_button")) {
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583066629735907327L);
pst.setLong(2, 562076608706723840L);
pst.setString(3, "查询");
pst.setString(4, "queryTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
//初始化cm_sys_button表
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583166629735907328L);
pst.setLong(2, 562076608706723840L);
pst.setString(3, "添加");
pst.setString(4, "addTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583166706466504704L);
pst.setLong(2, 562076608706723840L);
pst.setString(3, "更新");
pst.setString(4, "upTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583166791195639808L);
pst.setLong(2, 562076608706723840L);
pst.setString(3, "删除");
pst.setString(4, "delTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583068347689271295L);
pst.setLong(2, 582393341447278592L);
pst.setString(3, "查询");
pst.setString(4, "queryTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583168347689271296L);
pst.setLong(2, 582393341447278592L);
pst.setString(3, "添加");
pst.setString(4, "addTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583068436348469247L);
pst.setLong(2, 582393341447278592L);
pst.setString(3, "更新");
pst.setString(4, "upTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583168436348469248L);
pst.setLong(2, 582393341447278592L);
pst.setString(3, "删除");
pst.setString(4, "delTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583170351580921856L);
pst.setLong(2, 562076608706723852L);
pst.setString(3, "添加操作");
pst.setString(4, "addButtonTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583170406463389696L);
pst.setLong(2, 562076608706723852L);
pst.setString(3, "删除");
pst.setString(4, "delTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583170462281187328L);
pst.setLong(2, 562076608706723852L);
pst.setString(3, "添加二级菜单");
pst.setString(4, "addSecondMenuTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583170592136839168L);
pst.setLong(2, 562076608706723852L);
pst.setString(3, "添加一级菜单");
pst.setString(4, "addFirstMenuTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583170689817985024L);
pst.setLong(2, 562076608706723852L);
pst.setString(3, "保存");
pst.setString(4, "upTag");
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
}
if (!EXIST_TABLES.contains("cm_sys_role_button")) {
//初始化cm_sys_role_button表
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583097571510779903L);
pst.setLong(2, 583066629735907327L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723840L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571510779904L);
pst.setLong(2, 583166629735907328L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723840L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571514974208L);
pst.setLong(2, 583166706466504704L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723840L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571519168512L);
pst.setLong(2, 583166791195639808L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723840L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571527557120L);
pst.setLong(2, 583170351580921856L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723852L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571535945728L);
pst.setLong(2, 583170406463389696L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723852L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571535945729L);
pst.setLong(2, 583170462281187328L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723852L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571540140032L);
pst.setLong(2, 583170592136839168L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723852L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571548528640L);
pst.setLong(2, 583170689817985024L);
pst.setLong(3, 1);
pst.setLong(4, 562076608706723852L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583097571561111551L);
pst.setLong(2, 583068347689271295L);
pst.setLong(3, 1);
pst.setLong(4, 582393341447278592L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571561111552L);
pst.setLong(2, 583168347689271296L);
pst.setLong(3, 1);
pst.setLong(4, 582393341447278592L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583097571565305855L);
pst.setLong(2, 583068436348469247L);
pst.setLong(3, 1);
pst.setLong(4, 582393341447278592L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, 583197571565305856L);
pst.setLong(2, 583168436348469248L);
pst.setLong(3, 1);
pst.setLong(4, 582393341447278592L);
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
}
//如果是多数据源模式
if (parameters.isMutiDataSource()) {
//遍历每个数据源
for (Map.Entry<String, DataSourceModel> modelEntry : ChildWindowConstant.dataSourceModelMap.entrySet()) {
DataSourceModel dataSourceModel = modelEntry.getValue();
insertCustomData(parameters, dataSourceModel.getCurrentTableCnNameMap(), dataSourceModel.getTablesQueryMap(), dataSourceModel.getTablesQueryEndAndCnMap(), connection);
}
} else {
insertCustomData(parameters, ChildWindowConstant.currentTableCnNameMap, ChildWindowConstant.tablesQueryMap, ChildWindowConstant.tablesQueryEndAndCnMap, connection);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "权限管理初始化数据时出错(mysql请使用5.7及以上版本):" + e.getMessage(), "错误",
JOptionPane.ERROR_MESSAGE);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException ignored) {
}
}
}
}
/**
* 插入自己定义的菜单等数据
*/
private static void insertCustomData(Parameters parameters, Map<String, String> currentTableCnNameMap, Map<String, Map<String, TablesQueryModel>> tablesQueryMap, Map<String, String> tablesQueryEndAndCnMap, Connection connection) throws SQLException {
PreparedStatement pst;
//添加自定义的菜单
List<CmSysMenu> cmSysMenus = getCmSysMenus(parameters, currentTableCnNameMap, tablesQueryMap, tablesQueryEndAndCnMap);
//按钮列表
List<CmSysButton> cmSysButtons = new ArrayList<>(10);
List<Long> menuIds = new ArrayList<>();
//插入cm_sys_menu表
for (CmSysMenu cmSysMenu : cmSysMenus) {
if (cmSysMenu.getParentId() == 0) {
//判断是否存在该菜单,存在,则不添加菜单数据
pst = connection.prepareStatement("SELECT menu_id FROM cm_sys_menu WHERE menu_name=?");
pst.setString(1, cmSysMenu.getMenuName());
ResultSet rs = pst.executeQuery();
if (rs.next()) {
menuIds.add(cmSysMenu.getMenuId());
continue;
}
}
if (menuIds.contains(cmSysMenu.getParentId())) {
continue;
}
pst = connection.prepareStatement("INSERT INTO cm_sys_menu(menu_id,parent_id,order_no,menu_name,menu_icon,url_address,create_time,create_user_id) VALUES(?,?,?,?,?,?,?,?)");
pst.setLong(1, cmSysMenu.getMenuId());
pst.setLong(2, cmSysMenu.getParentId());
pst.setLong(3, cmSysMenu.getOrderNo());
pst.setString(4, cmSysMenu.getMenuName());
pst.setString(5, cmSysMenu.getMenuIcon());
pst.setString(6, cmSysMenu.getUrlAddress());
pst.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
pst.setLong(8, 1);
pst.executeUpdate();
pst.close();
//插入cm_sys_role_menu表
pst = connection.prepareStatement("INSERT INTO cm_sys_role_menu(role_menu_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?)");
pst.setLong(1, SnowflakeIdWorker.generateId());
pst.setLong(2, 1);
pst.setLong(3, cmSysMenu.getMenuId());
pst.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
pst.setLong(5, 1);
pst.executeUpdate();
pst.close();
//插入cm_sys_button表(需要在模板标签上添加moduleTagId属性)
//如果是二级菜单,则插入按钮
if (cmSysMenu.getParentId() != 0) {
//如果是单表查询,插入增删改按钮
if (!cmSysMenu.getUrlAddress().contains("Muti")) {
//查询
CmSysButton cmSysButtonQuery = new CmSysButton();
cmSysButtonQuery.setButtonId(SnowflakeIdWorker.generateId());
cmSysButtonQuery.setMenuId(cmSysMenu.getMenuId());
cmSysButtonQuery.setButtonName("查询");
cmSysButtonQuery.setModuleTagId("queryTag");
//添加按钮
CmSysButton cmSysButtonAdd = new CmSysButton();
cmSysButtonAdd.setButtonId(SnowflakeIdWorker.generateId());
cmSysButtonAdd.setMenuId(cmSysMenu.getMenuId());
cmSysButtonAdd.setButtonName("添加");
cmSysButtonAdd.setModuleTagId("addTag");
//更新按钮
CmSysButton cmSysButtonUpdate = new CmSysButton();
cmSysButtonUpdate.setButtonId(SnowflakeIdWorker.generateId());
cmSysButtonUpdate.setMenuId(cmSysMenu.getMenuId());
cmSysButtonUpdate.setButtonName("更新");
cmSysButtonUpdate.setModuleTagId("upTag");
//删除按钮
CmSysButton cmSysButtonDelete = new CmSysButton();
cmSysButtonDelete.setButtonId(SnowflakeIdWorker.generateId());
cmSysButtonDelete.setMenuId(cmSysMenu.getMenuId());
cmSysButtonDelete.setButtonName("删除");
cmSysButtonDelete.setModuleTagId("delTag");
//加入列表
cmSysButtons.add(cmSysButtonQuery);
cmSysButtons.add(cmSysButtonAdd);
cmSysButtons.add(cmSysButtonUpdate);
cmSysButtons.add(cmSysButtonDelete);
}
}
}
//插入cm_sys_button表
for (CmSysButton cmSysButton : cmSysButtons) {
pst = connection.prepareStatement("INSERT INTO cm_sys_button(button_id,menu_id,button_name,module_tag_Id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, cmSysButton.getButtonId());
pst.setLong(2, cmSysButton.getMenuId());
pst.setString(3, cmSysButton.getButtonName());
pst.setString(4, cmSysButton.getModuleTagId());
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
//插入cm_sys_role_button表
pst = connection.prepareStatement("INSERT INTO cm_sys_role_button(role_button_id,button_id,role_id,menu_id,create_time,create_user_id) VALUES(?,?,?,?,?,?)");
pst.setLong(1, SnowflakeIdWorker.generateId());
pst.setLong(2, cmSysButton.getButtonId());
pst.setLong(3, 1);
pst.setLong(4, cmSysButton.getMenuId());
pst.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
pst.setLong(6, 1);
pst.executeUpdate();
pst.close();
}
}
public static List<CmSysMenu> getCmSysMenus(Parameters parameters, Map<String, String> currentTableCnNameMap, Map<String, Map<String, TablesQueryModel>> tablesQueryMap, Map<String, String> tablesQueryEndAndCnMap) {
List<CmSysMenu> cmSysMenus = new ArrayList<>(10);
//查询所有单表 一个单表默认为一个一级菜单,同时包含一个二级子菜单
for (Map.Entry<String, String> entry : currentTableCnNameMap.entrySet()) {
//获取表英文名
String tableEng = entry.getKey();
//获取表中文名
String tableCn = entry.getValue();
//组装menu
//一级菜单
CmSysMenu menuParent = new CmSysMenu();
menuParent.setMenuId(SnowflakeIdWorker.generateId());
menuParent.setMenuName(tableCn);
menuParent.setOrderNo(menuParent.getMenuId());
menuParent.setParentId(0L);
menuParent.setMenuIcon(CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "icon icon-chart" : "fa fa fa-bar-chart-o");
menuParent.setTableEng(tableEng);
menuParent.setLevel(MenuLevel.PARENT);
//二级地址菜单
CmSysMenu menuChild = new CmSysMenu();
menuChild.setMenuId(SnowflakeIdWorker.generateId());
menuChild.setParentId(menuParent.getMenuId());
menuChild.setOrderNo(menuChild.getMenuId());
menuChild.setMenuName("信息管理");
menuChild.setUrlAddress(tableEng + (CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "/list" : "/list.html"));
menuParent.setTableEng(tableEng);
menuParent.setLevel(MenuLevel.CHILD);
//添加到cmSysMenus中
cmSysMenus.add(menuParent);
cmSysMenus.add(menuChild);
}
//查询所有多表 模块名为一级菜单 里面的map 每个map里的方法为一个二级菜单
for (Map.Entry<String, Map<String, TablesQueryModel>> entry : tablesQueryMap.entrySet()) {
//获取模块英文名
String modelNameEng = entry.getKey();
//获取模块中文名
String modelNameCn = tablesQueryEndAndCnMap.get(modelNameEng);
//添加模块一级菜单
CmSysMenu menuParent = new CmSysMenu();
menuParent.setMenuId(SnowflakeIdWorker.generateId());
menuParent.setParentId(0L);
menuParent.setMenuName(modelNameCn);
menuParent.setOrderNo(menuParent.getMenuId());
menuParent.setMenuIcon(CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "icon icon-chart" : "fa fa fa-bar-chart-o");
menuParent.setTableEng(modelNameEng);
menuParent.setLevel(MenuLevel.PARENT);
//添加到cmSysMenus中
cmSysMenus.add(menuParent);
//获取模块下的所有方法,添加二级菜单
Map<String, TablesQueryModel> methodMap = entry.getValue();
for (Map.Entry<String, TablesQueryModel> methodEntry : methodMap.entrySet()) {
//添加二级菜单
CmSysMenu menuChild = new CmSysMenu();
menuChild.setMenuId(SnowflakeIdWorker.generateId());
menuChild.setParentId(menuParent.getMenuId());
menuChild.setOrderNo(menuChild.getMenuId());
menuChild.setMenuName(methodEntry.getValue().getMethodName_cn());
menuChild.setUrlAddress(modelNameEng + "Muti/" + methodEntry.getKey() + (CodeConstant.OLD_THEME.equals(parameters.getThemeVal()) ? "List" : "List.html"));
menuChild.setTableEng(modelNameEng);
menuParent.setLevel(MenuLevel.CHILD);
//添加到cmSysMenus中
cmSysMenus.add(menuChild);
}
}
if (parameters.isCloudModel()) {
List<CmSysMenu> cloudMenus = parameters.getCloudMenus();
cmSysMenus.forEach(menu -> {
if (!cloudMenus.contains(menu)) {
cloudMenus.add(menu);
}
});
return cloudMenus;
}
return cmSysMenus;
}
}
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 によって変換されたページ (->オリジナル) /