CreateCode.java 67.6 KB
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 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
package com.huaheng.test;

import java.io.*;
import java.sql.*;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class CreateCode {

    public static void main(String[] args)
    {
        try {
            //language=SQL
            String sql = "select TABLE_NAME, TABLE_COMMENT from information_schema.tables where table_schema = 'liuzhouzhituo'";
            List<Map<String, Object>> tableList = getDataList(sql);
            //language=SQL
            sql = "SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT FROM information_schema.columns WHERE table_schema = 'liuzhouzhituo'";
            List<Map<String, Object>> columnList = getDataList(sql);
//            sql = "SELECT * FROM config_header WHERE deleted = FALSE and enable = TRUE";
//            List<Map<String, Object>> configHeadeCcolumnList = getDataList(sql);
//            sql = "SELECT * FROM config_detail WHERE deleted = FALSE and enable = TRUE";
//            List<Map<String, Object>> configDetailColumnList = getDataList(sql);
            Map<String, String> packageNames = getPackages();

            if (tableList.size() > 0 && columnList.size() > 0) {


                createMapper(tableList, columnList, packageNames);
//                createModel(tableList, columnList);
//                createDao(tableList, columnList, packageNames);
//                createService(tableList);
//                createServiceImpl(tableList);
//                createController(tableList, columnList);
            }
        } catch (Exception ex) {
            // 处理 JDBC 错误
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
    }
//
//    private static void  createEnumerate (List<Map<String, Object>> tableList, List<Map<String, Object>> columnList)
//    {
//        System.out.println("====================开始生成MODEL====================================");
//
//        String directory = "src/main/java/com/huaheng/wms/enumerate";
//        StringBuilder sb = new StringBuilder();
//
//        for(Map<String, Object> tableMap : tableList)
//        {
//            String tableName = getStringValue(tableMap.get("TABLE_NAME"));
//            String modelName = underlineConvertUpper(tableName);
//
//            sringBuilderAppend(sb, 2, "package com.huaheng.wms.enumerate;");
//
//            sringBuilderAppend(sb, 2, MessageFormat.format("public enum {0}Column {'", modelName));
//
//            for(Map<String, Object> columnMap : columnList)
//            {
//                if (columnMap.get("TABLE_NAME").equals(tableName))
//                {
//                    String columnName = getStringValue(columnMap.get("COLUMN_NAME"));
//                    String columnComment = getStringValue(columnMap.get("COLUMN_COMMENT"));
//                    String dataType = sqlToModel(getStringValue(columnMap.get("DATA_TYPE")));
//                    String methodName = underlineConvertUpper(getStringValue(columnMap.get("COLUMN_NAME")));
//                    String isNull = getStringValue(columnMap.get("IS_NULLABLE"));
//                    String columnDefault = getStringValue(columnMap.get("COLUMN_DEFAULT"));
//
//                    if (isNull.equals("NO") && columnDefault == null && !columnName.equals("id"))
//                    {
//                        if (dataType.equals("String"))
//                            sringBuilderAppend(sb, 1, MessageFormat.format("    @NotBlank(message=\"{0}不能为空\")", columnComment));
//                        else
//                            sringBuilderAppend(sb, 1, MessageFormat.format("    @NotNull(message=\"{0}不能为空\")", columnComment));
//                    }
//                    sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiModelProperty(value = \"{0}\")", columnComment));
//                    sringBuilderAppend(sb, 1, MessageFormat.format("    private {0} {1};", dataType, columnName));
//                    if (dataType.equals("String"))
//                    {
//                        sringBuilderAppend(sb, 1, MessageFormat.format("    public void set{0}({1} {2})  '{' this.{2} = {2} == null ? null : {2}.trim(); '}'", methodName, dataType, columnName));
//                    }
//                    else
//                    {
//                        sringBuilderAppend(sb, 1, MessageFormat.format("    public void set{1}({0} {2})  '{' this.{2} = {2}; '}'", dataType, methodName, columnName));
//                    }
//                    sringBuilderAppend(sb, 2, MessageFormat.format("    public {0} get{1}()  '{' return this.{2}; '}'", dataType, methodName, columnName));
//                }
//            }
//            sringBuilderAppend(sb, 2, "}");
//            if (sb.length() > 0)
//            {
//                createFile(directory, modelName + ".java", sb.toString());
//                sb.delete(0, sb.length());
//                // 输出数据
//                System.out.println(MessageFormat.format("生成 模型:{0} ", modelName));
//            }
//        }
//
//        System.out.println("====================生成MODEL完成====================================");
//    }


//    private static void  createModel (List<Map<String, Object>> tableList, List<Map<String, Object>> columnList)
//    {
//        System.out.println("====================开始生成MODEL====================================");
//
//        String directory = "src/main/java/com/huaheng/wms/model";
//        StringBuilder sb = new StringBuilder();
//
//        for(Map<String, Object> tableMap : tableList)
//        {
//            String tableName = getStringValue(tableMap.get("TABLE_NAME"));
//            String modelName = underlineConvertUpper(tableName);
//
//            sringBuilderAppend(sb, 2, "package com.huaheng.wms.model;");
//            sringBuilderAppend(sb, 1, "import io.swagger.annotations.ApiModelProperty;");
//            sringBuilderAppend(sb, 1, "import javax.validation.constraints.*;");
//            sringBuilderAppend(sb, 2, "import java.math.BigDecimal;");
//            sringBuilderAppend(sb, 2, "import java.util.Date;");
//            sringBuilderAppend(sb, 2, MessageFormat.format("public class {0}  extends BaseModel '{'", modelName));
//
//            for(Map<String, Object> columnMap : columnList)
//            {
//                if (columnMap.get("TABLE_NAME").equals(tableName))
//                {
//                    String columnName = getStringValue(columnMap.get("COLUMN_NAME"));
//                    String columnComment = getStringValue(columnMap.get("COLUMN_COMMENT"));
//                    String dataType = sqlToModel(getStringValue(columnMap.get("DATA_TYPE")));
//                    String methodName = underlineConvertUpper(getStringValue(columnMap.get("COLUMN_NAME")));
//                    String isNull = getStringValue(columnMap.get("IS_NULLABLE"));
//                    String columnDefault = getStringValue(columnMap.get("COLUMN_DEFAULT"));
//
//                    if (isNull.equals("NO") && columnDefault == null && !columnName.equals("id"))
//                    {
//                        if (dataType.equals("String"))
//                            sringBuilderAppend(sb, 1, MessageFormat.format("    @NotBlank(message=\"{0}不能为空\")", columnComment));
//                        else
//                            sringBuilderAppend(sb, 1, MessageFormat.format("    @NotNull(message=\"{0}不能为空\")", columnComment));
//                    }
//                    sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiModelProperty(value = \"{0}\")", columnComment));
//                    sringBuilderAppend(sb, 1, MessageFormat.format("    private {0} {1};", dataType, columnName));
//                    if (dataType.equals("String"))
//                    {
//                        sringBuilderAppend(sb, 1, MessageFormat.format("    public void set{0}({1} {2})  '{' this.{2} = {2} == null ? null : {2}.trim(); '}'", methodName, dataType, columnName));
//                    }
//                    else
//                    {
//                        sringBuilderAppend(sb, 1, MessageFormat.format("    public void set{1}({0} {2})  '{' this.{2} = {2}; '}'", dataType, methodName, columnName));
//                    }
//                    sringBuilderAppend(sb, 2, MessageFormat.format("    public {0} get{1}()  '{' return this.{2}; '}'", dataType, methodName, columnName));
//                }
//            }
//            sringBuilderAppend(sb, 2, "}");
//            if (sb.length() > 0)
//            {
//                createFile(directory, modelName + ".java", sb.toString());
//                sb.delete(0, sb.length());
//                // 输出数据
//                System.out.println(MessageFormat.format("生成 模型:{0} ", modelName));
//            }
//        }
//
//        System.out.println("====================生成MODEL完成====================================");
//    }

    private static void  createMapper (List<Map<String, Object>> tableList, List<Map<String, Object>> columnList, Map<String, String> packageNames)
    {
        System.out.println("====================开始生成Mapper====================================");

        String tableName = "";
        String packageName = null;
        String modelName = null;
        String humpName = null;
        String directory = null;
        StringBuilder mapperSB = new StringBuilder();
        StringBuilder columnNameSB = new StringBuilder();

        for(Map<String, Object> tableMap : tableList)
        {
            tableName = getStringValue(tableMap.get("TABLE_NAME"));
            packageName = packageNames.get(tableName);
            //modelName = underlineConvertUpper(tableName);

            if (packageName == null)  continue;
            directory = "src/main/resources/mybatis/" + packageName.split("\\.")[3];
            modelName = packageName.split("\\.")[5];
            packageName = packageName.substring(0, packageName.lastIndexOf("."));

            for(Map<String, Object> columnMap : columnList)
                if (columnMap.get("TABLE_NAME").equals(tableName))
                    columnNameSB.append(columnMap.get("COLUMN_NAME").toString() + ", ");

            columnNameSB.delete(columnNameSB.length() - 2, columnNameSB.length() - 1);
            sringBuilderAppend(mapperSB, 1, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sringBuilderAppend(mapperSB, 1, "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("<mapper namespace=\"{0}.mapper.{1}MapperAuto\">", packageName, modelName));

            //生成 selectListEntityByLike 方法
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  <select id=\"selectListEntityByLike\" resultType=\"{0}.domain.{1}\">", packageName, modelName));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("   SELECT {0} ",  columnNameSB.toString()));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("   FROM {0}",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));

                    if (columnNameItem.toLowerCase().equals("companyid") || columnNameItem.toLowerCase().equals("companycode"))
                    {
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0}List != null and {0}List.size() > 0 \"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} in ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        <foreach collection=\"{0}List\" item=\"{0}Item\" open=\"(\" separator=\",\" close=\")\">", columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("            #'{'{0}Item'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "        </foreach>");
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                    if (dataType.equals("date") || dataType.equals("datetime") || dataType.equals("timestamp"))
                    {
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"params != null and params.{0}Begin != null and params.{0}Begin != ''''\"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} &gt;= #'{'params.{0}Begin'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"params != null and params.{0}End != null and params.{0}End != ''''\"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} &lt;= #'{'params.{0}End'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                    else
                    {
                        String Operate = getOperate(columnNameItem, dataType);
                        if (Operate.equals("="))     {
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null \"> ",  columnNameItem));
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'{0}'}'",  columnNameItem));
                        }
                        else if (Operate.equals("equals")){
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null and {0} != '''' \"> ",  columnNameItem));
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'{0}'}'",  columnNameItem));

                        }
                        else    {
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null and {0} != ''''\"> ",  columnNameItem));
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("        <bind name=\"{0}Pattern\" value=\"''%'' + {0} + ''%''\" />", columnNameItem));
                            sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} like #'{'{0}Pattern'}'", columnNameItem));
                        }
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 2, "  </select>");

            //生成 selectListEntityByEqual 方法
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  <select id=\"selectListEntityByEqual\" resultType=\"{0}.domain.{1}\">", packageName, modelName));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("   SELECT {0} ",  columnNameSB.toString()));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("   FROM {0}",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    if (columnNameItem.toLowerCase().equals("companyid") || columnNameItem.toLowerCase().equals("companycode"))
                    {
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0}List != null and {0}List.size() > 0 \"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} in ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        <foreach collection=\"{0}List\" item=\"{0}Item\" open=\"(\" separator=\",\" close=\")\">", columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("            #'{'{0}Item'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "        </foreach>");
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null\"> ", columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'{0}'}'", columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 2, "  </select>");

            //生成 selectListMapByEqual 方法
            sringBuilderAppend(mapperSB, 1, "  <select id=\"selectListMapByEqual\" resultType=\"java.util.HashMap\">");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("      SELECT $'{'columns'}' FROM {0}",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));

                    if (columnNameItem.toLowerCase().equals("companyid") || columnNameItem.toLowerCase().equals("companycode"))
                    {
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"condition.{0}List != null and condition.{0}List.size() > 0 \"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} in ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        <foreach collection=\"condition.{0}List\" item=\"{0}Item\" open=\"(\" separator=\",\" close=\")\">", columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("            #'{'{0}Item'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "        </foreach>");
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"condition.{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'condition.{0}'}'",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 2, "  </select>");

            //生成 selectEntityById 方法
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  <select id=\"selectEntityById\" resultType=\"{0}.domain.{1}\">", packageName, modelName));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("      SELECT {0} FROM {1} WHERE id = #'{'id'}'",  columnNameSB.toString(), tableName));
            sringBuilderAppend(mapperSB, 2, "  </select>");

            //生成 selectFirstEntity 方法
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  <select id=\"selectFirstEntity\" resultType=\"{0}.domain.{1}\">", packageName, modelName));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  SELECT {0} ",  columnNameSB.toString()));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  FROM {0}",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));

                    if (columnNameItem.toLowerCase().equals("companyid") || columnNameItem.toLowerCase().equals("companycode"))
                    {
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0}List != null and {0}List.size() > 0 \"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} in ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        <foreach collection=\"{0}List\" item=\"{0}Item\" open=\"(\" separator=\",\" close=\")\">", columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("            #'{'{0}Item'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "        </foreach>");
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'{0}'}'",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 1, "   LIMIT 1 ");
            sringBuilderAppend(mapperSB, 2, "  </select>");

            //生成 selectFirstMap 方法
            sringBuilderAppend(mapperSB, 1, "  <select id=\"selectFirstMap\" resultType=\"java.util.HashMap\">");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("      SELECT $'{'columns'}' FROM {0}",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));

                    if (columnNameItem.toLowerCase().equals("companyid") || columnNameItem.toLowerCase().equals("companycode"))
                    {
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"condition.{0}List != null  and condition.{0}List.size() > 0 \"> ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} in ",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("        <foreach collection=\"condition.{0}List\" item=\"{0}Item\" open=\"(\" separator=\",\" close=\")\">", columnNameItem));
                        sringBuilderAppend(mapperSB, 1, MessageFormat.format("            #'{'{0}Item'}'",  columnNameItem));
                        sringBuilderAppend(mapperSB, 1, "        </foreach>");
                        sringBuilderAppend(mapperSB, 1, "    </if>");
                    }
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"condition.{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'condition.{0}'}'",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 1, "   LIMIT 1 ");
            sringBuilderAppend(mapperSB, 2, "  </select>");

            //生成 insert 方法
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  <insert id=\"insert\" parameterType=\"{0}.domain.{1}\" keyProperty=\"id\" useGeneratedKeys=\"true\" >", packageName, modelName));
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  INSERT INTO {0} ",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    if (columnNameItem.equals("id"))  continue;;
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        {0}, ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </trim>");
            sringBuilderAppend(mapperSB, 1, "  <trim prefix=\" values (\" suffix=\")\" suffixOverrides=\",\">");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    if (columnNameItem.equals("id"))  continue;;
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        #'{'{0}, jdbcType={1}'}', ",  columnNameItem, convertJdbcType(dataType)));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </trim>");
            sringBuilderAppend(mapperSB, 2, "  </insert>");

            //生成 updateByModel 方法
            sringBuilderAppend(mapperSB, 1, "  <update id=\"updateByModel\">");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  UPDATE {0} ",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <set>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    if (columnNameItem.equals("id"))  continue;;
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null\"> ",  columnMap.get("COLUMN_NAME")));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        {0} = #'{'{0}, jdbcType={1}'}', ",  columnNameItem, convertJdbcType(dataType)));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </set>");
            sringBuilderAppend(mapperSB, 1, "   WHERE id = #{id,jdbcType=INTEGER}");
            sringBuilderAppend(mapperSB, 2, "  </update>");

            //生成 updateByCondition 方法
            sringBuilderAppend(mapperSB, 1, "  <update id=\"updateByCondition\">");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  UPDATE {0} ",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <set>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String dataType = getStringValue(columnMap.get("DATA_TYPE"));
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    if (columnNameItem.equals("id"))  continue;;
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"record.{0} != null\"> ",  columnMap.get("COLUMN_NAME")));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        {0} = #'{'record.{0}, jdbcType={1}'}', ",  columnNameItem, convertJdbcType(dataType)));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </set>");
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"condition.{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'condition.{0}'}'",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 2, "  </update>");

            //生成 delete 方法
            sringBuilderAppend(mapperSB, 1, "  <delete id=\"deleteById\"> ");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  DELETE FROM {0} WHERE id = #'{'id, jdbcType=INTEGER'}' ",  tableName));
            sringBuilderAppend(mapperSB, 2, "  </delete>");

            //生成 delete 方法
            sringBuilderAppend(mapperSB, 1, "  <delete id=\"deleteByCondition\"> ");
            sringBuilderAppend(mapperSB, 1, MessageFormat.format("  DELETE FROM {0} ",  tableName));
            sringBuilderAppend(mapperSB, 1, "  <where>");
            for(Map<String, Object> columnMap : columnList)
            {
                if (columnMap.get("TABLE_NAME").equals(tableName))
                {
                    String columnNameItem = getStringValue(columnMap.get("COLUMN_NAME"));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("    <if test=\"{0} != null\"> ",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, MessageFormat.format("        AND {0} = #'{'{0}'}'",  columnNameItem));
                    sringBuilderAppend(mapperSB, 1, "    </if>");
                }
            }
            sringBuilderAppend(mapperSB, 1, "  </where>");
            sringBuilderAppend(mapperSB, 2, "  </delete>");
            sringBuilderAppend(mapperSB, 2, "  </mapper>");
            if (mapperSB.length() > 0)
            {
                createFile(directory, modelName + "MapperAuto.xml", mapperSB.toString());
                mapperSB.delete(0, mapperSB.length());
                columnNameSB.delete(0, columnNameSB.length());
                // 输出数据
                System.out.println(MessageFormat.format("生成: {0}MapperAuto.xml", modelName));
            }
        }

        System.out.println("====================生成Mapper完成====================================");
    }

//    private static void  createDao (List<Map<String, Object>> tableList, List<Map<String, Object>> columnList, Map<String, String> packageNames)
//    {
//        System.out.println("====================开始生成Dao====================================");
//
//        String tableName = "";
//        String packageName = null;
//        String modelName = null;
//        String humpName = null;
//        String directory = null;
//
//        for(Map<String, Object> tableMap : tableList)
//        {
//            tableName = getStringValue(tableMap.get("TABLE_NAME"));
//            packageName = packageNames.get(tableName);
//            modelName = underlineConvertUpper(tableName);
//
//            if (packageName == null)  continue;
//            directory = "src/main/java/com/huaheng/pc/" + packageName.split("\\.")[3] +"/"+ modelName +"/mapper";
//            StringBuilder sb = new StringBuilder();
//
//            modelName = underlineConvertUpper(getStringValue(tableMap.get("TABLE_NAME")));
//            String mapperName = modelName + "MapperAuto";
//
//            sringBuilderAppend(sb, 2, "package com.huaheng.wms.dao.db1.autogeneration;");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.model.{0};", modelName));
//            sringBuilderAppend(sb, 1, "import org.apache.ibatis.annotations.Param;");
//            sringBuilderAppend(sb, 1, "import java.util.List;");
//            sringBuilderAppend(sb, 2, "import java.util.Map;");
//
//            sringBuilderAppend(sb, 2, MessageFormat.format("public interface {0} '{'", mapperName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    List<{0}> selectListEntityByLike({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    List<{0}> selectListEntityByEqual({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    List<Map<String, Object>> selectListMapByEqual(@Param(\"columns\") String columns, @Param(\"condition\") {0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    {0} selectEntityById(Integer id);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    {0} selectFirstEntity({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    Map<String, Object> selectFirstMap(@Param(\"columns\") String columns, @Param(\"condition\") {0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int insert({0} record);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int updateByModel({0} record);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int updateByCondition(@Param(\"record\") {0} record, @Param(\"condition\") {0} condition);", modelName));
//            sringBuilderAppend(sb, 2, "    int deleteById(Integer id);");
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int deleteByCondition({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, "}");
//
//            if (sb.length() > 0)
//            {
//                createFile(directory, mapperName + ".java", sb.toString());
//                sb.delete(0, sb.length());
//                // 输出数据
//                System.out.println(MessageFormat.format("生成 Dao:{0} ", mapperName));
//            }
//        }
//
//        System.out.println("====================生成Dao完成====================================");
//    }

//    private static void  createService (List<Map<String, Object>> tableList)
//    {
//        System.out.println("====================开始生成Service====================================");
//
//        String directory = "src/main/java/com/huaheng/wms/service/autogeneration";
//        StringBuilder sb = new StringBuilder();
//
//        for(Map<String, Object> tableMap : tableList)
//        {
//            String modelName = underlineConvertUpper(getStringValue(tableMap.get("TABLE_NAME")));
//            String serviceName = modelName + "Service";
//
//            sringBuilderAppend(sb, 2, "package com.huaheng.wms.service.autogeneration;");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.model.{0};", modelName));
//            sringBuilderAppend(sb, 1, "import java.util.List;");
//            sringBuilderAppend(sb, 2, "import java.util.Map;");
//
//            sringBuilderAppend(sb, 2, MessageFormat.format("public interface {0} '{'", serviceName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    List<{0}> selectListEntityByLike({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    List<{0}> selectListEntityByEqual({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    {0} selectFirstEntity({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    {0} selectEntityById(Integer id);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    List<Map<String, Object>> selectListMapByEqual(String columnList, {0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    Map<String, Object> selectFirstMap(String columnList, {0} condition);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int insert({0} record);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int updateByModel({0} record);", modelName));
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int updateByCondition({0} record, {0} condition);", modelName));
//            sringBuilderAppend(sb, 2, "    int deleteById(Integer id);");
//            sringBuilderAppend(sb, 2, MessageFormat.format("    int deleteByCondition({0} condition);", modelName));
//            sringBuilderAppend(sb, 2, "}");
//
//            if (sb.length() > 0)
//            {
//                createFile(directory, serviceName + ".java", sb.toString());
//                sb.delete(0, sb.length());
//                // 输出数据
//                System.out.println(MessageFormat.format("生成 Service:{0} ", serviceName));
//            }
//        }
//
//        System.out.println("====================生成Service完成====================================");
//    }

//    private static void  createServiceImpl (List<Map<String, Object>> tableList)
//    {
//        System.out.println("====================开始生成ServiceImpl====================================");
//
//        String directory = "src/main/java/com/huaheng/wms/serviceImpl/autogeneration/";
//        StringBuilder sb = new StringBuilder();
//
//        for(Map<String, Object> tableMap : tableList)
//        {
//            String modelName = underlineConvertUpper(getStringValue(tableMap.get("TABLE_NAME")));
//            String ServiceImplName = modelName + "ServiceImpl";
//
//            sringBuilderAppend(sb, 2, "package com.huaheng.wms.serviceImpl.autogeneration;");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.model.{0};", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.dao.db1.autogeneration.{0}mapper;", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.service.autogeneration.{0}Service;", modelName));
//            sringBuilderAppend(sb, 1, "import com.github.pagehelper.PageHelper;");
//            sringBuilderAppend(sb, 1, "import org.springframework.stereotype.Service;");
//            sringBuilderAppend(sb, 1, "import javax.annotation.Resource;");
//            sringBuilderAppend(sb, 1, "import java.util.List;");
//            sringBuilderAppend(sb, 2, "import java.util.Map;");
//
//            sringBuilderAppend(sb, 1, "@Service");
//            sringBuilderAppend(sb, 2, MessageFormat.format("public class {0}ServiceImpl implements {0}Service '{'", modelName));
//
//            sringBuilderAppend(sb, 1, "    @Resource");
//            sringBuilderAppend(sb, 2, MessageFormat.format("    private {0}AutoMapper aotuMapper;", modelName));
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public List<{0}> selectListEntityByLike({0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.selectListEntityByLike(condition);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public List<{0}> selectListEntityByEqual({0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.selectListEntityByEqual(condition);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public {0} selectFirstEntity({0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        {0} item = aotuMapper.selectFirstEntity(condition);", modelName));
//            sringBuilderAppend(sb, 1, "        return item;");
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public {0} selectEntityById(Integer id) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.selectEntityById(id);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public List<Map<String, Object>> selectListMapByEqual(String columns, {0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.selectListMapByEqual(columns, condition);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public Map<String, Object> selectFirstMap(String columns, {0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        Map<String, Object> item = aotuMapper.selectFirstMap(columns, condition);", modelName));
//            sringBuilderAppend(sb, 1, "        return item;");
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public int insert({0} record) '{'", modelName));
//            sringBuilderAppend(sb, 1, "        return aotuMapper.insert(record);");
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public int updateByModel({0} record) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.updateByModel(record);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public int updateByCondition({0} record, {0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.updateByCondition(record, condition);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public int deleteById(Integer id) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.deleteById(id);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public int deleteByCondition({0} condition) '{'", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        return aotuMapper.deleteByCondition(condition);", modelName));
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 2, "}");
//
//            if (sb.length() > 0)
//            {
//                createFile(directory, ServiceImplName + ".java", sb.toString());
//                sb.delete(0, sb.length());
//                // 输出数据
//                System.out.println(MessageFormat.format("生成 ServiceImpl:{0} ", ServiceImplName));
//            }
//        }
//
//        System.out.println("====================生成ServiceImpl完成====================================");
//    }

//    private static void  createController (List<Map<String, Object>> tableList, List<Map<String, Object>> columnList)
//    {
//        System.out.println("====================开始生成Controller====================================");
//
//        String directory = "src/main/java/com/huaheng/wms/controller";
//        StringBuilder sb = new StringBuilder();
//
//        for(Map<String, Object> tableMap : tableList)
//        {
//            String tableName = getStringValue(tableMap.get("TABLE_NAME"));
//            String modelName = underlineConvertUpper(tableName);
//            String humpName = FirstCharToLower(modelName);
//            String ServiceImplName = modelName + "Controller";
//            String tableComment = getStringValue(tableMap.get("TABLE_COMMENT"));
//            List<String> columNameList = new ArrayList<String>();
//            for(Map<String, Object> columnMap : columnList)
//            {
//                if (columnMap.get("TABLE_NAME").equals(tableName))
//                {
//                    columNameList.add(columnMap.get("COLUMN_NAME").toString());
//                }
//            }
//            sringBuilderAppend(sb, 2, "package com.huaheng.wms.controller;");
//
//            sringBuilderAppend(sb, 1, "import com.huaheng.wms.core.aop.AnnotationLog;");
//            sringBuilderAppend(sb, 1, "import com.huaheng.wms.core.ret.*;");
//            sringBuilderAppend(sb, 1, "import com.huaheng.wms.core.utils.*;");
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.model.{0};", modelName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("import com.huaheng.wms.service.autogeneration.{0}Service;", modelName));
//            sringBuilderAppend(sb, 1, "import com.github.pagehelper.*;");
//            sringBuilderAppend(sb, 1, "import org.springframework.validation.annotation.Validated;");
//            sringBuilderAppend(sb, 1, "import org.springframework.web.bind.annotation.*;");
//            sringBuilderAppend(sb, 1, "import io.swagger.annotations.*;");
//            sringBuilderAppend(sb, 1, "import javax.annotation.Resource;");
//            sringBuilderAppend(sb, 2, "import java.util.List;");
//
//            sringBuilderAppend(sb, 1, "@CrossOrigin");
//            sringBuilderAppend(sb, 1, "@RestController");
//            sringBuilderAppend(sb, 1, MessageFormat.format("@RequestMapping(\"/{0}\")", humpName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("@Api(tags = '{'\"{0}Controller\"'}', description = \"{1}操作接口\")", modelName, tableComment));
//            sringBuilderAppend(sb, 2, MessageFormat.format("public class {0}Controller '{'", modelName));
//
//            sringBuilderAppend(sb, 1, "    @Resource");
//            sringBuilderAppend(sb, 2, MessageFormat.format("    private {0}Service {1}Service;", modelName, humpName));
//            // 列表展示
//            sringBuilderAppend(sb, 1, "    @PostMapping(\"/list\")");
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiOperation(\"{0}列表\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public RetResult<PageInfo<{1}>> list(@RequestBody @ApiParam(value=\"{0}对象\") {1} condition) throws Exception '{'", tableComment, modelName));
//            if (columNameList.contains("deleted"))
//                sringBuilderAppend(sb, 1, "        condition.setDeleted(false);");
//            if (columNameList.contains("warehouseId"))
//                sringBuilderAppend(sb, 1, "        condition.setWarehouseId(UserInfoUtils.getWarehouseId());");
//            sringBuilderAppend(sb, 1, "        PageHelper.startPage(condition.getPageNumber(), condition.getPageSize());");
//            sringBuilderAppend(sb, 1, MessageFormat.format("        List<{0}> list = {1}Service.selectListEntityByLike(condition);", modelName, humpName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        PageInfo<{0}> pageInfo = new PageInfo<{0}>(list);", modelName));
//            sringBuilderAppend(sb, 1, "        return RetResponse.makeOKRsp(pageInfo);");
//            sringBuilderAppend(sb, 2, "    }");
//            // 内容查看
//            sringBuilderAppend(sb, 1, "    @PostMapping(\"/selectById\")");
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiOperation(\"{0}内容\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public RetResult<{0}> selectById(@RequestBody @ApiParam(value=\"{1}id\") Integer id) throws Exception '{'", modelName, tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        {0} item = {1}Service.selectEntityById(id);", modelName, humpName));
//            sringBuilderAppend(sb, 1, "        return RetResponse.makeOKRsp(item);");
//            sringBuilderAppend(sb, 2, "    }");
//            //新增
//            sringBuilderAppend(sb, 1, "    @PostMapping(\"/insert\")");
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiOperation(\"{0}添加\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @AnnotationLog(remark = \"{0}添加\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public RetResult<Integer> insert(@RequestBody @Validated @ApiParam(value=\"{0}对象\") {1} {2}) throws Exception '{' ", tableComment, modelName, humpName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setId(null);", humpName));
//            if (columNameList.contains("created"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setCreated(null);", humpName));
//            if (columNameList.contains("createdBy"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setCreatedBy(UserInfoUtils.getCode());", humpName));
//            if (columNameList.contains("lastUpdated"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setLastUpdated(null);", humpName));
//            if (columNameList.contains("lastUpdatedBy"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setLastUpdatedBy(null);", humpName));
//            if (columNameList.contains("enable"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setEnable(true);", humpName));
//            if (columNameList.contains("deleted"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setDeleted(false);", humpName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        Integer state = {0}Service.insert({0});", humpName));
//            sringBuilderAppend(sb, 1, "        return RetResponse.makeOKRsp(state);");
//            sringBuilderAppend(sb, 2, "    }");
//            //修改
//            sringBuilderAppend(sb, 1, "    @PostMapping(\"/update\")");
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiOperation(\"{0}修改\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @AnnotationLog(remark = \"{0}修改\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public RetResult<Integer> update(@RequestBody @ApiParam(value=\"{0}对象\") {1} {2}) throws Exception '{' ", tableComment, modelName, humpName));
//            if (columNameList.contains("created"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setCreated(null);", humpName));
//            if (columNameList.contains("createdBy"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setCreatedBy(null);", humpName));
//            if (columNameList.contains("lastUpdatedBy"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setLastUpdatedBy(UserInfoUtils.getCode());", humpName));
//            if (columNameList.contains("lastUpdated"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setLastUpdated(null);", humpName));
//            if (columNameList.contains("deleted"))
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setDeleted(false);", humpName));
//            sringBuilderAppend(sb, 1, MessageFormat.format("        Integer state = {0}Service.updateByModel({0});", humpName));
//            sringBuilderAppend(sb, 1, "        return RetResponse.makeOKRsp(state);");
//            sringBuilderAppend(sb, 2, "    }");
//            //删除
//            sringBuilderAppend(sb, 1, "    @PostMapping(\"/deleteById\")");
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @ApiOperation(\"{0}删除\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    @AnnotationLog(remark = \"{0}删除\")", tableComment));
//            sringBuilderAppend(sb, 1, MessageFormat.format("    public RetResult<Integer> deleteById(@RequestBody @ApiParam(value=\"{0}id\") Integer id) throws Exception '{' ", tableComment));
//            if (columNameList.contains("deleted"))
//            {
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0} {1} = new {0}();", modelName, humpName));
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setId(id);", humpName));
//                sringBuilderAppend(sb, 1, MessageFormat.format("        {0}.setDeleted(true);", humpName));
//                sringBuilderAppend(sb, 1, MessageFormat.format("        Integer state = {0}Service.updateByModel({0});", humpName));
//            }
//            else
//            {
//                sringBuilderAppend(sb, 1, MessageFormat.format("        Integer state = {1}Service.deleteById(id);", modelName, humpName));
//            }
//            sringBuilderAppend(sb, 1, "        return RetResponse.makeOKRsp(state);");
//            sringBuilderAppend(sb, 2, "    }");
//
//            sringBuilderAppend(sb, 2, "}");
//
//            if (sb.length() > 0)
//            {
//                createFile(directory, ServiceImplName + ".java", sb.toString());
//                sb.delete(0, sb.length());
//                columNameList.clear();
//                // 输出数据
//                System.out.println(MessageFormat.format("生成 Controller:{0} ", ServiceImplName));
//            }
//        }
//
//        System.out.println("====================生成Controller完成====================================");
//    }

    /**
     *  根据SQL查询数据,并且返回List<Map<String, Object>>
     * @param sql
     * @return
     */
    private static List<Map<String, Object>> getDataList(String sql)
    {
        System.out.println("====================开始生成List<Map<String, Object>>数据====================================");
        // JDBC 驱动名及数据库 URL
        // String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";


        // 数据库的URL、用户名、密码,需要根据自己的设置
        String DB_URL = "jdbc:mysql://172.16.29.45:3306/liuzhouzhituo?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false";
        String USER = "softhuaheng";
        String PASS = "HHrobot123.";

        Connection conn = null;
        Statement stmt = null;
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();

        try{
            // 注册 JDBC 驱动
//             Class.forName("com.mysql.jdbc.Driver");

            // 打开链接
            conn = DriverManager.getConnection(DB_URL, USER, PASS);
            System.out.println("连接到数据库。。。。。。");

            // 执行查询
            stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            System.out.println("执行查询。。。。。。");

            //获取架构,然后填充到 List<Map<String, Object>>
            ResultSetMetaData md = rs.getMetaData();
            while (rs.next()) {
                Map<String, Object> rowData = new HashMap<String, Object>();//声明Map
                for (int i = 1; i <= md.getColumnCount(); i++) {
                    rowData.put(md.getColumnName(i), rs.getObject(i));  //获取键名及值
                }
                dataList.add(rowData);
            }

            stmt.close();
            conn.close();
        }
        catch(SQLException ex)
        {
            // 处理 JDBC 错误
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        catch(Exception ex)
        {
            // 处理 Class.forName 错误
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        finally
        {
            // 关闭资源
            try
            {
                if(stmt!=null) stmt.close();
            }
            catch(SQLException ex)
            {
                System.out.println(ex.getMessage());
                ex.printStackTrace();
            }
            try
            {
                if(conn!=null) conn.close();
            }
            catch(SQLException ex)
            {
                System.out.println(ex.getMessage());
                ex.printStackTrace();
            }
        }
        System.out.println("====================开始返回List<Map<String, Object>>数据====================================");
        return dataList;
    }

    /**
     *  写文件到指定位置
     * @param path
     * @param fileName
     * @param content
     */
    private static void  createFile (String path, String fileName, String content)
    {
        File file = null;
        FileOutputStream outPut = null;
        OutputStreamWriter writer = null;
        try
        {
            file = new File(path);
            if(!file.isDirectory() || !file.exists())  file.mkdirs();

            // 构建FileOutputStream对象,文件不存在会自动新建
            outPut = new FileOutputStream(path + "/" + fileName);

            // 构建OutputStreamWriter对象,参数可以指定编码,默认为操作系统默认编码,windows上是gbk
            writer = new OutputStreamWriter(outPut, "UTF-8");

            // 写入到缓冲区
            writer.append(content);

            // 换行
            writer.append("\r\n");

            // 刷新缓存冲,写入到文件,如果下面已经没有写入的内容了,直接close也会写入
            writer.flush();
        }
        catch(FileNotFoundException ex)
        {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        catch(IOException ex)
        {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                //关闭写入流,同时会把缓冲区内容写入文件,所以上面的注释掉
                writer.close();

                // 关闭输出流,释放系统资源
                outPut.close();
            }
            catch(IOException ex)
            {
                System.out.println(ex.getMessage());
                ex.printStackTrace();
            }
        }
    }

    /***
     * 去掉下划线,并且1.将首写字母大写  2.将首字母大写
     * @param content
     * @return
     */
    private static String  underlineConvertUpper (String content)
    {
        if (content == null)  return null;
        Boolean Uppper = true;
        StringBuilder sb = new StringBuilder();
        if (content.length() > 0)
        {
            char[] contentChar = content.toCharArray();
            for(int i=0; i<contentChar.length; i++)
            {
                if (contentChar[i] == '_')
                {
                    Uppper = true;
                }
                else
                {
                    if (contentChar[i] > 96 && Uppper)
                    {
                        sb.append((char) (contentChar[i] - 32));
                    }
                    else
                    {
                        sb.append(contentChar[i]);
                    }
                    Uppper = false;
                }
            }
        }
        return sb.toString();
    }

    private static String  FirstCharToLower (String content)
    {
        char[] contentArray = content.toCharArray();
        contentArray[0] = Character.toLowerCase(contentArray[0]);
        return  new String(contentArray);
    }

    private static String  FirstCharToUpper (String content)
    {
        char[] contentArray = content.toCharArray();
        contentArray[0] = Character.toUpperCase(contentArray[0]);
        return  new String(contentArray);
    }
    /**
     * 将SQL类型映射为Java类型
     * @param SqlType
     * @return
     */
    private static String  sqlToModel (String SqlType)
    {
        switch(SqlType)
        {
            case "char" :
            case "varchar" :
            case "tinytext" :
            case "mediumtext" :
            case "text" :
                return "String";
            case "tinyint" :
                return "Byte";
            case "smallint" :
                return "Short";
            case "mediumint" :
            case "int" :
            case "integer" :
                return "Integer";
            case "bigint" :
                return "Long";
            case "real" :
            case "float" :
                return "Float";
            case "double" :
                return "Double";
            case "numeric" :
            case "decimal" :
                return "BigDecimal";
            case "bit" :
                return "Boolean";
            case "time" :
                return "Time";
            case "date" :
            case "datetime" :
            case "timestamp" :
                return "Date";
            case "binary":
            case "varbinary":
                return "Byte[]";
            default :
                return "";
        }
    }

    private static String  convertJdbcType (String sqlType)
    {
        if (sqlType == null)  return null;
        String jdbcType = sqlType.toUpperCase();
        if (jdbcType.equals("INT")) 	return "INTEGER";
        else if (jdbcType.equals("DATETIME")) return  "TIMESTAMP";
        else  return jdbcType;
    }

    /**
     *  在StringBuilder中增加换行
     * @param sb
     * @param lineCount
     * @param content
     */
    private static void  sringBuilderAppend (StringBuilder sb, Integer lineCount, String content)
    {
        sb.append(content);
        for (int i=0; i< lineCount; i++)
        {
            sb.append(System.getProperty("line.separator"));
        }
    }

    /**
     *  将对象转为字符串
     * @param object
     * @return
     */
    private static String getStringValue(Object object)
    {
        if (object == null)  return null;
        else return object.toString();
    }

    /**
     *  将List<string>转化为字符串
     * @param list
     * @param suffix
     * @return
     */
    private static String convertString(List<String> list , String suffix)
    {
        StringBuilder sb = new StringBuilder();
        for(String item : list)
        {
            sb.append(item + suffix);
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

    /**
     *  根据SQL数据类型来获取操作符
     * @param SqlType
     * @return
     */
    private static String getOperate(String columnName, String SqlType)
    {
        if (columnName.toLowerCase().indexOf("code") > -1 || columnName.toLowerCase().indexOf("type") > -1)    {
            return "equals";
        }

        switch(SqlType)    {
            case "char" :
            case "varchar" :
            case "tinytext" :
            case "mediumtext" :
            case "text" :
                return "like";
            default :
                return "=";
        }
    }

    private  static  String getIdentifier(String modelName, String columnName)
    {
        String  tableName = modelName.replace("History","");
        if (columnName.equals("firstStatus") || columnName.equals("lastStatus"))
        {
            if (tableName.equals("receiptHeader"))  return "receiptHeaderStatus";
            if (tableName.equals("shipmentHeader"))  return "shipmentHeaderStatus";
        }
        if(columnName.equals("type"))
            return  tableName + "Type";
        else
            return  columnName;
    }

    private static  Map<String, String> getPackages() {
        Map<String, String> packages = new HashMap<String, String>();
        packages.put("company","com.huaheng.pc.general.company.Company");
        packages.put("warehouse_company","com.huaheng.pc.general.company.WarehouseCompany");
        packages.put("container","com.huaheng.pc.general.container.Container");
        packages.put("container_type","com.huaheng.pc.config.containerType.ContainerType");
        packages.put("customer","com.huaheng.pc.general.customer.Customer");
        packages.put("cyclecount_adjust","com.huaheng.pc.inventory.cyclecountAdjust.CyclecountAdjust");
        packages.put("cyclecount_adjustdetail","com.huaheng.pc.inventory.cyclecountAdjustDetail.CyclecountAdjustDetail");
        packages.put("cyclecount_detail","com.huaheng.pc.inventory.cyclecountDetail.CyclecountDetail");
        packages.put("cyclecount_header","com.huaheng.pc.inventory.cyclecountHeader.CyclecountHeader");
        packages.put("inventory","com.huaheng.pc.inventory.inventory.Inventory");
        packages.put("inventory_transaction","com.huaheng.pc.inventory.inventoryTransaction.InventoryTransaction");
        packages.put("location","com.huaheng.pc.general.location.Location");
        packages.put("location_type","com.huaheng.pc.config.locationType.LocationType");
        packages.put("material","com.huaheng.pc.general.material.Material");
        packages.put("receipt_container_detail","com.huaheng.pc.receipt.receiptContainerDetail.ReceiptContainerDetail");
        packages.put("receipt_container_header","com.huaheng.pc.receipt.receiptContainerHeader.ReceiptContainerHeader");
        packages.put("receipt_detail","com.huaheng.pc.receipt.receiptDetail.ReceiptDetail");
        packages.put("receipt_detail_history","com.huaheng.pc.receipt.receiptDetailHistory.ReceiptDetailHistory");
        packages.put("receipt_header","com.huaheng.pc.receipt.receiptHeader.ReceiptHeader");
        packages.put("receipt_header_history","com.huaheng.pc.receipt.receiptHeaderHistory.ReceiptHeaderHistory");
        packages.put("shipment_container_detail","com.huaheng.pc.shipment.shipmentContainerDetail.ShipmentContainerDetail");
        packages.put("shipment_container_header","com.huaheng.pc.shipment.shipmentContainerHeader.ShipmentContainerHeader");
        packages.put("shipment_detail","com.huaheng.pc.shipment.shipmentDetail.ShipmentDetail");
        packages.put("shipment_detail_history","com.huaheng.pc.shipment.shipmentDetailHistory.ShipmentDetailHistory");
        packages.put("shipment_header","com.huaheng.pc.shipment.shipmentHeader.ShipmentHeader");
        packages.put("shipment_header_history","com.huaheng.pc.shipment.shipmentHeaderHistory.ShipmentHeaderHistory");
        packages.put("supplier","com.huaheng.pc.general.supplier.Supplier");
//        packages.put("sys_config","system");
//        packages.put("sys_dept","system");
//        packages.put("sys_dict_data","system");
//        packages.put("sys_dict_type","system");
//        packages.put("sys_job","monitor");
//        packages.put("sys_job_log","monitor");
//        packages.put("sys_logininfor","monitor");
//        packages.put("sys_menu","system");
//        packages.put("sys_notice","system");
//        packages.put("sys_oper_log","monitor");
//        packages.put("sys_role","system");
//        packages.put("sys_role_menu","system");
//        packages.put("sys_user","system");
//        packages.put("sys_user_company","system");
//        packages.put("sys_user_online","system");
//        packages.put("sys_user_role","system");
        packages.put("task","com.huaheng.pc.task.task.Task");
        packages.put("agvtask","com.huaheng.pc.task.agvTask.AgvTask");
        packages.put("task_detail","com.huaheng.pc.task.taskDetail.TaskDetail");
        packages.put("warehouse","com.huaheng.pc.general.warehouse.Warehouse");
        packages.put("zone","com.huaheng.pc.config.zone.Zone");
        packages.put("zone_capacity","com.huaheng.pc.config.zoneCapacity.ZoneCapacity");
        packages.put("send_email","com.huaheng.common.mail.alarmmail.SendEmail");
        packages.put("alarm_flow","com.huaheng.common.mail.alarmmail.AlarmFlow");
        packages.put("alarm_type","com.huaheng.common.mail.alarmmail.AlarmType");
//        packages.put("interface_ssp_detail","com.huaheng.pc.config.zone.domain.SSPdetail");
//        packages.put("interface_ssp_header","com.huaheng.pc.config.zone.domain.SSPheader");
        packages.put("container_capacity","com.huaheng.pc.config.containercapacity.ContainerCapacity");
        return  packages;
    }

}