diff --git a/apps/drug/views.py b/apps/drug/views.py index 8c08a1a..96becf8 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -101,8 +101,9 @@ def drug_return(): # 获取参数 bar_code = request.values.get("bar_code") func_type = request.values.get("func_type") - place = request.values.get("place") + # place = request.values.get("place") # user_id = request.values.get("user_id") + remain = request.values.get("remain") # 默认用户id,后续从token 中获取 # user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1' @@ -118,8 +119,9 @@ def drug_return(): else: # 药剂归还,进入归还事务处理 drug_info.status = DrugStatus.Normal - if place: - drug_info.client_id = place + drug_info.remain = remain + # if place: + # drug_info.client_id = place # user_info = BllUser().findEntity(EntityUser.user_id == user_id) user_info = g.current_user diff --git a/apps/drug_template/views.py b/apps/drug_template/views.py index dc26960..ed124f2 100644 --- a/apps/drug_template/views.py +++ b/apps/drug_template/views.py @@ -85,9 +85,11 @@ def select_drug_info(): @token_auth.login_required def bind_tmp_input_db(): tmp_content = request.values.get("tmplate_content") - customer_id = request.values.get("customer_id", '1002437b-debf-46d6-b186-3e16bcf0cc0f') + customer_id = request.values.get("customer_id") + if not customer_id: + customer_id = '1002437b-debf-46d6-b186-3e16bcf0cc0f' func_type = request.values.get("func_type") - client_id = request.values.get("client_id") + # client_id = request.values.get("client_id") # client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1' bar_code = request.values.get("bar_code") # user_id = request.values.get("user_id") @@ -119,7 +121,7 @@ def bind_tmp_input_db(): "variety_id": drug_variety.variety_id, "bar_code": bar_code, "customer_id": customer_id, - "client_id": client_id, + # "client_id": client_id, "inventory_warning_value":10, "shelf_life_warning_value":10, "use_days_warning_value":10, @@ -152,11 +154,12 @@ def bind_tmp_input_db(): # user_id = user_info.user_id # user_id_pt = request.values.get("user_id_pt", '34306da6-0f11-11ed-ba01-009027e3906b') # BllUserTemporaryAuth().create_temporary_auth(user_ids=[user_id, user_id_pt], auth_type=1) + obj = CreateBarcode() obj.create_drug_lobel_code(**new_dict) BllMedicament().drugPutIn( drug_entity, - BllClient().findEntity(EntityClient.client_id==client_id), + BllClient().findEntity(EntityClient.client_id==drug_entity.client_id), user_info ) return jsonify(Utils.true_return(msg="药剂入库成功")) diff --git a/apps/monitor/views.py b/apps/monitor/views.py index 5e67d55..15e6cf4 100644 --- a/apps/monitor/views.py +++ b/apps/monitor/views.py @@ -23,6 +23,8 @@ monitor_router = Blueprint('monitor', __name__) # @token_auth.login_required def get_day_monitor(): client_id = request.values.get("client_id") + # TODO 添加房间筛选 + client_place = request.values.get("client_place") start_time = request.values.get("start_time") end_time = request.values.get("end_time") page = request.values.get("page", 1) @@ -36,7 +38,8 @@ def get_day_monitor(): data_list = BllHumitureRecord().get_client_day_log( client_id=client_id, start_time=start_time, - end_time=end_time, page_param=page_param + end_time=end_time, page_param=page_param, + client_place=client_place ) if not download_tp: return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords})) @@ -58,6 +61,8 @@ def get_day_monitor(): @token_auth.login_required def get_day_monitor_info(): client_id = request.values.get("client_id") + # TODO 添加房间筛选 + client_place = request.values.get("client_place") start_time = request.values.get("start_time") end_time = request.values.get("end_time") page = request.values.get("page", 1) @@ -72,7 +77,8 @@ def get_day_monitor_info(): client_id=client_id, start_time=start_time, end_time=end_time, - page_param=page_param + page_param=page_param, + client_place=client_place ) if not download_tp: return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords})) diff --git a/apps/report/views.py b/apps/report/views.py index d8ea45d..996f655 100644 --- a/apps/report/views.py +++ b/apps/report/views.py @@ -66,6 +66,9 @@ def get_stock_data_info(): func_type = request.values.get("func_type") page = int(request.values.get('page', 1)) page_size = int(request.values.get('page_size', 15)) + # TODO 添加房间筛选 + client_place = request.values.get("client_place") + client_id = request.values.get("client_id") page_param = PageParam(page, page_size) # 导出报表功能 @@ -75,7 +78,10 @@ def get_stock_data_info(): data_list = BllMedicament().get_stock_all_info( name=name, func_type=func_type, - page_param=page_param) + page_param=page_param, + client_place=client_place, + client_id=client_id + ) data_list = Utils.msyql_table_model(data_list) if not download_tp: if data_list: @@ -104,6 +110,7 @@ def drun_input_info(): manufacturer = request.values.get("manufacturer") start_time = request.values.get("start_time") end_time = request.values.get("end_time") + seach_user = request.values.get("seach_user") func_type = request.values.get("func_type") @@ -129,7 +136,8 @@ def drun_input_info(): page_param=page_param, customer_id=customer_id, client_id=client_id, - client_speci=client_place + client_speci=client_place, + seach_user=seach_user ) # 数据处理,列表key:value格式 @@ -319,6 +327,10 @@ def drug_log_type_info(): end_time = request.values.get("end_time") page_param = PageParam(page, page_size) + # TODO 添加房间筛选 + client_place = request.values.get("client_place") + client_id = request.values.get("client_id") + # 报表数据 download_tp = request.values.get("download_type", 0) if download_tp: @@ -330,7 +342,9 @@ def drug_log_type_info(): statue_type=statue_type, name=name, start_time=start_time, end_time=end_time, - page_param=page_param + page_param=page_param, + client_place=client_place, + client_id=client_id ) data_list = Utils.msyql_table_model(data_list) if not download_tp: diff --git a/apps/temporary_auth/views.py b/apps/temporary_auth/views.py index 9267f09..1c0ae9d 100644 --- a/apps/temporary_auth/views.py +++ b/apps/temporary_auth/views.py @@ -28,10 +28,11 @@ temporary_bp = Blueprint("temporary_auth", __name__) @temporary_bp.route("/get_drug_group_list", methods=["POST"]) def get_use_drug_list(): client_id = request.values.get("client_id") + seach_word = request.values.get("seach_word") page = request.values.get("page") page_size = request.values.get("page_size") page_param = PageParam(int(page), int(page_size)) - data = BllMedicament().use_drug_info_list(client_id=client_id, page_param=page_param) + data = BllMedicament().use_drug_info_list(client_id=client_id, seach_word=seach_word, page_param=page_param) data_list = Utils.msyql_table_model(data_list=data) return jsonify(Utils.true_return(data={"data_list":data_list, "total_count": page_param.totalRecords})) @@ -158,10 +159,13 @@ def solve_apply(): # 展示待登记列表 @temporary_bp.route("/register_drug_list", methods=["GET", "POST"]) +@token_auth.login_required def get_register_drug(): - data = BllMedicament().execute(f"select * from rms_medicament where status=4").fetchall() - data_list = Utils.msyql_table_model(data) - return jsonify(Utils.true_return(data=data_list)) + page = request.values.get("page") + page_size = request.values.get("page_size") + page_param = PageParam(int(page), int(page_size)) + data = BllMedicament().get_register_list(user=g.current_user, page_param=page_param) + return jsonify(Utils.true_return(data={"data_list":Utils.msyql_table_model(data), "total_count": page_param.totalRecords})) # 登记接口 @@ -183,6 +187,9 @@ def set_register(): remain = request.values.get("remain") # obj = BllMedicament().findEntity(EntityMedicament.medicament_id==drug_id) if obj: + # 开瓶日期 + if not obj.remark13: + setattr(obj, "remark13", Utils.get_str_datetime()) setattr(obj, "remain", remain) setattr(obj, "status", 2) BllMedicament().update(obj) diff --git a/db_logic/humiture_record.py b/db_logic/humiture_record.py index 1220631..feb0d18 100644 --- a/db_logic/humiture_record.py +++ b/db_logic/humiture_record.py @@ -52,7 +52,7 @@ class BllHumitureRecord(Repository): # 获取每日记录,按时间,柜体分组展示 - def get_client_day_log(self, client_id, start_time, end_time, page_param): + def get_client_day_log(self, client_id, start_time, end_time, page_param, client_place): filter_base = "" if client_id: filter_base += f" client_id='{client_id}'" @@ -62,7 +62,10 @@ class BllHumitureRecord(Repository): filter_base += f" record_date>= '{start_time}' and record_date<= '{end_time}' " if filter_base: filter_base = f" where {filter_base} " - + #TODO 添加房间筛选 + filter_base1 = "" + if client_place: + filter_base1 += f"where client_speci='{client_place}'" sql_all = f""" select a.client_id, a.client_name, a.day_date, a.avg_wd, a.avg_sd, a.avg_voc, b.place from ( @@ -72,7 +75,9 @@ class BllHumitureRecord(Repository): round(avg(humidity),2) avg_sd, round(avg(voc_content),2) avg_voc from rms_humiture_record {filter_base} GROUP BY client_id, DATE_FORMAT(record_date,'%Y-%m-%d') - ) a LEFT JOIN rms_client as b on a.client_id=b.client_id ORDER BY day_date desc + ) a LEFT JOIN (select * from rms_client {filter_base1}) as b on a.client_id=b.client_id + where b.place is not null + ORDER BY day_date desc """ try: count_number = len(self.execute(sql_all).fetchall()) @@ -84,7 +89,7 @@ class BllHumitureRecord(Repository): return self.execute(sql_all).fetchall() # 获取每日记录详情 - def get_client_day_log_info(self, client_id, start_time, end_time, page_param): + def get_client_day_log_info(self, client_id, start_time, end_time, page_param, client_place): filter_base = "" if client_id: filter_base += f" client_id='{client_id}'" @@ -94,13 +99,33 @@ class BllHumitureRecord(Repository): filter_base += f" record_date>= '{start_time}' and record_date<= '{end_time}' " if filter_base: filter_base = f" where {filter_base}" + #TODO 添加房间筛选 + filter_base1 = "" + if client_place: + filter_base1 += f"where client_speci='{client_place}'" + # sql_all = f""" + # select + # DATE_FORMAT(record_date,'%H:%i:%s') day_date, + # round(temperature,2) as wd, + # round(humidity,2) as sd, + # round(voc_content,2) as voc + # from rms_humiture_record {filter_base} ORDER BY record_date + # """ sql_all = f""" - select - DATE_FORMAT(record_date,'%H:%i:%s') day_date, - round(temperature,2) as wd, - round(humidity,2) as sd, - round(voc_content,2) as voc - from rms_humiture_record {filter_base} ORDER BY record_date + select a.*, b.place from ( + select + client_id, + DATE_FORMAT(record_date,'%H:%i:%s') day_date, + round(temperature,2) as wd, + round(humidity,2) as sd, + round(voc_content,2) as voc + from rms_humiture_record {filter_base} + ) a LEFT JOIN ( + select * from rms_client {filter_base1} + ) b on a.client_id = b.client_id + where place is not null + ORDER BY a.day_date + """ try: count_number = len(self.execute(sql_all).fetchall()) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index 4e64b90..dabf02e 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -25,19 +25,34 @@ class BllMedicament(Repository): def update(self, entity): entity.remark30 = '0' return super().update(entity) + + def get_register_list(self, user, page_param): + sql_all = f""" + select * from rms_medicament where status=4 and by_user_id='{user.user_id}' + """ + try: + total_count = self.execute(f"select count(*) num from rms_medicament where status=4 and by_user_id='{user.user_id}'").fetchone().num + except Exception: + total_count = 0 + page_param.totalRecords = total_count + # 调用分页组装sql + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() # 获取可入库层数据 def get_drug_save_db_info(self, drug_name, func_type): sql_all = f""" - select name, IFNULL(num,0) number, c.client_id, cell_code, cell_speci from ( + select name, IFNULL(num,0) number, c.client_name, c.client_id, cell_code, cell_speci from ( select cell_code, a.client_id, cell_speci, client_name from ( select * from rms_client_cell ) a LEFT JOIN( select client_id, client_name from rms_client ) b on a.client_id = b.client_id ) c LEFT JOIN( - select NAME, client_id, flow_position_code, count(*) num from rms_medicament where `name` like '%{drug_name}%' and status=1, func_type={func_type} GROUP BY client_id, flow_position_code + select name, client_id, flow_position_code, count(*) num + from rms_medicament where `name` like '%{drug_name}%' and status=1 and func_type={func_type} + GROUP BY client_id, flow_position_code ) d on c.client_id=d.client_id and c.cell_code=d.flow_position_code HAVING number < 40 @@ -48,9 +63,12 @@ class BllMedicament(Repository): if i.client_id in data_dict.keys(): data_dict[i.client_id]["client_cell"].append(i.cell_speci) else: - data_dict[i.client_id]["client_id"] = i.client_id - data_dict[i.client_id]["client_name"] = i.client_name - data_dict[i.client_id]["client_cell"] = [i.cell_speci] + client_dict = { + "client_id": i.client_id, + "client_name": i.client_name, + "client_cell": [i.cell_speci] + } + data_dict[i.client_id] = client_dict data_list = [] for k,v in data_dict.items(): data_list.append(v) @@ -253,6 +271,7 @@ class BllMedicament(Repository): # 创建事务 self.beginTrans() entityDrug.remark30 = '0' + entityDrug.client_code = entityClient.client_code self.session.add(entityDrug) if entityDrug.status == 1: self.session.add(entityDrugRecord) @@ -371,7 +390,7 @@ class BllMedicament(Repository): # 获取库存信息总览 - def get_stock_all_info(self, page_param, func_type, name=None): + def get_stock_all_info(self, page_param, func_type,client_id, name=None, client_place=None): filter_base = "" if name: filter_base = f" `name` LIKE '%{name}%'" @@ -379,17 +398,43 @@ class BllMedicament(Repository): if filter_base: filter_base += " and " filter_base += f" func_type='{func_type}' " + if client_id: + if filter_base: + filter_base += " and " + filter_base += f" client_id='{client_id}' " if filter_base: filter_base = f" where {filter_base}" - sql_all =f""" - select DISTINCT - `name`, speci, cas_number,net_weight_unit, purity, - manufacturer, distributor, net_weight, net_weight_unit, - client_id, put_in_user_name,category,expiration_date - - 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 + #TODO 添加房间筛选 + filter_base1 = "" + if client_place: + filter_base1 += f"where client_speci='{client_place}'" + + # sql_all =f""" + # select DISTINCT + # `name`, speci, cas_number,net_weight_unit, purity, + # manufacturer, distributor, net_weight, net_weight_unit, + # client_id, put_in_user_name,category,expiration_date + + # 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 a.*, b.client_name from ( + select DISTINCT + `name`, speci, cas_number, purity, + manufacturer, distributor, net_weight, net_weight_unit, + client_id, put_in_user_name,category,expiration_date,put_in_date, + + 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 + )a LEFT JOIN ( + select * from rms_client {filter_base1} + ) b on a.client_id=b.client_id + where b.client_name is not null + order by a.put_in_date desc """ # 首次查询,判断长度,做分页使用 try: @@ -403,7 +448,7 @@ class BllMedicament(Repository): return self.execute(sql_all).fetchall() #获取所有药剂列表 - def getAllDrugList(self, search_word, manufacturer, start_time, end_time, func_type, page_param, customer_id=None, client_id=None, client_speci=None): + def getAllDrugList(self, search_word, manufacturer, start_time, end_time, func_type, page_param, seach_user, customer_id=None, client_id=None, client_speci=None): # (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord) filter_base = "" if customer_id: @@ -436,19 +481,22 @@ class BllMedicament(Repository): if filter_base: filter_base += " and " filter_base += f" func_type={func_type}" - + if seach_user: + if filter_base: + filter_base += " and " + filter_base += f" put_in_user_name like '%{seach_user}%'" if filter_base: filter_base = "where " + filter_base # select * from rms_medicament {filter_base} #TODO 添加房间筛选 filter_base1 = "" - # if client_speci: - # filter_base1 += f"where client_speci='{client_speci}'" + if client_speci: + filter_base1 += f"where client_speci='{client_speci}'" sql_all = f""" select a.*,b.client_name from ( select name, english_name,bar_code,manufacturer,speci,remain,purity,production_date,shelf_life,expiration_date,put_in_date,put_in_user_name, - status,by_user_name,client_id, count(*) count_number + status,by_user_name,client_id from rms_medicament {filter_base} ) a LEFT JOIN( select client_id,client_name from rms_client {filter_base1} @@ -474,13 +522,14 @@ class BllMedicament(Repository): return self.execute(sql_all).fetchall() # 入库、领用、归还记录 - def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, func_type, statue_type, page_param): + def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, func_type, client_id, statue_type, page_param, client_place): filter_base1 = f" WHERE record_type={record_type} " if put_in_user_name: filter_base1 += f" and create_user_name like '%{put_in_user_name}%'" if start_time and end_time: filter_base1 += f" and create_date >= '{start_time}' and create_date <= '{end_time}'" - + if client_id: + filter_base1 += f" and client_id='{client_id}'" filter_base2 = '' if name: name = f"%{name}%" @@ -497,6 +546,10 @@ class BllMedicament(Repository): filter_base2 += f" func_type='{func_type}' " if filter_base2: filter_base2 = f" where {filter_base2}" + #TODO 添加房间筛选 + filter_base = "" + if client_place: + filter_base += f"where client_speci='{client_place}'" sql_all = f""" select `name`, english_name, bar_code, purity, @@ -511,8 +564,8 @@ class BllMedicament(Repository): 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 + LEFT JOIN(select client_id,client_name from rms_client {filter_base}) c on a.client_id=c.client_id + where name is not null and client_name is not null ORDER BY create_date desc """ try: count_number = len(self.execute(sql_all).fetchall()) @@ -558,20 +611,17 @@ class BllMedicament(Repository): return self.execute(sql_all).fetchall() # 可领用试剂列表 - def use_drug_info_list(self, client_id, page_param): + def use_drug_info_list(self, client_id, seach_word, page_param): filter_base = "" if client_id: filter_base += f"client_id='{client_id}'" + if seach_word: + if filter_base: + filter_base += " and " + name = f"%{seach_word}%" + filter_base += f" (`name` like '{name}' or english_name like '{name}') " if filter_base: filter_base = f" and {filter_base}" - """ - select - `name`, speci, purity, count(*) drug_num, manufacturer, distributor - from - rms_medicament WHERE `status`=1 {filter_base} - GROUP BY - `name`, speci, purity, client_id - """ sql_all = f""" select a.*,b.client_name from ( select diff --git a/demo.py b/demo.py index a7377ba..830371d 100644 --- a/demo.py +++ b/demo.py @@ -30,29 +30,28 @@ def picture_shoot(image_name='img.png', image_path=r'C:/local_project/imgs') -> cv2.destroyAllWindows() # if __name__ == '__main__': # picture_shoot() -import json -data_list = [ - {"id": 1, "use_content": json.dumps([{"name":"氨水","num":1,"client_id":"1c39cb24-07f8-11ed-abd4-f47b094925e1","purity":"25~28%","speci":"500"}])}, - {"id": 2, "use_content": json.dumps([{"name":"双氧水","num":1,"client_id":"1c39cb24-07f8-11ed-abd4-f47b094925e1","purity":"25~28%","speci":"500"}])}, - {"id": 4, "use_content": json.dumps([{"name":"硫酸水","num":1,"client_id":"1c39cb24-07f8-11ed-abd4-f47b094925e1","purity":"25~28%","speci":"500"}])}, -] -drug_list = [] -update_id = '' -client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1' -drug_info = {"name": "双氧水"} -for d in data_list: - if update_id: - break - use_content = json.loads(d["use_content"]) - for j in range(len(use_content)): - # for j in use_content: - j_info = use_content[j] - if j_info["client_id"] == client_id and j_info["name"] == drug_info["name"] and j_info["purity"] == "25~28%" and j_info["speci"] == "500": - if not j_info.get("use_num"): - j_info["use_num"] = 0 - if int(j_info["use_num"]) == int(j_info["num"]): - continue - else: - j_info["use_num"] += 1 - update_id = d["id"] - print(use_content) \ No newline at end of file +# from db_logic.module import BllModule +from Common.Utils import Utils +data = BllModule().findList(EntityModule.module_type=='4') +for i in data: + i.module_name = str(i.module_name).replace("耗材", "对照品") + + BllModule().update(i) + +# data = BllModule().execute("select * from rms_module where module_type=2 order by sort_index").fetchall() +# data_list = Utils.msyql_table_model(data) +# inster_list = [] +# ind = 48 +# for i in range(len(data_list)): +# d = data_list[i] +# del d['module_id'] +# d['module_type'] = 4 +# d['module_name'] = d['module_name'].replace("试剂", "对照品") +# d['module_code'] = d['module_code'].replace("Drug", "DZP") +# d['sort_index'] = ind +# d['module_weight'] = ind + +# inster_list.append(EntityModule(**d)) +# ind += 1 +# print(11111) +# BllModule().insert_many(inster_list) \ No newline at end of file diff --git a/main.py b/main.py index d50836a..e381b49 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ ''' import sys sys.path.append(".") +import os from config.server import create_app from Common.exception_base import APIException from config.SystemConfig import SystemConfig