修改预警信息bug;

修改首页展示接口
duizhaopin
apan 2 years ago
parent bbb2c6f9cd
commit 5362927ab9

@ -3,7 +3,7 @@
'''
@Date:2022/07/18 16:19:33
'''
from flask import jsonify, request
from flask import jsonify, request, g
from db_logic.medicament import BllMedicament
from models.warning_models import EntityWarning
@ -35,6 +35,29 @@ def get_record_type_drug_record_json():
return jsonify(Utils.true_return(data=data))
# 主概览 当日入库-领用-归还,预警列表, 信息总览
@home_router.route("/home_info", methods=["GET", "POST"])
def get_home_info():
resp_data = {
"new_day_record_number":{},
"warning_list": [],
"warning_data_info": {"count_number":0, "data_list":[]}
}
try:
resp_data["new_day_record_number"] = BllMedicamentRecord().getTodayDrugRecordCount()
warning_obj = BllWarning()
resp_data["warning_list"] = Utils.msyql_table_model(warning_obj.getWarningList())
warning_data_list, number_all = warning_obj.get_waring_type_classify()
resp_data["warning_data_info"] = {
"count_number": number_all,
"data_list": warning_data_list
}
return jsonify(Utils.true_return(data=resp_data))
except Exception as error:
return jsonify(Utils.except_return(msg=f"error:{error}", data=resp_data))
# 试剂余量
@home_router.route("/home_drug_remaining", methods=["GET", "POST"])
def drug_remaining():
@ -46,24 +69,34 @@ def drug_remaining():
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": Utils.msyql_table_model(data_list)}))
# 预警信息总览
@home_router.route("/warning_info_classify", methods=["GET", "POST"])
def warning_info_classify():
data, total_num = BllWarning().get_waring_type_classify()
return jsonify(Utils.true_return(data={"total_count": total_num, "data": data}))
# @home_router.route("/warning_info_classify", methods=["GET", "POST"])
# def warning_info_classify():
# data, total_num = BllWarning().get_waring_type_classify()
# return jsonify(Utils.true_return(data={"total_count": total_num, "data": data}))
# 获取预警信息列表接口
@home_router.route('/home_warning_list', methods=["GET", "POST"])
def get_warning_list():
customer_id = request.values.get('customer_id', '')
# customer_id = request.values.get('customer_id', '')
seach_word = request.values.get("seach_word")
start_time = request.values.get("start_time")
end_time = request.values.get("end_time")
object_type = request.values.get("object_type")
page = request.values.get('page', 1)
page_size = request.values.get('page_size', 15)
page_param = PageParam(page, page_size)
warning_list = BllWarning.getWarningList(customerId=customer_id, pageParam=page_param)
warning_list = BllWarning().getWarningList(
pageParam=page_param,
start_time=start_time,
end_time=end_time,
key_word=seach_word,
object_type=object_type
)
if warning_list:
data = {
"total_count": page_param.totalRecords,
"data_list": warning_list
"data_list": Utils.msyql_table_model(warning_list)
}
return jsonify(Utils.true_return(data=data))
else:
@ -78,8 +111,8 @@ def update_warning_type():
obj = BllWarning().findEntity(EntityWarning.warning_id == warning_id)
# obj.object_type = 2
obj.solve_date= Utils.get_str_datetime()
obj.solve_user_id = ''
obj.solve_user_name = ''
obj.solve_user_id = g.current_user.user_id
obj.solve_user_name = g.current_user.user_name
obj.is_solve=1
BllWarning().update(obj)

@ -42,9 +42,9 @@ class BllMedicament(Repository):
def get_drug_surplus(self, client_id, page_param):
sql_all = """
select
`name`, english_name, cas_number, net_weight_unit, purity,
`name`, english_name, cas_number, speci, net_weight_unit, purity,
sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) surplus_number
from rms_medicament %s GROUP BY `name`, cas_number, purity
from rms_medicament %s GROUP BY `name`, speci, purity
"""
# 动态添加查询条件
where_base = ""
@ -54,12 +54,18 @@ class BllMedicament(Repository):
where_base = " where " + where_base
# 组装sql
sql_all = sql_all % where_base
# 查询页总数
try:
total_count = len(self.execute(sql_all).fetchall())
except Exception:
total_count = 0
# count_sql = f"SELECT count(*) FROM rms_medicament %s GROUP BY `name`, cas_number, purity" % where_base
page_param.totalRecords = total_count
# 调用分页组装sql
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 %s GROUP BY `name`, cas_number, purity" % where_base
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
return data_list
# 获取试剂库存消耗

@ -66,19 +66,38 @@ class BllMedicamentRecord(Repository):
# return jsonData
#获取今日药剂流转信息数量
def getTodayDrugRecordCount(self, customerId, clientId):
todayDate = datetime.datetime.now().strftime("%Y-%m-%d")
# 使用类型进行分组,直接获取入库,领用,归还的数量
recordListNew = self.session.query(
self.entityType.record_type,
func.count('record_id')
).select_from(self.entityType).filter(
EntityMedicamentRecord.customer_id == customerId,
EntityMedicamentRecord.client_id == clientId,
func.date_format(EntityMedicamentRecord.create_date, '%Y-%m-%d') == todayDate
).group_by(EntityMedicamentRecord.record_type).all()
return dict(recordListNew)
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
"""
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()
data_list = Utils.msyql_table_model(sql_data)
n_a = 0
n_b = 0
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":100,
"type_number": n_a - n_b
}
)
return data_list
def get_drug_log_time_name(self, record_type_list):
sql_all = """
@ -407,7 +426,7 @@ class BllMedicamentRecord(Repository):
# return result
if __name__ == '__main__':
aaa = BllMedicamentRecord().report_home_drug_useing_classify()
aaa = BllMedicamentRecord().getTodayDrugRecordCount('', '')
print(aaa)
# import random
# from db_logic.medicament_record import BllMedicamentRecord

@ -18,15 +18,43 @@ class BllWarning(Repository):
return super().__init__(entityType)
#获取预警列表
def getWarningList(self,customerId,pageParam,keyWord=''):
keyWord='%'+keyWord+'%'
orm_query= self.findList().filter(
EntityWarning.customer_id==customerId
).filter(
or_(EntityWarning.object_name.like(keyWord),
EntityWarning.warning_user_name.like(keyWord))
).order_by(desc(EntityWarning.warning_date))
return self.queryPage(orm_query,pageParam)
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}"
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()
# keyWord='%'+keyWord+'%'
# orm_query= self.findList().filter(
# EntityWarning.customer_id==customerId
# ).filter(
# or_(EntityWarning.object_name.like(keyWord),
# EntityWarning.warning_user_name.like(keyWord))
# ).order_by(desc(EntityWarning.warning_date))
# return self.queryPage(orm_query,pageParam)
#获取预警类型数量
def getWarningCount(self):
@ -48,7 +76,8 @@ class BllWarning(Repository):
new_data_list = []
for i in data_list:
new_dic = {
"ratio": str(round(i["type_number"] / all_number, 2) * 100) + "%"
# "ratio": str(round(i["type_number"] / all_number, 2) * 100) + "%"
"ratio": Utils.classify(i["type_number"], all_number)
}
new_dic.update(**i)
new_data_list.append(new_dic)

Loading…
Cancel
Save