Commit f8184c42 by lcx

报表

parent 434b9a9a
...@@ -224,11 +224,30 @@ public ApiResponse MenuReport([CustomizeValidator(RuleSet = "Menu"), FromBody] R ...@@ -224,11 +224,30 @@ public ApiResponse MenuReport([CustomizeValidator(RuleSet = "Menu"), FromBody] R
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[Route("table")] [Route("table/normal")]
[HttpPost] [HttpPost]
public ApiResponse Table([FromBody] ConditionRequest request) public ApiResponse TableNormal([FromBody] ConditionRequest request)
{ {
var list = reportService.Table(request); if (request == null)
return new ApiResponse(ResponseType.OK, "", new TableData());
var list = reportService.TableNormal(request);
return new ApiResponse(ResponseType.OK, "", list);
}
/// <summary>
/// 科室绩效对比
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("table/special")]
[HttpPost]
public ApiResponse TableSpecial([FromBody] ConditionRequest request)
{
if (request == null)
return new ApiResponse(ResponseType.OK, "", new TableData());
var list = reportService.TableSpecial(request);
return new ApiResponse(ResponseType.OK, "", list); return new ApiResponse(ResponseType.OK, "", list);
} }
} }
......
...@@ -1455,6 +1455,20 @@ ...@@ -1455,6 +1455,20 @@
<param name="request"></param> <param name="request"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.ReportController.TableNormal(Performance.DtoModels.ConditionRequest)">
<summary>
绩效汇报表
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ReportController.TableSpecial(Performance.DtoModels.ConditionRequest)">
<summary>
科室绩效对比
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ReportGlobalController.GetAllReportGlobal(System.Int32)"> <member name="M:Performance.Api.Controllers.ReportGlobalController.GetAllReportGlobal(System.Int32)">
<summary> <summary>
获取报表配置信息 获取报表配置信息
......
...@@ -6,6 +6,12 @@ namespace Performance.DtoModels ...@@ -6,6 +6,12 @@ namespace Performance.DtoModels
{ {
public class ConditionRequest public class ConditionRequest
{ {
public int HospitalId { get; set; }
public int GroupId { get; set; }
public int ReportId { get; set; }
public int[] Year { get; set; } public int[] Year { get; set; }
public int[] Month { get; set; } public int[] Month { get; set; }
...@@ -15,22 +21,31 @@ public class ConditionRequest ...@@ -15,22 +21,31 @@ public class ConditionRequest
public string[] UnitType { get; set; } public string[] UnitType { get; set; }
} }
public class Condition
{
public int Year { get; set; }
public int Month { get; set; }
public string AccountingUnit { get; set; }
public string UnitType { get; set; }
}
public class TableData public class TableData
{ {
public List<Header> Headers { get; set; } public List<Column> Columns { get; set; }
public string Data { get; set; } public string Data { get; set; }
} }
public class Header public class Column
{ {
public string Date { get; set; } public string Label { get; set; }
public string AccountingUnit { get; set; } public string Prop { get; set; }
public string UnitType { get; set; } public List<Column> Children { get; set; }
public string Field { get; set; }
} }
public class QueryData public class QueryData
...@@ -51,6 +66,29 @@ public class QueryData ...@@ -51,6 +66,29 @@ public class QueryData
public string ItemName { get; set; } public string ItemName { get; set; }
public Nullable<decimal> Value { get; set; } public decimal? Value { get; set; }
public List<QueryData> Children { get; set; }
}
public class QueryResult
{
public string Fixed1 { get; set; }
public string Fixed2 { get; set; }
public string Fixed3 { get; set; }
public string Fixed4 { get; set; }
public string Fixed5 { get; set; }
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
public decimal? Value { get; set; }
} }
} }
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.DtoModels.Request; using Performance.DtoModels.Request;
using Performance.EntityModels; using Performance.EntityModels;
...@@ -405,44 +406,608 @@ public void ExecProc(string execsql, object param) ...@@ -405,44 +406,608 @@ public void ExecProc(string execsql, object param)
} }
} }
public TableData Table(ConditionRequest request) #region normal
public TableData TableNormal(ConditionRequest request)
{ {
TableData tableData = new TableData(); TableData tableData = new TableData();
try try
{ {
var condition = request.Year.Join(request.Month, t => true, t => true, (t1, t2) => new { t1, t2 }); List<QueryResult> results = perforReportRepository.DapperQuery<QueryResult>(sql, request)?.ToList();
if (results == null || !results.Any()) return tableData;
var data = perforReportRepository.DapperQuery<QueryData>("", new { }); (int rowNum, int columnNum) = GetRowAndColumnLevel(results);
if (data == null || !data.Any()) return tableData;
List<Column> columns = new List<Column>();
Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions = new Dictionary<string, Expression<Func<QueryResult, bool>>>();
switch (columnNum)
{
case 1:
columns = GetLevel1Columns(results, rowNum, colConditions);
break;
case 2:
columns = GetLevel2Columns(results, rowNum, colConditions);
break;
case 3:
columns = GetLevel3Columns(results, rowNum, colConditions);
break;
}
tableData.Columns = columns;
JArray array = GetFixedData(results, colConditions, rowNum);
tableData.Data = JsonHelper.Serialize(array);
}
catch (Exception ex)
{
logger.LogError(ex.Message);
}
return tableData;
}
private (int rowNum, int columnNum) GetRowAndColumnLevel(List<QueryResult> results)
{
List<Func<QueryResult, bool>> rows = new List<Func<QueryResult, bool>>
{
t => !string.IsNullOrEmpty(t.Fixed1),
t => !string.IsNullOrEmpty(t.Fixed2),
t => !string.IsNullOrEmpty(t.Fixed3),
t => !string.IsNullOrEmpty(t.Fixed4),
t => !string.IsNullOrEmpty(t.Fixed5),
};
int rowIndex = 0;
foreach (var item in rows)
{
if (!results.Any(item))
break;
rowIndex++;
}
List<Func<QueryResult, bool>> columns = new List<Func<QueryResult, bool>>
{
t => !string.IsNullOrEmpty(t.Column1),
t => !string.IsNullOrEmpty(t.Column2),
t => !string.IsNullOrEmpty(t.Column3),
};
int columnIndex = 0;
foreach (var item in columns)
{
if (!results.Any(item))
break;
columnIndex++;
}
return (rowIndex, columnIndex);
}
private List<Column> GetLevel1Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions)
{
List<Column> columns = new List<Column>();
for (int i = 0; i < rowNum; i++)
{
columns.Add(new Column
{
Label = "",
Prop = $"fixed_{i + 1}"
});
}
var level1 = results.Where(t => !string.IsNullOrEmpty(t.Column1)).Select(t => t.Column1).Distinct();
columns.AddRange(level1.Select(t =>
{
var col = new Column
{
Label = t,
Prop = $"field_{t}"
};
colConditions.Add(col.Prop, exp => exp.Column1 == t);
return col;
}));
return columns;
}
private List<Column> GetLevel2Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions)
{
List<Column> columns = new List<Column>();
for (int i = 0; i < rowNum; i++)
{
columns.Add(new Column
{
Label = "",
Prop = $"fixed_{i + 1}"
});
}
var columnData = results.Select(t => new { Column1 = t.Column1.NoBlank(), Column2 = t.Column2.NoBlank() }).Distinct();
var level1 = columnData.Where(t => !string.IsNullOrEmpty(t.Column1))?.Select(t => t.Column1).Distinct().OrderBy(t => t);
if (level1 == null || !level1.Any()) return columns;
foreach (var item in level1)
{
var column = new Column { Label = item, Prop = $"field_{item}" };
var level2 = columnData.Where(t => t.Column1 == item && !string.IsNullOrEmpty(t.Column2))?.Select(t => t.Column2).Distinct().OrderBy(t => t);
if (level2 == null || !level2.Any()) continue;
column.Children = level2.Select(item2 =>
{
var col = new Column
{
Label = item2,
Prop = $"field_{item}_{item2}"
};
colConditions.Add(col.Prop, exp => exp.Column1 == item && exp.Column2 == item2);
return col;
}).ToList();
columns.Add(column);
}
return columns;
}
private List<Column> GetLevel3Columns(List<QueryResult> results, int rowNum, Dictionary<string, Expression<Func<QueryResult, bool>>> colConditions)
{
List<Column> columns = new List<Column>();
for (int i = 0; i < rowNum; i++)
{
columns.Add(new Column
{
Label = "",
Prop = $"fixed_{i + 1}"
});
}
var columnData = results.Select(t => new { Column1 = t.Column1.NoBlank(), Column2 = t.Column2.NoBlank(), Column3 = t.Column3.NoBlank() }).Distinct();
var level1 = columnData.Where(t => !string.IsNullOrEmpty(t.Column1))?.Select(t => t.Column1).Distinct().OrderBy(t => t);
if (level1 == null || !level1.Any()) return columns;
foreach (var item1 in level1)
{
var column1 = new Column { Label = item1, Prop = $"field_{item1}", Children = new List<Column>() };
var level2 = columnData.Where(t => t.Column1 == item1 && !string.IsNullOrEmpty(t.Column2))?.Select(t => t.Column2).Distinct().OrderBy(t => t);
if (level2 == null || !level2.Any()) continue;
foreach (var item2 in level2)
{
var column2 = new Column { Label = item1, Prop = $"field_{item1}_{item2}" };
var level3 = columnData.Where(t => t.Column1 == item1 && t.Column2 == item2 && !string.IsNullOrEmpty(t.Column3))?.Select(t => t.Column3).Distinct().OrderBy(t => t);
if (level3 == null || !level3.Any()) continue;
column2.Children = level3.Select(item3 =>
{
var col = new Column
{
Label = item2,
Prop = $"field_{item1}_{item2}_{item3}"
};
colConditions.Add(col.Prop, exp => exp.Column1 == item1 && exp.Column2 == item2 && exp.Column3 == item3);
return col;
}).ToList();
column1.Children.Add(column2);
}
columns.Add(column1);
}
return columns;
}
private JArray GetFixedData(List<QueryResult> results, Dictionary<string, Expression<Func<QueryResult, bool>>> expressions, int rowNum)
{
Dictionary<Expression<Func<QueryResult, bool>>, JObject> fixedexpressions = new Dictionary<Expression<Func<QueryResult, bool>>, JObject>();
switch (rowNum)
{
case 1:
fixedexpressions = GetFixed1Data(results);
break;
case 2:
fixedexpressions = GetFixed2Data(results);
break;
case 3:
fixedexpressions = GetFixed3Data(results);
break;
case 4:
fixedexpressions = GetFixed4Data(results);
break;
case 5:
fixedexpressions = GetFixed5Data(results);
break;
}
if (fixedexpressions == null || !fixedexpressions.Any()) return new JArray();
JArray jArray = new JArray();
foreach (var item in fixedexpressions)
{
JObject jobj = item.Value;
foreach (var expdic in expressions)
{
var exp = item.Key.And(expdic.Value);
var value = results.Where(exp.Compile())?.Sum(t => t.Value);
jobj[expdic.Key] = value == 0 ? null : value;
}
jArray.Add(jobj);
}
return jArray;
}
private Dictionary<Expression<Func<QueryResult, bool>>, JObject> GetFixed1Data(List<QueryResult> results)
{
Dictionary<Expression<Func<QueryResult, bool>>, JObject> fixedexpressions = new Dictionary<Expression<Func<QueryResult, bool>>, JObject>();
var fixedData = results.Select(t => t.Fixed1.NoBlank()).Distinct();
if (fixedData != null && fixedData.Any())
{
int index = 1;
foreach (var item in fixedData)
{
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item;
JObject jobj = new JObject
{
["index"] = index,
["fixed_1"] = item
};
fixedexpressions.Add(exp, jobj);
index++;
}
}
return fixedexpressions;
}
private Dictionary<Expression<Func<QueryResult, bool>>, JObject> GetFixed2Data(List<QueryResult> results)
{
Dictionary<Expression<Func<QueryResult, bool>>, JObject> fixedexpressions = new Dictionary<Expression<Func<QueryResult, bool>>, JObject>();
var fixedData = results.Select(t => new { Fixed1 = t.Fixed1.NoBlank(), Fixed2 = t.Fixed2.NoBlank() }).Distinct();
if (fixedData != null && fixedData.Any())
{
int index = 1;
foreach (var item in fixedData)
{
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2;
JObject jobj = new JObject
{
["index"] = index,
["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2,
};
fixedexpressions.Add(exp, jobj);
index++;
}
}
return fixedexpressions;
}
private Dictionary<Expression<Func<QueryResult, bool>>, JObject> GetFixed3Data(List<QueryResult> results)
{
Dictionary<Expression<Func<QueryResult, bool>>, JObject> fixedexpressions = new Dictionary<Expression<Func<QueryResult, bool>>, JObject>();
var fixedData = results.Select(t => new
{
Fixed1 = t.Fixed1.NoBlank(),
Fixed2 = t.Fixed2.NoBlank(),
Fixed3 = t.Fixed3.NoBlank()
}).Distinct();
if (fixedData != null && fixedData.Any())
{
int index = 1;
foreach (var item in fixedData)
{
Expression<Func<QueryResult, bool>> exp = (f) => f.Fixed1 == item.Fixed1 && f.Fixed2 == item.Fixed2 && f.Fixed3 == item.Fixed3;
JObject jobj = new JObject
{
["index"] = index,
["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2,
["fixed_3"] = item.Fixed3,
};
fixedexpressions.Add(exp, jobj);
index++;
}
}
return fixedexpressions;
}
private Dictionary<Expression<Func<QueryResult, bool>>, JObject> GetFixed4Data(List<QueryResult> results)
{
Dictionary<Expression<Func<QueryResult, bool>>, JObject> fixedexpressions = new Dictionary<Expression<Func<QueryResult, bool>>, JObject>();
var fixedData = results.Select(t => new
{
Fixed1 = t.Fixed1.NoBlank(),
Fixed2 = t.Fixed2.NoBlank(),
Fixed3 = t.Fixed3.NoBlank(),
Fixed4 = t.Fixed4.NoBlank()
}).Distinct();
if (fixedData != null && fixedData.Any())
{
int index = 1;
foreach (var item in fixedData)
{
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
{
["index"] = index,
["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2,
["fixed_3"] = item.Fixed3,
["fixed_4"] = item.Fixed4,
};
fixedexpressions.Add(exp, jobj);
index++;
}
}
return fixedexpressions;
}
private Dictionary<Expression<Func<QueryResult, bool>>, JObject> GetFixed5Data(List<QueryResult> results)
{
Dictionary<Expression<Func<QueryResult, bool>>, JObject> fixedexpressions = new Dictionary<Expression<Func<QueryResult, bool>>, JObject>();
var fixedData = results.Select(t => new
{
Fixed1 = t.Fixed1.NoBlank(),
Fixed2 = t.Fixed2.NoBlank(),
Fixed3 = t.Fixed3.NoBlank(),
Fixed4 = t.Fixed4.NoBlank(),
Fixed5 = t.Fixed5.NoBlank()
}).Distinct();
if (fixedData != null && fixedData.Any())
{
int index = 1;
foreach (var item in fixedData)
{
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
{
["index"] = index,
["fixed_1"] = item.Fixed1,
["fixed_2"] = item.Fixed2,
["fixed_3"] = item.Fixed3,
["fixed_4"] = item.Fixed4,
["fixed_5"] = item.Fixed5,
};
fixedexpressions.Add(exp, jobj);
index++;
}
}
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
#region special
public TableData TableSpecial(ConditionRequest request)
{
TableData tableData = new TableData();
try
{
var conditions = GetConditions(request);
if (conditions == null || !conditions.Any()) return tableData;
#region columns
List<Column> columns = new List<Column>
{
new Column
{
Label = "月份",
Children = new List<Column>
{
new Column { Label = "核算单元", Children = new List<Column> { new Column { Label = "核算组别", Prop = "itemname" } } }
}
}
};
foreach (var condition in conditions)
{
string key = $"field_{condition.Year}_{condition.Month}_{condition.AccountingUnit}_{condition.UnitType}";
columns.Add(new Column
{
Label = $"{condition.Year}{condition.Month}月",
Children = new List<Column>
{
new Column { Label = condition.AccountingUnit, Children = new List<Column> { new Column { Label = condition.UnitType, Prop = key } } }
}
});
}
tableData.Columns = columns;
var groupData = data.GroupBy(t => new { t.SourceType, t.Category, t.ItemName }); #endregion
var data = perforReportRepository.DapperQuery<QueryData>(querysql, request);
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();
var groupType = type.GroupBy(t => t.SourceType).Select(t => new var groupType = type.GroupBy(t => t.SourceType).Select(t => new
{ {
Type = t.Key, SourceType = t.Key,
Count = t.Count() Count = t.Count()
}).OrderBy(t => t.Type).ThenBy(t => t.Count); }).OrderBy(t => t.SourceType).ThenBy(t => t.Count);
// 含有子集 #region data
foreach (var item in groupType.Where(t => t.Count > 1))
JArray jarray = new JArray();
int index = 0;
// 不包含子集
foreach (var sourcetype in groupType.Where(t => t.Count == 1).Select(t => t.SourceType))
{ {
var conditionData = data.Where(t => t.SourceType == sourcetype);
if (conditionData == null || !conditionData.Any()) continue;
JObject jobj = new JObject { ["rownumber"] = index, ["itemname"] = sourcetype };
index++;
foreach (var item in conditions)
{
string key = $"field_{item.Year}_{item.Month}_{item.AccountingUnit}_{item.UnitType}";
var value = conditionData?.Where(t => t.Year == item.Year && t.Month == item.Month && t.AccountingUnit == item.AccountingUnit && t.UnitType == item.UnitType)?.Sum(t => t.Value);
jobj[key] = value == 0 ? null : value;
}
jarray.Add(jobj);
} }
// 不包含子集含有子集 // 含有子集
foreach (var item in groupType.Where(t => t.Count == 1)) foreach (var sourcetype in groupType.Where(t => t.Count > 1).Select(t => t.SourceType))
{ {
JObject level1 = new JObject { ["rownumber"] = index, ["itemname"] = sourcetype };
index++;
JArray level1Arr = new JArray();
var categories = type.Where(t => t.SourceType == sourcetype);
if (categories == null || !categories.Any()) continue;
foreach (var category in categories.Select(t => t.Category).Distinct().OrderBy(t => t))
{
JObject level2 = new JObject { ["rownumber"] = index, ["itemname"] = category };
index++;
JArray level2Arr = new JArray();
var itemnames = categories.Where(t => t.Category == category);
if (itemnames == null || !itemnames.Any()) continue;
foreach (var itemname in itemnames.Select(t => t.ItemName).Distinct().OrderBy(t => t))
{
var conditionData = data.Where(t => t.SourceType == sourcetype && t.Category == category && t.ItemName == itemname);
if (conditionData == null || !conditionData.Any()) continue;
JObject level3 = new JObject { ["rownumber"] = index, ["itemname"] = itemname };
index++;
foreach (var item in conditions)
{
string key = $"field_{item.Year}_{item.Month}_{item.AccountingUnit}_{item.UnitType}";
var value = conditionData?.Where(t => t.Year == item.Year && t.Month == item.Month && t.AccountingUnit == item.AccountingUnit && t.UnitType == item.UnitType)?.Sum(t => t.Value);
level3[key] = value == 0 ? null : value;
}
level2Arr.Add(level3);
}
if (level2Arr != null && level2Arr.Any())
{
level2["children"] = level2Arr;
level1Arr.Add(level2);
}
}
if (level1Arr != null && level1Arr.Any())
{
level1["children"] = level1Arr;
jarray.Add(level1);
}
} }
tableData.Data = JsonHelper.Serialize(jarray);
#endregion
} }
catch (Exception) catch (Exception ex)
{ {
logger.LogError($"Table Error: {ex}");
} }
return tableData; return tableData;
} }
private List<Condition> GetConditions(ConditionRequest request)
{
List<Condition> conditions = new List<Condition>();
if (request.AccountingUnit == null || !request.AccountingUnit.Any())
throw new PerformanceException("请选择核算单元");
if (request.UnitType == null || !request.UnitType.Any())
throw new PerformanceException("请选择核算组别");
if (request.Year == null || !request.Year.Any())
request.Year = new int[] { DateTime.Now.Year };
if (request.Month == null || !request.Month.Any())
request.Month = new int[] { DateTime.Now.Month };
var departmentInfos = request.AccountingUnit.Join(request.UnitType, account => true, unit => true, (account, unit) => new { account, unit });
var dateInfo = request.Year.Join(request.Month, year => true, month => true, (year, month) => new { year, month });
conditions = departmentInfos.Join(dateInfo, outer => true, innner => true, (outer, innner) => new { outer, innner })
.Select(t => new Condition
{
AccountingUnit = t.outer.account,
UnitType = t.outer.unit,
Year = t.innner.year,
Month = t.innner.month
}).OrderBy(t => t.Year).ThenBy(t => t.Month).ThenBy(t => t.AccountingUnit).ThenBy(t => t.UnitType).ToList();
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
} }
} }
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