diff --git a/apps/report/views.py b/apps/report/views.py index 5ba14b9..9cd199f 100644 --- a/apps/report/views.py +++ b/apps/report/views.py @@ -134,8 +134,8 @@ def drun_input_info(): func_type=func_type, start_time=start_time, end_time=end_time, - page_param=page_param, - customer_id=customer_id, + page_param=page_param, + customer_id=customer_id, client_id=client_id, client_speci=client_place, seach_user=seach_user @@ -164,6 +164,8 @@ def drun_input_info(): def stock_loss_info(): # 获取参数 seach_word = request.values.get('seach_word') + start_time = request.values.get("start_time") + end_time = request.values.get("end_time") func_type = request.values.get("func_type") @@ -179,9 +181,12 @@ def stock_loss_info(): # 获取数据结果 data = BllMedicamentRecord().durg_stock_loss( - seach_word=seach_word, + seach_word=seach_word, func_type=func_type, - page_param=page_param) + page_param=page_param, + start_time=start_time, + end_time=end_time, + ) if not download_tp: return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) else: @@ -195,7 +200,7 @@ def stock_loss_info(): return rsp else: return jsonify(Utils.false_return()) - + @@ -209,6 +214,8 @@ def get_drug_use_expend(): page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) + start_time = request.values.get("start_time") + end_time = request.values.get("end_time") # 报表数据 download_tp = request.values.get("download_type", 0) @@ -218,7 +225,10 @@ def get_drug_use_expend(): data = BllMedicamentRecord().durg_useing_info( seach_word=seach_word, func_type=func_type, - page_param=page_param) + page_param=page_param, + start_time=start_time, + end_time=end_time, + ) if not download_tp: return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) else: @@ -253,7 +263,7 @@ def get_drug_user_use_expend(): page_param = None # 获取数据 data = BllMedicamentRecord().user_use_info( - seach_user=seach_user, + seach_user=seach_user, func_type=func_type, start_time=start_time, end_time=end_time, @@ -291,11 +301,11 @@ def drug_use_frequency(): page_param = None data = BllMedicamentRecord().use_frequency( - seach_word=seach_word, - start_time=start_time, + seach_word=seach_word, + start_time=start_time, end_time=end_time, func_type=func_type, - client_id=client_id, + client_id=client_id, page_param=page_param) if not download_tp: return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) @@ -458,4 +468,4 @@ def get_report_inventory(): :return: [{chemicals: 化学品, total_num: 库存量, total_weight: 总重量}] """ inventory_list = get_all_inventory() - return jsonify(Utils.true_return(data=inventory_list)) \ No newline at end of file + return jsonify(Utils.true_return(data=inventory_list)) diff --git a/db_logic/medicament_record.py b/db_logic/medicament_record.py index b017508..7c120e0 100644 --- a/db_logic/medicament_record.py +++ b/db_logic/medicament_record.py @@ -103,7 +103,7 @@ class BllMedicamentRecord(Repository): sql_all = " UNION ".join(sql_list) # print(sql_all) return self.execute(sql_all).fetchall() - + # 获取报表统计主页,使用频率 def get_use_avg_number(self, func_type): sql_all = f""" @@ -124,7 +124,7 @@ class BllMedicamentRecord(Repository): 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], @@ -151,8 +151,8 @@ class BllMedicamentRecord(Repository): name_info_dict = {} for name in name_info_list: name_info_dict[name[-1]] = name - # 组装数据 - type_num = [] + # 组装数据 + type_num = [] for i in data_li: name_info = name_info_dict.get(i['record_type']) new_dic = { @@ -208,7 +208,7 @@ class BllMedicamentRecord(Repository): new_dic.update(**i) data_list.append(new_dic) return data_list - + # 获取报表统计主页人员用量消耗 def report_home_user_use_info(self, func_type): sql_all = f""" @@ -258,7 +258,7 @@ class BllMedicamentRecord(Repository): 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 = "" if seach_word: seach_word = f"%{seach_word}%" @@ -267,6 +267,10 @@ class BllMedicamentRecord(Repository): if filter_base: filter_base += " and " 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: filter_base = f" where {filter_base}" sql_all = f""" @@ -298,7 +302,7 @@ class BllMedicamentRecord(Repository): 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 filter_base = "" if seach_word: @@ -308,6 +312,11 @@ class BllMedicamentRecord(Repository): if filter_base: filter_base += " and " 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: filter_base = f" where {filter_base}" sql_all = f""" @@ -316,7 +325,7 @@ class BllMedicamentRecord(Repository): 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 + 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 """ @@ -440,7 +449,7 @@ class BllMedicamentRecord(Repository): import random data = list(self.execute("select medicament_id from rms_medicament").fetchall()) # print(random.choice(data)[0]) - # + # obj_list = [] for i in range(100): obj = EntityMedicamentRecord( @@ -461,7 +470,7 @@ class BllMedicamentRecord(Repository): # #获取药剂最后一次使用余量 # def getLastRecordRemain(self, drugId): # 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: # result = BllMedicamentRecord().execute(SQL) @@ -473,7 +482,7 @@ class BllMedicamentRecord(Repository): # #删除药剂最后一次领用记录 # def deleteLastUseRecord(self, drugId): # 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) # return result @@ -488,4 +497,4 @@ if __name__ == '__main__': # from Common.Utils import PageParam # page_param = PageParam(1, 10) # typ_dic = BllMedicamentRecord().inster_log_list() -# print(typ_dic) \ No newline at end of file +# print(typ_dic)