parent
d16a0aab41
commit
39782b3d90
@ -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
|
@ -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)
|
Loading…
Reference in new issue