Commit c02a7144 by lcx

数据为null过滤

parent ebbfab54
...@@ -48,7 +48,7 @@ public ApiResponse Info([FromBody]SelectionRequest report) ...@@ -48,7 +48,7 @@ public ApiResponse Info([FromBody]SelectionRequest report)
[HttpPost] [HttpPost]
public ApiResponse Search([FromBody]SearchReportRequest report) public ApiResponse Search([FromBody]SearchReportRequest report)
{ {
var result = reportDataService.GetReportData(report.HospitalId, report.GroupId, report.ReportId, report.Values); var result = reportDataService.GetReportData(report.HospitalId, report.GroupId, report.ReportId, report.Values ?? new List<SelectionValues>());
return new ApiResponse(ResponseType.OK, result); return new ApiResponse(ResponseType.OK, result);
} }
......
...@@ -104,10 +104,11 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId, ...@@ -104,10 +104,11 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId,
var formats = GetParameterFormats(); var formats = GetParameterFormats();
var groupSelections = groupselectionRepository.GetEntities(w => w.GroupId == groupId); var groupSelections = groupselectionRepository.GetEntities(w => w.GroupId == groupId);
var arr2 = groupSelections.Select(w => w.SelectionId); var arr2 = groupSelections?.Select(w => w.SelectionId) ?? new List<int?>();
var dispaly = new int[] { (int)SelectionState.UsableAndDispaly, (int)SelectionState.UsableAndNotDispaly }; var dispaly = new int[] { (int)SelectionState.UsableAndDispaly, (int)SelectionState.UsableAndNotDispaly };
var selections = selectionRepository.GetEntities(w => arr2.Contains(w.ID) && w.State.HasValue && dispaly.Contains(w.State.Value)); var selections = selectionRepository.GetEntities(w => arr2.Contains(w.ID) && w.State.HasValue && dispaly.Contains(w.State.Value))
?? new List<rep_selection>();
List<ReportData> result = new List<ReportData>(); List<ReportData> result = new List<ReportData>();
foreach (var report in reports) foreach (var report in reports)
...@@ -115,8 +116,12 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId, ...@@ -115,8 +116,12 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId,
var sql = report.Content.ToLower(); var sql = report.Content.ToLower();
//不重复条件,动态拼接WHERE条件 //不重复条件,动态拼接WHERE条件
selections = GetNoRepeatSelections(sql, formats, selections); string @where = "";
string @where = GetFilterSelection(selections, values); if (selections != null && selections.Any())
{
selections = GetNoRepeatSelections(sql, formats, selections);
@where = GetFilterSelection(selections, values);
}
@where += $" and hospitalid={hospitalId}"; @where += $" and hospitalid={hospitalId}";
// 固定占位符 // 固定占位符
var pairs = PredefinePlaceholder(values); var pairs = PredefinePlaceholder(values);
...@@ -152,6 +157,8 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId, ...@@ -152,6 +157,8 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId,
private string GetFilterSelection(List<rep_selection> selections, List<SelectionValues> values) private string GetFilterSelection(List<rep_selection> selections, List<SelectionValues> values)
{ {
string where = ""; string where = "";
if (values == null || !values.Any())
return where;
foreach (var selection in selections) foreach (var selection in selections)
{ {
var value = values.FirstOrDefault(w => w.Title == selection.InputName)?.Values; var value = values.FirstOrDefault(w => w.Title == selection.InputName)?.Values;
...@@ -302,7 +309,7 @@ private string ReplacePlaceholder(List<rep_selection> selections, List<Selection ...@@ -302,7 +309,7 @@ private string ReplacePlaceholder(List<rep_selection> selections, List<Selection
{ {
foreach (var selection in selections) foreach (var selection in selections)
{ {
var value = values.FirstOrDefault(w => w.Title == selection.InputName).Values; var value = values.FirstOrDefault(w => w.Title == selection.InputName)?.Values;
if (value == null || !value.Any()) if (value == null || !value.Any())
continue; continue;
foreach (var pattern in formats) foreach (var pattern in formats)
......
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