def data_preparation(jzdbtest_session, apply_prefix, apply_suffix, apply_code, user_id, organ_id, net_id): # Create apply id and register the id apply_sn = SerialNumber(insert_time=datetime.now(), update_time=datetime.now(), operator_id=0, delete_flag=0, type=2, prefix=apply_prefix, suffix=apply_suffix, number=apply_code) register_prefix, register_suffix, register_code = DataPreparation.create_serial_number( 'RE', jzdbtest_session) reg_sn = SerialNumber(insert_time=datetime.now(), update_time=datetime.now(), operator_id=0, delete_flag=0, type=1, prefix=register_prefix, suffix=register_suffix, number=register_code) # Create apply product_code = ['1006', '1007'][random.randint(0, 1)] customer = Generator.generate_customer() cr = DataPreparation.customer_register(register_code, customer, product_code, user_id, organ_id, net_id) apply = DataPreparation.customer_apply(apply_code, register_code, customer, product_code, user_id, organ_id, net_id) # Create user id information id_card = DataPreparation.customer_id_card(apply_code, customer) # Check files check_file_1 = DataPreparation.customer_check_file(apply_code, 1) check_file_2 = DataPreparation.customer_check_file(apply_code, 2) check_file_3 = DataPreparation.customer_check_file(apply_code, 3) # Customer basic information basic_info = DataPreparation.customer_application_info_pre( apply_code, customer) # Customer policy information, if product id is 1007 if product_code == '1007': policy = DataPreparation.customer_policy(apply_code) with jzdbtest_session.begin(): jzdbtest_session.add(policy) jzdbtest_session.add( DataPreparation.customer_policy_photo(apply_code, policy.id)) with jzdbtest_session.begin(): jzdbtest_session.add_all([ apply_sn, reg_sn, cr, apply, id_card, check_file_1, check_file_2, check_file_3, basic_info ]) # Create credits pboc1, pboc2 = DataPreparation.api_pboc(apply_code, jzdbtest_session) file_result = DataPreparation.customer_check_file_result(apply_code) # Customer information review apply_confirm_result = DataPreparation.customer_applyconfirm_result( apply_code) # Entire customer information application_info = DataPreparation.customer_application_info(apply_code) # Intermedia agreements agreement2, agreement3, agreement4 = DataPreparation.customer_intermediary_agreement_file( apply_code) with jzdbtest_session.begin(): jzdbtest_session.add_all([ pboc1, pboc2, file_result, apply_confirm_result, application_info, agreement2, agreement3, agreement4 ]) # Intermedia agreements review media_file_result = DataPreparation.customer_intermediary_agreement_result( apply_code) with jzdbtest_session.begin(): jzdbtest_session.add(media_file_result) return product_code, customer
for i in range(int(record_size)): logger.info('To create data #{}'.format(str(i + 1))) apply_prefix, apply_suffix, apply_code = DataPreparation.create_serial_number( 'AP', jzdbtest_session) product_code, customer = data_preparation(jzdbtest_session, apply_prefix, apply_suffix, apply_code, user_id, organ_id, net_id) telephone_verification_preparation(product_code, apply_code, jzdbtest_session) logger.info('To create workflow #{}'.format(str(i + 1))) workflow = WorkflowTrigger(apply_code, user_id=user_id) branch_workflow(workflow) if xarg == 'interview': file_audit_workflow(workflow, file_auditor) solution_confirm_workflow(workflow) intermedia_file_audit(workflow, agreement_auditor) launch_phone_verification_workflow(workflow, product_code) launch_branch_registration_workflow(workflow, customer.name, customer.id_number) print('{} data have been imported.'.format(str(record_size))) sso_session.close() jzdbtest_session.close() else: # for export simulated data with open(xarg + '.csv', 'w') as csv: for _ in range(int(record_size)): customer = Generator.generate_customer() csv.write(str(customer) + '\n')