From 64f50d8fff8117d2aa49c5b6ff0ab9308850d074 Mon Sep 17 00:00:00 2001 From: tangxuan <2233783319@qq.com> Date: Thu, 23 Mar 2023 23:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=8F=90=E4=BA=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/drug/views.py | 81 ++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/apps/drug/views.py b/apps/drug/views.py index f508855..8113280 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -372,26 +372,36 @@ def get_dangerous_list(): # @token_auth.login_required def save_drug_img_info(): # 药剂类别 - variety_id = request.values.get("variety_id") - medicament_id = request.values.get("medicament_id") - file_base64 = request.files.get("file") + # variety_id = request.values.get("variety_id") + # medicament_id = request.values.get("medicament_id") + if request.values.get("selected"): + medicament_list = json.loads(request.values.get("selected")) + else: + medicament_list = [{ + "variety_id": request.values.get("variety_id"), + "medicament_id": request.values.get("medicament_id"), + }] + # try: gaopaiyi_obj = GaoPaiYi() img_path = f"{Utils.UUID()}.jpg" file_base64.save(os.path.join(gaopaiyi_obj.path, img_path)) - # 根据条码查询试剂信息 - drug_info = BllMedicament().findEntity( - EntityMedicament.medicament_id == medicament_id) - if not drug_info: - return jsonify(Utils.false_return(msg="试剂信息有误")) - obj = EntityMedicamentRelationImage( - name=drug_info.name, - variety_id=variety_id, - medicament_id=medicament_id, - pic_url=img_path, - create_date=Utils.get_str_datetime(), - ) - BllMedicamentRelationImage().insert(obj) + for medicament in medicament_list: + variety_id = medicament.get("variety_id") + medicament_id = medicament.get("medicament_id") + # 根据条码查询试剂信息 + drug_info = BllMedicament().findEntity( + EntityMedicament.medicament_id == medicament_id) + if not drug_info: + return jsonify(Utils.false_return(msg="试剂信息有误")) + obj = EntityMedicamentRelationImage( + name=drug_info.name, + variety_id=variety_id, + medicament_id=medicament_id, + pic_url=img_path, + create_date=Utils.get_str_datetime(), + ) + BllMedicamentRelationImage().insert(obj) return jsonify(Utils.true_return(msg="上传成功")) @@ -405,24 +415,33 @@ def get_drug_img(img_path): @token_auth.login_required def use_gaopaiyi(): # 药剂类别 - variety_id = request.values.get("variety_id") - medicament_id = request.values.get("medicament_id") + # variety_id = request.values.get("variety_id") + # medicament_id = request.values.get("medicament_id") + if request.values.get("selected"): + medicament_list = json.loads(request.values.get("selected")) + else: + medicament_list = [{ + "variety_id": request.values.get("variety_id"), + "medicament_id": request.values.get("medicament_id"), + }] pic_data = GaoPaiYi().getPic() if pic_data['code'] == 0: - - # 根据条码查询试剂信息 - drug_info = BllMedicament().findEntity( - EntityMedicament.medicament_id == medicament_id) - - obj = EntityMedicamentRelationImage( - name=drug_info.name, - variety_id=variety_id, - medicament_id=medicament_id, - pic_url=pic_data['path'], - create_date=Utils.get_str_datetime(), - ) - BllMedicamentRelationImage().insert(obj) + for medicament in medicament_list: + variety_id = medicament.get("variety_id") + medicament_id = medicament.get("medicament_id") + # 根据条码查询试剂信息 + drug_info = BllMedicament().findEntity( + EntityMedicament.medicament_id == medicament_id) + + obj = EntityMedicamentRelationImage( + name=drug_info.name, + variety_id=variety_id, + medicament_id=medicament_id, + pic_url=pic_data['path'], + create_date=Utils.get_str_datetime(), + ) + BllMedicamentRelationImage().insert(obj) data = Utils.true_return(msg="高拍仪拍照成功") else: data = Utils.false_return(msg=pic_data['msg'])