From 938d1da43d18e11069bb7d41b5f47fc9c638659b Mon Sep 17 00:00:00 2001 From: apan Date: Fri, 5 Aug 2022 18:05:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=89=82=E7=AE=A1=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E3=80=81=E6=B5=81=E8=BD=AC=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/drug/views.py | 36 ++++++++++++++++++++++++----------- db_logic/medicament.py | 21 ++++++++++++++++++++ db_logic/medicament_record.py | 7 ++----- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/apps/drug/views.py b/apps/drug/views.py index 0118bc9..04e6135 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -6,14 +6,12 @@ import datetime from flask import jsonify, request, g from flask import Blueprint -from sqlalchemy import and_ from db_logic.client import BllClient from db_logic.medicament import BllMedicament +from db_logic.medicament_record import BllMedicamentRecord from models.medicament_models import EntityMedicament -from db_logic.user import BllUser -from models.user_models import EntityUser from models.client_models import EntityClient from Common.Utils import DrugStatus, PageParam, Utils from Common.auth import token_auth @@ -134,18 +132,23 @@ def get_drug_info(): # 试剂管理 -@drug_router.route("/drug_manage", methods=["GET", "POST"]) +@drug_router.route("/drug_list", methods=["GET", "POST"]) @token_auth.login_required def get_drug_manage(): seach_word = request.values.get("seach_word") client_id = request.values.get("client_id") - data_list = BllMedicament().get_drug_info_distinct_list(seach_word=seach_word, client_id=client_id) + page = int(request.values.get("page", 1)) + 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, client_id=client_id, page_param=page_param + ) return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list))) -# 编辑/新增数据 +# 编辑数据 @drug_router.route("/add_update", methods=["GET", "POST"]) @token_auth.login_required def drug_add_update(): @@ -161,13 +164,24 @@ def drug_add_update(): bar_code = request.values.get("bar_code") medicament_obj = BllMedicament().findEntity(medicament_id) if medicament_id: - obj = BllMedicament().findEntity( - and_( - EntityMedicament.bar_code == bar_code) - ) - return Utils.true_return() + obj = BllMedicament().findEntity(EntityMedicament.bar_code == bar_code) + if obj.medicament_id == medicament_obj.medicament_id: + for i in finds_list: + setattr(medicament_obj, i, request.values.get(i)) + BllMedicament().update(medicament_obj) + else: + return jsonify(Utils.true_return(msg="条码不能重复")) + return jsonify(Utils.true_return(msg="试剂id不能为空")) # 流转记录 +@drug_router.route("/get_durg_record", methods=["GET", "POST"]) +@token_auth.login_required +def get_durg_record(): + page = int(request.values.get("page", 1)) + page_size = int(request.values.get("page_size", 10)) + page_param = PageParam(page, page_size) + data_list = BllMedicamentRecord().get_drug_flow_log(page_param=page_param) + return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count":page_param.totalRecords})) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index 76bdcba..8cddedc 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -105,6 +105,27 @@ class BllMedicament(Repository): ) return self.queryPage(orm_query, pageParam) + # 试剂管理 + def get_drug_list(self, client_id, seach_word, page_param): + filter_base = "" + if client_id: + filter_base += f" client_id='{client_id}' " + if seach_word: + seach_word = f"%{seach_word}%" + if filter_base: + filter_base += " and " + filter_base += f" `name` like '{seach_word}' or english_name like '{seach_word}' " + sql_all = f""" + select * from rms_medicament {filter_base} + """ + try: + count_number = len(self.execute(sql_all).fetchall()) + except Exception: + count_number = 0 + page_param.totalRecords=count_number + page_sql = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(page_sql).fetchall() + # 选择药剂入库--试剂详情 def get_drug_info_distinct_list(self, seach_word, page_param, client_id=None): sql_all = """ diff --git a/db_logic/medicament_record.py b/db_logic/medicament_record.py index 3697ffc..b51c1da 100644 --- a/db_logic/medicament_record.py +++ b/db_logic/medicament_record.py @@ -43,11 +43,8 @@ class BllMedicamentRecord(Repository): """ count_sql = "select count(*) from rms_medicament_record" page_param.totalRecords = self.execute(count_sql).fetchone()[0] - sql_all += ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows) - data = Utils.msyql_table_model(self.execute(sql_all)) - # print(data) - return data - # return self.execute(sql_all) + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() # #获取指定用户流转记录 # def getUserDrugRecordList(self, pageParam, customerId, userId=None):