diff --git a/apps/drug_template/views.py b/apps/drug_template/views.py index 9d77b11..8cafb88 100644 --- a/apps/drug_template/views.py +++ b/apps/drug_template/views.py @@ -53,7 +53,7 @@ def show_template(): # 选择药剂入库 -@tmp_router.route("/select_drug", methods=["GET", "POST"]) +@tmp_router.route("/select_drug", methods=["POST"]) def select_drug_info(): seach_word =request.values.get("seach_word") page = int(request.values.get("page", 1)) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index ef08f76..8467bd7 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -98,7 +98,7 @@ class BllMedicament(Repository): # 选择药剂入库--试剂详情 def get_drug_info_distinct_list(self, seach_word, page_param, client_id=None): sql_all = """ - select %s from rms_medicament %s + select * from rms_medicament %s """ # 分组查询 group_base = " group by `name`, cas_number, net_weight_unit" @@ -107,17 +107,22 @@ class BllMedicament(Repository): if client_id: where_base += f"client_id='{client_id}'" if seach_word: + seach_word = f"%{seach_word}%" if where_base: where_base += " and" where_base += f" `name` like '{seach_word}' or english_name like '{seach_word}'" if where_base: where_base = "where" + where_base # 组装最终sql - run_sql = sql_all % ("*", where_base+group_base) + run_sql = sql_all % where_base+group_base + try: + count_number = len(self.execute(run_sql).fetchall()) + except Exception: + count_number = 0 + page_param.totalRecords = count_number + # 分页sql run_sql = Utils.sql_paging_assemble(run_sql, page_param) run_sql_data = self.execute(run_sql).fetchall() - page_param.totalRecords = self.execute( - sql_all % ("count(*)", where_base + group_base)).fetchone()[0] return run_sql_data # 药剂入库