69 lines
2.9 KiB
C#
69 lines
2.9 KiB
C#
using AyaNova.Biz;
|
|
using AyaNova.DataList;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AyaNova.KPI
|
|
{
|
|
internal class WorkOrderCreatedCount : IAyaKPI
|
|
{
|
|
private string _metaQuery = null;
|
|
private string _dataQuery = null;
|
|
private string _errorMessage = null;
|
|
|
|
public AuthorizationRoles AllowedRoles
|
|
{
|
|
get => AuthorizationRoles.BizAdmin |
|
|
AuthorizationRoles.BizAdminRestricted |
|
|
AuthorizationRoles.ServiceRestricted |
|
|
AuthorizationRoles.Service |
|
|
AuthorizationRoles.Accounting;
|
|
}
|
|
|
|
public string MetaQuery => _metaQuery;
|
|
public string DataQuery => _dataQuery;
|
|
public string ErrorMessage => _errorMessage;
|
|
|
|
public void BuildQuery(KPIRequestOptions options, long userId)
|
|
{
|
|
//build data and meta queries
|
|
|
|
//validate criteria exists
|
|
if (!options.Criteria.ContainsKey("timeSpan"))
|
|
{
|
|
_errorMessage = "Missing 'timeSpan' criteria";
|
|
return;
|
|
}
|
|
|
|
if (!options.Criteria.ContainsKey("interval"))
|
|
{
|
|
_errorMessage = "Missing 'interval' criteria";
|
|
return;
|
|
}
|
|
|
|
var timeSpan = (string)options.Criteria["timeSpan"];
|
|
var interval = (string)options.Criteria["interval"];
|
|
var dateWhere = DataListSqlFilterCriteriaBuilder.DataFilterToColumnCriteria("aworkorder.createddate", UiFieldDataType.DateTime, "no-operator", timeSpan, options.ClientTimeStamp);
|
|
var wotags = options.Criteria["wotags"].ToObject<List<string>>();
|
|
bool wotagsany = options.Criteria["wotagsany"].ToObject<bool>();
|
|
var woitemtags = options.Criteria["woitemtags"].ToObject<List<string>>();
|
|
bool woitemtagsany = options.Criteria["woitemtagsany"].ToObject<bool>();
|
|
string woTagsWhere = DataListSqlFilterCriteriaBuilder.TagFilterToSqlCriteriaHelper("aworkorder.tags", wotags, wotagsany);
|
|
string woItemTagsWhere = DataListSqlFilterCriteriaBuilder.TagFilterToSqlCriteriaHelper("aworkorderitem.tags", woitemtags, woitemtagsany); ;
|
|
|
|
_dataQuery = @$"SELECT row_to_json(t) as res from (
|
|
SELECT COUNT(AWORKORDER.ID) Y,
|
|
DATE_TRUNC('{interval}',AWORKORDER.createddate) X
|
|
FROM AWORKORDER
|
|
WHERE {dateWhere} {woTagsWhere} {woItemTagsWhere}
|
|
GROUP BY X
|
|
ORDER BY X ASC
|
|
) t";
|
|
_metaQuery = string.Empty;
|
|
// @"SELECT row_to_json(t) as res from (
|
|
// select name from auser where id = 10
|
|
// ) t";
|
|
}
|
|
|
|
|
|
}//eoc
|
|
}//eons |