This commit is contained in:
2022-02-25 00:34:25 +00:00
parent e0bf2cb733
commit 0424e78fb7
5 changed files with 144 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ namespace AyaNova.KPI
AuthorizationRoles AllowedRoles { get; }
//build the data and meta queries based on the criteria and this kpi's standard query
void BuildQuery(string criteria, DateTimeOffset clientTimeStamp);
void BuildQuery(KPIRequestOptions options);
string MetaQuery{get;}//Query to fetch json meta data for report purposes mainly (lookup stuff like names etc where applicable)
string DataQuery{get;}//Query to fetch json format data for result set
string ErrorMessage{get;}//if there was a problem then this is set with the error message

View File

@@ -18,7 +18,7 @@ namespace AyaNova.KPI
// Get the kpi data requested
//
//
internal static async Task<JObject> GetResponseAsync(AyContext ct, string kpiName, string criteria, DateTimeOffset clientTimeStamp, AuthorizationRoles userRoles, ILogger log, long userId)
internal static async Task<JObject> GetResponseAsync(AyContext ct, KPIRequestOptions options, AuthorizationRoles userRoles, ILogger log, long userId)
{
/*
@@ -30,8 +30,17 @@ namespace AyaNova.KPI
}
*/
//instantiate the list
var kpi = KPIFactory.GetAyaKPI(kpiName);
kpi.BuildQuery(criteria, clientTimeStamp);
var kpi = KPIFactory.GetAyaKPI(options.KPIName);
if (!AyaNova.Api.ControllerHelpers.Authorized.HasAnyRole(userRoles, kpi.AllowedRoles))
{
return JObject.FromObject(new
{
error = "NOT AUTHORIZED"
});
}
kpi.BuildQuery(options);
if (!string.IsNullOrWhiteSpace(kpi.ErrorMessage))
{

View File

@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using System;
namespace AyaNova.KPI
{
//string kpiName, string criteria, DateTimeOffset clientTimeStamp
public sealed class KPIRequestOptions
{
[FromBody]
public string KPIName { get; set; }
[FromBody]
public string Criteria { get; set; }
[FromBody]
public DateTimeOffset Template { get; set; }
public KPIRequestOptions()
{
KPIName=string.Empty;
Criteria=string.Empty;
}
}
}

View File

@@ -10,17 +10,31 @@ namespace AyaNova.KPI
{
private string _metaQuery = null;
private string _dataQuery = null;
private string _errorMessage=null;
private string _errorMessage = null;
public AuthorizationRoles AllowedRoles { get => BizRoles.GetRoleSet(AyaType.WorkOrderItemLabor).ReadFullRecord; }
public string MetaQuery => _metaQuery;
public string DataQuery => _dataQuery;
public string ErrorMessage => _errorMessage;
public void BuildQuery(string criteria, DateTimeOffset clientTimeStamp)
public void BuildQuery(KPIRequestOptions options)
{
//build data and meta queries
_dataQuery = @"SELECT row_to_json(t) as res from (
select SUM(AWORKORDERITEMLABOR.serviceratequantity) SERVICERATESUM, date_trunc('month',AWORKORDERITEMLABOR.servicestartdate) timeframe
FROM AWORKORDER
LEFT JOIN AWORKORDERITEM ON AWORKORDER.ID = AWORKORDERITEM.WORKORDERID
LEFT JOIN AWORKORDERITEMLABOR ON AWORKORDERITEM.ID = AWORKORDERITEMLABOR.WORKORDERITEMID
WHERE AWORKORDERITEMLABOR.userid = 10
GROUP BY timeframe
ORDER BY timeframe ASC
) t";
_metaQuery = @"SELECT row_to_json(t) as res from (
select name from auser where id = 10
) t";
}
// public string GetVariantCriteria(string variant)