Commit 00229b28 by Mac Stephens

Changed complaint warnings query to fix issue with logic and updated endpoint to…

Changed complaint warnings query to fix issue with logic and updated endpoint to ensure all is working correctly, sent queries to mark for PG update
parent d5960cdf
......@@ -1048,71 +1048,26 @@ object ApiDatabaseModule: TApiDatabaseModule
object uqComplaintWarnings: TUniQuery
Connection = ucENTCAD
SQL.Strings = (
'with ctx as ('
' select ca.agency, ca.addressid'
' from complaint_active ca'
' where ca.complaintid = :COMPLAINTID'
'),'
'sys as ('
' select s.warningdistance'
' from system s'
' join ctx on s.agency = ctx.agency'
'),'
'adr as ('
' select a.xcoord, a.ycoord'
' from address a'
' join ctx on a.addressid = ctx.addressid'
')'
'select'
' wt.code_desc,'
' trim('
' nvl(a.strnumber, '#39#39') || '#39' '#39' ||'
' nvl(a.strhnumber, '#39#39') || '#39' '#39' ||'
' nvl(a.strprefix, '#39#39') || '#39' '#39' ||'
' nvl(a.strname, '#39#39') || '#39' '#39' ||'
' nvl(a.strsuffix, '#39#39') ||'
' case when a.apartment is not null then '#39' '#39' || a.apartment el' +
'se '#39#39' end ||'
' case when a.city is not null then '#39', '#39' || a.city else '#39#39' end'
' ) as address_text,'
' case'
' when w.addressid <> (select addressid from ctx) then '#39'[SECON' +
'DARY ADDRESS] - '#39' || nvl(w.notes, '#39#39')'
' else nvl(w.notes, '#39#39')'
' end as notes,'
' abs(sqrt(power(a.xcoord - (select xcoord from adr), 2) + power' +
'(a.ycoord - (select ycoord from adr), 2))) as distance'
'from dis_warning w'
'join cd_warningtype wt on w.code = wt.code'
'join address a on w.addressid = a.addressid'
'where w.status = 1'
'and ('
' a.addressid = (select addressid from ctx)'
' or ('
' (select xcoord from adr) > 0'
' and (select ycoord from adr) > 0'
' and nvl((select warningdistance from sys), 0) > 0'
' and a.xcoord between (select xcoord from adr) - (select warn' +
'ingdistance from sys)'
' and (select xcoord from adr) + (select warnin' +
'gdistance from sys)'
' and a.ycoord between (select ycoord from adr) - (select warn' +
'ingdistance from sys)'
' and (select ycoord from adr) + (select warnin' +
'gdistance from sys)'
' )'
')'
'order by'
' distance,'
' decode(w.code, '#39'POL'#39', 1, '#39'FIR'#39', 2, 3),'
' wt.code_desc')
'SELECT'
' wt.CODE_DESC,'
' a.STRNUMBER,'
' a.STRHNUMBER,'
' a.STRPREFIX,'
' a.STRNAME,'
' a.STRSUFFIX,'
' a.APARTMENT,'
' a.CITY,'
' w.NOTES'
'FROM COMPLAINT_ACTIVE ca'
'JOIN DIS_WARNING w'
' ON w.ADDRESSID = ca.ADDRESSID'
'JOIN CD_WARNINGTYPE wt'
' ON w.CODE = wt.CODE'
'JOIN ADDRESS a'
' ON w.ADDRESSID = a.ADDRESSID'
'WHERE ca.COMPLAINTID = :COMPLAINTID'
' AND w.STATUS = 1'
'ORDER BY wt.CODE_DESC')
ReadOnly = True
Left = 488
Top = 76
......@@ -1122,6 +1077,48 @@ object ApiDatabaseModule: TApiDatabaseModule
Name = 'COMPLAINTID'
Value = nil
end>
object uqComplaintWarningsCODE_DESC: TStringField
FieldName = 'CODE_DESC'
ReadOnly = True
Size = 120
end
object uqComplaintWarningsSTRNUMBER: TFloatField
FieldName = 'STRNUMBER'
ReadOnly = True
end
object uqComplaintWarningsSTRHNUMBER: TStringField
FieldName = 'STRHNUMBER'
ReadOnly = True
Size = 1
end
object uqComplaintWarningsSTRPREFIX: TStringField
FieldName = 'STRPREFIX'
ReadOnly = True
Size = 1
end
object uqComplaintWarningsSTRNAME: TStringField
FieldName = 'STRNAME'
ReadOnly = True
end
object uqComplaintWarningsSTRSUFFIX: TStringField
FieldName = 'STRSUFFIX'
ReadOnly = True
Size = 2
end
object uqComplaintWarningsAPARTMENT: TStringField
FieldName = 'APARTMENT'
ReadOnly = True
Size = 6
end
object uqComplaintWarningsCITY: TStringField
FieldName = 'CITY'
ReadOnly = True
end
object uqComplaintWarningsNOTES: TStringField
FieldName = 'NOTES'
ReadOnly = True
Size = 1000
end
end
object uqUnitDetails: TUniQuery
Connection = ucENTCAD
......
......@@ -179,6 +179,15 @@ type
uqComplaintHistoryDATEREPORTED: TDateTimeField;
uqComplaintHistoryDPRIORITY: TStringField;
uqComplaintHistoryDCALLTYPE: TStringField;
uqComplaintWarningsCODE_DESC: TStringField;
uqComplaintWarningsSTRNUMBER: TFloatField;
uqComplaintWarningsSTRHNUMBER: TStringField;
uqComplaintWarningsSTRPREFIX: TStringField;
uqComplaintWarningsSTRNAME: TStringField;
uqComplaintWarningsSTRSUFFIX: TStringField;
uqComplaintWarningsAPARTMENT: TStringField;
uqComplaintWarningsCITY: TStringField;
uqComplaintWarningsNOTES: TStringField;
procedure uqComplaintListCalcFields(DataSet: TDataSet);
procedure uqMapComplaintsCalcFields(DataSet: TDataSet);
private
......
......@@ -797,6 +797,9 @@ var
dataArr: TJSONArray;
rowObj: TJSONObject;
returnedCount: Integer;
addressText: string;
apartmentText: string;
cityText: string;
begin
Logger.Log(3, '---TApiService.GetComplaintWarnings initiated: ' + ComplaintId);
......@@ -819,9 +822,30 @@ begin
rowObj := TJSONObject.Create;
dataArr.AddElement(rowObj);
rowObj.AddPair('CodeDesc', FieldByName('CODE_DESC').AsString);
rowObj.AddPair('Address', FieldByName('ADDRESS_TEXT').AsString);
rowObj.AddPair('Notes', FieldByName('NOTES').AsString);
addressText := Trim(
ApiDB.uqComplaintWarningsSTRNUMBER.AsString + ' ' +
ApiDB.uqComplaintWarningsSTRHNUMBER.AsString + ' ' +
ApiDB.uqComplaintWarningsSTRPREFIX.AsString + ' ' +
ApiDB.uqComplaintWarningsSTRNAME.AsString + ' ' +
ApiDB.uqComplaintWarningsSTRSUFFIX.AsString
);
apartmentText := Trim(ApiDB.uqComplaintWarningsAPARTMENT.AsString);
if apartmentText <> '' then
addressText := Trim(addressText + ' ' + apartmentText);
cityText := Trim(ApiDB.uqComplaintWarningsCITY.AsString);
if cityText <> '' then
begin
if addressText <> '' then
addressText := addressText + ', ' + cityText
else
addressText := cityText;
end;
rowObj.AddPair('CodeDesc', ApiDB.uqComplaintWarningsCODE_DESC.AsString);
rowObj.AddPair('Address', addressText);
rowObj.AddPair('Notes', ApiDB.uqComplaintWarningsNOTES.AsString);
Inc(returnedCount);
Next;
......
[Settings]
LogFileNum=665
LogFileNum=666
webClientVersion=0.1.0
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