试剂管理-禁用;

msds数据库
duizhaopin
apan 2 years ago
parent d16a0aab41
commit 39782b3d90

@ -7,10 +7,13 @@ import datetime
from flask import jsonify, request, g
from flask import Blueprint
from db_logic.client import BllClient
from db_logic.dangerous import BllDangerous
from db_logic.medicament import BllMedicament
from db_logic.medicament_record import BllMedicamentRecord
from db_logic.msds import BllMsDs
from db_logic.user_medicament import BllUserMedicament
from models.medicament_models import EntityMedicament
from models.client_models import EntityClient
from Common.Utils import DrugStatus, PageParam, Utils
@ -149,7 +152,7 @@ def get_drug_manage():
# 编辑数据
@drug_router.route("/add_update", methods=["GET", "POST"])
@drug_router.route("/update", methods=["GET", "POST"])
@token_auth.login_required
def drug_add_update():
finds_list = [
@ -157,7 +160,6 @@ def drug_add_update():
"purity", "shelf_life", "production_date", "expiration_date",
"use_days_warning_value", "shelf_life_warning_value",
"inventory_warning_value", "speci", "net_weight_unit", "net_weight",
# 缺少说明字段
"is_supervise", "is_weigh"
]
medicament_id = request.values.get("medicament_id")
@ -185,15 +187,72 @@ def get_durg_record():
#################################
##验证通过后需要添加至试剂领用处。##
#################################
# 分配禁用用户
@drug_router.route("/user_ban_list", methods=["GET", "POST"])
# @token_auth.login_required
def drug_ban_user_list():
seach_user = request.values.get("seach_user")
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data_list = BllUserMedicament().get_user_jin_medicament(seach_user=seach_user, page_param=page_param)
return jsonify(Utils.true_return(data={"data": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
# 确认禁用
@drug_router.route("/user_ban_confirm", methods=["GET", "POST"])
# @token_auth.login_required
def drug_ban_user_confirm():
user_id = request.values.get("user_id")
drug_id = request.values.get("drug_id")
data = BllUserMedicament().inster_user_drug(user_id, drug_id)
if data:
return jsonify(Utils.true_return())
else:
return jsonify(Utils.false_return())
# 获取用户禁用试剂列表
@drug_router.route("/user_ban_drug_list", methods=["GET", "POST"])
def get_user_ban_drug_list():
user_id = request.values.get("user_id")
data_list = BllUserMedicament().get_user_drug_name(user_id)
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list)))
# 取消禁用试剂
@drug_router.route("/user_ban_relieve", methods=["GET", "POST"])
def user_ban_relieve():
user_id = request.values.get("user_id")
drug_list = request.values.get("drug_list")
data = BllUserMedicament().del_user_ban_drug(user_id=user_id, drug_list=drug_list)
if data:
return jsonify(Utils.true_return(msg="删除成功"))
else:
return jsonify(Utils.false_return(msg="删除失败"))
# msds数据展示
@drug_router.route("/msds_db_list", methods=["GET", "POST"])
def get_msds_list():
seach_word = request.values.get("seach_word")
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data_list = BllMsDs().get_seach_list(seach_word=seach_word, page_param=page_param)
return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_cout": page_param.totalRecords}))
# 危化品数据展示
@drug_router.route("/dangerous_db_list", methods=["GET", "POST"])
def get_dangerous_list():
seach_word = request.values.get("seach_word")
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data_list = BllDangerous().get_seach_list(seach_word=seach_word, page_param=page_param)
return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_cout": page_param.totalRecords}))

@ -3,6 +3,6 @@ clientid = 000
customer_id = 1
serverip = 0.0.0.0
port = 9001
# dbconntion = mysql+pymysql://root:123456@127.0.0.1/local_rms_db?charset=utf8
dbconntion = mysql+pymysql://root:123456@127.0.0.1/local_rms_db?charset=utf8
# dbconntion = mysql+pymysql://yanyi:tangyan86910282@111.231.67.55/yy_rms_multiple?charset=utf8
dbconntion = mysql+pymysql://root:tangyan86910282@127.0.0.1/yy_rms_multiple?charset=utf8
# dbconntion = mysql+pymysql://root:tangyan86910282@127.0.0.1/yy_rms_multiple?charset=utf8

@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/08/08 15:24:09
'''
import sys
sys.path.append('.')
from db_logic.db_base import Repository
from models.msds_dangerous_models import EntityDangerous
from Common.Utils import Utils
#用户操作业务逻辑类
class BllDangerous(Repository):
def __init__(self, entityType=EntityDangerous):
super().__init__(entityType)
def get_seach_list(self, seach_word, page_param):
filter_base = ""
if seach_word:
seach_word = f"'%{seach_word}%'"
filter_base += f" name like {seach_word} or english_name like {seach_word}"
sql_all = f"""
select * from rms_msds {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()

@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/08/08 15:17:46
'''
import sys
sys.path.append('.')
from sqlalchemy import and_
from db_logic.db_base import Repository
from models.msds_dangerous_models import EntityMsDs
from Common.Utils import Utils
#用户操作业务逻辑类
class BllMsDs(Repository):
def __init__(self, entityType=EntityMsDs):
super().__init__(entityType)
def get_seach_list(self, seach_word, page_param):
filter_base = ""
if seach_word:
seach_word = f"'%{seach_word}%'"
filter_base += f" name like {seach_word} or english_name like {seach_word}"
sql_all = f"""
select * from rms_msds {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()

@ -0,0 +1,90 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/08/08 13:17:47
'''
import sys
from Common.Utils import Utils
sys.path.append('.')
from sqlalchemy import and_
from db_logic.db_base import Repository
from models.user_models import EntityUserMedicament
class BllUserMedicament(Repository):
def __init__(self, entityType=EntityUserMedicament):
super().__init__(entityType)
def is_jin_zhi_user(self, user_id, drug_id):
obj = self.findEntity(and_(
EntityUserMedicament.user_id==user_id,
EntityUserMedicament.drug_id==drug_id
))
# 无记录返回True
# 有记录返回Flase
if obj:
return False
else:
return True
def get_user_jin_medicament(self, seach_user, page_param):
filter_base = ""
if seach_user:
filter_base += f" real_name like '%{seach_user}%'"
if filter_base:
filter_base = f" where {filter_base}"
sql_all = f"""
select
a.user_id, b.real_name, b.role_name, group_concat(c.`name`) drug_name
from rms_user_medicament as a
LEFT JOIN (select real_name, user_id, role_name from rms_user {filter_base})
as b on a.user_id=b.user_id
LEFT JOIN rms_medicament_variety as c on a.drug_id=c.variety_id
GROUP BY a.user_id
"""
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_user_drug_name(self, user_id):
sql_all = f"""
SELECT b.variety_id, b.`name` from (
select * from rms_user_medicament where user_id= '{user_id}'
) a LEFT JOIN rms_medicament_variety as b on a.drug_id=b.variety_id
"""
return self.execute(sql_all).fetchall()
def del_user_ban_drug(self, user_id, drug_list):
try:
data_list = self.findList(and_(
EntityUserMedicament.user_id==user_id,
EntityUserMedicament.drug_id.in_(eval(drug_list))
)).all()
for i in data_list:
self.session.delete(i)
self.session.commit()
return True
except:
return False
def inster_user_drug(self, user_id, variety_id):
try:
obj = EntityUserMedicament(
user_id=user_id,
drug_id=variety_id
)
self.insert(obj)
return True
except:
return False

@ -41,7 +41,7 @@ class EntityMedicament(Base):
inventory_warning_value = Column(Integer, comment="库存")
shelf_life_warning_value = Column(Integer, comment="保质期到期提前预警天数")
use_days_warning_value = Column(Integer, comment="使用超期预警天数")
is_weigh = Column(Integer, default=1, comment="是否称重")
is_weigh = Column(Integer, default=0, comment="是否称重")
weigh_flag = Column(Integer, default=0, comment="称重标志")
remain = Column(String(50), comment="库存余量")
@ -60,14 +60,14 @@ class EntityMedicament(Base):
cell_position_code = Column(String(50), comment="试剂所在抽屉位置信息")
place = Column(String(50), comment="位置")
status = Column(Integer, comment="当前状态1在库2出库3空瓶")
is_supervise = Column(Integer, comment="是否监管")
is_supervise = Column(Integer, comment="是否监管", default=0)
by_user_date = Column(String(50), comment="最后使用日期")
by_user_id = Column(String(50), comment="最后使用人ID")
by_user_name = Column(String(50), comment="最后使用人名称")
put_in_date = Column(String(50), comment="入库日期")
put_in_user_id = Column(String(50), comment="入库用户ID")
put_in_user_name = Column(String(50), comment="入库用户名")
is_add = Column(Integer, comment="")
is_add = Column(Integer, comment="", default=0)
user_auditing = Column(String(50), comment="用户审计")
remark1 = Column(String(50), comment='扩展字段1')
@ -116,7 +116,7 @@ class EntityMedicamentTemplate(Base):
client_name = Column(String(50), comment="终端名称")
template_name = Column(String(50), comment="模板名称")
template_content = Column(Text, comment="模板内容")
is_wait_export = Column(Integer, comment="是否等待导入")
is_wait_export = Column(Integer, comment="是否等待导入", default=0)
template_base64 = Column(Text, comment="模板Base64值")
start_bar_code = Column(String(50), comment="开始条形码")
bar_code_count = Column(Integer, comment="条形码数量")
@ -177,7 +177,7 @@ class EntityMedicamentVariety(Base):
net_weight = Column(String(50), comment="净含量")
tp = Column(String(50), comment="类型")
is_supervise = Column(Integer, comment="是否监管")
is_supervise = Column(Integer, comment="是否监管", default=0)
inventory_warning_value = Column(Integer, comment="库存预警量")
shelf_life_warning_value = Column(Integer, comment="保质期到期提前预警天数")
use_days_warning_value = Column(Integer, comment="领用超期预警天数")

@ -0,0 +1,63 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/08/08 14:32:29
'''
import sys
sys.path.append('.')
from sqlalchemy import Text, String, Integer, Column
from models.models_base import Base, get_uuid
class ModelBase(Base):
__abstract__ = True
id = Column(String(50), primary_key=True,comment="id", default=get_uuid)
name = Column(Text, comment="药剂名称")
english_name = Column(Text, comment="英文名称")
cas_number = Column(String(50), comment="药剂cas码")
molecular_formula = Column(String(50), comment="分子式")
molecular_weight = Column(String(50), comment="分子量")
physical_data = Column(Text, comment="物理数据")
toxicity_data = Column(Text, default="", comment="毒性数据")
use = Column(Text, default="", comment="用途")
stability = Column(Text, default="", comment="稳定性")
ecological = Column(Text, default="", comment="生态性")
precautions = Column(Text, default="", comment="注意事项")
storage_method = Column(Text, default="", comment="存储方法")
client_storage_require = Column(Text, default="", comment="柜体存储要求")
provision = Column(String(50), default="", comment="领用归还规定")
class EntityMsDs(ModelBase):
__tablename__ = "rms_msds"
__table_args__ = (
{
"comment": "msds数据库"
}
)
class EntityDangerous(ModelBase):
__tablename__ = "rms_dangerous"
__table_args__ = (
{
"comment": "危化品数据库"
}
)
drug_attribute = Column(String(50), comment="试剂属性")
storage_taboo = Column(Text, comment="存储禁忌")
if __name__ == '__main__':
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config.SystemConfig import SystemConfig
from sqlalchemy.pool import NullPool
engine = create_engine(SystemConfig.getConfig(
'dbconntion'), poolclass=NullPool)
DBSession = sessionmaker(bind=engine, expire_on_commit=False)
# 创建session对象
session = DBSession()
Base.metadata.create_all(engine)

@ -73,3 +73,45 @@ class EntityRole(Base):
is_enabled = Column(Integer, comment="是否启用", default=1)
description = Column(String(50), comment="备注")
is_add = Column(Integer, comment="", default=1)
# 禁用用户
class EntityUserMedicament(Base):
__tablename__ = "rms_user_medicament"
__table_args__ = (
{
"comment": "用户试剂权限"
}
)
id = Column(String(50), primary_key=True, comment="ID", default=get_uuid)
user_id = Column(String(50),comment="用户ID")
drug_id = Column(String(50), comment="试剂ID")
# # 用户终端限制
# class EntityClientUser(Base):
# __tablename__ = "rms_client_user"
# __table_args__ = (
# {
# "comment": "用户终端权限"
# }
# )
# id = Column(String(50), primary_key=True, comment="ID", default=get_uuid)
# client_id = Column(String(50),comment="终端id")
# user_id = Column(String(50), comment="用户ID")
if __name__ == '__main__':
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config.SystemConfig import SystemConfig
from sqlalchemy.pool import NullPool
engine = create_engine(SystemConfig.getConfig(
'dbconntion'), poolclass=NullPool)
DBSession = sessionmaker(bind=engine, expire_on_commit=False)
# 创建session对象
session = DBSession()
Base.metadata.create_all(engine)

Loading…
Cancel
Save