bo/api/v3/bi/db/aicode/{template}

http://localhost:5900/bo/api/v3/bi/db/aicode/db2appid?ignore=true&ownerId=tosoft&sysId&mediaType=text&suffix=sql

http://localhost:5900/bo/api/v3/bi/db/aicode/db2appid?ignore=true&ownerId=tosoft&sysId&mediaType=text&suffix=sql

[
     {
        "connName":"ConnBo",
        "databaseName":"tosoft_auth_bo",
        "tableOutPath":"~/App_Temp/{{table_owner_id}}/AiCode/db2appid/{{table_conn_name}}/{{table_name_hline}}.sql",
        "outPath":"~/App_Temp/{{global_owner_id}}/AiCode/db2appid/{{global_conn_name}}/all.sql",
        "tableNames":[{
            "tableName":"bo_job"
        }]
    }
]

[
     {
        "connName":"ConnBo",
        "databaseName":"tosoft_auth_bo",
        "tableNames":[]
    }
]

sbOutPath.Replace("{{table_name_lowner}}", tableL);
sbOutPath.Replace("{{table_name_class}}", tableC);
sbOutPath.Replace("{{table_name_field}}", tableF);
sbOutPath.Replace("{{table_name_hline}}", tableH);
sbOutPath.Replace("{{table_owner_id}}", ownerId);
sbOutPath.Replace("{{table_sys_id}}", sysId);

 if (!string.IsNullOrEmpty(conn.OutPath))
{
    StringBuilder sbOutPath = new StringBuilder(conn.OutPath);
    sbOutPath.Replace("{{global_owner_id}}", ownerId);
    sbOutPath.Replace("{{global_sys_id}}", sysId);
    sbOutPath.Replace("{{global_conn_name}}", conn.ConnName);
    FileUtil.CreateFileAndContentAsync(sbOutPath.ToString(), sbDbSql.ToString(), encoding);
}

http://localhost:5900/bo/api/v3/bi/db/aicode/all?ignore=true&ownerId=tosoft&sysId&mediaType=text&suffix=sql

/bo/api/v3/bi/db/aicode/all

/bo/api/v3/bi/db/aicode/all?ignore=true&ownerId=tosoft&sysId&mediaType=text&suffix=sql

[
    {
        "template":"db2appid",
        "suffix":"sql",
        "databasePos":[
             {
                "connName":"ConnBo",
                "databaseName":"tosoft_auth_bo",
                "tableOutPath":"~/App_Temp/{{table_owner_id}}/AiCode/db2appid/{{table_conn_name}}/{{table_name_hline}}.sql",
                "outPath":"~/App_Temp/{{global_owner_id}}/AiCode/db2appid/{{global_conn_name}}/all.sql",
                "tableNames":[{
                    "tableName":"bo_job"
                }]
            }, {
                "connName":"ConnBs",
                "databaseName":"tosoft_auth_bs",
                "tableOutPath":"~/App_Temp/{{table_owner_id}}/AiCode/db2appid/{{table_conn_name}}/{{table_name_hline}}.sql",
                "outPath":"~/App_Temp/{{global_owner_id}}/AiCode/db2appid/{{global_conn_name}}/all.sql",
                "tableNames":[]
            }
        ]
    }
]

tables.sql

sbTableLine.Replace("{{columns}}", sbColumnLines.ToString());
sbTableLine.Replace("{{db_name}}", conn.DatabaseName);
sbTableLine.Replace("{{table_name}}", table.Name.ToLower());
sbTableLine.Replace("{{table_field}}", RegexUtil.ConvertDownLine2CamelCase(table.Name));                    
sbSql.Replace("{{owner_id}}", ownerId);
sbSql.Replace("{{sys_id}}", sysId);

columns.sql

sbColumnLine.Replace("{{column_name}}", colunm.Name.ToLower());
sbColumnLine.Replace("{{column_title}}", colunm.Title);
sbColumnLine.Replace("{{column_field}}", RegexUtil.ConvertDownLine2CamelCase(colunm.Name));
sbColumnLine.Replace("{{column_data_type}}", colunm.DataType);
sbColumnLine.Replace("{{column_max_length}}", colunm.MaxLength?.ToString());
sbColumnLine.Replace("{{column_is_primary}}", colunm.IsPrimary == true ? "1" : "0");
sbColumnLine.Replace("{{column_is_null}}", colunm.IsNullValue == true ? "1" : "0");
sbColumnLine.Replace("{{column_is_required}}", colunm.IsRequired == true ? "1" : "0");

代码说明

  foreach (var conn in body)
            {
                PFGlobalParameter pf = new PFGlobalParameter
                {
                    ConnName = conn.ConnName,
                    OwnerId = ownerId,
                    SysId = sysId
                };
                ResultPager<SqlTable> result = new ResultPager<SqlTable>();
                result.Data = _dbTableService.GetMedaTableAndViewByDataBase(ownerId, sysId, pf.ConnName);
                IEnumerable<SqlColumn> lstColumns = new List<SqlColumn>();
                if (!string.IsNullOrEmpty(columnSqlF))
                {
                    lstColumns = _dbColumnService.GetTableColumnByTbName(ownerId, sysId, pf.ConnName, result.Data.Select(temp => temp.TbName.ToLower()));
                }
                foreach (var table in result.Data)
                {
                    if (conn.TableNames.Any() && conn.TableNames.Count(temp => temp.TableName.ToLower() == table.Name.ToLower()) == 0)
                    {
                        continue;
                    }
                    StringBuilder sbColumnLines = new StringBuilder();
                    var lstCurCol = lstColumns.Where(temp => (temp.TbName ?? temp.TableName).ToLower() == table.Name.ToLower());
                    if (lstCurCol.Any())
                    {
                        foreach (var colunm in lstCurCol)
                        {
                            StringBuilder sbColumnLine = new StringBuilder();
                            sbColumnLine.Append(columnSqlF);
                            sbColumnLine.Replace("{{column_name}}", colunm.Name.ToLower());
                            sbColumnLine.Replace("{{column_title}}", colunm.Title);
                            sbColumnLine.Replace("{{column_field}}", RegexUtil.ConvertDownLine2CamelCase(colunm.Name));
                            sbColumnLine.Replace("{{column_data_type}}", colunm.DataType);
                            sbColumnLine.Replace("{{column_max_length}}", colunm.MaxLength?.ToString());
                            sbColumnLine.Replace("{{column_is_primary}}", colunm.IsPrimary == true ? "1" : "0");
                            sbColumnLine.Replace("{{column_is_null}}", colunm.IsNullValue == true ? "1" : "0");
                            sbColumnLine.Replace("{{column_is_required}}", colunm.IsRequired == true ? "1" : "0");
                            sbColumnLines.AppendLine(sbColumnLine.ToString());
                        }
                    }
                    StringBuilder sbTableLine = new StringBuilder();
                    sbTableLine.Append(tableSqlF);
                    sbTableLine.Replace("{{columns}}", sbColumnLines.ToString());
                    sbTableLine.Replace("{{db_name}}", conn.DatabaseName);
                    sbTableLine.Replace("{{table_name}}", table.Name.ToLower());
                    sbTableLine.Replace("{{table_field}}", RegexUtil.ConvertDownLine2CamelCase(table.Name));
                    sbSql.AppendLine(sbTableLine.ToString());
                }
            }
            sbSql.Replace("{{owner_id}}", ownerId);
            sbSql.Replace("{{sys_id}}", sysId);
            var data = Encoding.UTF8.GetBytes(sbSql.ToString());
            if (mediaType == "html")
            {
                Response.ContentType = "text/html";
                await Response.Body.WriteAsync(data, 0, data.Length);
            }
            else if (mediaType == "text")
            {
                Response.ContentType = "text/plain";
                await Response.Body.WriteAsync(data, 0, data.Length);
            }
            else
            {
                Response.ContentType = "text/json";
                await Response.Body.WriteAsync(data, 0, data.Length);
文档更新时间: 2023-04-10 11:02   作者:admin