From bbb2c6f9cd684e025162545937e70f383c34b324 Mon Sep 17 00:00:00 2001 From: apan Date: Mon, 1 Aug 2022 13:24:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3bug;=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=A5=E8=A1=A8=E6=97=B6=E9=97=B4=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Utils.py | 2 + apps/report/views.py | 133 +++++++++++++++++++++--------- db_logic/medicament.py | 45 ++++++++--- db_logic/medicament_record.py | 147 +++++++++++++++++++++------------- 4 files changed, 224 insertions(+), 103 deletions(-) diff --git a/Common/Utils.py b/Common/Utils.py index fa188a0..f2272d9 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -11,6 +11,7 @@ import platform import hashlib import uuid import psutil +import math from config.SystemConfig import SystemConfig # 判断当前系统是linux还是windows @@ -39,6 +40,7 @@ class Utils(object): def classify(num, all_num, fl=2): return str(round(float(round(float(num) / all_num, fl)) * 100)) + "%" + # return str(round(float(round(math.ceil(num) / all_num, fl)) * 100)) + "%" #获取唯一识别码 def UUID(): diff --git a/apps/report/views.py b/apps/report/views.py index 64f336c..e115136 100644 --- a/apps/report/views.py +++ b/apps/report/views.py @@ -15,30 +15,62 @@ from flask import Blueprint report_router = Blueprint("report", __name__) # 获取报表统计页面展示 -@report_router.route('/report_home', methods=["GET", "POST"]) -def report_home_info(): - # 试剂使用统计 - data_list = BllMedicamentRecord().get_drug_record_count() - return jsonify(Utils.true_return(data=data_list)) +# @report_router.route('/report_home', methods=["GET", "POST"]) +# def report_home_info(): +# # 试剂使用统计 +# data_list = BllMedicamentRecord().get_drug_record_count() +# return jsonify(Utils.true_return(data=data_list)) + +# # 消耗统计 +# @report_router.route("/drug_stock_use_classify", methods=["GET", "POST"]) +# def get_drug_stock_use_classify(): +# data_list, total_number = BllMedicament().get_drug_stock_use_classify() +# return jsonify(Utils.true_return(data={"total_count":total_number, "data":data_list})) + + +# # 试剂用量消耗 +# @report_router.route("/drug_use_classify", methods=["GET", "POST"]) +# def get_drug_use_classify(): +# data_list = BllMedicamentRecord().report_home_drug_useing_classify() +# return jsonify(Utils.true_return(data=data_list)) + +# # 用户试剂消耗 +# @report_router.route("/drug_user_use_info", methods=["GET", "POST"]) +# def get_drug_user_use_number(): +# data_list = BllMedicamentRecord().report_home_user_use_info() +# return jsonify(Utils.true_return(data=data_list)) + +# 报表统计主页 +@report_router.route("/report_home", methods=["GET", "POST"]) +def report_home_show(): + resp_data = { + "drug_use_type_data": "", + "drug_stock_expend": {"count_number":0, "data":""}, + "drug_use_expend":"", + "user_use_expend": "" + + } + try: + obj_data = BllMedicamentRecord() + # 试剂使用统计 + drug_use_type_data = obj_data.get_drug_record_count() + # 消耗统计部分 + drug_stock_expend, num_all = BllMedicament().get_drug_stock_use_classify() + # 试剂用量消耗 + drug_use_expend = obj_data.report_home_drug_useing_classify() + # 用户试剂消耗 + user_use_expend = obj_data.report_home_user_use_info() + resp_data["drug_use_type_data"] = drug_use_type_data + resp_data["drug_stock_expend"] = { + "count_number": num_all, + "data": drug_stock_expend + } + resp_data["drug_use_expend"] = drug_use_expend + resp_data["user_use_expend"] = user_use_expend + return jsonify(Utils.true_return(data=resp_data)) + except Exception as error: + return jsonify(Utils.except_return(msg=f"error:{error}", data=resp_data)) -# 消耗统计 -@report_router.route("/drug_stock_use_classify", methods=["GET", "POST"]) -def get_drug_stock_use_classify(): - data_list, total_number = BllMedicament().get_drug_stock_use_classify() - return jsonify(Utils.true_return(data={"total_count":total_number, "data":data_list})) - - -# 试剂用量消耗 -@report_router.route("/drug_use_classify", methods=["GET", "POST"]) -def get_drug_use_classify(): - data_list = BllMedicamentRecord().report_home_drug_useing_classify() - return jsonify(Utils.true_return(data=data_list)) - -# 用户试剂消耗 -@report_router.route("/drug_user_use_info", methods=["GET", "POST"]) -def get_drug_user_use_number(): - data_list = BllMedicamentRecord().report_home_user_use_info() - return jsonify(Utils.true_return(data=data_list)) @@ -51,7 +83,8 @@ def get_stock_data_info(): page_size = int(request.values.get('page_size', 15)) page_param = PageParam(page, page_size) data_list = BllMedicament().get_stock_all_info( - name=name, page_param=page_param) + name=name, + page_param=page_param) data_list = Utils.msyql_table_model(data_list) if data_list: return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data_list})) @@ -64,10 +97,11 @@ def get_stock_data_info(): def drun_input_info(): # 获取参数 seach_word = request.values.get('seach_word') - # manufacturer = request.values.get("manufacturer") - # customer_id = request.values.get("customer_id") - # 获取配置文件内的客户id - customer_id = SystemConfig.getConfig("customer_id") + manufacturer = request.values.get("manufacturer") + start_time = request.values.get("start_time") + end_time = request.values.get("end_time") + # 客户id + customer_id = None client_id = request.values.get("client_id") # 分页处理 page = int(request.values.get("page", 1)) @@ -75,7 +109,10 @@ def drun_input_info(): page_param = PageParam(page, page_size) # 获取数据 data = BllMedicament().getAllDrugList( - search_word=seach_word, + search_word=seach_word, + manufacturer=manufacturer, + start_time=start_time, + end_time=end_time, page_param=page_param, customer_id=customer_id, client_id=client_id @@ -92,11 +129,17 @@ def drun_input_info(): def stock_loss_info(): # 获取参数 seach_word = request.values.get('seach_word') + start_time = request.values.get('start_time') + end_time = request.values.get('end_time') page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) # 获取数据结果 - data = BllMedicamentRecord().durg_stock_loss(seach_word, page_param=page_param) + data = BllMedicamentRecord().durg_stock_loss( + seach_word=seach_word, + start_time=start_time, + end_time=end_time, + page_param=page_param) return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) @@ -106,11 +149,17 @@ def stock_loss_info(): def get_drug_use_expend(): # 参数获取 seach_word = request.values.get('seach_word') + start_time = request.values.get('start_time') + end_time = request.values.get('end_time') page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) # 获取数据 - data = BllMedicamentRecord().durg_useing_info(seach_word, page_param=page_param) + data = BllMedicamentRecord().durg_useing_info( + seach_word=seach_word, + start_time=start_time, + end_time=end_time, + page_param=page_param) return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) @@ -119,12 +168,17 @@ def get_drug_use_expend(): def get_drug_user_use_expend(): # 参数获取 seach_user = request.values.get('seach_user') + start_time = request.values.get('start_time') + end_time = request.values.get('end_time') page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) # 获取数据 data = BllMedicamentRecord().user_use_info( - seach_user=seach_user, page_param=page_param) + seach_user=seach_user, + start_time=start_time, + end_time=end_time, + page_param=page_param) return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) @@ -133,10 +187,17 @@ def get_drug_user_use_expend(): def drug_use_frequency(): seach_word = request.values.get('seach_word') client_id = request.values.get("client_id") + start_time = request.values.get('start_time') + end_time = request.values.get('end_time') page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) - data = BllMedicamentRecord().use_frequency(seach_word=seach_word, client_id=client_id, page_param=page_param) + data = BllMedicamentRecord().use_frequency( + seach_word=seach_word, + start_time=start_time, + end_time=end_time, + client_id=client_id, + page_param=page_param) return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) @@ -149,14 +210,14 @@ def drug_log_type_info(): record_type = request.values.get("record_type") put_in_user_name = request.values.get("user_name") name = request.values.get("name") - # start_time = request.values.get("start_time") - # end_time = request.values.get("end_time") + start_time = request.values.get("start_time") + end_time = request.values.get("end_time") page_param = PageParam(page, page_size) data_list = BllMedicament().drug_show_type_info( record_type=record_type, put_in_user_name=put_in_user_name, statue_type=statue_type, name=name, - # start_time=start_time, end_time=end_time, + start_time=start_time, end_time=end_time, page_param=page_param ) data_list = Utils.msyql_table_model(data_list) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index d3ff89a..68d8252 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -67,13 +67,17 @@ class BllMedicament(Repository): sql_all = """ select count(medicament_id) count_number, `status` from rms_medicament GROUP BY `status` """ + # 查看分组数据 data = self.execute(sql_all).fetchall() + # 计算总数 data_number = sum([i[0] for i in data]) data_li = Utils.msyql_table_model(data) data_list = [] + # 计算百分比,组装数据 for i in data_li: new_dict = { - "ratio": str(round(i["count_number"] / data_number,2) * 100) + "%" + # "ratio": str(round(i["count_number"] / data_number,2) * 100) + "%" + "ratio": Utils.classify(i['count_number'], data_number) } new_dict.update(i) data_list.append(new_dict) @@ -244,8 +248,7 @@ class BllMedicament(Repository): # 拼接查询条件及分组条件 filter_base = "" if name: - filter_base = f"where `name` LIKE %'{name}'%" - + filter_base = f" where `name` LIKE %'{name}'%" filter_base += " GROUP BY `name`, speci, purity" sql_all = sql_all % filter_base @@ -262,13 +265,17 @@ class BllMedicament(Repository): return sql_data #获取所有药剂列表 - def getAllDrugList(self, search_word, page_param, customer_id=None, client_id=None): + + def getAllDrugList(self, search_word, manufacturer, start_time, end_time, page_param, customer_id=None, client_id=None): # (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord) sql_all = """ - select `name`,speci, manufacturer, distributor, net_weight_unit, remain, production_date, expiration_date, + select `name`, bar_code, status, speci, manufacturer, distributor, net_weight_unit, remain, production_date, expiration_date, shelf_life, put_in_user_name, put_in_date, english_name, purity, is_supervise, by_user_name from rms_medicament %s """ + # manufacturer = manufacturer, + # start_time = start_time, + # end_time = end_time, # 动态添加查询条件 filter_base = "" if customer_id: @@ -277,12 +284,23 @@ class BllMedicament(Repository): if filter_base: filter_base += " and " filter_base += f"client_id='{client_id}'" - # 模糊搜索 + # 名称搜索 if search_word: seach_w = f"%{search_word}%" if filter_base: filter_base += " and " filter_base += f" `name` like '{seach_w}' or english_name like '{seach_w}' or manufacturer like '{seach_w}'" + # 厂商搜索 + if manufacturer: + manufacturer = f"%{manufacturer}%" + if filter_base: + filter_base += " and " + filter_base += f"manufacturer like '{manufacturer}'" + # 时间范围搜索 + if start_time and end_time: + if filter_base: + filter_base += " and " + filter_base += f"put_in_date >= '{start_time}' and put_in_date<='{end_time}'" if filter_base: filter_base = "where " + filter_base sql_all = sql_all % filter_base @@ -297,7 +315,7 @@ class BllMedicament(Repository): return self.execute(sql_all).fetchall() # 入库、领用、归还记录 - def drug_show_type_info(self, record_type, put_in_user_name, name, statue_type, page_param): + def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, statue_type, page_param): sql_all = """ SELECT b.`name`, b.english_name, b.bar_code, b.purity, b.cas_number, a.use_quantity, b.`status`, a.create_date, a.create_user_name, b.client_id @@ -311,22 +329,23 @@ class BllMedicament(Repository): filter_sql = f"WHERE record_type={record_type}" if put_in_user_name: - filter_sql += f" and create_user_name like {put_in_user_name}" - # if start_time and end_time: - # filter_sql += f"and create_date >= {start_time} and create_date <= {end_time}" + filter_sql += f" and create_user_name like '{put_in_user_name}'" + if start_time and end_time: + filter_sql += f" and create_date >= '{start_time}' and create_date <= '{end_time}'" filter_sql_1 = '' if statue_type: filter_sql_1 = f" where `status`={statue_type}" if name: + name = f"%{name}%" if filter_sql_1: - filter_sql_1 += "and" + filter_sql_1 += " and" else: filter_sql_1 += " where " filter_sql_1 += f" `name` like '{name}' or english_name like '{name}'" sql_all = sql_all % (filter_sql, filter_sql_1) - finds = ["name", "english_name", "bar_code", - "purity", "cas_number", "use_quantity", "status", "create_date", "create_user_name", "client_id"] + # finds = ["name", "english_name", "bar_code", + # "purity", "cas_number", "use_quantity", "status", "create_date", "create_user_name", "client_id"] try: count_number = len(self.execute(sql_all).fetchall()) except Exception: diff --git a/db_logic/medicament_record.py b/db_logic/medicament_record.py index 073cbf8..3e12c90 100644 --- a/db_logic/medicament_record.py +++ b/db_logic/medicament_record.py @@ -80,31 +80,43 @@ class BllMedicamentRecord(Repository): return dict(recordListNew) - def get_drug_log_time_name(self, record_type): - sql_all = f""" - select a.`name` `name`,a.medicament_id, b.create_date create_date from ( - - select `name`, medicament_id from rms_medicament - ) a RIGHT JOIN( - - select medicament_id, create_date from rms_medicament_record WHERE record_type={record_type} ORDER BY create_date desc LIMIT 1 - ) b on a.medicament_id=b.medicament_id - """ - return self.execute(sql_all).fetchall()[0] + def get_drug_log_time_name(self, record_type_list): + sql_all = """ + select a.`name` `name`,a.medicament_id, b.create_date create_date, b.record_type from ( + select `name`, medicament_id from rms_medicament + ) a RIGHT JOIN( + select medicament_id, create_date, record_type from rms_medicament_record WHERE record_type=%s ORDER BY create_date desc LIMIT 1 + ) b on a.medicament_id=b.medicament_id + """ + sql_list = [] + for record_type in record_type_list: + sql_list.append( + sql_all % record_type + ) + sql_all = " UNION ".join(sql_list) + # print(sql_all) + return self.execute(sql_all).fetchall() # 获取报表统计主页入库记录信息 def get_drug_record_count(self): sql_all = """ select COUNT(record_id) count_number, record_type from rms_medicament_record GROUP BY record_type """ + # 获取分类数量 data = self.execute(sql_all).fetchall() data_li = Utils.msyql_table_model(data) data_list = [] + # 获取时间维度最后一条名称及时间 + name_info_list = self.get_drug_log_time_name([1,2,3]) + name_info_dict = {} + for name in name_info_list: + name_info_dict[name[-1]] = name + # 组装数据 for i in data_li: - name_date = self.get_drug_log_time_name(i["record_type"]) + name_info = name_info_dict.get(i['record_type']) new_dic = { - "name": name_date[0], - "date_time": name_date[2] + "name": name_info[0], + "date_time": name_info[2] } new_dic.update(**i) data_list.append(new_dic) @@ -112,22 +124,26 @@ class BllMedicamentRecord(Repository): # 获取报表统计主页试剂用量消耗 def report_home_drug_useing_classify(self): + # select a.count_id count_number, b.`name` from ( + # select count(record_id) count_id, medicament_id from rms_medicament_record GROUP BY medicament_id + # ) a LEFT JOIN( + # select `name`, medicament_id from rms_medicament + # ) b on a.medicament_id=b.medicament_id sql_all = """ - select a.count_id count_number, b.`name` from ( - + select a.`name`, sum(b.count_id) count_num from ( + select `name`, medicament_id, speci, purity from rms_medicament) a LEFT JOIN( select count(record_id) count_id, medicament_id from rms_medicament_record GROUP BY medicament_id - ) a LEFT JOIN( - select `name`, medicament_id from rms_medicament - ) b on a.medicament_id=b.medicament_id + )b on a.medicament_id=b.medicament_id GROUP BY `name`, speci, purity """ data = self.execute(sql_all).fetchall() - data_number = sum([i[0] for i in data]) + data_number = sum([float(i[1]) for i in data]) data_li = Utils.msyql_table_model(data) data_list = [] for i in data_li: new_dic = { - "ratio": Utils.classify(i["count_number"], data_number) + "ratio": Utils.classify(i["count_num"], data_number) } + i["count_num"] = int(i["count_num"]) new_dic.update(**i) data_list.append(new_dic) return data_list @@ -168,12 +184,11 @@ class BllMedicamentRecord(Repository): new_dic[k] = v if not isinstance(v, Decimal) else float(v) data_list.append(new_dic) if finds: - print(base_num) base_num += float(new_dic.get(finds)) return data_list, base_num # 获取库存消耗数据 - def durg_stock_loss(self, seach_word, page_param): + def durg_stock_loss(self, seach_word, start_time, end_time, page_param): sql_all = """ select c.`name`, c.cas_number,c.speci, c.net_weight_unit, c.purity, c.enter_stock, sum(CASE WHEN c.`status`=1 THEN 1 ELSE 0 END) in_stock, @@ -184,17 +199,21 @@ class BllMedicamentRecord(Repository): select medicament_id, `name`, cas_number, speci, purity, net_weight_unit, `status` from rms_medicament %s ) a LEFT JOIN( - SELECT medicament_id, sum(CASE WHEN record_type=1 THEN 1 ELSE 0 END) enter_stock from rms_medicament_record GROUP BY medicament_id + SELECT medicament_id, sum(CASE WHEN record_type=1 THEN 1 ELSE 0 END) enter_stock from rms_medicament_record %s GROUP BY medicament_id ) b on b.medicament_id = a.medicament_id ) c GROUP BY `name`, purity, speci """ # 拼接搜索条件 + filter_base1 = "" if seach_word: seach_word = f"%{seach_word}%" - sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'" - else: - sql_all = sql_all % "" + filter_base1 = f" where `name` like '{seach_word}' or english_name like '{seach_word}'" + filter_base2 = "" + if start_time and end_time: + filter_base2 += f" where create_date >= '{start_time}' and create_date <= '{end_time}'" + + sql_all = sql_all % (filter_base1, filter_base2) # 查询获取数据条目数 try: count_number = len(self.execute(sql_all).fetchall()) @@ -208,7 +227,9 @@ class BllMedicamentRecord(Repository): return data_list # 试剂用量消耗 - def durg_useing_info(self, seach_word, page_param): + def durg_useing_info(self, seach_word, start_time, end_time, page_param): + # select medicament_id, FORMAT(sum(use_quantity),2) sum_use, sum(CASE WHEN record_type=2 THEN 1 ELSE 0 END) c_two from rms_medicament_record %s GROUP BY medicament_id + sql_all = """ select c.`name`, c.purity, c.speci, c.cas_number, c.net_weight_unit, sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) on_in, @@ -218,16 +239,20 @@ class BllMedicamentRecord(Repository): select medicament_id, `name`, speci, cas_number, purity, net_weight_unit, `status` from rms_medicament %s ) a LEFT JOIN( - select medicament_id, FORMAT(sum(use_quantity),2) sum_use, sum(CASE WHEN record_type=2 THEN 1 ELSE 0 END) c_two from rms_medicament_record GROUP BY medicament_id + select medicament_id, FORMAT(sum(use_quantity),2) sum_use, count(record_id) c_two from rms_medicament_record where record_type=2 %s GROUP BY medicament_id ) b on a.medicament_id=b.medicament_id ) c GROUP BY `name`, purity, speci """ # 拼接查询条件 + filter_base1 = "" if seach_word: - seach_word = f"%{seach_word}%" - sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'" - else: - sql_all = sql_all % "" + filter_base1 = f"where `name` like '{seach_word}' or english_name like '%{seach_word}%'" + filter_base2 = "" + if start_time and end_time: + filter_base2 = f" and create_date >= '{start_time}' and create_date <= '{end_time}'" + + sql_all = sql_all %(filter_base1, filter_base2) + # 获取数量 try: count_number = len(self.execute(sql_all).fetchall()) @@ -239,11 +264,14 @@ class BllMedicamentRecord(Repository): data, ratio_all = self.default_data_list(page_sql_all, "use_level") # 拼接百分比数据 for i in data: - i["ratio"] = Utils.classify(i["use_level"], ratio_all) + try: + i["ratio"] = Utils.classify(i["use_level"], ratio_all) + except Exception: + i["ratio"] = "0%" return data # 人员用量消耗 - def user_use_info(self, page_param, seach_user=None): + def user_use_info(self, page_param, start_time, end_time, seach_user=None): # sql_all = """ # select c.by_user_name, c.by_user_id, c.sum_use use_number, IFNULL(c.c_two, 0) use_level from ( # select a.*, b.c_two, b.sum_use from( @@ -265,13 +293,16 @@ class BllMedicamentRecord(Repository): ) b on a.create_user_id = b.user_id """ # 查询条件组合 - filter_sql = "" + filter_base = "" if seach_user: - filter_sql += f"where by_user_name like '%{seach_user}%'" - if filter_sql: - sql_all = sql_all % filter_sql - else: - sql_all = sql_all % "" + filter_base += f"by_user_name like '%{seach_user}%'" + if start_time and end_time: + if filter_base: + filter_base += " and " + filter_base += f" create_date >= '{start_time}' and create_date <= '{end_time}'" + if filter_base: + filter_base = " where " + filter_base + sql_all = sql_all % filter_base # 分页总数 try: count_number = len(self.execute(sql_all).fetchall()) @@ -283,11 +314,14 @@ class BllMedicamentRecord(Repository): data, ratio_all = self.default_data_list(sql_all, "use_amount") # 数据处理 for i in data: - i["ratio"] = Utils.classify(i["use_amount"], ratio_all) + try: + i["ratio"] = Utils.classify(i["use_amount"], ratio_all) + except Exception: + i["ratio"] = "0%" return data # 使用频率 - def use_frequency(self, page_param, client_id=None, seach_word=None): + def use_frequency(self, page_param, start_time, end_time,client_id=None, seach_word=None): sql_all = """ select c.`name`, c.purity, c.speci, c.cas_number, c.net_weight_unit, sum( CASE WHEN c.`status` = 1 THEN 1 ELSE 0 END ) new_on, @@ -299,23 +333,26 @@ class BllMedicamentRecord(Repository): select medicament_id, sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) two_type, sum( CASE WHEN record_type = 3 THEN 1 ELSE 0 END ) three_type - from rms_medicament_record GROUP BY medicament_id + from rms_medicament_record %s GROUP BY medicament_id )b on a.medicament_id=b.medicament_id ) c GROUP BY `name`, purity, speci """ # 查询条件sql组合 - filter_sql = "" + filter_base1 = "" if client_id: - filter_sql += f" client_id='{client_id}' " + filter_base1 += f" client_id='{client_id}' " if seach_word: - if filter_sql: - filter_sql += "and " + if filter_base1: + filter_base1 += "and " seach_word = f"%{seach_word}%" - filter_sql += f" `name` like '{seach_word}' or english_name like '{seach_word}'" - if filter_sql: - sql_all = sql_all % f"where {filter_sql}" - else: - sql_all = sql_all % "" + filter_base1 += f" `name` like '{seach_word}' or english_name like '{seach_word}'" + if filter_base1: + filter_base1 = " where " + filter_base1 + filter_base2 = "" + if start_time and end_time: + filter_base2 += f" where create_date >= '{start_time}' and create_date <= '{end_time}'" + + sql_all = sql_all % (filter_base1, filter_base2) # 查询数据列表长度 try: count_number = len(self.execute(sql_all).fetchall()) @@ -369,7 +406,9 @@ class BllMedicamentRecord(Repository): # result = BllMedicamentRecord().executeNoParam(SQL) # return result -# if __name__ == '__main__': +if __name__ == '__main__': + aaa = BllMedicamentRecord().report_home_drug_useing_classify() + print(aaa) # import random # from db_logic.medicament_record import BllMedicamentRecord # # customerId, clientId = None, '8db7e540-070f-11ed-a286-f47b094925e1'