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.

107 lines
3.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
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 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
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 not con_info.get("use_num"):
con_info["use_num"] = 0
if int(con_info["use_num"]) < int(con_info["num"]):
con_info["use_num"] += 1
break_bool = False
obj = self.findEntity(self.entityType.id == d.id)
obj.use_content = json.dumps(use_content)
self.update(obj)
def get_stay_use_list(self, client_id, user):
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()
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"] != client_id:
continue
if j.get("use_num") != 0:
n = int(j.get("num")) - int(j.get("use_num"))
if n > 0:
j["stay_use_num"] = n
data_list.append(j)
return data_list