26641ca0 by 周伟奇

add auto excel

1 parent 43ce3393
......@@ -2217,3 +2217,12 @@ RPA_RESULT_MAP = {
RE_RPA_RESULT_MAP = {v: k for k, v in RPA_RESULT_MAP.items()}
AUTO_WB_FIELD = (
('application_id', 'aa_type', 'ocr_latest_comparison_time', 'ocr_auto_result_pass', 'ocr_whole_result_pass',
'rpa_result', 'rpa_1st_eye_tat', 'rpa_2nd_eye_tat', 'rpa_3rd_eye_tat', 'rpa_total_tat', 'rpa_activated_time',
'rpa_get_case_from_ocr_time', 'rpa_get_case_from_oc_time', 'rpa_payment_authorize_time', 'rpa_second_eye_time'),
('application_id', 'aa_type', 'latest_comparison_time', 'auto_result', 'whole_result', 'rpa_result',
'rpa_1st_eye_tat', 'rpa_2nd_eye_tat', 'rpa_3rd_eye_tat', 'rpa_total_tat', 'rpa_activated_time',
'rpa_get_case_from_ocr_time', 'rpa_get_case_from_oc_time', 'rpa_payment_authorize_time', 'rpa_second_eye_time')
)
......
......@@ -1369,9 +1369,54 @@ class AutoSettlementExcelView(GenericView):
# 获取auto settlement excel
@use_args(auto_list_args, location='querystring')
def get(self, request, args):
business_type = args.get('business_type')
application_id = args.get('application_id')
get_case_from_ocr_time_start = args.get('get_case_from_ocr_time_start')
get_case_from_ocr_time_end = args.get('get_case_from_ocr_time_end')
activated_time_start = args.get('activated_time_start')
activated_time_end = args.get('activated_time_end')
comparison_time_start = args.get('comparison_time_start')
comparison_time_end = args.get('comparison_time_end')
auto_result = args.get('auto_result', '')
whole_result = args.get('whole_result', '')
rpa_result = args.get('rpa_result', '')
if isinstance(auto_result, int):
auto_result = consts.RESULT_MAP.get(auto_result)
if isinstance(whole_result, int):
whole_result = consts.RESULT_MAP.get(whole_result)
if isinstance(rpa_result, int):
rpa_result = consts.RPA_RESULT_MAP.get(rpa_result)
application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q()
auto_result_query = Q(ocr_auto_result_pass=auto_result) if not isinstance(auto_result, str) else Q()
whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q()
rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q()
time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start,
rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1)) \
if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q()
time2_query = Q(rpa_activated_time__gte=activated_time_start,
rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \
if activated_time_start is not None and activated_time_end is not None else Q()
time3_query = Q(ocr_latest_comparison_time__gte=comparison_time_start,
ocr_latest_comparison_time__lt=comparison_time_end + datetime.timedelta(days=1)) \
if comparison_time_start is not None and comparison_time_end is not None else Q()
query = application_id_query & auto_result_query & whole_result_query & rpa_result_query \
& time1_query & time2_query & time3_query
auto_class = HILAutoSettlement if business_type in consts.HIL_SET else AFCAutoSettlement
auto_queryset = auto_class.objects.filter(query).values_list(*consts.AUTO_WB_FIELD[0]).order_by(
'-ocr_latest_comparison_time')
wb = Workbook()
ws = wb.active
ws.append(['序号', '告警id', '设备编号'])
ws.append(consts.AUTO_WB_FIELD[1])
for row in auto_queryset:
ws.append(row)
io_content = io.BytesIO() # 创建在内存中处理对象
wb.save(io_content)
wb.close()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!