Commit d2764d99 by 1391696987

每月汇报表返回结果平级转层级

parent 064e84b5
......@@ -79,7 +79,7 @@ public class StatisticsQueryResultDto
/// </summary>
public int? IsComparison { get; set; }
public List<StatisticsColumn> Columns { get; set; }
public List<Dictionary<string, string>> Datas { get; set; }
public List<Dictionary<string, object>> Datas { get; set; }
}
public class StatisticsColumn
......
......@@ -187,14 +187,14 @@ private StatisticsQueryResultDto StatisticsQuery7(StatisticsQuery query, report_
{
pairs.Add(item.Title, item.Values);
}
var table = new List<Dictionary<string, string>>();
var table = new List<Dictionary<string, object>>();
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (!string.IsNullOrEmpty(statistics.TotalScript))
{
var (sql, param) = GetSqlQuery(statistics.TotalScript, pairs);
var data = connection.Query(sql, param);
table = JsonHelper.Deserialize<List<Dictionary<string, string>>>(JsonHelper.Serialize(data));
table = JsonHelper.Deserialize<List<Dictionary<string, object>>>(JsonHelper.Serialize(data));
}
}
var columns = new List<StatisticsColumn>();
......@@ -251,14 +251,14 @@ private StatisticsQueryResultDto StatisticsQuery(StatisticsQuery query, report_s
{
pairs.Add(item.Title, item.Values);
}
var table = new List<Dictionary<string, string>>();
var table = new List<Dictionary<string, object>>();
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (!string.IsNullOrEmpty(statistics.TotalScript))
{
var (sql, param) = GetSqlQuery(statistics.TotalScript, pairs);
var data = connection.Query(sql, param);
table = JsonHelper.Deserialize<List<Dictionary<string, string>>>(JsonHelper.Serialize(data));
table = JsonHelper.Deserialize<List<Dictionary<string, object>>>(JsonHelper.Serialize(data));
}
}
var columns = new List<StatisticsColumn>();
......@@ -313,11 +313,14 @@ private StatisticsQueryResultDto StatisticsTreeQuery(StatisticsQuery query, List
pairs.Add(item.Title, item.Values);
}
var table = new List<Dictionary<string, string>>();
var table = new List<Dictionary<string, object>>();
// 层级有几层,则数据就有几层
foreach (var item in reportStatisticsTree)
{
var row = new Dictionary<string, string>();
var row = new Dictionary<string, object>();
row.Add("ID", item.ID);
row.Add("ParentID", item.ParentID);
row.Add("项目", item.Name);
if (reportStatisticsTree.Any(w => !string.IsNullOrEmpty(w.TotalScript) || !string.IsNullOrEmpty(w.TotalFormula)))
{
......@@ -351,12 +354,31 @@ private StatisticsQueryResultDto StatisticsTreeQuery(StatisticsQuery query, List
}
table.Add(row);
}
// 平级转层级
var statisticsTree = StatisticsTree(table, 0);
return new StatisticsQueryResultDto
{
IsComparison = query.IsComparison,
Columns = columns,
Datas = table,
Datas = statisticsTree,
};
}
private List<Dictionary<string, object>> StatisticsTree(List<Dictionary<string, object>> oldTree,int parentID)
{
if (oldTree.Any(w => (int)w["ParentID"] == parentID))
{
List<Dictionary<string, object>> newTree = new List<Dictionary<string, object>>();
foreach (var item in oldTree.Where(t => (int)t["ParentID"] == parentID))
{
item.Add("Children", StatisticsTree(oldTree, (int)item["ID"]));
newTree.Add(item);
}
return newTree;
}
else return null;
}
}
}
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