@ -103,7 +103,7 @@ class BllMedicamentRecord(Repository):
sql_all = " UNION " . join ( sql_list )
sql_all = " UNION " . join ( sql_list )
# print(sql_all)
# print(sql_all)
return self . execute ( sql_all ) . fetchall ( )
return self . execute ( sql_all ) . fetchall ( )
# 获取报表统计主页,使用频率
# 获取报表统计主页,使用频率
def get_use_avg_number ( self , func_type ) :
def get_use_avg_number ( self , func_type ) :
sql_all = f """
sql_all = f """
@ -124,7 +124,7 @@ class BllMedicamentRecord(Repository):
else :
else :
use_number = sum ( [ float ( i [ 1 ] ) for i in sql_data ] )
use_number = sum ( [ float ( i [ 1 ] ) for i in sql_data ] )
drug_num = len ( sql_data )
drug_num = len ( sql_data )
resp_data = {
resp_data = {
" avg_use_number " : round ( use_number / drug_num ) ,
" avg_use_number " : round ( use_number / drug_num ) ,
" max_name " : sql_data [ 0 ] [ 0 ] ,
" max_name " : sql_data [ 0 ] [ 0 ] ,
@ -151,8 +151,8 @@ class BllMedicamentRecord(Repository):
name_info_dict = { }
name_info_dict = { }
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 = [ ]
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 = {
@ -208,7 +208,7 @@ class BllMedicamentRecord(Repository):
new_dic . update ( * * i )
new_dic . update ( * * i )
data_list . append ( new_dic )
data_list . append ( new_dic )
return data_list
return data_list
# 获取报表统计主页人员用量消耗
# 获取报表统计主页人员用量消耗
def report_home_user_use_info ( self , func_type ) :
def report_home_user_use_info ( self , func_type ) :
sql_all = f """
sql_all = f """
@ -258,7 +258,7 @@ class BllMedicamentRecord(Repository):
return data_list , base_num
return data_list , base_num
# 获取库存消耗数据
# 获取库存消耗数据
def durg_stock_loss ( self , seach_word , func_type , page_param ):
def durg_stock_loss ( self , seach_word , func_type , page_param , start_time , end_time ):
filter_base = " "
filter_base = " "
if seach_word :
if seach_word :
seach_word = f " % { seach_word } % "
seach_word = f " % { seach_word } % "
@ -267,6 +267,10 @@ class BllMedicamentRecord(Repository):
if filter_base :
if filter_base :
filter_base + = " and "
filter_base + = " and "
filter_base + = f " func_type= ' { func_type } ' "
filter_base + = f " func_type= ' { func_type } ' "
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 :
if filter_base :
filter_base = f " where { filter_base } "
filter_base = f " where { filter_base } "
sql_all = f """
sql_all = f """
@ -298,7 +302,7 @@ class BllMedicamentRecord(Repository):
return data_list
return data_list
# 试剂用量消耗
# 试剂用量消耗
def durg_useing_info ( self , seach_word , func_type , page_param ):
def durg_useing_info ( self , seach_word , func_type , page_param , start_time , end_time ):
# 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
filter_base = " "
filter_base = " "
if seach_word :
if seach_word :
@ -308,6 +312,11 @@ class BllMedicamentRecord(Repository):
if filter_base :
if filter_base :
filter_base + = " and "
filter_base + = " and "
filter_base + = f " func_type= ' { func_type } ' "
filter_base + = f " func_type= ' { func_type } ' "
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 :
if filter_base :
filter_base = f " where { filter_base } "
filter_base = f " where { filter_base } "
sql_all = f """
sql_all = f """
@ -316,7 +325,7 @@ class BllMedicamentRecord(Repository):
IFNULL ( c_two , 0 ) use_num , IFNULL ( sum_use , 0 ) use_level from (
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
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 (
) 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
select medicament_id , FORMAT ( sum ( use_quantity ) , 2 ) sum_use , count ( medicament_id ) c_two from rms_medicament_record where record_type = 3 GROUP BY medicament_id
) b on a . medicament_id = b . medicament_id { filter_base } GROUP BY ` name ` , purity , speci order by use_level desc
) b on a . medicament_id = b . medicament_id { filter_base } GROUP BY ` name ` , purity , speci order by use_level desc
"""
"""
@ -440,7 +449,7 @@ class BllMedicamentRecord(Repository):
import random
import random
data = list ( self . execute ( " select medicament_id from rms_medicament " ) . fetchall ( ) )
data = list ( self . execute ( " select medicament_id from rms_medicament " ) . fetchall ( ) )
# print(random.choice(data)[0])
# print(random.choice(data)[0])
#
#
obj_list = [ ]
obj_list = [ ]
for i in range ( 100 ) :
for i in range ( 100 ) :
obj = EntityMedicamentRecord (
obj = EntityMedicamentRecord (
@ -461,7 +470,7 @@ class BllMedicamentRecord(Repository):
# #获取药剂最后一次使用余量
# #获取药剂最后一次使用余量
# def getLastRecordRemain(self, drugId):
# def getLastRecordRemain(self, drugId):
# SQL = """
# SQL = """
# select RecordRemain from rms_medicamentrecord WHERE MedicamentId='""" + drugId + """' ORDER BY CreateDate DESC LIMIT 1
# select RecordRemain from rms_medicamentrecord WHERE MedicamentId='""" + drugId + """' ORDER BY CreateDate DESC LIMIT 1
# """
# """
# try:
# try:
# result = BllMedicamentRecord().execute(SQL)
# result = BllMedicamentRecord().execute(SQL)
@ -473,7 +482,7 @@ class BllMedicamentRecord(Repository):
# #删除药剂最后一次领用记录
# #删除药剂最后一次领用记录
# def deleteLastUseRecord(self, drugId):
# def deleteLastUseRecord(self, drugId):
# SQL = """
# SQL = """
# delete from rms_medicamentrecord WHERE MedicamentId='""" + drugId + """' and RecordType=2 ORDER BY CreateDate DESC LIMIT 1
# delete from rms_medicamentrecord WHERE MedicamentId='""" + drugId + """' and RecordType=2 ORDER BY CreateDate DESC LIMIT 1
# """
# """
# result = BllMedicamentRecord().executeNoParam(SQL)
# result = BllMedicamentRecord().executeNoParam(SQL)
# return result
# return result
@ -488,4 +497,4 @@ if __name__ == '__main__':
# from Common.Utils import PageParam
# from Common.Utils import PageParam
# page_param = PageParam(1, 10)
# page_param = PageParam(1, 10)
# typ_dic = BllMedicamentRecord().inster_log_list()
# typ_dic = BllMedicamentRecord().inster_log_list()
# print(typ_dic)
# print(typ_dic)