Commit c0e4cb3e by jianshuqin

优化离线导出

parent 64ac43a3
...@@ -117,6 +117,11 @@ namespace Bailun.DC.Models.Component.DTO ...@@ -117,6 +117,11 @@ namespace Bailun.DC.Models.Component.DTO
public DBEnum? DataDB { get; set; } public DBEnum? DataDB { get; set; }
/// <summary> /// <summary>
/// 连接超时时间
/// </summary>
public int? ConnectionTimeout { get; set; }
/// <summary>
/// 数据默认排序SQL /// 数据默认排序SQL
/// </summary> /// </summary>
public string DataSortSql { get; set; } public string DataSortSql { get; set; }
......
...@@ -155,6 +155,11 @@ namespace Bailun.DC.Models.Component.Entity ...@@ -155,6 +155,11 @@ namespace Bailun.DC.Models.Component.Entity
public bool? is_auto_search { get; set; } public bool? is_auto_search { get; set; }
/// <summary> /// <summary>
/// 连接超时时间
/// </summary>
public int? connection_timeout { get; set; }
/// <summary>
/// 是否删除 /// 是否删除
/// </summary> /// </summary>
[IgnoreUpdate] [IgnoreUpdate]
......
...@@ -33,7 +33,9 @@ namespace Bailun.DC.Services.Component ...@@ -33,7 +33,9 @@ namespace Bailun.DC.Services.Component
{ {
Task task = Task.Factory.StartNew(() => Task task = Task.Factory.StartNew(() =>
{ {
var exportResult = service.Export(queryFilter); try
{
(string, byte[]) exportResult = service.Export(queryFilter);
if (exportResult.Item2 != null && exportResult.Item2?.Length > 0) if (exportResult.Item2 != null && exportResult.Item2?.Length > 0)
{ {
string suffix = exportResult.Item1.Substring(exportResult.Item1.IndexOf(".")); string suffix = exportResult.Item1.Substring(exportResult.Item1.IndexOf("."));
...@@ -54,6 +56,11 @@ namespace Bailun.DC.Services.Component ...@@ -54,6 +56,11 @@ namespace Bailun.DC.Services.Component
{ {
this.Save(result.Data.Value, null, null, OfflineDownloadStatusEnum.Fail, "无数据导出"); this.Save(result.Data.Value, null, null, OfflineDownloadStatusEnum.Fail, "无数据导出");
} }
}
catch (Exception ex)
{
this.Save(result.Data.Value, null, null, OfflineDownloadStatusEnum.Fail, ex.Message);
}
}); });
} }
} }
...@@ -122,7 +129,7 @@ namespace Bailun.DC.Services.Component ...@@ -122,7 +129,7 @@ namespace Bailun.DC.Services.Component
JObject json = default(JObject); JObject json = default(JObject);
if (!string.IsNullOrWhiteSpace(cookies)) if (!string.IsNullOrWhiteSpace(cookies))
{ {
var user = HttpHelper.NetHelper.Request("http://sso.bailuntec.com/GetUserResource", new string[] { "Authorization" }, new string[] { cookies }); var user = HttpHelper.NetHelper.Request("http://sso.bailuntec.com/GetUserResource", new string[] { "Authorization" }, new string[] { cookies.Replace("%20", " ") });
json = JObject.Parse(user); json = JObject.Parse(user);
} }
if (json != null && json["statusCode"].ToString() == "200" && json["result"]["success"].ToString().ToLower() == "true") if (json != null && json["statusCode"].ToString() == "200" && json["result"]["success"].ToString().ToLower() == "true")
......
...@@ -67,6 +67,7 @@ namespace Bailun.DC.Services.Component ...@@ -67,6 +67,7 @@ namespace Bailun.DC.Services.Component
SelectRowMethod = entity.select_row_method, SelectRowMethod = entity.select_row_method,
OperateColumnName = entity.operate_column_name, OperateColumnName = entity.operate_column_name,
OperateColumnWidth = entity.operate_column_width, OperateColumnWidth = entity.operate_column_width,
ConnectionTimeout = entity.connection_timeout,
ListCrumb = !string.IsNullOrWhiteSpace(entity.crumbs) ? DeserializeCollection<string>(entity.crumbs) : null, ListCrumb = !string.IsNullOrWhiteSpace(entity.crumbs) ? DeserializeCollection<string>(entity.crumbs) : null,
ListJavascriptSrc = !string.IsNullOrWhiteSpace(entity.javascript_src) ? DeserializeCollection<string>(entity.javascript_src) : null, ListJavascriptSrc = !string.IsNullOrWhiteSpace(entity.javascript_src) ? DeserializeCollection<string>(entity.javascript_src) : null,
ListFilterControl = !string.IsNullOrWhiteSpace(entity.filter_controls) ? DeserializeCollection<dynamic>(entity.filter_controls) : null, ListFilterControl = !string.IsNullOrWhiteSpace(entity.filter_controls) ? DeserializeCollection<dynamic>(entity.filter_controls) : null,
...@@ -570,6 +571,7 @@ namespace Bailun.DC.Services.Component ...@@ -570,6 +571,7 @@ namespace Bailun.DC.Services.Component
operate_column_name = dto.OperateColumnName, operate_column_name = dto.OperateColumnName,
operate_column_width = dto.OperateColumnWidth, operate_column_width = dto.OperateColumnWidth,
operate_controls_position = dto.OperateControlsPosition, operate_controls_position = dto.OperateControlsPosition,
connection_timeout = dto.ConnectionTimeout,
gmt_modified = DateTime.Now, gmt_modified = DateTime.Now,
crumbs = dto.ListCrumb.Count(l => !string.IsNullOrWhiteSpace(l) && !l.Equals("null", StringComparison.OrdinalIgnoreCase)) > 0 ? JsonConvert.SerializeObject(dto.ListCrumb) : null, crumbs = dto.ListCrumb.Count(l => !string.IsNullOrWhiteSpace(l) && !l.Equals("null", StringComparison.OrdinalIgnoreCase)) > 0 ? JsonConvert.SerializeObject(dto.ListCrumb) : null,
javascript_src = dto.ListJavascriptSrc?.Count(l => !string.IsNullOrWhiteSpace(l) && !l.Equals("null", StringComparison.OrdinalIgnoreCase)) > 0 ? JsonConvert.SerializeObject(dto.ListJavascriptSrc) : null, javascript_src = dto.ListJavascriptSrc?.Count(l => !string.IsNullOrWhiteSpace(l) && !l.Equals("null", StringComparison.OrdinalIgnoreCase)) > 0 ? JsonConvert.SerializeObject(dto.ListJavascriptSrc) : null,
...@@ -721,12 +723,12 @@ namespace Bailun.DC.Services.Component ...@@ -721,12 +723,12 @@ namespace Bailun.DC.Services.Component
else if (fieldFilter.Operator.Trim().Equals("=") || fieldFilter.Operator.ToUpper().Trim().Equals("IS")) else if (fieldFilter.Operator.Trim().Equals("=") || fieldFilter.Operator.ToUpper().Trim().Equals("IS"))
{ {
sql.Append("AND "); sql.Append("AND ");
sql.Append($"( `{ fieldFilter.Field }` IS NULL OR { fieldFilter.Field } = '' ) "); sql.Append($"( `{fieldFilter.Field}` IS NULL OR {fieldFilter.Field} = '' ) ");
} }
else if (fieldFilter.Operator.Trim().Equals("!=") || fieldFilter.Operator.ToUpper().Trim().Equals("<>")) else if (fieldFilter.Operator.Trim().Equals("!=") || fieldFilter.Operator.ToUpper().Trim().Equals("<>"))
{ {
sql.Append("AND "); sql.Append("AND ");
sql.Append($"( `{ fieldFilter.Field }` IS NOT NULL AND { fieldFilter.Field } <> '' ) "); sql.Append($"( `{fieldFilter.Field}` IS NOT NULL AND {fieldFilter.Field} <> '' ) ");
} }
} }
} }
...@@ -821,7 +823,7 @@ namespace Bailun.DC.Services.Component ...@@ -821,7 +823,7 @@ namespace Bailun.DC.Services.Component
{ {
case DataTypeEnum.Table: case DataTypeEnum.Table:
totalSql = $"SELECT COUNT({selectSql}) FROM `{entity.DataValue}` {whereSql}"; totalSql = $"SELECT COUNT({selectSql}) FROM `{entity.DataValue}` {whereSql}";
dataSql = $"SELECT {selectSql} FROM `{entity.DataValue}` {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}"; dataSql = $"SELECT {selectSql} FROM `{entity.DataValue}` {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty)} LIMIT {offset} , {fetch}";
break; break;
default: default:
//默认参数 //默认参数
...@@ -846,12 +848,12 @@ namespace Bailun.DC.Services.Component ...@@ -846,12 +848,12 @@ namespace Bailun.DC.Services.Component
} }
} }
totalSql = $"{setSql} SELECT COUNT({selectSql}) FROM ( {entity.DataValue} ) AS A {whereSql}"; totalSql = $"{setSql} SELECT COUNT({selectSql}) FROM ( {entity.DataValue} ) AS A {whereSql}";
dataSql = $"{setSql} SELECT {selectSql} FROM ( {entity.DataValue} ) AS A {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}"; dataSql = $"{setSql} SELECT {selectSql} FROM ( {entity.DataValue} ) AS A {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty)} LIMIT {offset} , {fetch}";
break; break;
} }
MySqlConnection db = this.GetDbConnection(entity); MySqlConnection db = this.GetDbConnection(entity);
int dataCount = db.QueryFirstOrDefault<int>(totalSql, sqlparam); int dataCount = db.QueryFirstOrDefault<int>(totalSql, sqlparam, commandTimeout: entity.ConnectionTimeout ?? 1000);
reader = (dataCount, dataCount > 0 ? db.ExecuteReader(dataSql, sqlparam) : null); reader = (dataCount, dataCount > 0 ? db.ExecuteReader(dataSql, sqlparam, commandTimeout: entity.ConnectionTimeout ?? 1000) : null);
return reader; return reader;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment