Commit 32495d57 by lcx

返回列头

parent 79216817
using System; using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
...@@ -8,8 +9,6 @@ public class ConditionRequest ...@@ -8,8 +9,6 @@ public class ConditionRequest
{ {
public int HospitalId { get; set; } public int HospitalId { get; set; }
public int GroupId { get; set; }
public int ReportId { get; set; } public int ReportId { get; set; }
public int[] Year { get; set; } public int[] Year { get; set; }
...@@ -36,7 +35,7 @@ public class TableData ...@@ -36,7 +35,7 @@ public class TableData
{ {
public List<Column> Columns { get; set; } public List<Column> Columns { get; set; }
public string Data { get; set; } public JArray Data { get; set; }
} }
public class Column public class Column
......
...@@ -16,12 +16,13 @@ namespace Performance.Services ...@@ -16,12 +16,13 @@ namespace Performance.Services
public class ReportService : IAutoInjection public class ReportService : IAutoInjection
{ {
private readonly ILogger<ReportService> logger; private readonly ILogger<ReportService> logger;
private PerforReportRepository perforReportRepository; private readonly PerforReportRepository perforReportRepository;
private PerforPerallotRepository perforPerallotRepository; private readonly PerforPerallotRepository perforPerallotRepository;
private PerforResbaiscnormRepository perforResbaiscnormRepository; private readonly PerforResbaiscnormRepository perforResbaiscnormRepository;
private PerforHospersonfeeRepository perforHospersonfeeRepository; private readonly PerforHospersonfeeRepository perforHospersonfeeRepository;
private PerforResaccountRepository perforResaccountRepository; private readonly PerforResaccountRepository perforResaccountRepository;
private PerforRepimportconfigRepository repimportconfigRepository; private readonly PerforRepimportconfigRepository repimportconfigRepository;
private readonly PerforRepreportRepository repreportRepository;
public ReportService( public ReportService(
ILogger<ReportService> logger, ILogger<ReportService> logger,
...@@ -30,7 +31,8 @@ public class ReportService : IAutoInjection ...@@ -30,7 +31,8 @@ public class ReportService : IAutoInjection
PerforResbaiscnormRepository perforResbaiscnormRepository, PerforResbaiscnormRepository perforResbaiscnormRepository,
PerforHospersonfeeRepository perforHospersonfeeRepository, PerforHospersonfeeRepository perforHospersonfeeRepository,
PerforRepimportconfigRepository repimportconfigRepository, PerforRepimportconfigRepository repimportconfigRepository,
PerforResaccountRepository perforResaccountRepository) PerforResaccountRepository perforResaccountRepository,
PerforRepreportRepository repreportRepository)
{ {
this.logger = logger; this.logger = logger;
this.perforReportRepository = perforReportRepository; this.perforReportRepository = perforReportRepository;
...@@ -39,6 +41,7 @@ public class ReportService : IAutoInjection ...@@ -39,6 +41,7 @@ public class ReportService : IAutoInjection
this.perforHospersonfeeRepository = perforHospersonfeeRepository; this.perforHospersonfeeRepository = perforHospersonfeeRepository;
this.perforResaccountRepository = perforResaccountRepository; this.perforResaccountRepository = perforResaccountRepository;
this.repimportconfigRepository = repimportconfigRepository; this.repimportconfigRepository = repimportconfigRepository;
this.repreportRepository = repreportRepository;
} }
/// <summary> /// <summary>
...@@ -593,31 +596,38 @@ public TableData TableNormal(ConditionRequest request) ...@@ -593,31 +596,38 @@ public TableData TableNormal(ConditionRequest request)
try try
{ {
List<QueryResult> results = perforReportRepository.DapperQuery<QueryResult>(sql, request)?.ToList(); var report = repreportRepository.GetEntity(t => t.ID == request.ReportId);
if (report == null) return tableData;
List<QueryResult> results = perforReportRepository.DapperQuery<QueryResult>(report.Content, new
{
request.HospitalId,
Year = request.Year?.FirstOrDefault() ?? DateTime.Now.Year,
Month = request.Month?.FirstOrDefault() ?? DateTime.Now.Month
})?.ToList();
if (results == null || !results.Any()) return tableData; if (results == null || !results.Any()) return tableData;
(int rowNum, int columnNum) = GetRowAndColumnLevel(results); (int rowNum, int columnNum) = GetRowAndColumnLevel(results);
List<Column> columns = new List<Column>(); List<Column> columns = new List<Column>();
Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions = new Dictionary<string, Expression<Func<QueryResult, bool>>>(); Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions = new Dictionary<string, Expression<Func<QueryResult, bool>>>();
var fixedDict = JsonHelper.Deserialize<Dictionary<string, string>>(report.QueryArguments) ?? new Dictionary<string, string>();
switch (columnNum) switch (columnNum)
{ {
case 1: case 1:
columns = GetLevel1Columns(results, rowNum, colConditions); columns = GetLevel1Columns(results, rowNum, colConditions, fixedDict);
break; break;
case 2: case 2:
columns = GetLevel2Columns(results, rowNum, colConditions); columns = GetLevel2Columns(results, rowNum, colConditions, fixedDict);
break; break;
case 3: case 3:
columns = GetLevel3Columns(results, rowNum, colConditions); columns = GetLevel3Columns(results, rowNum, colConditions, fixedDict);
break; break;
} }
tableData.Columns = columns; tableData.Columns = columns;
JArray array = GetFixedData(results, colConditions, rowNum); tableData.Data = GetFixedData(results, colConditions, rowNum);
tableData.Data = JsonHelper.Serialize(array);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -667,16 +677,17 @@ public TableData TableNormal(ConditionRequest request) ...@@ -667,16 +677,17 @@ public TableData TableNormal(ConditionRequest request)
return (rowIndex, columnIndex); return (rowIndex, columnIndex);
} }
private List<Column> GetLevel1Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions) private List<Column> GetLevel1Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions, Dictionary<string, string> fixedDict)
{ {
List<Column> columns = new List<Column>(); List<Column> columns = new List<Column>();
for (int i = 0; i < rowNum; i++) for (int i = 0; i < rowNum; i++)
{ {
string key = $"fixed_{i + 1}";
columns.Add(new Column columns.Add(new Column
{ {
Label = "", Label = fixedDict.ContainsKey(key) ? fixedDict[key] : "",
Prop = $"fixed_{i + 1}" Prop = key
}); });
} }
...@@ -696,16 +707,17 @@ private List<Column> GetLevel1Columns(List<QueryResult> results, int rowNum, Dic ...@@ -696,16 +707,17 @@ private List<Column> GetLevel1Columns(List<QueryResult> results, int rowNum, Dic
return columns; return columns;
} }
private List<Column> GetLevel2Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions) private List<Column> GetLevel2Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions, Dictionary<string, string> fixedDict)
{ {
List<Column> columns = new List<Column>(); List<Column> columns = new List<Column>();
for (int i = 0; i < rowNum; i++) for (int i = 0; i < rowNum; i++)
{ {
string key = $"fixed_{i + 1}";
columns.Add(new Column columns.Add(new Column
{ {
Label = "", Label = fixedDict.ContainsKey(key) ? fixedDict[key] : "",
Prop = $"fixed_{i + 1}" Prop = key
}); });
} }
...@@ -736,16 +748,17 @@ private List<Column> GetLevel2Columns(List<QueryResult> results, int rowNum, Dic ...@@ -736,16 +748,17 @@ private List<Column> GetLevel2Columns(List<QueryResult> results, int rowNum, Dic
return columns; return columns;
} }
private List<Column> GetLevel3Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions) private List<Column> GetLevel3Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions, Dictionary<string, string> fixedDict)
{ {
List<Column> columns = new List<Column>(); List<Column> columns = new List<Column>();
for (int i = 0; i < rowNum; i++) for (int i = 0; i < rowNum; i++)
{ {
string key = $"fixed_{i + 1}";
columns.Add(new Column columns.Add(new Column
{ {
Label = "", Label = fixedDict.ContainsKey(key) ? fixedDict[key] : "",
Prop = $"fixed_{i + 1}" Prop = key
}); });
} }
...@@ -836,7 +849,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres ...@@ -836,7 +849,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item; Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item;
JObject jobj = new JObject JObject jobj = new JObject
{ {
["index"] = index, ["rownumber"] = index,
["fixed_1"] = item ["fixed_1"] = item
}; };
fixedexpressions.Add(exp, jobj); fixedexpressions.Add(exp, jobj);
...@@ -858,7 +871,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres ...@@ -858,7 +871,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2; Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2;
JObject jobj = new JObject JObject jobj = new JObject
{ {
["index"] = index, ["rownumber"] = index,
["fixed_1"] = item.Fixed1, ["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2, ["fixed_2"] = item.Fixed2,
}; };
...@@ -886,7 +899,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres ...@@ -886,7 +899,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3; Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3;
JObject jobj = new JObject JObject jobj = new JObject
{ {
["index"] = index, ["rownumber"] = index,
["fixed_1"] = item.Fixed1, ["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2, ["fixed_2"] = item.Fixed2,
["fixed_3"] = item.Fixed3, ["fixed_3"] = item.Fixed3,
...@@ -916,7 +929,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres ...@@ -916,7 +929,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3 && f.Fixed4 == item.Fixed4; Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3 && f.Fixed4 == item.Fixed4;
JObject jobj = new JObject JObject jobj = new JObject
{ {
["index"] = index, ["rownumber"] = index,
["fixed_1"] = item.Fixed1, ["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2, ["fixed_2"] = item.Fixed2,
["fixed_3"] = item.Fixed3, ["fixed_3"] = item.Fixed3,
...@@ -948,7 +961,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres ...@@ -948,7 +961,7 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3 && f.Fixed4 == item.Fixed4 && f.Fixed5 == item.Fixed5; Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3 && f.Fixed4 == item.Fixed4 && f.Fixed5 == item.Fixed5;
JObject jobj = new JObject JObject jobj = new JObject
{ {
["index"] = index, ["rownumber"] = index,
["fixed_1"] = item.Fixed1, ["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2, ["fixed_2"] = item.Fixed2,
["fixed_3"] = item.Fixed3, ["fixed_3"] = item.Fixed3,
...@@ -962,38 +975,6 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres ...@@ -962,38 +975,6 @@ private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expres
return fixedexpressions; return fixedexpressions;
} }
private static readonly string sql = @"select fixed1, column1, column2, sum(value) value from
(
select
category `fixed1`, '本月' `column2`,
max(
case when itemname in ('药品收入', '材料收入') then '考核前绩效'
when itemname in ('检验收入', '检查收入') then '考核后绩效'
else '调节后绩效' end) `column1`,
sum(
case when itemname in ('药品收入', '材料收入') then currentvalue
when itemname in ('检验收入', '检查收入') then currentvalue
else currentvalue end)`value`
from report_performance where ifnull(itemname, '') <> '' and sourcetype = '收入'
and category in ('门诊收入', '住院收入') and hospitalid = 12 and year = 2020 and month = 7
group by category, itemname
union all
select
category `fixed1`, '上月' `column2`,
max(
case when itemname in ('药品收入', '材料收入') then '考核前绩效'
when itemname in ('检验收入', '检查收入') then '考核后绩效'
else '调节后绩效' end) `column1`,
sum(
case when itemname in ('药品收入', '材料收入') then lastissuevalue
when itemname in ('检验收入', '检查收入') then lastissuevalue
else currentvalue end)`value`
from report_performance where ifnull(itemname, '') <> '' and sourcetype = '收入'
and category in ('门诊收入', '住院收入') and hospitalid = 12 and year = 2020 and month = 7
group by category, itemname
) t group by fixed1, column1, column2 order by fixed1, column1, column2;
";
#endregion #endregion
#region special #region special
...@@ -1038,7 +1019,10 @@ public TableData TableSpecial(ConditionRequest request) ...@@ -1038,7 +1019,10 @@ public TableData TableSpecial(ConditionRequest request)
#endregion #endregion
var data = perforReportRepository.DapperQuery<QueryData>(querysql, request); var report = repreportRepository.GetEntity(t => t.ID == request.ReportId);
if (report == null) return tableData;
var data = perforReportRepository.DapperQuery<QueryData>(report.Content, request);
if (data == null || !data.Any()) return tableData; if (data == null || !data.Any()) return tableData;
var type = data.Select(t => new { SourceType = t.SourceType.NoBlank(), Category = t.Category.NoBlank(), ItemName = t.ItemName.NoBlank() }).Distinct(); var type = data.Select(t => new { SourceType = t.SourceType.NoBlank(), Category = t.Category.NoBlank(), ItemName = t.ItemName.NoBlank() }).Distinct();
...@@ -1122,7 +1106,7 @@ public TableData TableSpecial(ConditionRequest request) ...@@ -1122,7 +1106,7 @@ public TableData TableSpecial(ConditionRequest request)
} }
} }
tableData.Data = JsonHelper.Serialize(jarray); tableData.Data = jarray;
#endregion #endregion
} }
...@@ -1165,28 +1149,6 @@ private List<Condition> GetConditions(ConditionRequest request) ...@@ -1165,28 +1149,6 @@ private List<Condition> GetConditions(ConditionRequest request)
return conditions; return conditions;
} }
private static readonly string querysql = @"
select
hospitalid, year, month, accountingunit,
if(length(concat(accountingunit, itemname)) % 2 = 1, '医生组', '护理组') unittype,
sourcetype, category, itemname, sum(currentvalue) value
from report_performance where ifnull(itemname, '') <> '' and sourcetype = '收入'
and category in ('门诊收入', '住院收入') and hospitalid = @hospitalid
and year in @year and month in @month and accountingunit in @accountingunit
group by hospitalid, year, month, accountingunit, unittype
union all
select
t1.hospitalid, t1.year, t1.month, t1.accountingunit,
if(length(concat(accountingunit, itemname)) % 2 = 1, '医生组', '护理组') unittype, '支出' sourcetype,
ifnull(if(t2.chargetype = '', '其他成本', t2.chargetype), '其他成本') category,
itemname, sum(currentvalue) value
from report_performance t1 left join cof_drugtype_disburse t2
on t1.itemname = t2.charge and t1.hospitalid = t2.hospitalid
where ifnull(itemname, '') <> '' and sourcetype = '支出' and t1.hospitalid = @hospitalid
and t1.year in @year and t1.month in @month and t1.accountingunit in @accountingunit
group by t1.hospitalid, t1.year, t1.month, t1.accountingunit, itemname";
#endregion #endregion
} }
} }
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