From 469a7d634e6d16b60fe71ddef0b38754c1e8202e Mon Sep 17 00:00:00 2001 From: "apan_youxiang@163.com" Date: Thu, 11 Aug 2022 10:10:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E8=BD=AC=E8=AE=B0=E5=BD=95=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E8=AF=95=E5=89=82id=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/drug/views.py | 5 ++++- db_logic/medicament_record.py | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/drug/views.py b/apps/drug/views.py index 3c46e97..f4e3b10 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -194,10 +194,13 @@ def drug_del(): @drug_router.route("/get_durg_record", methods=["GET", "POST"]) @token_auth.login_required def get_durg_record(): + medicament_id = request.values.get("medicament_id") page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) - data_list = BllMedicamentRecord().get_drug_flow_log(page_param=page_param) + data_list = BllMedicamentRecord().get_drug_flow_log( + medicament_id=medicament_id, + page_param=page_param) return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count":page_param.totalRecords})) diff --git a/db_logic/medicament_record.py b/db_logic/medicament_record.py index 55292d5..09c08d6 100644 --- a/db_logic/medicament_record.py +++ b/db_logic/medicament_record.py @@ -30,16 +30,26 @@ class BllMedicamentRecord(Repository): # 获取流转记录 - def get_drug_flow_log(self, page_param): - sql_all = """ + + def get_drug_flow_log(self, medicament_id, page_param): + filter_base = "" + if medicament_id: + filter_base += f" medicament_id='{medicament_id}' " + if filter_base: + filter_base = f" where {filter_base}" + sql_all = f""" select a.`name`, a.speci, a.bar_code, a.cas_number, a.purity, a.client_id, a.`status`, b.create_date, b.create_user_name from( - select medicament_id, `name`, speci, bar_code, cas_number, purity, client_id, `status` from rms_medicament + select medicament_id, `name`, speci, bar_code, cas_number, purity, client_id, `status` from rms_medicament ) a RIGHT JOIN( - select medicament_id, create_date, create_user_id, create_user_name from rms_medicament_record order by create_date desc + select medicament_id, create_date, create_user_id, create_user_name from rms_medicament_record {filter_base} order by create_date desc ) b on b.medicament_id=a.medicament_id """ - count_sql = "select count(*) from rms_medicament_record" - page_param.totalRecords = self.execute(count_sql).fetchone()[0] + # count_sql = "select count(*) from rms_medicament_record" + try: + count_number = len(self.execute(sql_all).fetchall()) + except Exception: + count_number = 0 + page_param.totalRecords = count_number sql_all = Utils.sql_paging_assemble(sql_all, page_param) return self.execute(sql_all).fetchall()