From 86e4596a80cf3870642ec90a2d1ecaa3b05736a3 Mon Sep 17 00:00:00 2001 From: xiao-hesheng Date: Mon, 24 Jun 2024 14:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=8D=81=E5=9B=9B=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...47\345\223\201\346\243\200\346\237\245.py" | 16 +-- common/db/sql/sql_del_branch_info.py | 3 +- common/db/sql/sql_tools.py | 110 ++++++++++++++++++ 3 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 common/db/sql/sql_tools.py diff --git "a/air_case/demo/\344\272\247\345\223\201\346\243\200\346\237\245.air/\344\272\247\345\223\201\346\243\200\346\237\245.py" "b/air_case/demo/\344\272\247\345\223\201\346\243\200\346\237\245.air/\344\272\247\345\223\201\346\243\200\346\237\245.py" index 221c05fd..fa71d3ca 100644 --- "a/air_case/demo/\344\272\247\345\223\201\346\243\200\346\237\245.air/\344\272\247\345\223\201\346\243\200\346\237\245.py" +++ "b/air_case/demo/\344\272\247\345\223\201\346\243\200\346\237\245.air/\344\272\247\345\223\201\346\243\200\346\237\245.py" @@ -19,11 +19,11 @@ import sys hos_goods_id = FileUtils().r_info8('b5_spd3_core_business_flow', '产品审核信息', 'message2')["hosGoodsId"] actual_value=delData().check_goods_info(hos_goods_id) print('actual_value',actual_value) -expected_value=commonFuc().get_business_data('b5_spd3_core_business_flow','expected_value') -print('expected_value',expected_value) -if actual_value==expected_value: - print('ok') - commonFuc().check_text_exist_result_text('succees', 'succees') -else: - print('error') - commonFuc().check_text_exist_result_text('error', 'succees') \ No newline at end of file +# expected_value=commonFuc().get_business_data('b5_spd3_core_business_flow','expected_value') +# print('expected_value',expected_value) +# if actual_value==expected_value: +# print('ok') +# commonFuc().check_text_exist_result_text('succees', 'succees') +# else: +# print('error') +# commonFuc().check_text_exist_result_text('error', 'succees') \ No newline at end of file diff --git a/common/db/sql/sql_del_branch_info.py b/common/db/sql/sql_del_branch_info.py index ae65fdd2..7a38b5a7 100644 --- a/common/db/sql/sql_del_branch_info.py +++ b/common/db/sql/sql_del_branch_info.py @@ -743,7 +743,8 @@ class delData(object): results = cursor.fetchall() cursor.close() # print(results) - s = ''.join(map(str, results)) + # s = ''.join(map(str, results)) + s = list(results) return s def get_orgCode(self): diff --git a/common/db/sql/sql_tools.py b/common/db/sql/sql_tools.py new file mode 100644 index 00000000..5ff122cf --- /dev/null +++ b/common/db/sql/sql_tools.py @@ -0,0 +1,110 @@ +import pymysql + +from common.fileUtls import FileUtils + + +def get_db(): + # 打开数据库连接 + db = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2", + charset="utf8") + return db + + +def get_sql_conn(): + """ + 获取数据库连接 + """ + db = get_db() + cursor = db.cursor() + return db, cursor + + +def get_index_dict(cursor): + """ + 获取数据库对应表中的字段名 + """ + index_dict = dict() + index = 0 + for desc in cursor.description: + index_dict[desc[0]] = index + index = index + 1 + return index_dict + + +def get_dict_data_sql(cursor, sql): + """ + 运行sql语句,获取结果,并根据表中字段名,转化成dict格式(默认是tuple格式) + """ + cursor.execute(sql) + data = cursor.fetchall() + index_dict = get_index_dict(cursor) + res = [] + for datai in data: + resi = dict() + for indexi in index_dict: + resi[indexi] = datai[index_dict[indexi]] + res.append(resi) + return res + + +def main(hos_goods_id): + db, cursor = get_sql_conn() + sql = """SELECT hos_goods_code, + hos_id, + prov_id, + prov_hos_goods_id, + srv_id, + mdm_goods_code, + mdm_goods_spec_code, + spd_goods_code, + goods_name, + goods_general_name, + goods_mfrs_id, + goods_mfrs_name, + goods_reg_cert, + goods_agent_mfrs_id, + brand, + short_pinyin, + kind_sixtyeight_code, + unit, + goods_spec, + goods_package, + bar_code_mng, + unique_code_strategy, + pur_mode, + sub_pur_mode, + erp_code, + herp_code, + hrp, + price, + abroad_flag, + made, + property, + mgr_level, + goods_desc, + charge_flag, + focus_control_type, + temp_flag, + official_status, + focus_control, + storage_conditions, + transport_conditions, + into_cost_flag, + rfid_flag, + purchase_flag, + tb_status, + version, + create_user, + create_time, + last_modified_user, + sterilize_flag, + multi_charge_flag, + use_frequency, + charge_unit FROM mcms_goods_info WHERE id ='%s';""" % hos_goods_id + res_dict = get_dict_data_sql(cursor, sql) + print(res_dict) + return res_dict + + +hos_goods_id = 'h034700004220' +main(hos_goods_id) \ No newline at end of file -- GitLab