From 615b56a4ff3518b94d2f1ef76ae85ee5295d25fe Mon Sep 17 00:00:00 2001 From: 13507605001 Date: Thu, 24 Nov 2022 15:41:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/auth.py | 7 +- apps/user/views.py | 5 +- db_logic/medicament.py | 297 +++++++++++++++---- db_logic/medicament_record.py | 544 +++++++++++++++++++++++++--------- db_logic/module_relation.py | 91 +++++- db_logic/user.py | 12 +- db_logic/warning.py | 29 +- models/user_models.py | 3 +- 8 files changed, 763 insertions(+), 225 deletions(-) diff --git a/Common/auth.py b/Common/auth.py index 039f319..8ef0d84 100644 --- a/Common/auth.py +++ b/Common/auth.py @@ -36,13 +36,14 @@ def verify_token(token): '''用于检查用户请求是否有token,并且token真实存在,还在有效期内''' # g.current_user = User.verify_jwt(token) if token else None g.current_user = BllUser().verify_jwt(token) - if g.current_user: + # if g.current_user: # 每次认证通过后(即将访问资源API),更新 last_seen 时间 - g.current_user.update_last_visit_date() - BllUser().update(g.current_user) + # g.current_user.update_last_visit_date() + # BllUser().update(g.current_user) return g.current_user is not None + @token_auth.error_handler def token_auth_error(): '''用于在 Token Auth 认证失败的情况下返回错误响应''' diff --git a/apps/user/views.py b/apps/user/views.py index bea6b8d..0da4381 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -22,9 +22,10 @@ def user_login(): password = request.values.get('password') # user_name = body.user_name # password = body.password - user_obj = BllUser().login(user_name=user_name, password=password) + user_obj, user_info = BllUser().login(user_name=user_name, password=password) if user_obj: - return jsonify(Utils.true_return(msg="登陆成功", data={"token":user_obj})) + print(user_obj) + return jsonify(Utils.true_return(msg="登陆成功", data={"token":user_obj, "user_info": user_info})) else: return jsonify(Utils.false_return(status=201, msg="登陆失败")) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index 1e0b443..37bdc50 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -70,20 +70,46 @@ 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": Utils.classify(i['count_number'], data_number) + # } + # new_dict.update(i) + # data_list.append(new_dict) + # return data_list, data_number + # 查看分组数据 data = self.execute(sql_all).fetchall() # 计算总数 data_number = sum([i[0] for i in data]) data_li = Utils.msyql_table_model(data) data_list = [] # 计算百分比,组装数据 + type_num = [] for i in data_li: new_dict = { # "ratio": str(round(i["count_number"] / data_number,2) * 100) + "%" "ratio": Utils.classify(i['count_number'], data_number) } new_dict.update(i) + type_num.append(str(i["status"])) data_list.append(new_dict) + set_num_li = list(set(["1", "2", "3"]).difference(set(type_num))) + for i in set_num_li: + data_list.append( + { + "status": int(i), + "rotio": "0%", + "count_number": "0" + } + ) return data_list, data_number @@ -249,60 +275,141 @@ class BllMedicament(Repository): # 获取领用和归还页面列表 def drug_use_return(self, status, page_param): - sql_all = """ - select * from rms_medicament %s + # sql_all = """ + # select * from rms_medicament %s + # """ + # sql_all = sql_all % (f"where status={status}", ) + + # count_sql = f"SELECT count(*) FROM rms_medicament where status={status}" + # page_param.totalRecords = self.execute(count_sql).fetchone()[0] + # sql_all = Utils.sql_paging_assemble(sql_all, page_param) + # data_list = self.execute(sql_all).fetchall() + # count_sql = f"SELECT count(*) FROM rms_medicament where status={status}" + # page_param.totalRecords = self.execute(count_sql).fetchone()[0] + sql_all = f""" + select * from rms_medicament where status={status} order by by_user_date desc """ - sql_all = sql_all % (f"where status={status}", ) - - count_sql = f"SELECT count(*) FROM rms_medicament where status={status}" - page_param.totalRecords = self.execute(count_sql).fetchone()[0] + try: + count_number = len(self.execute(sql_all).fetchall()) + except: + count_number = 0 + page_param.totalRecords = count_number sql_all = Utils.sql_paging_assemble(sql_all, page_param) data_list = self.execute(sql_all).fetchall() - count_sql = f"SELECT count(*) FROM rms_medicament where status={status}" - page_param.totalRecords = self.execute(count_sql).fetchone()[0] return data_list # 获取库存信息总览 def get_stock_all_info(self, page_param, name=None): - sql_all = """ - select DISTINCT `name`, speci, cas_number,net_weight_unit, purity, client_id, + # sql_all = """ + # select DISTINCT `name`, speci, cas_number,net_weight_unit, purity, client_id, + # sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number, + # sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain + # FROM rms_medicament %s + # """ + # # 拼接查询条件及分组条件 + # filter_base = "" + # if name: + # filter_base = f" where `name` LIKE '%{name}%'" + # filter_base += " GROUP BY `name`, speci, purity" + # sql_all = sql_all % filter_base + + # # 首次查询,判断长度,做分页使用 + # 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) + # sql_data = self.execute(sql_all).fetchall() + + # return sql_data + filter_base = "" + if name: + filter_base = f" `name` LIKE '%{name}%'" + if filter_base: + filter_base = f" where {filter_base}" + # sql_all =f""" + # select DISTINCT `name`, speci, cas_number,net_weight_unit, purity, client_id, + # sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number, + # sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain + # FROM rms_medicament {filter_base} GROUP BY `name`, speci, purity order by put_in_date desc + # """ + sql_all =f""" + select DISTINCT + `name`, speci, cas_number,net_weight_unit, purity, + manufacturer, distributor, net_weight, net_weight_unit, + client_id, + sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number, sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain - FROM rms_medicament %s + FROM rms_medicament {filter_base} GROUP BY `name`, speci, purity order by put_in_date desc """ # 拼接查询条件及分组条件 - filter_base = "" - if name: - filter_base = f" where `name` LIKE '%{name}%'" - filter_base += " GROUP BY `name`, speci, purity" - sql_all = sql_all % filter_base + # 首次查询,判断长度,做分页使用 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) - sql_data = self.execute(sql_all).fetchall() - - return sql_data + if page_param: + page_param.totalRecords = count_number + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() #获取所有药剂列表 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`, 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, - # 动态添加查询条件 + # # (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord) + # sql_all = """ + # 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: + # filter_base = f"customer_id='{customer_id}'" + # if client_id: + # 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 + # # 获取数量做分页 + # try: + # count_number= len(self.execute(sql_all).fetchall()) + # except Exception: + # count_number = 0 + # page_param.totalRecords = count_number + # # 进行分页sql拼接 + # sql_all = Utils.sql_paging_assemble(sql_all, page_param) + # return self.execute(sql_all).fetchall() + # (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord) filter_base = "" if customer_id: filter_base = f"customer_id='{customer_id}'" @@ -315,7 +422,7 @@ class BllMedicament(Repository): 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}'" + filter_base += f" (`name` like '{seach_w}' or english_name like '{seach_w}' or manufacturer like '{seach_w}') " # 厂商搜索 if manufacturer: manufacturer = f"%{manufacturer}%" @@ -327,58 +434,118 @@ class BllMedicament(Repository): 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 + # select * from rms_medicament {filter_base} + sql_all = f""" + select a.*,b.client_name from ( + select * from rms_medicament {filter_base} + ) a LEFT JOIN( + select client_id,client_name from rms_client + ) b on a.client_id=b.client_id + where client_name is not null + order by put_in_date desc + """ + # manufacturer = manufacturer, + # start_time = start_time, + # end_time = end_time, + # 动态添加查询条件 # 获取数量做分页 try: count_number= len(self.execute(sql_all).fetchall()) except Exception: count_number = 0 - page_param.totalRecords = count_number + # 进行分页sql拼接 - sql_all = Utils.sql_paging_assemble(sql_all, page_param) + if page_param: + page_param.totalRecords = count_number + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() # 入库、领用、归还记录 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, b.speci, a.use_quantity, b.`status`, a.create_date, a.create_user_name, b.client_id - FROM ( - SELECT medicament_id, use_quantity, create_user_name, create_date FROM rms_medicament_record %s - ) a LEFT JOIN ( - SELECT medicament_id, `name`, english_name, bar_code, purity, speci, cas_number, net_weight, remain, `status`, by_user_date, by_user_name, client_id - FROM rms_medicament %s - ) b on b.medicament_id = a.medicament_id - """ - filter_sql = f"WHERE record_type={record_type}" + # sql_all = """ + # SELECT + # b.`name`, b.english_name, b.bar_code, b.purity, b.cas_number, b.speci, a.use_quantity, b.`status`, a.create_date, a.create_user_name, b.client_id + # FROM ( + # SELECT medicament_id, use_quantity, create_user_name, create_date FROM rms_medicament_record %s + # ) a LEFT JOIN ( + # SELECT medicament_id, `name`, english_name, bar_code, purity, speci, cas_number, net_weight, remain, `status`, by_user_date, by_user_name, client_id + # FROM rms_medicament %s + # ) b on b.medicament_id = a.medicament_id + # """ + # 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_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" + # 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"] + # try: + # count_number = len(self.execute(sql_all).fetchall()) + # except Exception: + # count_number = 0 + # page_param.totalRecords = count_number + # sql_all_page = Utils.sql_paging_assemble(sql_all, page_param) + # return self.execute(sql_all_page).fetchall() + filter_base1 = f" WHERE record_type={record_type} " if put_in_user_name: - filter_sql += f" and create_user_name like '%{put_in_user_name}%'" + filter_base1 += 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}" + filter_base1 += f" and create_date >= '{start_time}' and create_date <= '{end_time}'" + + filter_base2 = '' if name: name = f"%{name}%" - if filter_sql_1: - 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"] + filter_base2 += f" (`name` like '{name}' or english_name like '{name}') " + + if statue_type: + if filter_base2: + filter_base2 += " and " + filter_base2 = f" `status`={statue_type}" + if filter_base2: + filter_base2 = f" where {filter_base2}" + sql_all = f""" + select + `name`, english_name, bar_code, purity, + cas_number, speci, use_quantity, `status`, + create_date, create_user_name, a.client_id, client_code, client_name, unit_code + from (select * from rms_medicament_record {filter_base1} + ) as a LEFT JOIN( + select + medicament_id, `name`, english_name, + bar_code, purity, speci, cas_number, + net_weight, remain, `status`, + by_user_date, by_user_name, unit_code + FROM rms_medicament {filter_base2} + ) as b on a.medicament_id=b.medicament_id + LEFT JOIN(select client_id,client_name from rms_client) c on a.client_id=c.client_id + where name is not null GROUP BY create_date desc + """ try: count_number = len(self.execute(sql_all).fetchall()) except Exception: count_number = 0 - page_param.totalRecords = count_number - sql_all_page = Utils.sql_paging_assemble(sql_all, page_param) - return self.execute(sql_all_page).fetchall() + if page_param: + page_param.totalRecords = count_number + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() # #获取指定用户当前领用药剂 diff --git a/db_logic/medicament_record.py b/db_logic/medicament_record.py index 09c08d6..8747a0a 100644 --- a/db_logic/medicament_record.py +++ b/db_logic/medicament_record.py @@ -30,21 +30,40 @@ class BllMedicamentRecord(Repository): # 获取流转记录 - 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 + # ) a RIGHT JOIN( + # 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" + # 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() 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 - ) a RIGHT JOIN( - 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 + + select a.*, b.create_date, b.create_user_name, b.record_type from( + select medicament_id, create_date, create_user_id, create_user_name, record_type from rms_medicament_record {filter_base} + ) b LEFT JOIN( + select * from rms_medicament {filter_base} + ) a on b.medicament_id=a.medicament_id order by create_date desc """ - # count_sql = "select count(*) from rms_medicament_record" try: count_number = len(self.execute(sql_all).fetchall()) except Exception: @@ -71,31 +90,64 @@ class BllMedicamentRecord(Repository): #获取今日药剂流转信息数量 def getTodayDrugRecordCount(self): - sql_all = """ - SELECT - record_type, count(record_id) type_number - FROM rms_medicament_record - where TO_DAYS(create_date)=TO_DAYS(NOW()) %s - GROUP BY record_type + # sql_all = """ + # SELECT + # record_type, count(record_id) type_number + # FROM rms_medicament_record + # where TO_DAYS(create_date)=TO_DAYS(NOW()) %s + # GROUP BY record_type + # """ + # filter_base ="" + # # if customer_id: + # # filter_base += f" and customer_id='{customer_id}'" + # # if client_id: + # # if filter_base: + # # filter_base += " and " + # # filter_base += f"client_id='{client_id}'" + # sql_all = sql_all % filter_base + # sql_data = self.execute(sql_all).fetchall() + # n_a, n_b = 0,0 + # data_list = [] + # default_list = [(1,0),(2,0),(3,0)] + # sql_data = sql_data if sql_data else default_list + # for i in sql_data: + # if i[0] == 2: + # n_a = i[1] + # if i[0] == 3: + # n_b = i[1] + # data_list.append({ + # "record_type":i[0], + # "type_number":i[1] + # }) + # data_list.append( + # { + # "record_type":100, + # "type_number": n_a - n_b + # } + # ) + # return data_list + sql_all = f""" + SELECT + record_type, count(record_id) type_number + FROM rms_medicament_record as a LEFT JOIN rms_medicament as b on a.medicament_id=b.medicament_id + where TO_DAYS(create_date)=TO_DAYS('{Utils.get_str_datetime()}') + GROUP BY record_type + """ - filter_base ="" + # filter_base ="" # if customer_id: # filter_base += f" and customer_id='{customer_id}'" # if client_id: # if filter_base: # filter_base += " and " # filter_base += f"client_id='{client_id}'" - sql_all = sql_all % filter_base + # sql_all = sql_all % filter_base sql_data = self.execute(sql_all).fetchall() - n_a, n_b = 0,0 + n_c = self.execute(f"select count(*) num from rms_medicament where `status`= 2").fetchone().num data_list = [] default_list = [(1,0),(2,0),(3,0)] sql_data = sql_data if sql_data else default_list for i in sql_data: - if i[0] == 2: - n_a = i[1] - if i[0] == 3: - n_b = i[1] data_list.append({ "record_type":i[0], "type_number":i[1] @@ -103,7 +155,7 @@ class BllMedicamentRecord(Repository): data_list.append( { "record_type":100, - "type_number": n_a - n_b + "type_number": n_c } ) return data_list @@ -127,7 +179,25 @@ class BllMedicamentRecord(Repository): # 获取报表统计主页,使用频率 def get_use_avg_number(self): - sql_all = """ + # sql_all = """ + # select a.`name`, IFNULL(b.count_number ,0) count_number from ( + # select medicament_id, purity, `name`, speci from rms_medicament + # ) a LEFT JOIN( + # select medicament_id, count(record_id) count_number from rms_medicament_record where record_type=2 GROUP BY medicament_id + # ) b + # on a.medicament_id=b.medicament_id GROUP BY a.purity, a.`name`, a.speci ORDER BY count_number desc + # """ + # sql_data = self.execute(sql_all).fetchall() + # use_number = sum([float(i[1]) for i in sql_data]) + # drug_num = len(sql_data) + + # resp_data = { + # "avg_use_number": round(use_number / drug_num), + # "max_name": sql_data[0][0], + # "max_number": sql_data[0][1] + # } + # return resp_data + sql_all = f""" select a.`name`, IFNULL(b.count_number ,0) count_number from ( select medicament_id, purity, `name`, speci from rms_medicament ) a LEFT JOIN( @@ -136,20 +206,53 @@ class BllMedicamentRecord(Repository): on a.medicament_id=b.medicament_id GROUP BY a.purity, a.`name`, a.speci ORDER BY count_number desc """ sql_data = self.execute(sql_all).fetchall() - use_number = sum([float(i[1]) for i in sql_data]) - drug_num = len(sql_data) + if not sql_data: + resp_data = { + "avg_use_number": 0, + "max_name": "", + "max_number": 0 + } + else: + use_number = sum([float(i[1]) for i in sql_data]) + drug_num = len(sql_data) - resp_data = { - "avg_use_number": round(use_number / drug_num), - "max_name": sql_data[0][0], - "max_number": sql_data[0][1] - } + resp_data = { + "avg_use_number": round(use_number / drug_num), + "max_name": sql_data[0][0], + "max_number": sql_data[0][1] + } return resp_data # 获取报表统计主页入库记录信息 def get_drug_record_count(self): - sql_all = """ - select COUNT(record_id) count_number, record_type from rms_medicament_record GROUP BY record_type + # 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_info = name_info_dict.get(i['record_type']) + # new_dic = { + # "name": name_info[0], + # "date_time": name_info[2] + # } + # new_dic.update(**i) + # data_list.append(new_dic) + # return data_list, self.get_use_avg_number() + sql_all = f""" + select count(record_id) count_number, record_type from ( + select record_id,medicament_id, record_type from rms_medicament_record + ) as a LEFT JOIN + rms_medicament as b on a.medicament_id=b.medicament_id + GROUP BY record_type """ # 获取分类数量 data = self.execute(sql_all).fetchall() @@ -160,7 +263,8 @@ class BllMedicamentRecord(Repository): name_info_dict = {} for name in name_info_list: name_info_dict[name[-1]] = name - # 组装数据 + # 组装数据 + type_num = [] for i in data_li: name_info = name_info_dict.get(i['record_type']) new_dic = { @@ -168,7 +272,17 @@ class BllMedicamentRecord(Repository): "date_time": name_info[2] } new_dic.update(**i) + type_num.append(str(i["record_type"])) data_list.append(new_dic) + set_num_li = list(set(["1", "2", "3"]).difference(set(type_num))) + for i in set_num_li: + data_list.append( + { + "record_type":int(i), + "name":"", + "date_time":"" + } + ) return data_list, self.get_use_avg_number() # 获取报表统计主页试剂用量消耗 @@ -208,14 +322,31 @@ class BllMedicamentRecord(Repository): # 获取报表统计主页人员用量消耗 def report_home_user_use_info(self): - sql_all = """ - select a.count_id count_number, a.create_user_id, a.create_user_name, b.avatar_url from( + # sql_all = """ + # select a.count_id count_number, a.create_user_id, a.create_user_name, b.avatar_url from( - select count(record_id) count_id, create_user_id,create_user_name from rms_medicament_record GROUP BY create_user_id - ) a LEFT JOIN( + # select count(record_id) count_id, create_user_id,create_user_name from rms_medicament_record GROUP BY create_user_id + # ) a LEFT JOIN( - select avatar_url, user_id from rms_user + # select avatar_url, user_id from rms_user + # ) b on a.create_user_id= b.user_id + + # """ + # data = self.execute(sql_all).fetchall() + # data_list = Utils.msyql_table_model(data) + # return data_list + sql_all = f""" + select a.count_id count_number, a.create_user_id, a.create_user_name, b.avatar_url from( + select count(record_id) count_id, create_user_id,create_user_name from + rms_medicament_record as c + LEFT JOIN + rms_medicament as d + on c.medicament_id=d.medicament_id + GROUP BY create_user_id + ) a LEFT JOIN( + select avatar_url, user_id from rms_user ) b on a.create_user_id= b.user_id + order by count_number desc """ data = self.execute(sql_all).fetchall() @@ -247,39 +378,72 @@ class BllMedicamentRecord(Repository): # 获取库存消耗数据 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, - sum(CASE WHEN c.`status`=2 THEN 1 ELSE 0 END) up_stock, - sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock - from ( - select a.*, b.enter_stock from ( - 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 %s GROUP BY medicament_id - ) b on b.medicament_id = a.medicament_id - ) c GROUP BY `name`, purity, speci + # 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, + # sum(CASE WHEN c.`status`=2 THEN 1 ELSE 0 END) up_stock, + # sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock + # from ( + # select a.*, b.enter_stock from ( + # 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 %s GROUP BY medicament_id + # ) b on b.medicament_id = a.medicament_id + # ) c GROUP BY `name`, purity, speci - """ - # 拼接搜索条件 - filter_base1 = "" + # """ + # # 拼接搜索条件 + # filter_base1 = "" + # if seach_word: + # seach_word = f"%{seach_word}%" + # 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()) + # except Exception: + # count_number = 0 + # page_param.totalRecords = count_number + # # 数据分页处理 + # sql_all = Utils.sql_paging_assemble(sql_all, page_param) + # # 获取处理后的数据 + # data_list, _ = self.default_data_list(sql_all) + # return data_list + filter_base = "" if seach_word: seach_word = f"%{seach_word}%" - 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}'" + filter_base += f" (`name` like '{seach_word}' or english_name like '{seach_word}') " + if filter_base: + filter_base = f" where {filter_base}" + sql_all = f""" + select `name`, cas_number,speci, net_weight_unit, purity, enter_stock, + sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) in_stock, + sum(CASE WHEN `status`=2 THEN 1 ELSE 0 END) up_stock, + sum(CASE WHEN `status`=3 THEN 1 ELSE 0 END) no_stock + from ( + select medicament_id, `name`, english_name,cas_number, speci, purity, net_weight_unit, `status`, func_type from rms_medicament + ) a LEFT JOIN( + SELECT medicament_id, count(medicament_id) enter_stock, create_date from rms_medicament_record where record_type=1 GROUP BY medicament_id + ) b on b.medicament_id = a.medicament_id + {filter_base} + + GROUP BY `name`, purity, speci - sql_all = sql_all % (filter_base1, filter_base2) + """ # 查询获取数据条目数 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) + if page_param: + page_param.totalRecords = count_number + # 数据分页处理 + sql_all = Utils.sql_paging_assemble(sql_all, page_param) # 获取处理后的数据 data_list, _ = self.default_data_list(sql_all) return data_list @@ -288,39 +452,72 @@ class BllMedicamentRecord(Repository): 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, - IFNULL(c.c_two,0) use_num, - IFNULL(c.sum_use,0) use_level from ( - select a.*, b.c_two, b.sum_use from( - 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, 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 = "" + # 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, + # IFNULL(c.c_two,0) use_num, + # IFNULL(c.sum_use,0) use_level from ( + # select a.*, b.c_two, b.sum_use from( + # 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, 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}%" + # 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()) + # except Exception: + # count_number = 0 + # page_param.totalRecords = count_number + # page_sql_all = Utils.sql_paging_assemble(sql_all, page_param) + # # 获取组建后的数据结果 + # data, ratio_all = self.default_data_list(page_sql_all, "use_level") + # # 拼接百分比数据 + # for i in data: + # try: + # i["ratio"] = Utils.classify(i["use_level"], ratio_all) + # except Exception: + # i["ratio"] = "0%" + # return data + filter_base = "" if seach_word: seach_word = f"%{seach_word}%" - 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) + filter_base += f" (`name` like '{seach_word}' or english_name like '{seach_word}') " + if filter_base: + filter_base = f" where {filter_base}" + sql_all = f""" + select `name`, purity, speci, cas_number, net_weight_unit, + sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) on_in, + IFNULL(c_two,0) use_num, IFNULL(sum_use,0) use_level from ( + select medicament_id, `name`, english_name, speci, cas_number, purity, net_weight_unit,put_in_date, `status`,func_type from rms_medicament + )as a LEFT JOIN( + select medicament_id, FORMAT(sum(use_quantity),2) sum_use, count(medicament_id) c_two from rms_medicament_record where record_type=2 GROUP BY medicament_id + ) b on a.medicament_id=b.medicament_id {filter_base} GROUP BY `name`, purity, speci + """ # 获取数量 try: count_number = len(self.execute(sql_all).fetchall()) except Exception: count_number = 0 - page_param.totalRecords = count_number - page_sql_all = Utils.sql_paging_assemble(sql_all, page_param) + if page_param: + page_param.totalRecords = count_number + sql_all = Utils.sql_paging_assemble(sql_all, page_param) # 获取组建后的数据结果 - data, ratio_all = self.default_data_list(page_sql_all, "use_level") + data, ratio_all = self.default_data_list(sql_all, "use_level") # 拼接百分比数据 for i in data: try: @@ -328,48 +525,89 @@ class BllMedicamentRecord(Repository): except Exception: i["ratio"] = "0%" return data - # 人员用量消耗 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( + # # select medicament_id, by_user_name, by_user_id 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 + # # ) b on a.medicament_id=b.medicament_id + # # ) c GROUP BY by_user_name, by_user_id + # # """ # 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( - # select medicament_id, by_user_name, by_user_id 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 - # ) b on a.medicament_id=b.medicament_id - # ) c GROUP BY by_user_name, by_user_id + # select a.*, b.role_name from ( + # select convert(sum(use_quantity), decimal(10,2)) use_amount, + # sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num, + # create_user_id, + # create_user_name + # from rms_medicament_record %s GROUP BY create_user_id + # ) a LEFT JOIN ( + # SELECT role_name, user_id FROM rms_user + # ) b on a.create_user_id = b.user_id # """ - sql_all = """ - select a.*, b.role_name from ( - select convert(sum(use_quantity), decimal(10,2)) use_amount, - sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num, - create_user_id, - create_user_name - from rms_medicament_record %s GROUP BY create_user_id - ) a LEFT JOIN ( - SELECT role_name, user_id FROM rms_user - ) b on a.create_user_id = b.user_id - """ - # 查询条件组合 + # # 查询条件组合 + # filter_base = "" + # if seach_user: + # 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()) + # except Exception: + # count_number = 0 + # page_param.totalRecords = count_number + # # 数据分页 + # sql_all=Utils.sql_paging_assemble(sql_all, page_param) + # data, ratio_all = self.default_data_list(sql_all, "use_amount") + # # 数据处理 + # for i in data: + # try: + # i["ratio"] = Utils.classify(i["use_amount"], ratio_all) + # except Exception: + # i["ratio"] = "0%" + # return data filter_base = "" if seach_user: - filter_base += f"by_user_name like '%{seach_user}%'" + filter_base += f" create_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 + filter_base = f" where {filter_base}" + sql_all = f""" + select + convert(sum(use_quantity), decimal(10,2)) use_amount, + sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num, + create_user_id, create_user_name, role_name + from rms_medicament_record as a + LEFT JOIN ( + SELECT role_name, user_id FROM rms_user + ) b on a.create_user_id = b.user_id + LEFT JOIN (select medicament_id, func_type from rms_medicament + ) as c on c.medicament_id = a.medicament_id + {filter_base} + """ + # 查询条件组合 + # 分页总数 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) + if page_param: + page_param.totalRecords = count_number + # 数据分页 + sql_all=Utils.sql_paging_assemble(sql_all, page_param) data, ratio_all = self.default_data_list(sql_all, "use_amount") # 数据处理 for i in data: @@ -378,48 +616,88 @@ class BllMedicamentRecord(Repository): except Exception: i["ratio"] = "0%" return data - # 使用频率 def use_frequency(self, page_param, start_time, end_time,client_id=None, seach_word=None): - sql_all = """ + # 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, + # c.client_id, sum(c.tp_2) sum_tp2, sum(c.tp_3) sum_tp3 from ( + # select a.*, IFNULL(b.two_type, 0) tp_2, IFNULL(b.three_type, 0) tp_3 from ( + # select medicament_id, `name`, speci, purity, cas_number, net_weight_unit, `status`, client_id from rms_medicament + # %s + # ) a LEFT JOIN( + # 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 %s GROUP BY medicament_id + # )b on a.medicament_id=b.medicament_id + # ) c GROUP BY `name`, purity, speci + # """ + # # 查询条件sql组合 + # filter_base1 = "" + # if client_id: + # filter_base1 += f" client_id='{client_id}' " + # if seach_word: + # if filter_base1: + # filter_base1 += "and " + # seach_word = f"%{seach_word}%" + # 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()) + # except Exception: + # count_number = 0 + # page_param.totalRecords = count_number + # # 处理数据 + # sql_all = Utils.sql_paging_assemble(sql_all, page_param) + # data, _ = self.default_data_list(sql_all) + # return data + filter_base1 = "" + if client_id: + filter_base1 += f" client_id='{client_id}' " + if seach_word: + if filter_base1: + filter_base1 += "and " + seach_word = f"%{seach_word}%" + 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 = f""" 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, c.client_id, sum(c.tp_2) sum_tp2, sum(c.tp_3) sum_tp3 from ( select a.*, IFNULL(b.two_type, 0) tp_2, IFNULL(b.three_type, 0) tp_3 from ( select medicament_id, `name`, speci, purity, cas_number, net_weight_unit, `status`, client_id from rms_medicament - %s + {filter_base1} ) a LEFT JOIN( 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 %s GROUP BY medicament_id + from rms_medicament_record {filter_base2} GROUP BY medicament_id )b on a.medicament_id=b.medicament_id ) c GROUP BY `name`, purity, speci """ # 查询条件sql组合 - filter_base1 = "" - if client_id: - filter_base1 += f" client_id='{client_id}' " - if seach_word: - if filter_base1: - filter_base1 += "and " - seach_word = f"%{seach_word}%" - 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()) except Exception: count_number = 0 - page_param.totalRecords = count_number - # 处理数据 - sql_all = Utils.sql_paging_assemble(sql_all, page_param) + if page_param: + page_param.totalRecords = count_number + # 处理数据 + sql_all = Utils.sql_paging_assemble(sql_all, page_param) data, _ = self.default_data_list(sql_all) return data diff --git a/db_logic/module_relation.py b/db_logic/module_relation.py index e2fd80e..e669f94 100644 --- a/db_logic/module_relation.py +++ b/db_logic/module_relation.py @@ -17,28 +17,64 @@ class BllModuleRelation(Repository): def get_login_user_module_list(self, user_id, role_id): + # sql_all = f""" + # select c.module_id, c.module_code, c.sort_index, c.module_name, c.module_type from( + + # SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type + # from rms_module_relation as a + # LEFT JOIN rms_module as b on a.module_id=b.module_id + # WHERE object_id='{user_id}' AND object_type=2 AND b.module_type!=1 + # UNION + # SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type + # from rms_module_relation as a + # LEFT JOIN rms_module as b on a.module_id=b.module_id + # WHERE object_id='{role_id}' AND object_type=1 AND b.module_type!=1 + # ) c ORDER BY c.sort_index asc + # """ + # sql_data = self.execute(sql_all).fetchall() + # data = Utils.msyql_table_model(sql_data) + # data_dict = { + # "client_manage": [], + # "drug_manage": [], + # "standard_manage": [], + # "consumables_manage": [], + # "instrument_manage": [] + # } + # for i in data: + # if i["module_type"] == "1": + # data_dict["client_manage"].append(i) + # elif i["module_type"] == "2": + # data_dict["drug_manage"].append(i) + # elif i["module_type"] == "3": + # data_dict["standard_manage"].append(i) + # elif i["module_type"] == "4": + # data_dict["consumables_manage"].append(i) + # elif i["module_type"] == "5": + # data_dict["instrument_manage"].append(i) + + # return data_dict + # # return self.execute(sql_all).fetchall() sql_all = f""" select c.module_id, c.module_code, c.sort_index, c.module_name, c.module_type from( SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type from rms_module_relation as a LEFT JOIN rms_module as b on a.module_id=b.module_id - WHERE object_id='{user_id}' AND object_type=2 AND b.module_type!=1 + WHERE object_id='{user_id}' AND object_type=2 UNION SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type from rms_module_relation as a LEFT JOIN rms_module as b on a.module_id=b.module_id - WHERE object_id='{role_id}' AND object_type=1 AND b.module_type!=1 + WHERE object_id='{role_id}' AND object_type=1 ) c ORDER BY c.sort_index asc """ sql_data = self.execute(sql_all).fetchall() data = Utils.msyql_table_model(sql_data) data_dict = { - "client_manage": [], + "client_manage":[], "drug_manage": [], "standard_manage": [], - "consumables_manage": [], - "instrument_manage": [] + "dangerous_manage": [], } for i in data: if i["module_type"] == "1": @@ -48,14 +84,41 @@ class BllModuleRelation(Repository): elif i["module_type"] == "3": data_dict["standard_manage"].append(i) elif i["module_type"] == "4": - data_dict["consumables_manage"].append(i) - elif i["module_type"] == "5": - data_dict["instrument_manage"].append(i) + data_dict["dangerous_manage"].append(i) return data_dict - # return self.execute(sql_all).fetchall() def get_user_module_list(self, user_info): + # sql_all = f""" + # select a.module_id, a.module_name, a.module_type, a.module_code, a.sort_index, + # CASE WHEN b.object_id is NULL THEN 0 ELSE 1 END have, IFNULL(b.object_type,0) object_type + # from ( + # select * from rms_module) a LEFT JOIN ( + # select * from rms_module_relation where object_id='{user_info.user_id}' or object_id='{user_info.role_id}' + # ) b on a.module_id = b.module_id + # """ + # sql_data = self.execute(sql_all).fetchall() + # data = Utils.msyql_table_model(sql_data) + # data_dict = { + # "client_manage": [], + # "drug_manage":[], + # "standard_manage":[], + # "consumables_manage": [], + # "instrument_manage":[] + # } + # for i in data: + # if i["module_type"] == "1": + # data_dict["client_manage"].append(i) + # elif i["module_type"] == "2": + # data_dict["drug_manage"].append(i) + # elif i["module_type"] == "3": + # data_dict["standard_manage"].append(i) + # elif i["module_type"] == "4": + # data_dict["consumables_manage"].append(i) + # elif i["module_type"] == "5": + # data_dict["instrument_manage"].append(i) + + # return data_dict sql_all = f""" select a.module_id, a.module_name, a.module_type, a.module_code, a.sort_index, CASE WHEN b.object_id is NULL THEN 0 ELSE 1 END have, IFNULL(b.object_type,0) object_type @@ -67,11 +130,10 @@ class BllModuleRelation(Repository): sql_data = self.execute(sql_all).fetchall() data = Utils.msyql_table_model(sql_data) data_dict = { - "client_manage": [], + "client_manage":[], "drug_manage":[], "standard_manage":[], - "consumables_manage": [], - "instrument_manage":[] + "dangerous_manage": [], } for i in data: if i["module_type"] == "1": @@ -81,12 +143,11 @@ class BllModuleRelation(Repository): elif i["module_type"] == "3": data_dict["standard_manage"].append(i) elif i["module_type"] == "4": - data_dict["consumables_manage"].append(i) - elif i["module_type"] == "5": - data_dict["instrument_manage"].append(i) + data_dict["dangerous_manage"].append(i) return data_dict + def get_role_module_list(self, role_id): sql_all = f""" select a.module_id, a.module_code, a.sort_index, a.module_name, a.module_type, diff --git a/db_logic/user.py b/db_logic/user.py index 74be613..906078c 100644 --- a/db_logic/user.py +++ b/db_logic/user.py @@ -32,14 +32,16 @@ class BllUser(Repository): ) if user_info: if user_info.is_enabled: - if user_info.check_password(password): - return self.get_jwt(user_info) - return False + if user_info.password == Utils.MD5(password): + self.last_visit_date=Utils.get_str_datetime() + self.update(user_info) + return self.get_jwt(user_info), user_info + return False, None # 用户密码修改 def update_password(self, user_info, old_password, new_password): - if user_info.check_password(old_password): - user_info.set_password(new_password) + if user_info.password == Utils.MD5(old_password): + user_info.password = Utils.MD5(new_password) self.update(user_info) return True, self.get_jwt(user_info) else: diff --git a/db_logic/warning.py b/db_logic/warning.py index 16161e3..59f754b 100644 --- a/db_logic/warning.py +++ b/db_logic/warning.py @@ -19,13 +19,40 @@ class BllWarning(Repository): #获取预警列表 def getWarningList(self, pageParam=None,key_word=None, object_type=None, start_time=None, end_time=None): + # sql_all = """ + # select * from rms_warning %s ORDER BY warning_date DESC + # """ + # filter_base = "" + # if key_word: + # key_word = f"'%{key_word}%'" + # filter_base += f" where object_name like {key_word} or warning_user_name like {key_word} or warning_content like {key_word}" + # if object_type: + # if filter_base: + # filter_base += " and " + # filter_base += f" object_type={object_type} " + # if start_time and end_time: + # if filter_base: + # filter_base += " and " + # filter_base += f" warning_date >={start_time} and warning_date <= {end_time} " + # sql_all = sql_all % filter_base + # total_count = 0 + # if not pageParam: + # sql_all += " limit 5" + # else: + # try: + # total_count = len(self.execute(sql_all).fetchall()) + # except Exception: + # total_count = 0 + # pageParam.totalRecords = total_count + # sql_all = Utils.sql_paging_assemble(sql_all=sql_all, page_param=pageParam) + # return self.execute(sql_all).fetchall() sql_all = """ select * from rms_warning %s ORDER BY warning_date DESC """ filter_base = "" if key_word: key_word = f"'%{key_word}%'" - filter_base += f" where object_name like {key_word} or warning_user_name like {key_word} or warning_content like {key_word}" + filter_base += f" where (object_name like {key_word} or warning_user_name like {key_word} or warning_content like {key_word})" if object_type: if filter_base: filter_base += " and " diff --git a/models/user_models.py b/models/user_models.py index c0c5da8..e4dec69 100644 --- a/models/user_models.py +++ b/models/user_models.py @@ -53,7 +53,8 @@ class EntityUser(Base): def check_password(self, password): '''验证密码与保存的 Hash 值是否匹配''' - return check_password_hash(self.password, password) + # return check_password_hash(self.password, password) + return Utils.MD5(password) == self.password class EntityRole(Base):