From 7f1c1090f075c2094ea834e19b11e0adfd2dddb4 Mon Sep 17 00:00:00 2001 From: cxw <1056036578@qq.com> Date: Mon, 9 Jan 2023 01:48:03 +0800 Subject: [PATCH] 1 --- Common/Utils.py | 4 +++ apps/drug_template/views.py | 4 ++- apps/shengou/views.py | 63 ++++++++++++++++++++++++++++++++- apps/temporary_auth/views.py | 1 + db_logic/medicament_template.py | 7 ++-- models/medicament_models.py | 2 +- 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/Common/Utils.py b/Common/Utils.py index 4fc7c7d..b208250 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -86,6 +86,10 @@ class Utils(object): # sqlalchemy 原生sql转换实体列表 def msyql_table_model(data_list): return[dict(i._mapping) for i in data_list] + # try: + # 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): diff --git a/apps/drug_template/views.py b/apps/drug_template/views.py index a7fe288..46f0b27 100644 --- a/apps/drug_template/views.py +++ b/apps/drug_template/views.py @@ -36,13 +36,15 @@ tmp_router = Blueprint("drug_tmplate", __name__) def show_template(): client_id = request.values.get("client_id") func_type = request.values.get("func_type") + is_add = request.values.get("is_add") page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) data = BllMedicamentTemplate().getAllTemplateList( client_id=client_id, func_type=func_type, - page_param=page_param + page_param=page_param, + is_add=int(is_add) ) data = Utils.msyql_table_model(data) new_data_list = [] diff --git a/apps/shengou/views.py b/apps/shengou/views.py index 7ba7595..34bfa56 100644 --- a/apps/shengou/views.py +++ b/apps/shengou/views.py @@ -10,6 +10,9 @@ import json from flask import Blueprint, request, jsonify, g from sqlalchemy import and_, or_ from db_logic.medicament_shengou import BllMedicamntShenGou +from db_logic.medicament_template import BllMedicamentTemplate +from db_logic.client import BllClient +from models.medicament_models import EntityMedicamentTemplate from models.medicament_models import EntityMedicamntShenGou from Common.report_shen_gou import ReportData from db_logic.user import BllUser @@ -35,6 +38,7 @@ def get_shengou_list(): data_list = [] for i in data: i_dict = dict(i._mapping) + # i_dict = dict(zip(i.keys(), [(x if x is not None else '') for x in i.values()])) i_dict['user_name'] = user_dict.get(i_dict["user_id"]) i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '') i_dict["solve_user_pt_name"] = user_dict.get(i_dict["solve_user_id_pt"], '') @@ -90,13 +94,20 @@ def update_shengou(): @token_auth.login_required def solve_shengou(): shengou_id =request.values.get("id") + func_type = request.values.get("func_type") user_id = g.current_user.user_id obj = BllMedicamntShenGou().findEntity(EntityMedicamntShenGou.id == shengou_id) if obj.is_solve == 1: return jsonify(Utils.false_return(msg="已受理,无需重复受理")) if str(request.values.get('result')) == "0": + if not obj.solve_user_id: + obj.solve_user_id = user_id + else: + if user_id == obj.solve_user_id: + return jsonify(Utils.false_return(msg="不能位同一人审批")) + obj.solve_user_id_pt=user_id + obj.is_solve = 2 obj.information = request.values.get("information") - obj.is_solve = 2 else: if not obj.solve_user_id: obj.solve_user_id = user_id @@ -105,6 +116,56 @@ def solve_shengou(): return jsonify(Utils.false_return(msg="不能位同一人审批")) obj.solve_user_id_pt=user_id obj.is_solve = 1 + + + tmp_name='' + data = BllClient().get_all_client_list(func_type=func_type) + data_list = Utils.msyql_table_model(data) + tmp_content = obj.use_content + user = BllUser().findEntity(obj.user_id) + client = data_list[0] + sql_all = """ + select bar_code_count, start_bar_code from rms_medicament_template where start_bar_code=(select max(start_bar_code) max_start from rms_medicament_template) + """ + # 获取最大的条形码和条形码数量 + tmp_obj = BllMedicamentTemplate().execute(sql_all).fetchone() + if tmp_obj: + max_barcode = int(tmp_obj.start_bar_code) + int(tmp_obj.bar_code_count) + else: + max_barcode = 100001 + start_bar_code = max_barcode + + try: + if not tmp_content or tmp_content == 'null': + return jsonify(Utils.false_return(msg="模板内容有误")) + if not tmp_name: + tmp_name = f'入库模板_{Utils.getFileName()}' + if isinstance(tmp_content, str): + # tmp_content = eval(tmp_content) + tmp_content = json.loads(tmp_content) + bar_code_count = 0 + for i in tmp_content: + bar_code_count += int(i['export_count']) + + obj1 = EntityMedicamentTemplate( + customer_id='1002437b-debf-46d6-b186-3e16bcf0cc0f', + client_id=client["client_id"], + client_name=client["client_name"], + template_name=tmp_name, + func_type=func_type, + template_content=json.dumps(tmp_content), + is_wait_export=1, + start_bar_code=start_bar_code, + bar_code_count=bar_code_count, + create_date=Utils.get_str_datetime(), + create_user_id=user.user_id, + create_user_name=user.real_name, + is_add=1 + ) + BllMedicamentTemplate().insert(obj1) + except Exception as e: + print(e) + obj.solve_date = Utils.get_str_datetime() BllMedicamntShenGou().update(obj) return jsonify(Utils.true_return()) diff --git a/apps/temporary_auth/views.py b/apps/temporary_auth/views.py index 90fd2ee..db70ff8 100644 --- a/apps/temporary_auth/views.py +++ b/apps/temporary_auth/views.py @@ -113,6 +113,7 @@ def get_info_list(): data_list = [] for i in data: i_dict = dict(i._mapping) + # i_dict = dict(zip(i.keys(), [(x if x is not None else '') for x in i.values()])) i_dict['user_name'] = user_dict.get(i_dict["user_id"]) i_dict["user_name_pt"] = user_dict.get(i_dict["user_id_pt"]) i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '') diff --git a/db_logic/medicament_template.py b/db_logic/medicament_template.py index 318e3a3..660a946 100644 --- a/db_logic/medicament_template.py +++ b/db_logic/medicament_template.py @@ -21,16 +21,17 @@ class BllMedicamentTemplate(Repository): return super().__init__(entityType) # 获取所有模板列表 - def getAllTemplateList(self, client_id, func_type, page_param): + def getAllTemplateList(self, client_id, func_type, page_param,is_add=0): filter_base = "" + filter_base += f" is_add='{is_add}' " if client_id: - filter_base += f" client_id='{client_id}' " + filter_base += f" and client_id='{client_id}' " if func_type: if filter_base: filter_base += " and " filter_base += f" func_type='{func_type}' " if filter_base: - filter_base = f" where {filter_base} " + filter_base = f" where {filter_base} " sql_all = f"select * from rms_medicament_template {filter_base} order by create_date desc" try: count_number = len(self.execute(sql_all).fetchall()) diff --git a/models/medicament_models.py b/models/medicament_models.py index 25a3698..fea5171 100644 --- a/models/medicament_models.py +++ b/models/medicament_models.py @@ -138,7 +138,7 @@ class EntityMedicamentTemplate(Base): create_date = Column(String(50), comment="创建日期") create_user_id = Column(String(50), comment="创建用户ID") create_user_name = Column(String(50), comment="创建用户名") - is_add = Column(Integer, comment="", default=0) + is_add = Column(Integer, comment="是否采购单生成", default=0) @classmethod def get_finds(cls):