分页修改

duizhaopin
apan 2 years ago
parent 2a51b4bae8
commit b9a8089d80

@ -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(): def select_drug_info():
seach_word =request.values.get("seach_word") seach_word =request.values.get("seach_word")
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))

@ -98,7 +98,7 @@ class BllMedicament(Repository):
# 选择药剂入库--试剂详情 # 选择药剂入库--试剂详情
def get_drug_info_distinct_list(self, seach_word, page_param, client_id=None): def get_drug_info_distinct_list(self, seach_word, page_param, client_id=None):
sql_all = """ sql_all = """
select %s from rms_medicament %s select * from rms_medicament %s
""" """
# 分组查询 # 分组查询
group_base = " group by `name`, cas_number, net_weight_unit" group_base = " group by `name`, cas_number, net_weight_unit"
@ -107,17 +107,22 @@ class BllMedicament(Repository):
if client_id: if client_id:
where_base += f"client_id='{client_id}'" where_base += f"client_id='{client_id}'"
if seach_word: if seach_word:
seach_word = f"%{seach_word}%"
if where_base: if where_base:
where_base += " and" where_base += " and"
where_base += f" `name` like '{seach_word}' or english_name like '{seach_word}'" where_base += f" `name` like '{seach_word}' or english_name like '{seach_word}'"
if where_base: if where_base:
where_base = "where" + where_base where_base = "where" + where_base
# 组装最终sql # 组装最终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 = Utils.sql_paging_assemble(run_sql, page_param)
run_sql_data = self.execute(run_sql).fetchall() 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 return run_sql_data
# 药剂入库 # 药剂入库

Loading…
Cancel
Save