报表动态条件

parent abf8c570
......@@ -51,7 +51,7 @@ public ApiResponse Rank([FromBody] HospitalIdRequest request)
public ApiResponse Selection([FromBody] SelectionRequest report)
{
var userId = claimService.GetUserId();
var result = reportDataService.GetReportSelection(report.GroupId, userId);
var result = reportDataService.GetReportSelection(report.GroupId, userId, report.HospitalId);
return new ApiResponse(ResponseType.OK, result);
}
......
......@@ -9,7 +9,7 @@ public class HospitalIdRequest
{
public int HospitalId { get; set; }
}
public class SelectionRequest
public class SelectionRequest : HospitalIdRequest
{
public int GroupId { get; set; }
}
......
......@@ -53,7 +53,7 @@ public class ReportDataService : IAutoInjection
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public List<SelectionOptions> GetReportSelection(int groupId, int userId)
public List<SelectionOptions> GetReportSelection(int groupId, int userId, int hospitalId)
{
List<SelectionOptions> options = new List<SelectionOptions>();
......@@ -71,10 +71,14 @@ public List<SelectionOptions> GetReportSelection(int groupId, int userId)
foreach (var item in selections.Where(t => t.State.HasValue && !dispaly.Contains(t.State.Value)))
{
SelectionOptionDefault handle = new SelectionOptionDefault();
//if (item.LoadType == (int)LoadType.InstantLoad && item.Type == 2)
// handle = new SelectionOptionDynamic();
SelectionOptions selection = new SelectionOptions(item);
selection.Options = handle.GetOptions(item);
if (item.LoadType == (int)LoadType.InstantLoad && item.Type == 2)
handle = new SelectionOptionDynamic(reportRepository, hospitalId);
SelectionOptions selection = new SelectionOptions(item)
{
Options = handle.GetOptions(item)
};
if (isMedical)
{
selection.Options.RemoveAll(t => t.Title == "全院");
......@@ -189,19 +193,19 @@ private string GetFilterSelection(List<rep_selection> selections, List<Selection
foreach (var selection in selections)
{
var value = values.FirstOrDefault(w => w.Title == selection.InputName)?.Values;
if (value == null || !value.Any())
continue;
if (selection.Joint.Equals(SQLOperator.Equal.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName}='{value.First()}'";
else if (selection.Joint.Equals(SQLOperator.Like.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} like '%{value.First()}%'";
else if (selection.Joint.Equals(SQLOperator.NotLike.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} not like '%{value.First()}%'";
else if (selection.Joint.Equals(SQLOperator.In.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} in ({string.Join(",", value.Select(t => $"'{t}'"))})";
else if (selection.Joint.Equals(SQLOperator.NotIn.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} not in ({string.Join(",", value.Select(t => $"'{t}'"))})";
if (value != null && value.Any(w => !string.IsNullOrEmpty(w)))
{
if (selection.Joint.Equals(SQLOperator.Equal.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName}='{value.First()}'";
else if (selection.Joint.Equals(SQLOperator.Like.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} like '%{value.First()}%'";
else if (selection.Joint.Equals(SQLOperator.NotLike.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} not like '%{value.First()}%'";
else if (selection.Joint.Equals(SQLOperator.In.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} in ({string.Join(",", value.Select(t => $"'{t}'"))})";
else if (selection.Joint.Equals(SQLOperator.NotIn.ToString(), StringComparison.OrdinalIgnoreCase))
where += $" and {selection.InputName} not in ({string.Join(",", value.Select(t => $"'{t}'"))})";
}
}
return where;
}
......@@ -400,16 +404,34 @@ public virtual List<TitleValue> GetOptions(rep_selection selection)
}
public class SelectionOptionDynamic : SelectionOptionDefault
{
private PerforRepreportRepository _reportRepository;
private readonly int _hospitalId;
public SelectionOptionDynamic(PerforRepreportRepository reportRepository, int hospitalId)
{
_reportRepository = reportRepository;
_hospitalId = hospitalId;
}
public override List<TitleValue> GetOptions(rep_selection selection)
{
//List<TitleValue> values = new List<TitleValue>();
//if (selection.Type != 1)
// return values;
List<TitleValue> values = new List<TitleValue>();
if (selection.Type != 2)
return values;
//if (string.IsNullOrEmpty(selection.Content))
// return values;
if (string.IsNullOrEmpty(selection.Content))
return values;
SortedDictionary<string, object> dic = new SortedDictionary<string, object>
{
{ "@hospitalid", _hospitalId},
};
string sql = selection.Content;
if (sql.IndexOf("@hospitalid", StringComparison.OrdinalIgnoreCase) > -1 && dic.ContainsKey("hospitalid"))
sql = Regex.Replace(sql, "@hospitalid", dic.GetValue<string>("hospitalid"), RegexOptions.IgnoreCase);
return base.GetOptions(selection);
// 执行SQL
var selections = _reportRepository.DapperQuery<TitleValue>(sql, null);
return selections == null ? new List<TitleValue>() : selections.ToList();
}
}
}
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