duizhaopin
13507605001 2 years ago
parent 2950a917bc
commit 615b56a4ff

@ -36,13 +36,14 @@ def verify_token(token):
'''用于检查用户请求是否有token并且token真实存在还在有效期内''' '''用于检查用户请求是否有token并且token真实存在还在有效期内'''
# g.current_user = User.verify_jwt(token) if token else None # g.current_user = User.verify_jwt(token) if token else None
g.current_user = BllUser().verify_jwt(token) g.current_user = BllUser().verify_jwt(token)
if g.current_user: # if g.current_user:
# 每次认证通过后即将访问资源API更新 last_seen 时间 # 每次认证通过后即将访问资源API更新 last_seen 时间
g.current_user.update_last_visit_date() # g.current_user.update_last_visit_date()
BllUser().update(g.current_user) # BllUser().update(g.current_user)
return g.current_user is not None return g.current_user is not None
@token_auth.error_handler @token_auth.error_handler
def token_auth_error(): def token_auth_error():
'''用于在 Token Auth 认证失败的情况下返回错误响应''' '''用于在 Token Auth 认证失败的情况下返回错误响应'''

@ -22,9 +22,10 @@ def user_login():
password = request.values.get('password') password = request.values.get('password')
# user_name = body.user_name # user_name = body.user_name
# password = body.password # 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: 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: else:
return jsonify(Utils.false_return(status=201, msg="登陆失败")) return jsonify(Utils.false_return(status=201, msg="登陆失败"))

@ -70,20 +70,46 @@ class BllMedicament(Repository):
sql_all = """ sql_all = """
select count(medicament_id) count_number, `status` from rms_medicament GROUP BY `status` 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 = self.execute(sql_all).fetchall()
# 计算总数 # 计算总数
data_number = sum([i[0] for i in data]) data_number = sum([i[0] for i in data])
data_li = Utils.msyql_table_model(data) data_li = Utils.msyql_table_model(data)
data_list = [] data_list = []
# 计算百分比,组装数据 # 计算百分比,组装数据
type_num = []
for i in data_li: for i in data_li:
new_dict = { 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) "ratio": Utils.classify(i['count_number'], data_number)
} }
new_dict.update(i) new_dict.update(i)
type_num.append(str(i["status"]))
data_list.append(new_dict) 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 return data_list, data_number
@ -249,60 +275,141 @@ class BllMedicament(Repository):
# 获取领用和归还页面列表 # 获取领用和归还页面列表
def drug_use_return(self, status, page_param): def drug_use_return(self, status, page_param):
sql_all = """ # sql_all = """
select * from rms_medicament %s # 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}", ) try:
count_number = len(self.execute(sql_all).fetchall())
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}" except:
page_param.totalRecords = self.execute(count_sql).fetchone()[0] count_number = 0
page_param.totalRecords = count_number
sql_all = Utils.sql_paging_assemble(sql_all, page_param) sql_all = Utils.sql_paging_assemble(sql_all, page_param)
data_list = self.execute(sql_all).fetchall() 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 return data_list
# 获取库存信息总览 # 获取库存信息总览
def get_stock_all_info(self, page_param, name=None): def get_stock_all_info(self, page_param, name=None):
sql_all = """ # sql_all = """
select DISTINCT `name`, speci, cas_number,net_weight_unit, purity, client_id, # 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 1 ELSE 0 END) count_number,
sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain 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: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number
# 组件分页参数,返回分页后数据 # 组件分页参数,返回分页后数据
sql_all = Utils.sql_paging_assemble(sql_all, page_param) if page_param:
sql_data = self.execute(sql_all).fetchall() page_param.totalRecords = count_number
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
return sql_data return self.execute(sql_all).fetchall()
#获取所有药剂列表 #获取所有药剂列表
def getAllDrugList(self, search_word, manufacturer, start_time, end_time, 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) # # (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord)
sql_all = """ # sql_all = """
select `name`, bar_code, status, 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 # shelf_life, put_in_user_name, put_in_date, english_name, purity, is_supervise, by_user_name
from rms_medicament %s # from rms_medicament %s
""" # """
# manufacturer = manufacturer, # # manufacturer = manufacturer,
# start_time = start_time, # # start_time = start_time,
# end_time = end_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 = "" filter_base = ""
if customer_id: if customer_id:
filter_base = f"customer_id='{customer_id}'" filter_base = f"customer_id='{customer_id}'"
@ -315,7 +422,7 @@ class BllMedicament(Repository):
seach_w = f"%{search_word}%" seach_w = f"%{search_word}%"
if filter_base: if filter_base:
filter_base += " and " 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: if manufacturer:
manufacturer = f"%{manufacturer}%" manufacturer = f"%{manufacturer}%"
@ -327,58 +434,118 @@ class BllMedicament(Repository):
if filter_base: if filter_base:
filter_base += " and " filter_base += " and "
filter_base += f"put_in_date >= '{start_time}' and put_in_date<='{end_time}'" filter_base += f"put_in_date >= '{start_time}' and put_in_date<='{end_time}'"
# 管理模块区分
if filter_base: if filter_base:
filter_base = "where " + 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: try:
count_number= len(self.execute(sql_all).fetchall()) count_number= len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number
# 进行分页sql拼接 # 进行分页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() 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): def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, statue_type, page_param):
sql_all = """ # sql_all = """
SELECT # 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 # 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 ( # FROM (
SELECT medicament_id, use_quantity, create_user_name, create_date FROM rms_medicament_record %s # SELECT medicament_id, use_quantity, create_user_name, create_date FROM rms_medicament_record %s
) a LEFT JOIN ( # ) 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 # 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 # FROM rms_medicament %s
) b on b.medicament_id = a.medicament_id # ) b on b.medicament_id = a.medicament_id
""" # """
filter_sql = f"WHERE record_type={record_type}" # 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: 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: if start_time and end_time:
filter_sql += f" and create_date >= '{start_time}' and create_date <= '{end_time}'" filter_base1 += f" and create_date >= '{start_time}' and create_date <= '{end_time}'"
filter_sql_1 = ''
if statue_type: filter_base2 = ''
filter_sql_1 = f" where `status`={statue_type}"
if name: if name:
name = f"%{name}%" name = f"%{name}%"
if filter_sql_1: filter_base2 += f" (`name` like '{name}' or english_name like '{name}') "
filter_sql_1 += " and"
else: if statue_type:
filter_sql_1 += " where " if filter_base2:
filter_sql_1 += f" `name` like '{name}' or english_name like '{name}'" filter_base2 += " and "
filter_base2 = f" `status`={statue_type}"
sql_all = sql_all % (filter_sql, filter_sql_1) if filter_base2:
# finds = ["name", "english_name", "bar_code", filter_base2 = f" where {filter_base2}"
# "purity", "cas_number", "use_quantity", "status", "create_date", "create_user_name", "client_id"] 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: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number if page_param:
sql_all_page = Utils.sql_paging_assemble(sql_all, page_param) page_param.totalRecords = count_number
return self.execute(sql_all_page).fetchall() sql_all = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(sql_all).fetchall()
# #获取指定用户当前领用药剂 # #获取指定用户当前领用药剂

@ -30,21 +30,40 @@ class BllMedicamentRecord(Repository):
# 获取流转记录 # 获取流转记录
def get_drug_flow_log(self, medicament_id, page_param): 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 = "" filter_base = ""
if medicament_id: if medicament_id:
filter_base += f" medicament_id='{medicament_id}' " filter_base += f" medicament_id='{medicament_id}' "
if filter_base: if filter_base:
filter_base = f" where {filter_base}" filter_base = f" where {filter_base}"
sql_all = f""" 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 a.*, b.create_date, b.create_user_name, b.record_type from(
) a RIGHT JOIN( select medicament_id, create_date, create_user_id, create_user_name, record_type from rms_medicament_record {filter_base}
select medicament_id, create_date, create_user_id, create_user_name from rms_medicament_record {filter_base} order by create_date desc ) b LEFT JOIN(
) b on b.medicament_id=a.medicament_id 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: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
@ -71,31 +90,64 @@ class BllMedicamentRecord(Repository):
#获取今日药剂流转信息数量 #获取今日药剂流转信息数量
def getTodayDrugRecordCount(self): def getTodayDrugRecordCount(self):
sql_all = """ # sql_all = """
SELECT # SELECT
record_type, count(record_id) type_number # record_type, count(record_id) type_number
FROM rms_medicament_record # FROM rms_medicament_record
where TO_DAYS(create_date)=TO_DAYS(NOW()) %s # where TO_DAYS(create_date)=TO_DAYS(NOW()) %s
GROUP BY record_type # 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: # if customer_id:
# filter_base += f" and customer_id='{customer_id}'" # filter_base += f" and customer_id='{customer_id}'"
# if client_id: # if client_id:
# if filter_base: # if filter_base:
# filter_base += " and " # filter_base += " and "
# filter_base += f"client_id='{client_id}'" # 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() 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 = [] data_list = []
default_list = [(1,0),(2,0),(3,0)] default_list = [(1,0),(2,0),(3,0)]
sql_data = sql_data if sql_data else default_list sql_data = sql_data if sql_data else default_list
for i in sql_data: for i in sql_data:
if i[0] == 2:
n_a = i[1]
if i[0] == 3:
n_b = i[1]
data_list.append({ data_list.append({
"record_type":i[0], "record_type":i[0],
"type_number":i[1] "type_number":i[1]
@ -103,7 +155,7 @@ class BllMedicamentRecord(Repository):
data_list.append( data_list.append(
{ {
"record_type":100, "record_type":100,
"type_number": n_a - n_b "type_number": n_c
} }
) )
return data_list return data_list
@ -127,7 +179,25 @@ class BllMedicamentRecord(Repository):
# 获取报表统计主页,使用频率 # 获取报表统计主页,使用频率
def get_use_avg_number(self): 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 a.`name`, IFNULL(b.count_number ,0) count_number from (
select medicament_id, purity, `name`, speci from rms_medicament select medicament_id, purity, `name`, speci from rms_medicament
) a LEFT JOIN( ) 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 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() sql_data = self.execute(sql_all).fetchall()
use_number = sum([float(i[1]) for i in sql_data]) if not sql_data:
drug_num = len(sql_data) resp_data = {
"avg_use_number": 0,
resp_data = { "max_name": "",
"avg_use_number": round(use_number / drug_num), "max_number": 0
"max_name": sql_data[0][0], }
"max_number": sql_data[0][1] 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]
}
return resp_data return resp_data
# 获取报表统计主页入库记录信息 # 获取报表统计主页入库记录信息
def get_drug_record_count(self): def get_drug_record_count(self):
sql_all = """ # sql_all = """
select COUNT(record_id) count_number, record_type from rms_medicament_record GROUP BY record_type # 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() data = self.execute(sql_all).fetchall()
@ -161,6 +264,7 @@ class BllMedicamentRecord(Repository):
for name in name_info_list: for name in name_info_list:
name_info_dict[name[-1]] = name name_info_dict[name[-1]] = name
# 组装数据 # 组装数据
type_num = []
for i in data_li: for i in data_li:
name_info = name_info_dict.get(i['record_type']) name_info = name_info_dict.get(i['record_type'])
new_dic = { new_dic = {
@ -168,7 +272,17 @@ class BllMedicamentRecord(Repository):
"date_time": name_info[2] "date_time": name_info[2]
} }
new_dic.update(**i) new_dic.update(**i)
type_num.append(str(i["record_type"]))
data_list.append(new_dic) 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() return data_list, self.get_use_avg_number()
# 获取报表统计主页试剂用量消耗 # 获取报表统计主页试剂用量消耗
@ -208,14 +322,31 @@ class BllMedicamentRecord(Repository):
# 获取报表统计主页人员用量消耗 # 获取报表统计主页人员用量消耗
def report_home_user_use_info(self): def report_home_user_use_info(self):
sql_all = """ # sql_all = """
select a.count_id count_number, a.create_user_id, a.create_user_name, b.avatar_url from( # 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 # select count(record_id) count_id, create_user_id,create_user_name from rms_medicament_record GROUP BY create_user_id
) a LEFT JOIN( # ) a LEFT JOIN(
# select avatar_url, user_id from rms_user
# ) b on a.create_user_id= b.user_id
select avatar_url, user_id from rms_user # """
# 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 ) b on a.create_user_id= b.user_id
order by count_number desc
""" """
data = self.execute(sql_all).fetchall() 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): def durg_stock_loss(self, seach_word, start_time, end_time, page_param):
sql_all = """ # sql_all = """
select c.`name`, c.cas_number,c.speci, c.net_weight_unit, c.purity, c.enter_stock, # 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`=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`=2 THEN 1 ELSE 0 END) up_stock,
sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock # sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock
from ( # from (
select a.*, b.enter_stock from ( # select a.*, b.enter_stock from (
select medicament_id, `name`, cas_number, speci, purity, net_weight_unit, `status` from rms_medicament # select medicament_id, `name`, cas_number, speci, purity, net_weight_unit, `status` from rms_medicament
%s # %s
) a LEFT JOIN( # ) 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 # 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 # ) b on b.medicament_id = a.medicament_id
) c GROUP BY `name`, purity, speci # ) 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: if seach_word:
seach_word = f"%{seach_word}%" seach_word = f"%{seach_word}%"
filter_base1 = f" where `name` like '{seach_word}' or english_name like '{seach_word}'" filter_base += f" (`name` like '{seach_word}' or english_name like '{seach_word}') "
filter_base2 = "" if filter_base:
if start_time and end_time: filter_base = f" where {filter_base}"
filter_base2 += f" where create_date >= '{start_time}' and create_date <= '{end_time}'" 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: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number if page_param:
# 数据分页处理 page_param.totalRecords = count_number
sql_all = Utils.sql_paging_assemble(sql_all, page_param) # 数据分页处理
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
# 获取处理后的数据 # 获取处理后的数据
data_list, _ = self.default_data_list(sql_all) data_list, _ = self.default_data_list(sql_all)
return data_list return data_list
@ -288,39 +452,72 @@ class BllMedicamentRecord(Repository):
def durg_useing_info(self, seach_word, start_time, end_time, 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 # 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 = """ # sql_all = """
select c.`name`, c.purity, c.speci, c.cas_number, c.net_weight_unit, # 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, # sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) on_in,
IFNULL(c.c_two,0) use_num, # IFNULL(c.c_two,0) use_num,
IFNULL(c.sum_use,0) use_level from ( # IFNULL(c.sum_use,0) use_level from (
select a.*, b.c_two, b.sum_use 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 # select medicament_id, `name`, speci, cas_number, purity, net_weight_unit, `status` from rms_medicament
%s # %s
) a LEFT JOIN( # ) 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 # 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 # ) b on a.medicament_id=b.medicament_id
) c GROUP BY `name`, purity, speci # ) 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" 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: if seach_word:
seach_word = f"%{seach_word}%" seach_word = f"%{seach_word}%"
filter_base1 = f"where `name` like '{seach_word}' or english_name like '{seach_word}'" filter_base += f" (`name` like '{seach_word}' or english_name like '{seach_word}') "
filter_base2 = "" if filter_base:
if start_time and end_time: filter_base = f" where {filter_base}"
filter_base2 = f" and create_date >= '{start_time}' and create_date <= '{end_time}'" sql_all = f"""
select `name`, purity, speci, cas_number, net_weight_unit,
sql_all = sql_all %(filter_base1, filter_base2) 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: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number if page_param:
page_sql_all = Utils.sql_paging_assemble(sql_all, 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: for i in data:
try: try:
@ -328,48 +525,89 @@ class BllMedicamentRecord(Repository):
except Exception: except Exception:
i["ratio"] = "0%" i["ratio"] = "0%"
return data return data
# 人员用量消耗 # 人员用量消耗
def user_use_info(self, page_param, start_time, end_time, 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(
# # 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 = """ # 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.role_name from (
# select a.*, b.c_two, b.sum_use from( # select convert(sum(use_quantity), decimal(10,2)) use_amount,
# select medicament_id, by_user_name, by_user_id from rms_medicament %s # sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num,
# ) a LEFT JOIN( # create_user_id,
# 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 # create_user_name
# ) b on a.medicament_id=b.medicament_id # from rms_medicament_record %s GROUP BY create_user_id
# ) c GROUP BY by_user_name, by_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 ( # filter_base = ""
select convert(sum(use_quantity), decimal(10,2)) use_amount, # if seach_user:
sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num, # filter_base += f"by_user_name like '%{seach_user}%'"
create_user_id, # if start_time and end_time:
create_user_name # if filter_base:
from rms_medicament_record %s GROUP BY create_user_id # filter_base += " and "
) a LEFT JOIN ( # filter_base += f" create_date >= '{start_time}' and create_date <= '{end_time}'"
SELECT role_name, user_id FROM rms_user # if filter_base:
) b on a.create_user_id = b.user_id # 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 = "" filter_base = ""
if seach_user: 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 start_time and end_time:
if filter_base: if filter_base:
filter_base += " and " filter_base += " and "
filter_base += f" create_date >= '{start_time}' and create_date <= '{end_time}'" filter_base += f" create_date >= '{start_time}' and create_date <= '{end_time}'"
if filter_base: if filter_base:
filter_base = " where " + filter_base filter_base = f" where {filter_base}"
sql_all = sql_all % 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: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number if page_param:
# 数据分页 page_param.totalRecords = count_number
sql_all=Utils.sql_paging_assemble(sql_all, page_param) # 数据分页
sql_all=Utils.sql_paging_assemble(sql_all, page_param)
data, ratio_all = self.default_data_list(sql_all, "use_amount") data, ratio_all = self.default_data_list(sql_all, "use_amount")
# 数据处理 # 数据处理
for i in data: for i in data:
@ -378,25 +616,49 @@ class BllMedicamentRecord(Repository):
except Exception: except Exception:
i["ratio"] = "0%" i["ratio"] = "0%"
return data return data
# 使用频率 # 使用频率
def use_frequency(self, page_param, start_time, end_time,client_id=None, seach_word=None): 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, # 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, # 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 ( # 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 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 # select medicament_id, `name`, speci, purity, cas_number, net_weight_unit, `status`, client_id from rms_medicament
%s # %s
) a LEFT JOIN( # ) a LEFT JOIN(
select medicament_id, # select medicament_id,
sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) two_type, # 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 # 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 %s GROUP BY medicament_id
)b on a.medicament_id=b.medicament_id # )b on a.medicament_id=b.medicament_id
) c GROUP BY `name`, purity, speci # ) c GROUP BY `name`, purity, speci
""" # """
# 查询条件sql组合 # # 查询条件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 = "" filter_base1 = ""
if client_id: if client_id:
filter_base1 += f" client_id='{client_id}' " filter_base1 += f" client_id='{client_id}' "
@ -404,22 +666,38 @@ class BllMedicamentRecord(Repository):
if filter_base1: if filter_base1:
filter_base1 += "and " filter_base1 += "and "
seach_word = f"%{seach_word}%" seach_word = f"%{seach_word}%"
filter_base1 += f" `name` like '{seach_word}' or english_name like '{seach_word}'" filter_base1 += f" (`name` like '{seach_word}' or english_name like '{seach_word}') "
if filter_base1: if filter_base1:
filter_base1 = " where " + filter_base1 filter_base1 = " where " + filter_base1
filter_base2 = "" filter_base2 = ""
if start_time and end_time: if start_time and end_time:
filter_base2 += f" where create_date >= '{start_time}' and create_date <= '{end_time}'" filter_base2 += f" where create_date >= '{start_time}' and create_date <= '{end_time}'"
sql_all = sql_all % (filter_base1, filter_base2) 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
{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 {filter_base2} GROUP BY medicament_id
)b on a.medicament_id=b.medicament_id
) c GROUP BY `name`, purity, speci
"""
# 查询条件sql组合
# 查询数据列表长度 # 查询数据列表长度
try: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number if page_param:
# 处理数据 page_param.totalRecords = count_number
sql_all = Utils.sql_paging_assemble(sql_all, page_param) # 处理数据
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
data, _ = self.default_data_list(sql_all) data, _ = self.default_data_list(sql_all)
return data return data

@ -17,28 +17,64 @@ class BllModuleRelation(Repository):
def get_login_user_module_list(self, user_id, role_id): 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""" sql_all = f"""
select c.module_id, c.module_code, c.sort_index, c.module_name, c.module_type from( 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 SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type
from rms_module_relation as a from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id 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 UNION
SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type SELECT a.module_id, b.module_code, b.sort_index, b.module_name, b.module_type
from rms_module_relation as a from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id 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 ) c ORDER BY c.sort_index asc
""" """
sql_data = self.execute(sql_all).fetchall() sql_data = self.execute(sql_all).fetchall()
data = Utils.msyql_table_model(sql_data) data = Utils.msyql_table_model(sql_data)
data_dict = { data_dict = {
"client_manage": [], "client_manage":[],
"drug_manage": [], "drug_manage": [],
"standard_manage": [], "standard_manage": [],
"consumables_manage": [], "dangerous_manage": [],
"instrument_manage": []
} }
for i in data: for i in data:
if i["module_type"] == "1": if i["module_type"] == "1":
@ -48,14 +84,41 @@ class BllModuleRelation(Repository):
elif i["module_type"] == "3": elif i["module_type"] == "3":
data_dict["standard_manage"].append(i) data_dict["standard_manage"].append(i)
elif i["module_type"] == "4": elif i["module_type"] == "4":
data_dict["consumables_manage"].append(i) data_dict["dangerous_manage"].append(i)
elif i["module_type"] == "5":
data_dict["instrument_manage"].append(i)
return data_dict return data_dict
# return self.execute(sql_all).fetchall()
def get_user_module_list(self, user_info): 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""" sql_all = f"""
select a.module_id, a.module_name, a.module_type, a.module_code, a.sort_index, 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 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() sql_data = self.execute(sql_all).fetchall()
data = Utils.msyql_table_model(sql_data) data = Utils.msyql_table_model(sql_data)
data_dict = { data_dict = {
"client_manage": [], "client_manage":[],
"drug_manage":[], "drug_manage":[],
"standard_manage":[], "standard_manage":[],
"consumables_manage": [], "dangerous_manage": [],
"instrument_manage":[]
} }
for i in data: for i in data:
if i["module_type"] == "1": if i["module_type"] == "1":
@ -81,12 +143,11 @@ class BllModuleRelation(Repository):
elif i["module_type"] == "3": elif i["module_type"] == "3":
data_dict["standard_manage"].append(i) data_dict["standard_manage"].append(i)
elif i["module_type"] == "4": elif i["module_type"] == "4":
data_dict["consumables_manage"].append(i) data_dict["dangerous_manage"].append(i)
elif i["module_type"] == "5":
data_dict["instrument_manage"].append(i)
return data_dict return data_dict
def get_role_module_list(self, role_id): def get_role_module_list(self, role_id):
sql_all = f""" sql_all = f"""
select a.module_id, a.module_code, a.sort_index, a.module_name, a.module_type, select a.module_id, a.module_code, a.sort_index, a.module_name, a.module_type,

@ -32,14 +32,16 @@ class BllUser(Repository):
) )
if user_info: if user_info:
if user_info.is_enabled: if user_info.is_enabled:
if user_info.check_password(password): if user_info.password == Utils.MD5(password):
return self.get_jwt(user_info) self.last_visit_date=Utils.get_str_datetime()
return False 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): def update_password(self, user_info, old_password, new_password):
if user_info.check_password(old_password): if user_info.password == Utils.MD5(old_password):
user_info.set_password(new_password) user_info.password = Utils.MD5(new_password)
self.update(user_info) self.update(user_info)
return True, self.get_jwt(user_info) return True, self.get_jwt(user_info)
else: else:

@ -19,13 +19,40 @@ class BllWarning(Repository):
#获取预警列表 #获取预警列表
def getWarningList(self, pageParam=None,key_word=None, object_type=None, start_time=None, end_time=None): 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 = """ sql_all = """
select * from rms_warning %s ORDER BY warning_date DESC select * from rms_warning %s ORDER BY warning_date DESC
""" """
filter_base = "" filter_base = ""
if key_word: if key_word:
key_word = f"'%{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 object_type:
if filter_base: if filter_base:
filter_base += " and " filter_base += " and "

@ -53,7 +53,8 @@ class EntityUser(Base):
def check_password(self, password): def check_password(self, password):
'''验证密码与保存的 Hash 值是否匹配''' '''验证密码与保存的 Hash 值是否匹配'''
return check_password_hash(self.password, password) # return check_password_hash(self.password, password)
return Utils.MD5(password) == self.password
class EntityRole(Base): class EntityRole(Base):

Loading…
Cancel
Save