调试试剂领用/归还接口

duizhaopin
apan 2 years ago
parent f41fc83dcb
commit 4c7aa7483b

@ -66,6 +66,10 @@ class Utils(object):
# sqlalchemy 原生sql转换实体列表
def msyql_table_model(data_list):
return[dict(i._mapping) for i in data_list]
# @classmethod
def to_dict(cls):
return {c.name: getattr(cls, c.name, None) for c in cls.__table__.columns}
#生成统一格式接口数据
def resultData(status, message, data=""):

@ -25,8 +25,12 @@ drug_router = Blueprint("drug", __name__)
def drug_collect():
# 获取参数
bar_code = request.values.get("bar_code")
user_id=request.values.get("user_id")
force_use = request.values.get("force_use", "False")
# user_id=request.values.get("user_id")
# 默认用户id后续从token 中获取
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
# 强制使用默认0不强制1强制
force_use = request.values.get("force_use")
force_use = force_use if force_use != '' else '0'
# 获取条码试剂
drug_entity = BllMedicament().findEntity(EntityMedicament.bar_code==bar_code)
@ -34,6 +38,7 @@ def drug_collect():
if not drug_entity:
data = Utils.false_return(msg="药剂条码无效")
elif drug_entity.status not in [DrugStatus.Normal, DrugStatus.Empty]:
print(drug_entity.status)
data = Utils.false_return(msg="药剂未在库")
elif drug_entity.status == DrugStatus.Empty:
data = Utils.false_return(msg="药剂已为空瓶")
@ -43,9 +48,11 @@ def drug_collect():
# 获取临期的试剂
drug_obj = BllMedicament().getDrugNearExpired(drug_entity.variety_id, customer_id)
date_str = lambda x: datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
drug_obj_date_str = date_str(drug_obj.expiration_date)
drug_entity_date_str = date_str(drug_entity.expiration_date)
# date_str = lambda x: datetime.datetime.strptime('', "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
# drug_obj_date_str = date_str(drug_obj.expiration_date)
drug_obj_date_str = datetime.datetime.strptime(drug_obj.expiration_date, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
# drug_entity_date_str = date_str(drug_entity.expiration_date)
drug_entity_date_str = datetime.datetime.strptime(drug_entity.expiration_date, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
if drug_obj.medicament_id != drug_entity.medicament_id and force_use == "False" and drug_obj_date_str != drug_entity_date_str:
data = Utils.false_return(status=2, msg=f'"{drug_entity.name}({drug_entity.bar_code})"此类药有更接近保质期的实例"{drug_obj.bar_code}", 存在于"{drug_obj.client_code}"号终端')
else:
@ -55,13 +62,16 @@ def drug_collect():
drug_entity.by_user_id=user_info.user_id
drug_entity.by_user_name=user_info.real_name
drug_entity.status=DrugStatus.Out
# print(Utils.to_dict(drug_entity))
# for k,v in drug_entity:
# print(k,v)
# 试剂领用--事务逻辑处理
BllMedicament().drugUse(
drug_entity,
BllClient().findEntity(EntityClient.client_id==client_id),
user_info
)
data = Utils.true_return(msg='领用成功',data=Utils.resultAlchemyData(drug_entity))
data = Utils.true_return(msg='领用成功', data=Utils.to_dict(drug_entity))
return jsonify(data)
@ -71,7 +81,9 @@ def drug_return():
# 获取参数
bar_code = request.values.get("bar_code")
place = request.values.get("place")
user_id = request.values.get("user_id")
# user_id = request.values.get("user_id")
# 默认用户id后续从token 中获取
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
# 根据条码查询试剂信息
@ -87,7 +99,7 @@ def drug_return():
drug_info.place = place
user_info = BllUser().findEntity(EntityUser.user_id == user_id)
BllMedicament().drugReturn(drug_info, BllClient().findEntity(drug_info.client_id), user_info)
data = Utils.true_return(msg="药剂归还成功", data=Utils.resultAlchemyData(drug_info))
data = Utils.true_return(msg="药剂归还成功", data=Utils.to_dict(drug_info))
return jsonify(data)
@ -99,7 +111,7 @@ def drug_use_retur_list():
page_size = request.values.get("page_size", 10)
page_param = PageParam(page, page_size)
data = BllMedicament().drug_use_return(status=status, page_param=page_param)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data}))
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": Utils.msyql_table_model(data)}))
# 试剂称重展示试剂详细信息

@ -23,12 +23,12 @@ class BllModuleRelation(Repository):
SELECT a.module_id, b.module_code, b.sort_index, b.module_name
from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id
WHERE object_id='{user_id}' AND object_type=2 AND b.module_type=1
WHERE object_id='{user_id}' AND object_type=2 AND b.module_type=2
UNION
SELECT a.module_id, b.module_code, b.sort_index, b.module_name
from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id
WHERE object_id='{role_id}' AND object_type=1 AND b.module_type=1
WHERE object_id='{role_id}' AND object_type=1 AND b.module_type=2
) c ORDER BY c.sort_index asc
"""
return self.execute(sql_all).fetchall()
@ -57,11 +57,13 @@ if __name__ == '__main__':
module_list = BllModuleRelation().get_user_module_list(
user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1', role_id='a699ff99-117b-11ed-a086-f47b094925e5')
module_list = Utils.msyql_table_model(module_list)
if len(module_list) > 6:
for module in module_list:
if module["module_code"] == "DataReport":
if module_list.index(module) in [1,2,4]:
module_list.pop(module_list.index(module))
module_list.insert(5, module)
# if len(module_list) > 6:
# for module in module_list:
# if module["module_code"] == "DataReport":
# if module_list.index(module) in [1,2,4]:
# module_list.pop(module_list.index(module))
# module_list.insert(5, module)
data = module_list
for i in data:
print(data)

@ -300,6 +300,9 @@ object_type=2 查询用户id
object_type=1 查询权限id
出库超期预警用户 12345 已领用 甲烷(123123123)3超过预警线, 1
药剂保质期预警药剂 甲烷(123123123)超过保质期预警线, 当前时间:%Y-%m-%d %H:%M:%S;设定警戒线10;位置:11号柜1-2-3
"""

@ -19,7 +19,7 @@ class EntityModule(Base):
)
module_id = Column(String(50), primary_key=True, comment="模块ID", default=get_uuid)
module_type = Column(String(50), comment="模块类型")
module_type = Column(String(50), comment="模块类型(1柜体,2后台)")
module_code = Column(String(50), comment="")
module_name = Column(String(50), comment="模块名称")
icon = Column(String(50), comment="图片")
@ -49,7 +49,7 @@ class EntityModuleRelation(Base):
customer_id = Column(String(50), comment="客户id")
object_type = Column(String(50), comment="类型")
object_id = Column(String(50), comment="类型id")
module_type = Column(String(50), comment="模块类型")
module_type = Column(String(50), comment="模块类型(1柜体,2后台)")
module_id = Column(String(50), comment="模块id")
create_date = Column(String(50), comment="创建时间")
create_user_id = Column(String(50), comment="创建用户id")

Loading…
Cancel
Save