Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_records_query(self):
- """
- Получаем список детальной информации о разговорах
- :return:
- """
- if self.order_by in ("caller_number", "called_number", "zone", "b_leg",
- "call_marked",
- # TODO возможно все же нужно оставить
- # "group_name",
- "queue_idstat",
- "wait_sec", "bsl_delta",
- "datetime", "session_end", "disconnect_code",
- "billable_session_length", "price", "summ") and self.order_type in ['DESC', 'ASC']:
- order_by_dict = {
- "caller_number": 3,
- "called_number": 4,
- "b_leg": 10,
- "disconnect_code": 23,
- "bsl_delta": 12,
- "queue_idstat": 9,
- # "zone": 6,
- "datetime": 7,
- "session_end": 8,
- "billable_session_length": 11,
- "wait_sec": 13,
- "summ": 14,
- "price": 15,
- "call_marked": 17
- }
- ord_col_num = order_by_dict.get(self.order_by, "b.id")
- order = '{} {}'.format(ord_col_num , self.order_type)
- else:
- order = "b.id desc"
- sql = """
- select
- b.general, -- 1
- b.caller_group_number, -- 2
- b.caller_number, -- 3
- array_agg(distinct b.called_number) as called_number, -- 4
- array_agg(distinct b.answer_number) as answer_number, -- 5
- array_agg(dc.disconnect_rus) as disconnect_code, -- 6
- array_agg(b.datetime + (%(time_shift)s||' hours')::interval) as dts, -- 7
- array_agg(b.session_end + (%(time_shift)s||' hours')::interval) as dte, -- 8
- array_agg(coalesce(q.name, get_schema_name(b.dialed_extension))) as queues, -- 9
- array_agg(case
- when b.b_leg is not null and inum.person_name is not null
- then inum.person_name || '( '|| b.b_leg||')'
- when b.b_leg is not null and inum.person_name is null and length(b.b_leg)>0
- then b.b_leg
- else
- ''
- end) as answered, -- 10
- array_agg(b.session_length::integer) as bsl, -- 11
- array_agg((case
- when b.called_account_id=%(account_id)s and (b.b_leg is null or b.b_leg = '') and inum.person_name is null
- then 0
- when b.called_account_id=%(account_id)s
- then b.billable_session_length - b.wait_sec
- when b.account_id = %(account_id)s and (b.b_leg is null or b.b_leg = '')
- then 0
- else
- b.billable_session_length end )::integer) as bsl_delta, -- 12
- array_agg(( case
- when b.called_account_id=%(account_id)s and (b.b_leg is null or b.b_leg = '') and inum.person_name is null
- then b.billable_session_length
- when b.called_account_id=%(account_id)s
- then b.wait_sec
- when b.account_id = %(account_id)s and (b.b_leg is null or b.b_leg = '')
- then b.session_length
- else b.wait_sec end )::integer) as wl, -- 13
- array_agg(b.summ) as summ, -- 14
- array_agg(b.price) as price, -- 15
- array_agg(distinct b.file) as file, -- 16
- array_agg( b.marked) as marked, -- 17
- array_agg( b.id) as id, -- 18
- array_agg( z.name) as zone, -- 19
- array_agg( b.flag_record_out) as outgoing, -- 20
- array_agg( b.session_id) as session, -- 21
- array_agg(get_tarif_time((case
- when b.called_account_id=%(account_id)s and (b.b_leg is null or b.b_leg = '') and inum.person_name is null
- then 0
- when b.called_account_id=%(account_id)s
- then b.billable_session_length - b.wait_sec
- when b.account_id = %(account_id)s and (b.b_leg is null or b.b_leg = '')
- then 0
- else
- b.billable_session_length end)::integer, b.account_id, %(account_id)s)) as tariff_time, --22
- array_agg( case when b.hangup_side = 'recv_bye' or b.hangup_side = 'send_refuse' then 'А' when b.hangup_side is null or length(b.hangup_side)<1 then ' ' else 'Б' end) as hangup_side, --23
- array_agg(b.fifo_service_rating) as fifo_service_rating --24
- from billservice_phonetransaction b
- left join tel_zones z on b.tel_zone_id = z.id
- left join internal_numbers inum on inum.username=b.b_leg -- and inum.account_id=b.account_id
- left join disconnect_code dc on dc.disconnect_eng=b.disconnect_code
- left join fs_queue q on b.queue_idstat=q.id
- where (1=1) {}
- group by
- b.general,
- b.caller_group_number,
- b.caller_number
- order by {}
- """.format(self.filter_content, order)
- return sql, self.filter_args
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement