From 5aebf0abdc24904d112552dca56069c2dabb888a Mon Sep 17 00:00:00 2001 From: tangxuan <2233783319@qq.com> Date: Wed, 29 Mar 2023 16:06:38 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=AF=95=E5=89=82=E7=AE=A1=E7=90=86=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=B2=A1=E6=9C=89=E5=B1=95=E7=A4=BA=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E5=88=97=202.=E8=AF=95=E5=89=82=E7=AE=A1=E7=90=86=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E6=9C=89=E7=AE=A1=E7=90=86=E5=88=86=E7=B1=BB=EF=BC=8C?= =?UTF-8?q?=E5=85=A5=E5=BA=93=E6=97=B6=E6=B2=A1=E6=9C=89=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=203.=E7=A7=B0=E9=87=8D=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=A9=BA=E7=93=B6=E6=97=B6=E4=BD=99=E9=87=8F=E8=A6=81=E5=8F=98?= =?UTF-8?q?=E4=B8=BA0=EF=BC=8C=E5=B9=B6=E4=B8=94=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=A9=BA=E7=93=B6=E6=97=B6=E4=B9=9F=E8=A6=81=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=E7=94=A8=E9=87=8F=EF=BC=8C=E6=8F=90=E7=A4=BA=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E9=87=8F=E4=BF=9D=E7=95=99=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E7=8E=B0=E5=9C=A8=E4=BC=9A=E5=87=BA=E7=8E=B0=E5=BE=88?= =?UTF-8?q?=E9=95=BF=E4=B8=80=E4=B8=B2=E6=95=B0=E5=AD=97=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=204.=E6=99=AE=E9=80=9A=E5=8D=B1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=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Utils.py | 29 +++++++++++------ apps/drug/views.py | 16 ++++++---- db_logic/medicament.py | 72 ++++++++++++++++++++++++------------------ 3 files changed, 70 insertions(+), 47 deletions(-) diff --git a/Common/Utils.py b/Common/Utils.py index 5e6b53f..f507ea6 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -34,7 +34,7 @@ class Utils(object): else: new_code = bar_code return bar_code, new_code - + def getDrugUnitCode(num): return f"{Utils.get_file_name_datetime()[:8]}{(3-len(str(num+1)))* '0' + str(num+1)}" @@ -47,7 +47,7 @@ class Utils(object): def get_str_datetime(): return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - + def get_file_name_datetime(): return datetime.datetime.now().strftime("%Y%m%d%H%M%S") @@ -58,7 +58,7 @@ class Utils(object): def classify(num, all_num, fl=2): return str(round(float(round(float(num) / all_num, fl)) * 100)) + "%" # return str(round(float(round(math.ceil(num) / all_num, fl)) * 100)) + "%" - + def model_to_dict(cls): return {c.name: getattr(cls, c.name, None) for c in cls.__table__.columns} @@ -82,7 +82,7 @@ class Utils(object): # 根据自定义字段及数据顺序进行返回 def mysqlfinds_list(data, finds): return [dict(zip(finds, i)) for i in data] - + # sqlalchemy 原生sql转换实体列表 def msyql_table_model(data_list): return[dict(i._mapping) for i in data_list] @@ -90,7 +90,7 @@ class Utils(object): # return [dict(zip(result.keys(), [(x if x is not None else '') for x in result.values()])) for result in data_list] # except: # return [dict(zip(i.keys(), i)) for i in data_list] - + # @classmethod def to_dict(cls): return {c.name: getattr(cls, c.name, None) for c in cls.__table__.columns} @@ -167,7 +167,7 @@ class Utils(object): return round(setTem + diffValue/coeValue, 1) else: return round(setTem - diffValue/coeValue, 1) - + # # 获取最近24小时的值 # def get_24_hours(self): # # 获取当前的小时值 @@ -257,12 +257,12 @@ class Utils(object): # data_temp.append('0.0') # # 返回字段 # series_list = [{ - # "name": client_obj.client_name, + # "name": client_obj.client_name, # "type": "line", # "data": data_temp, # "markPoint":{ # "data": [ - # {"type": "max", "name": "最大值"}, + # {"type": "max", "name": "最大值"}, # {"type": "min", "name": "最小值"} # ] # }, @@ -304,6 +304,17 @@ class Utils(object): } return data + @staticmethod + def reserve_decimal(num, n=2): + """ + 保留n位小数 + :param num: 浮点数 + :param n: 小数位数 + :return: + """ + deci = "0." + "0" * n + return Decimal(num).quantize(Decimal(deci)) + if __name__ == '__main__': a = Utils.get_file_name_datetime()[:4] @@ -369,4 +380,4 @@ class CabinetStatus(object): AbnormalLightStatus = None # 异常灯是否亮 class DooropenUser(): - user_id ='' \ No newline at end of file + user_id ='' diff --git a/apps/drug/views.py b/apps/drug/views.py index f4f53bb..38836df 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -92,7 +92,7 @@ def drug_collect(): # print(k,v) # 试剂领用--事务逻辑处理 BllMedicament().drugUse( - drug_entity, + drug_entity, BllClient().findEntity(EntityClient.client_id==client_id), user_info, notes =notes @@ -116,8 +116,8 @@ def drug_return(): remain = request.values.get("remain") # 默认用户id,后续从token 中获取 # user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1' - - + + # 根据条码查询试剂信息 drug_info = BllMedicament().findEntity(EntityMedicament.bar_code==bar_code) if not drug_info: @@ -220,7 +220,7 @@ def get_drug_info(): return jsonify(Utils.true_return(data=data[0])) else: return jsonify(Utils.false_return(msg="条码有误")) - + @@ -237,7 +237,7 @@ def get_drug_manage(): page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) data_list = BllMedicament().get_drug_list( - seach_word=seach_word, + seach_word=seach_word, b_code=b_code, client_id=client_id, func_type=func_type, page_param=page_param ) @@ -306,15 +306,17 @@ def drug_set_empty_bottle(): empty_str = request.values.get("empty_str") obj = BllMedicament() drug_obj = obj.findEntity(EntityMedicament.medicament_id == drug_id) + remain_result = obj.calculate_use_drug(drug_obj, weight_remain=0) if drug_obj: if drug_obj.status == 3: return jsonify(Utils.false_return(msg="该试剂为空瓶,无需设置")) else: drug_obj.status = 3 + drug_obj.remain = 0 if empty_str: drug_obj.remark11=empty_str obj.update(drug_obj) - return jsonify(Utils.true_return()) + return jsonify(Utils.true_return(data=remain_result)) else: return jsonify(Utils.false_return(msg="试剂id有误")) @@ -591,4 +593,4 @@ def print_select_drug_code(): obj = CreateBarcode() obj.create_drug_lobel_code(**new_dict) - return jsonify(Utils.true_return(msg="打印完成")) \ No newline at end of file + return jsonify(Utils.true_return(msg="打印完成")) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index 8bcd48e..e7a75ca 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -32,10 +32,10 @@ class BllMedicament(Repository): def get_register_list(self, user, page_param): # sql_all = f""" - # select * from rms_user_apply - # where - # user_id='{user.user_id}' and - # is_solve=1 and + # select * from rms_user_apply + # where + # user_id='{user.user_id}' and + # is_solve=1 and # solve_date > DATE_SUB('{Utils.get_str_datetime()}', INTERVAL 10 hour) # """ @@ -79,8 +79,8 @@ class BllMedicament(Repository): # 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 and func_type={func_type} + # 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 @@ -239,7 +239,7 @@ class BllMedicament(Repository): filter_base += f" (`name` like '{seach_word}' or english_name like '{seach_word}') " # 搜索bar_code if b_code: - if len(b_code) > 10: + if len(b_code) > 10 and str(func_type) == "1": new_code = '' for i in range(int(len(b_code) / 2)): new_code = b_code[i*2:(i+1)*2] + new_code @@ -248,14 +248,14 @@ class BllMedicament(Repository): new_code = f"%{new_code}%" if filter_base: filter_base += " and " - filter_base += f" bar_code like '{new_code}' " - if filter_base: - if len(seach_word) > 10: - new_code = '' - for i in range(int(len(seach_word) / 2)): - new_code = seach_word[i*2:(i+1)*2] + new_code - else: - new_code = seach_word + filter_base += f" bar_code like '{new_code}' or remark12 like '{new_code}' " + # if filter_base: + # if len(seach_word) > 10: + # new_code = '' + # for i in range(int(len(seach_word) / 2)): + # new_code = seach_word[i*2:(i+1)*2] + new_code + # else: + # new_code = seach_word # TODO 确认下面这段和上面修改b_code代码作用 # new_code = f"%{new_code}%" # if filter_base: @@ -269,7 +269,7 @@ class BllMedicament(Repository): if filter_base: filter_base = f" where {filter_base}" sql_all = f""" - select * from rms_medicament {filter_base} order by put_in_date desc + select * from rms_medicament {filter_base} and status != 3 order by put_in_date desc """ try: count_number = len(self.execute(sql_all).fetchall()) @@ -379,7 +379,6 @@ class BllMedicament(Repository): drug = BllMedicament().findEntity(entityDrug.medicament_id) lastRemain = float(drug.remain) - remain_result = {"is_liquid": False, "use_volume": 0, "use_quality": 0} if entityClient.client_id not in client_list: entityDrugRecord = EntityMedicamentRecord( @@ -398,15 +397,6 @@ class BllMedicament(Repository): create_user_name=entityUser.real_name, ) - # 液体用量 = 用量质量 / 密度 - medicament_variety_obj = BllMedicamentVariety().findEntity( - EntityMedicamentVariety.variety_id == entityDrug.variety_id) - if medicament_variety_obj.net_weight_unit == 'ml' and medicament_variety_obj.density: - use_volume = (float(lastRemain) - float( - entityDrug.remain if entityDrug.remain else 0)) / medicament_variety_obj.density - entityDrugRecord.use_volume = use_volume - remain_result["is_liquid"] = True - remain_result["use_volume"] = use_volume self.session.add(entityDrugRecord) entityVariety = BllMedicamentVariety().findEntity(entityDrug.variety_id) if(entityDrug.remain != 0): @@ -417,7 +407,7 @@ class BllMedicament(Repository): self.session.merge(entityVariety) self.commitTrans() - remain_result["use_quality"] = float(lastRemain) - float(entityDrug.remain if entityDrug.remain else 0) + remain_result = self.calculate_use_drug(drug, weight_remain=float(entityDrug.remain)) return remain_result # 药剂登记 @@ -489,13 +479,13 @@ class BllMedicament(Repository): filter_base1 += f"where place='{client_place}'" # sql_all =f""" - # select DISTINCT - # `name`, speci, cas_number,net_weight_unit, purity, + # 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 + # 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""" @@ -982,6 +972,26 @@ class BllMedicament(Repository): self.session.merge(drug_entry) self.commitTrans() + @staticmethod + def calculate_use_drug(drug, weight_remain=0.0): + """ + 计算用量 + :return: {"is_liquid": 是否为液体, "use_volume": 液体用量, "use_quality": 固体用量, "net_weight_unit": 单位} + """ + medicament_variety_obj = BllMedicamentVariety().findEntity( + EntityMedicamentVariety.variety_id == drug.variety_id) + remain_result = { + "is_liquid": False, + "use_volume": 0, + "use_quality": float(drug.remain) - float(weight_remain), + "net_weight_unit": medicament_variety_obj.net_weight_unit + } + # 液体 + if medicament_variety_obj.net_weight_unit == 'ml' and medicament_variety_obj.density: + use_volume = remain_result["use_quality"] / medicament_variety_obj.density + remain_result["is_liquid"] = True + remain_result["use_volume"] = Utils.reserve_decimal(use_volume, 2) + return remain_result