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.
184 lines
6.8 KiB
184 lines
6.8 KiB
#!/usr/bin/env python
|
|
# -*- encoding: utf-8 -*-
|
|
'''
|
|
@Date: 2022/12/14 15:15:48
|
|
'''
|
|
import sys
|
|
sys.path.append('.')
|
|
|
|
import json
|
|
from db_logic.db_base import Repository
|
|
from models.power_models import EntityUserApply
|
|
from Common.Utils import Utils
|
|
from sqlalchemy import and_
|
|
from db_logic.medicament import BllMedicament
|
|
from models.medicament_models import EntityMedicament
|
|
|
|
class BllUserApply(Repository):
|
|
|
|
def __init__(self, entityType=EntityUserApply):
|
|
super().__init__(entityType)
|
|
|
|
# 根据用户角色进行列表返回
|
|
def get_list_info(self, func_type, page_param, user):
|
|
fileter_base = ""
|
|
# if client_id:
|
|
# fileter_base += f" client_id='{client_id}'"
|
|
if func_type:
|
|
if fileter_base:
|
|
fileter_base += " and "
|
|
fileter_base += f" func_type={func_type}"
|
|
if user.role_name == "普通用户":
|
|
if fileter_base:
|
|
fileter_base += " and "
|
|
fileter_base += f" user_id = '{user.user_id}'"
|
|
if user.user_id not in ["19b08f17-e517-47f0-8086-feaf513f7615"]:
|
|
if fileter_base:
|
|
fileter_base += " and "
|
|
fileter_base += f" (solve_user_id_sh != '' or user_id = '{user.user_id}')"
|
|
if fileter_base:
|
|
fileter_base = f" where {fileter_base}"
|
|
"""
|
|
select a.*, b.client_name from (
|
|
select * from rms_user_apply {fileter_base}
|
|
) a LEFT JOIN (
|
|
select * from rms_client
|
|
) b on a.client_id=b.client_id
|
|
order by a.create_date desc
|
|
|
|
"""
|
|
sql_all = f"""
|
|
select * from rms_user_apply {fileter_base} order by is_solve asc, create_date desc
|
|
|
|
"""
|
|
try:
|
|
count_number = self.execute(f"select count(*) num from rms_user_apply {fileter_base} order by create_date desc").fetchone().num
|
|
except Exception:
|
|
count_number = 0
|
|
if page_param:
|
|
page_param.totalRecords = count_number
|
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
|
return self.execute(sql_all).fetchall()
|
|
|
|
|
|
def update_use_content(self, client_id, user, drug_info):
|
|
sql_all = f"""
|
|
select * from rms_user_apply
|
|
where
|
|
user_id='{user.user_id}' and
|
|
is_solve=1 and
|
|
solve_date > DATE_SUB('{Utils.get_str_datetime()}', INTERVAL 10 hour)
|
|
|
|
"""
|
|
data = self.execute(sql_all).fetchall()
|
|
break_bool = True
|
|
apply_data=''
|
|
num =''
|
|
for d in data:
|
|
if not break_bool:
|
|
break
|
|
use_content = json.loads(d.use_content)
|
|
for j in range(len(use_content)):
|
|
con_info = use_content[j]
|
|
if con_info["client_id"] == client_id:
|
|
# if con_info["name"] == drug_info.name and con_info["purity"] == drug_info.purity and con_info["speci"] == drug_info.speci:
|
|
if con_info["medicament_id"] == drug_info.medicament_id:
|
|
con_info["use_num"] = 1
|
|
# if int(con_info["use_num"]) < int(con_info["num"]):
|
|
# con_info["use_num"] += 1
|
|
break_bool = False
|
|
apply_data =d
|
|
num =len(use_content)
|
|
|
|
if apply_data and num:
|
|
use_num=0
|
|
use_content1 = json.loads(apply_data.use_content)
|
|
for i in range(len(use_content1)):
|
|
con_info = use_content1[i]
|
|
if con_info.get("use_num"):
|
|
use_num +=1
|
|
|
|
obj = self.findEntity(self.entityType.id == d.id)
|
|
obj.use_content = json.dumps(use_content)
|
|
if use_num >=num:
|
|
obj.is_solve =3
|
|
#设置申请单完成
|
|
self.update(obj)
|
|
|
|
# 获取待领用列表
|
|
def get_stay_use_list(self, client_id, user_id):
|
|
client_list=[client_id]
|
|
if client_id =='72e70542-b70d-11e8-aea5-448a5bc6c411':
|
|
client_list.extend(['72e70542-b70d-11e8-aea5-448a5bc6c412','72e70542-b70d-11e8-aea5-448a5bc6c413','72e70542-b70d-11e8-aea5-448a5bc6c414'])
|
|
if client_id =='72e70542-b70d-11e8-aea5-448a5bc6c415':
|
|
client_list.extend(['72e70542-b70d-11e8-aea5-448a5bc6c416'])
|
|
print(client_list)
|
|
sql_all = f"""
|
|
select * from rms_user_apply
|
|
where
|
|
user_id='{user_id}' and
|
|
is_solve=1 and
|
|
solve_date > DATE_SUB('{Utils.get_str_datetime()}', INTERVAL 10 hour)
|
|
|
|
"""
|
|
data = self.execute(sql_all).fetchall()
|
|
data_list = []
|
|
for i in data:
|
|
use_content = json.loads(i.use_content)
|
|
for j_index in range(len(use_content)):
|
|
j = use_content[j_index]
|
|
if j["client_id"] not in client_list:
|
|
continue
|
|
if not j.get("use_num"):
|
|
# j["stay_use_num"] = j.get("use_num")
|
|
drugobj =BllMedicament().findEntity(and_(EntityMedicament.status==1,EntityMedicament.medicament_id == j.get("medicament_id")))
|
|
print(drugobj,'889898989898989')
|
|
if drugobj:
|
|
data_list.append(j)
|
|
print(data_list)
|
|
return data_list
|
|
|
|
|
|
def get_apply_list(self,user1,user2):
|
|
print(user1,user2)
|
|
sql_all = f"""
|
|
select * from rms_user_apply
|
|
where
|
|
user_id='{user1.user_id}' and user_id_pt='{user2.user_id}' and
|
|
is_solve=1 and
|
|
solve_date > DATE_SUB('{Utils.get_str_datetime()}', INTERVAL 10 hour)
|
|
|
|
"""
|
|
print(sql_all)
|
|
data = self.execute(sql_all).fetchall()
|
|
print(data)
|
|
if data:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def get_apply_solve_user_list(self):
|
|
"""
|
|
获取所有管理员以及审批通过的有效期内的人员及陪同人员
|
|
:return: 有效用户列表
|
|
"""
|
|
sql_all = f"""
|
|
SELECT u.user_id,u.real_name,u.role_id
|
|
FROM rms_user u
|
|
JOIN rms_role r ON u.role_id = r.role_id
|
|
WHERE r.role_name IN ('管理员', '危化品管理员')
|
|
OR u.user_id IN (
|
|
SELECT solve_user_id
|
|
FROM rms_user_apply
|
|
WHERE is_solve = 1 and '{Utils.get_str_datetime()}' < DATE_ADD(solve_date, INTERVAL time_hour hour)
|
|
)
|
|
OR u.user_id IN (
|
|
SELECT solve_user_id_pt
|
|
FROM rms_user_apply
|
|
WHERE is_solve = 1 and '{Utils.get_str_datetime()}' < DATE_ADD(solve_date, INTERVAL time_hour hour)
|
|
)
|
|
"""
|
|
data = self.execute(sql_all).fetchall()
|
|
return data
|
|
|