You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yy_rms_39zhiyao_duizhao/db_logic/user_medicament.py

90 lines
2.7 KiB

#!/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