Hal De 2 lat temu
rodzic
commit
cf60ef3e86
1 zmienionych plików z 10 dodań i 8 usunięć
  1. 10 8
      app/app.py

+ 10 - 8
app/app.py

@@ -579,27 +579,29 @@ async def getUserCDR(user,
                      limit=None,
                      offset=None,
                      order='ASC'):
-  _q = f'''SELECT * FROM cdr AS c INNER JOIN (SELECT linkedid FROM cdr WHERE'''
+  _linked_q = f'''SELECT linkedid from cdr WHERE'''
   if direction:
     direction=direction.lower()
   if direction in ('in', True, '1', 'incoming', 'inbound'):
     direction = 'inbound'
-    _q += f''' dst="{user}"'''
+    _linked_q += f''' dst="{user}"'''
   elif direction in ('out', False, '0', 'outgoing', 'outbound'):
     direction = 'outbound'
-    _q += f''' cnum="{user}"'''
+    _linked_q += f''' cnum="{user}"'''
   else:
     direction = None
-    _q += f''' (cnum="{user}" or dst="{user}")'''
+    _linked_q += f''' (cnum="{user}" or dst="{user}")'''
   if end is None:
     end = dt.now()
   if start is None:
     start=(end - td(hours=24))
-  _q += f''' AND calldate BETWEEN "{start}" AND "{end}" GROUP BY linkedid'''
+  _linked_q += f''' AND calldate BETWEEN "{start}" AND "{end}" GROUP BY linkedid'''
   if None not in (limit, offset):
-    _q += f''' LIMIT {offset},{limit}'''
-  _q += f''') AS c2 ON c.linkedid = c2.linkedid;'''
-  #app.logger.warning('SQL: {}'.format(_q))
+    _linked_q += f''' LIMIT {offset},{limit}'''
+  start1 = (start-td(hours=4))
+  end1 = (end+td(hours=4))
+  _q = f'''SELECT * FROM cdr  WHERE linkedid in ({_linked_q}) and calldate BETWEEN "{start1}" AND "{end1}";'''
+  app.logger.warning('SQL: {}'.format(_q))
   _cdr = {}
   async for row in db.iterate(query=_q):
     if (row['disposition']=='FAILED' and row['lastapp']=='Queue'):