コード例 #1
0
ファイル: Dao.cs プロジェクト: LaiHotchner/TestCode
        private static string GetContent(HotchnerTable table)
        {
            var daoClassName = Backend_Devices.GetDaoClassName(table);
            var entityName   = Backend_Devices.GetEntityName(table);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("package " + Backend_Devices.DaoPackagePrefix + ";");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"import {Backend_Code.GetPagingParameterEntity()};");
            stringBuilder.AppendLine($"import {Backend_Devices.EntityPackagePrefix}.{entityName};");
            stringBuilder.AppendLine("import org.apache.ibatis.annotations.Param;");
            stringBuilder.AppendLine("import org.springframework.stereotype.Repository;");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("import java.util.List;");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("@Repository");
            stringBuilder.AppendLine("public interface " + daoClassName + " {");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    int {Backend_Devices.GetCreateMethodName(table)}(@Param(\"infoList\")List<{entityName}> infoList);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    int {Backend_Devices.GetDeleteByIdMethodName(table)}(@Param(\"id\") long id);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    int {Backend_Devices.GetUpdateMethodName(table)}(@Param(\"info\") {entityName} info);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    {entityName} {Backend_Devices.GetByIdMethodName(table)}(@Param(\"id\") long id);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    List<{entityName}> {Backend_Devices.GetAllMethodName(table)}(@Param(\"parameter\")PagingParameter parameter);");
            stringBuilder.AppendLine("}");

            return(stringBuilder.ToString());
        }
コード例 #2
0
        private static string GetContent(HotchnerTable table)
        {
            var entityName       = Backend_Devices.GetEntityName(table);
            var serviceClassName = Backend_Devices.GetServiceInterfaceClassName(table);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("package " + Backend_Devices.DeviceServiceInterfacePackagePrefix + ";");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"import {Backend_Code.GetPagingParameterEntity()};");
            stringBuilder.AppendLine($"import {Backend_Devices.EntityPackagePrefix}.{entityName};");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("import java.util.List;");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("public interface " + serviceClassName + " {");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    int {Backend_Devices.GetCreateMethodName(table)}(List<{entityName}> infoList);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    int {Backend_Devices.GetDeleteByIdMethodName(table)}(long id);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    int {Backend_Devices.GetUpdateMethodName(table)}({entityName} info);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    {entityName} {Backend_Devices.GetByIdMethodName(table)}(long id);");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine($"    List<{entityName}> {Backend_Devices.GetAllMethodName(table)}(PagingParameter parameter);");
            stringBuilder.AppendLine("}");

            return(stringBuilder.ToString());
        }
コード例 #3
0
        private static void SaveTemplateToCsv(string templateContent, HotchnerTable table)
        {
            var templateFileName = CommonMethod.GetTemplateName(table);
            var filePath         = $"{DesktopOutputPath}{templateFileName}";
            var postmanPath      = $"{PostmanOutputPath}{templateFileName}";

            File.WriteAllText(filePath, templateContent, Encoding.UTF8);
            File.WriteAllText(postmanPath, templateContent, Encoding.UTF8);
        }
コード例 #4
0
        private static string GetSearchConcatString(HotchnerTable table)
        {
            var builder = new StringBuilder();

            builder.Append("            and CONCAT(");
            foreach (var row in table.RowList)
            {
                if (row.SupportRetrival)
                {
                    builder.Append(row.Name + ", ");
                }
            }
            builder.Remove(builder.Length - 2, 2);
            builder.Append(")like concat('%',#{keyword},'%')");
            return(builder.ToString());
        }
コード例 #5
0
        private static string GetContent(HotchnerTable table)
        {
            StringBuilder outterBuilder = new StringBuilder();

            outterBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
            outterBuilder.AppendLine("<!DOCTYPE mapper PUBLIC \" -//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >");
            outterBuilder.AppendLine();
            outterBuilder.AppendLine($"<mapper namespace=\"{Backend_Statistic.DaoPackagePrefix}.{Dao.GetDaoClassName(table)}\">");

            outterBuilder.AppendLine($"    <select id=\"{Dao.GetEachStatisticInfo_MethodName(table)}\" " +
                                     $"parameterType=\"java.lang.String\" " +
                                     $"resultType=\"{Backend_Statistic.EntityPackagePrefix}.{Entity.StatisticInfoClass}\">");
            outterBuilder.AppendLine($"                SELECT count(1), '{table.PascalMethodName}' as deviceType FROM public.{table.DbTableName}");
            outterBuilder.AppendLine("                    where available = 1 ${condition}");
            outterBuilder.AppendLine("    </select>");
            outterBuilder.AppendLine("</mapper>");

            return(outterBuilder.ToString());
        }
コード例 #6
0
        private static void GenerateEntity(string entityFolderPath, HotchnerTable table)
        {
            var           entityName    = Backend_Devices.GetEntityName(table);
            StringBuilder entityBuilder = new StringBuilder();

            entityBuilder.AppendLine("package " + Backend_Devices.EntityPackagePrefix + ";");
            entityBuilder.AppendLine("");
            entityBuilder.AppendLine("import java.sql.Timestamp;");
            entityBuilder.AppendLine("import java.util.Date;");
            entityBuilder.AppendLine("");
            entityBuilder.AppendLine($"public class {entityName} " + "{");

            foreach (var row in table.RowList)
            {
                entityBuilder.AppendLine($"    // {row.Description}");
                entityBuilder.AppendLine($"    private {RowTypeJavaDict[row.RowType]} {row.Name.ToLower()};");
            }
            entityBuilder.AppendLine("");

            foreach (var row in table.RowList)
            {
                string javeType        = RowTypeJavaDict[row.RowType];
                string firstUpOtherLow = CommonMethod.GetFirstUpAndOtherLowString(row.Name);
                string nameLower       = row.Name.ToLower();

                entityBuilder.AppendLine($"    public {javeType} get{firstUpOtherLow}() " + "{");
                entityBuilder.AppendLine($"        return {row.Name.ToLower()};");
                entityBuilder.AppendLine("    }");
                entityBuilder.AppendLine("");
                entityBuilder.AppendLine($"    public void set{firstUpOtherLow}({javeType} {nameLower}) " + "{");
                entityBuilder.AppendLine($"        this.{nameLower} = {nameLower};");
                entityBuilder.AppendLine("    }");
                entityBuilder.AppendLine("");
            }

            entityBuilder.AppendLine("}");

            var content  = entityBuilder.ToString();
            var filePath = entityFolderPath + $"\\{entityName}.java";

            File.WriteAllText(filePath, content, new UTF8Encoding(false));
        }
コード例 #7
0
        private static string GenerateScssContent(HotchnerTable table)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("app-" + table.AngularComponentName + "{");
            stringBuilder.AppendLine("  inf-file-upload {");
            stringBuilder.AppendLine("    .inf-button-text {");
            stringBuilder.AppendLine("      padding: 0.2em 1em 0 1em !important;");
            stringBuilder.AppendLine("    }");
            stringBuilder.AppendLine("");
            stringBuilder.AppendLine("    .inf-button {");
            stringBuilder.AppendLine("      height: 30px;");
            stringBuilder.AppendLine("      margin-top: 5px;");
            stringBuilder.AppendLine("    }");
            stringBuilder.AppendLine("");
            stringBuilder.AppendLine("  form {");
            stringBuilder.AppendLine("    .input-label {");
            stringBuilder.AppendLine("      margin-top: 10px;");
            stringBuilder.AppendLine("      }");
            stringBuilder.AppendLine("    }");
            stringBuilder.AppendLine("  }");
            stringBuilder.AppendLine("}");
            return(stringBuilder.ToString());
        }
コード例 #8
0
        internal static string Get_Delete_Url(HotchnerTable table)
        {
            var apiUrlName = GetApiUrlName(table);

            return($"DELETE_{ apiUrlName}");
        }
コード例 #9
0
        private static string GenerateTemplateContent(HotchnerTable table)
        {
            StringBuilder templateBuilder = new StringBuilder();

            foreach (var row in table.RowList)
            {
                var rowName = row.Name.ToLower();
                if (rowName == "id")
                {
                    continue;
                }

                templateBuilder.Append(rowName + "(" + row.Description + "),");
            }
            templateBuilder.Remove(templateBuilder.Length - 1, 1);
            templateBuilder.Append("\r\n");

            Random random        = new Random();
            int    generateCount = random.Next(50, 200);

            for (int i = 0; i < generateCount; i++)
            {
                var rowBuilder = new StringBuilder();
                foreach (var row in table.RowList)
                {
                    var rowName = row.Name.ToLower();
                    var rowType = RowTypeCSharpDict[row.RowType];

                    if (rowName == "id")
                    {
                        continue;
                    }
                    if (GenerateMc(i, rowBuilder, row, table))
                    {
                        continue;
                    }
                    if (GenerateAdminCode(random, rowBuilder, row))
                    {
                        continue;
                    }
                    if (GenerateLongitude(random, rowBuilder, row))
                    {
                        continue;
                    }
                    if (GenerateLatitude(random, rowBuilder, row))
                    {
                        continue;
                    }
                    if (GenerateSzx(random, rowBuilder, row))
                    {
                        continue;
                    }
                    if (GenerateSxx(random, rowBuilder, row))
                    {
                        continue;
                    }
                    if (GenerateZxlc(random, rowBuilder, row))
                    {
                        continue;
                    }
                    if (GenerateSstldw(random, rowBuilder, row))
                    {
                        continue;
                    }

                    if (rowType == "long")
                    {
                        rowBuilder.Append(random.Next(100, 100000) + ",");
                    }
                    else if (rowType == "int")
                    {
                        rowBuilder.Append(random.Next(100, 1000) + ",");
                    }
                    else if (rowType == "double")
                    {
                        rowBuilder.Append(random.NextDouble() * random.Next(10, 100) + ",");
                    }
                    else if (rowType == "Boolean")
                    {
                        rowBuilder.Append(random.Next(0, 2) % 2 == 0 ? "true," : "false,");
                    }
                    else if (rowType == "String")
                    {
                        rowBuilder.Append(row.Description + random.Next(10, 100) + ",");
                    }
                    else if (rowType == "DateTime")
                    {
                        rowBuilder.Append(DateTime.Now.AddDays(random.Next(0, 100)).AddHours(random.Next(1, 24)).ToString() + ",");
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                rowBuilder.Remove(rowBuilder.Length - 1, 1);

                templateBuilder.AppendLine(rowBuilder.ToString());
            }

            var templateContent = templateBuilder.ToString();

            return(templateContent);
        }
コード例 #10
0
 // In Dao, use this to query postion
 public static string GetPositions_EachTable(HotchnerTable table)
 {
     return($"get{table.PascalMethodName}Positions");
 }
コード例 #11
0
        internal static string Get_FIND_ALL_Url(HotchnerTable table)
        {
            var apiUrlName = GetApiUrlName(table);

            return($"FIND_ALL_{ apiUrlName}");
        }
コード例 #12
0
ファイル: ServiceImpl.cs プロジェクト: LaiHotchner/TestCode
 private static string GetDaoFieldName(HotchnerTable table)
 {
     return($"{table.camelcaseMethodName}Dao");
 }
コード例 #13
0
        internal static string Get_Update_Url(HotchnerTable table)
        {
            var apiUrlName = GetApiUrlName(table);

            return($"UPDATE_{ apiUrlName}");
        }
コード例 #14
0
 internal static string GetServiceInterfaceClassName(HotchnerTable table)
 {
     return(table.PascalMethodName + "Service");
 }
コード例 #15
0
 internal static string GetControllerClassName(HotchnerTable table)
 {
     return(table.PascalMethodName + "Controller");
 }
コード例 #16
0
 internal static string GetMapperFileName(HotchnerTable table)
 {
     return(table.PascalMethodName + "Mapper");
 }
コード例 #17
0
 internal static string GetDaoClassName(HotchnerTable table)
 {
     return(table.PascalMethodName + "Dao");
 }
コード例 #18
0
 internal static string GetEntityName(HotchnerTable table)
 {
     return(table.PascalMethodName);
 }
コード例 #19
0
        private static string GetSqlContentByTable(HotchnerTable table)
        {
            StringBuilder sqlContentBuilder = new StringBuilder();

            sqlContentBuilder.AppendLine($"-- Table: public.{table.DbTableName}");
            sqlContentBuilder.AppendLine();
            sqlContentBuilder.AppendLine($"DROP TABLE IF EXISTS public.{table.DbTableName};");
            sqlContentBuilder.AppendLine($"DROP SEQUENCE  IF EXISTS public.{table.DbTableName}_id_seq;");
            sqlContentBuilder.AppendLine();
            sqlContentBuilder.AppendLine($"CREATE SEQUENCE public.\"{table.DbTableName}_id_seq\"");
            sqlContentBuilder.AppendLine("    INCREMENT 1");
            sqlContentBuilder.AppendLine("    START 1");
            sqlContentBuilder.AppendLine("    MINVALUE 1");
            sqlContentBuilder.AppendLine("    MAXVALUE 9223372036854775807");
            sqlContentBuilder.AppendLine("    CACHE 1;");
            sqlContentBuilder.AppendLine();
            sqlContentBuilder.AppendLine($"ALTER SEQUENCE public.\"{table.DbTableName}_id_seq\"");
            sqlContentBuilder.AppendLine("    OWNER TO sde;");
            sqlContentBuilder.AppendLine();
            sqlContentBuilder.AppendLine($"CREATE TABLE public.{table.DbTableName}");
            sqlContentBuilder.AppendLine("(");

            foreach (var row in table.RowList)
            {
                if (row.Name.ToUpper() == "ID")
                {
                    sqlContentBuilder.AppendLine($"    {row.Name.ToLower()} {RowTypeSqlDict[row.RowType]} NOT NULL DEFAULT nextval('{table.DbTableName}_{row.Name.ToLower()}_seq'::regclass),");
                }
                else if (row.RowType == "RAW(16)" || row.RowType == "RAW")
                {
                    sqlContentBuilder.AppendLine($"    {row.Name.ToLower()} {RowTypeSqlDict[row.RowType]} ,");  //NOT NULL
                }
                else
                {
                    sqlContentBuilder.AppendLine($"    {row.Name.ToLower()} {RowTypeSqlDict[row.RowType]} ,");
                }
            }
            // 逻辑删除标记
            sqlContentBuilder.AppendLine("    available integer DEFAULT 1,");

            if (table.DbTableName == "jj_aj_001")
            {
                // 这是一个mapping表,和其他表不一样,没有主键
                // 同时需要删除最后一个逗号,因为有\r\n,所以是倒数第三个
                sqlContentBuilder.Remove(sqlContentBuilder.Length - 3, 1);
            }
            else
            {
                sqlContentBuilder.AppendLine($"    CONSTRAINT pk_{table.DbTableName}_id PRIMARY KEY (id)");
            }

            sqlContentBuilder.AppendLine(")");
            sqlContentBuilder.AppendLine("TABLESPACE pg_default;");
            sqlContentBuilder.AppendLine();
            sqlContentBuilder.AppendLine($"ALTER TABLE public.{table.DbTableName}");
            sqlContentBuilder.AppendLine("    OWNER to sde;");
            sqlContentBuilder.AppendLine($"COMMENT ON TABLE public.{table.DbTableName}");
            sqlContentBuilder.AppendLine($"    IS '{table.TableDescription}';");
            sqlContentBuilder.AppendLine();

            foreach (var row in table.RowList)
            {
                sqlContentBuilder.AppendLine($"COMMENT ON COLUMN public.{table.DbTableName}.{row.Name}");
                sqlContentBuilder.AppendLine($"    IS '{row.Description}';");
            }
            sqlContentBuilder.AppendLine();

            var sqlcontent = sqlContentBuilder.ToString();

            return(sqlcontent);
        }
コード例 #20
0
 private static bool GenerateMc(int index, StringBuilder rowBuilder, HotchnerRow row, HotchnerTable table)
 {
     if (row.Name.ToLower() == "mc")
     {
         var mc = table.Label + index;
         rowBuilder.Append(mc + ",");
         return(true);
     }
     return(false);
 }
コード例 #21
0
ファイル: CommonMethod.cs プロジェクト: LaiHotchner/TestCode
 public static string GetTemplateName(HotchnerTable table)
 {
     return($"{table.Label}.csv");
     //return $"{table.PascalMethodName}_{table.TableDescription}.csv";
 }
コード例 #22
0
 internal static string GetImportConfirmMethodName(HotchnerTable table)
 {
     return($"import{table.PascalMethodName}Confirm");
 }
コード例 #23
0
ファイル: Controller.cs プロジェクト: LaiHotchner/TestCode
 private static string GetDeviceServiceFieldName(HotchnerTable table)
 {
     return(table.camelcaseMethodName + "Service");
 }
コード例 #24
0
 private static string GetMapperFileName(HotchnerTable table)
 {
     return(table.PascalMethodName + "StatisticMapper");
 }
コード例 #25
0
 // 在ServiceImpl层之后,需要调用不同设备的Dao_Retrieval去查询不同设备的信息,因此一个逻辑包含两个方法名
 public static string GetListMethodName_EachDao_GetRetrievalResult(HotchnerTable table)
 {
     return($"get{table.PascalMethodName}RetrievalResult");
 }
コード例 #26
0
 internal static string GetAllMethodName(HotchnerTable table)
 {
     return($"getAll{table.PascalMethodName}");
 }
コード例 #27
0
 internal static string GetUpdateMethodName(HotchnerTable table)
 {
     return($"update{table.PascalMethodName}");
 }
コード例 #28
0
 private static string GetFormName(HotchnerTable table)
 {
     return(table.PascalMethodName + "Form");
 }
コード例 #29
0
        public static List <HotchnerTable> OpenCSV(string filePath)
        {
            Encoding     encoding = Encoding.UTF8;
            FileStream   fs       = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            StreamReader sr       = new StreamReader(fs, encoding);

            HotchnerResult result = new HotchnerResult();
            string         strLine;
            var            table   = new HotchnerTable();
            var            rowList = new List <HotchnerRow>();

            // 前两行是描述字段
            sr.ReadLine();
            sr.ReadLine();
            while ((strLine = sr.ReadLine()) != null)
            {
                string[] aryLine = strLine.Split(',');
                if (string.IsNullOrEmpty(aryLine[1]))
                {
                    if (table.Index != 0)
                    {
                        table.RowList.AddRange(rowList);
#warning 给所有表添加一个admin_code,所属派出所字段
                        table.AppendAdminCodeRowToTable();
                        result.TableList.Add(table);
                    }

                    table   = new HotchnerTable();
                    rowList = new List <HotchnerRow>();
                    continue;
                }

                if (!string.IsNullOrEmpty(aryLine[0]))
                {
                    int.TryParse(aryLine[0], out int index);
                    table.Index                = index;
                    table.DbTableName          = aryLine[1];
                    table.AngularComponentName = aryLine[2];
                    table.camelcaseMethodName  = aryLine[3];
                    table.PascalMethodName     = aryLine[4];
                    table.Label                = aryLine[5];
                    table.TableDescription     = aryLine[6];
                }
                else
                {
                    var row = new HotchnerRow
                    {
                        Name            = aryLine[1].Trim().ToUpper(),
                        RowType         = aryLine[2].Trim().ToUpper(),
                        Description     = aryLine[3].Trim().ToUpper(),
                        SupportRetrival = !string.IsNullOrEmpty(aryLine[4].Trim())
                    };
                    if (!result.ColumnType.ContainsKey(row.RowType))
                    {
                        result.ColumnType.Add(row.RowType, row.RowType);
                    }
                    rowList.Add(row);
                }
            }
            // Add the last table in result
            table.RowList.AddRange(rowList);
            table.AppendAdminCodeRowToTable();
            // Add the last table in result

            result.TableList.Add(table);
            sr.Close();
            fs.Close();

            var orderResult = GetOrderedTables(result);
            return(orderResult);
        }
コード例 #30
0
 internal static string GetByIdMethodName(HotchnerTable table)
 {
     return($"get{table.PascalMethodName}ById");
 }