Commit c0e4cb3e by jianshuqin

优化离线导出

parent 64ac43a3
......@@ -117,6 +117,11 @@ namespace Bailun.DC.Models.Component.DTO
public DBEnum? DataDB { get; set; }
/// <summary>
/// 连接超时时间
/// </summary>
public int? ConnectionTimeout { get; set; }
/// <summary>
/// 数据默认排序SQL
/// </summary>
public string DataSortSql { get; set; }
......
......@@ -155,6 +155,11 @@ namespace Bailun.DC.Models.Component.Entity
public bool? is_auto_search { get; set; }
/// <summary>
/// 连接超时时间
/// </summary>
public int? connection_timeout { get; set; }
/// <summary>
/// 是否删除
/// </summary>
[IgnoreUpdate]
......
......@@ -33,7 +33,9 @@ namespace Bailun.DC.Services.Component
{
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)
{
string suffix = exportResult.Item1.Substring(exportResult.Item1.IndexOf("."));
......@@ -54,6 +56,11 @@ namespace Bailun.DC.Services.Component
{
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
JObject json = default(JObject);
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);
}
if (json != null && json["statusCode"].ToString() == "200" && json["result"]["success"].ToString().ToLower() == "true")
......
......@@ -67,6 +67,7 @@ namespace Bailun.DC.Services.Component
SelectRowMethod = entity.select_row_method,
OperateColumnName = entity.operate_column_name,
OperateColumnWidth = entity.operate_column_width,
ConnectionTimeout = entity.connection_timeout,
ListCrumb = !string.IsNullOrWhiteSpace(entity.crumbs) ? DeserializeCollection<string>(entity.crumbs) : 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,
......@@ -570,6 +571,7 @@ namespace Bailun.DC.Services.Component
operate_column_name = dto.OperateColumnName,
operate_column_width = dto.OperateColumnWidth,
operate_controls_position = dto.OperateControlsPosition,
connection_timeout = dto.ConnectionTimeout,
gmt_modified = DateTime.Now,
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,
......@@ -721,12 +723,12 @@ namespace Bailun.DC.Services.Component
else if (fieldFilter.Operator.Trim().Equals("=") || fieldFilter.Operator.ToUpper().Trim().Equals("IS"))
{
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("<>"))
{
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
{
case DataTypeEnum.Table:
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;
default:
//默认参数
......@@ -846,12 +848,12 @@ namespace Bailun.DC.Services.Component
}
}
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;
}
MySqlConnection db = this.GetDbConnection(entity);
int dataCount = db.QueryFirstOrDefault<int>(totalSql, sqlparam);
reader = (dataCount, dataCount > 0 ? db.ExecuteReader(dataSql, sqlparam) : null);
int dataCount = db.QueryFirstOrDefault<int>(totalSql, sqlparam, commandTimeout: entity.ConnectionTimeout ?? 1000);
reader = (dataCount, dataCount > 0 ? db.ExecuteReader(dataSql, sqlparam, commandTimeout: entity.ConnectionTimeout ?? 1000) : null);
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