后端代码同步

duizhaopin
tangxuan 2 years ago
parent 6681a261f8
commit 28abb76c24

@ -99,14 +99,13 @@ class CreateBarcode:
</head>
<body>
<div style="display:flex; align-content: center;width:100%">
<p style="font-size:6px; width: 100%;">
<span style="font-size:8px;width: 100%;">华润三九制药</span> <br />
<p style="font-size:8px;font-family:黑体; width: 100%;">
<br />
试剂名称: {} <br />
级别: {} <br />
批号: {} <br />
编号: {} <br />
货位号: {} <br />
<img src="{}">
货位号: {} {}
</p>
</div>
</body>
@ -115,7 +114,8 @@ class CreateBarcode:
kwargs.get("purity"),
kwargs.get("standard_code"),
kwargs.get("remark12"),
kwargs.get("place"),
kwargs.get("client_name"),
kwargs.get("flow_position_code"),
kwargs.get("file_path"),
)
document.setHtml(html)

@ -9,6 +9,7 @@ from sqlalchemy import and_
from Common.Utils import Utils, PageParam
from Common.auth import token_auth
from Common.screen import get_all_client_cell_ratio
from db_logic.client import BllClient
from db_logic.client_cell import BllClientCell
from db_logic.client_cell_user import BllClientCellUser
@ -20,7 +21,8 @@ from db_logic.humiture_record import BllHumitureRecord
from db_logic.medicament import BllMedicament
from models.client_models import EntityClient, EntityClientCell, EntityClientCellUser
from models.medicament_models import EntityMedicament, EntityMedicamentRecord, EntityMedicamentTemplate, EntityMedicamentVariety
from models.medicament_models import EntityMedicament, EntityMedicamentRecord, EntityMedicamentTemplate, \
EntityMedicamentVariety
from models.humiture_models import EntityHumitureRecord
client_router = Blueprint("client", __name__)
@ -37,7 +39,7 @@ def get_client_list():
# 查看列表分页
@client_router.route("/get_list", methods=["GET","POST"])
@client_router.route("/get_list", methods=["GET", "POST"])
@token_auth.login_required
def getclient_list():
seach_word = request.values.get("seach_word")
@ -50,7 +52,7 @@ def getclient_list():
)
data_list = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
# 新增and编辑
@client_router.route("/add_or_update", methods=["POST"])
@ -63,7 +65,7 @@ def client_add_update():
finds_list = dir(EntityClient)
if client_id:
client_obj = BllClient().findEntity(
EntityClient.client_id==client_id
EntityClient.client_id == client_id
)
if obj:
for i in finds_list:
@ -116,10 +118,11 @@ def client_add_update():
# client_obj = EntityClient()
# for i in finds:
# setattr(client_obj, i, request.values.get(i))
# BllClient().insert(client_obj)
# return jsonify(Utils.true_return(msg="添加成功"))
# 锁定或解锁柜体
@client_router.route("/update_status", methods=["POST"])
@token_auth.login_required
@ -129,12 +132,13 @@ def update_status():
obj = BllClient()
client_obj = obj.findEntity(EntityClient.client_id == client_id)
if client_obj:
client_obj.is_enabled=status_type
client_obj.is_enabled = status_type
obj.update(client_obj)
return jsonify(Utils.true_return(msg="修改成功"))
else:
return jsonify(Utils.false_return("柜体不存在"))
# 删除柜体
@client_router.route("/del", methods=["POST"])
@token_auth.login_required
@ -144,7 +148,7 @@ def client_del():
if drug_obj:
return jsonify(Utils.false_return(msg="请先删除柜体内试剂数据"))
else:
BllClient().delete(EntityClient.client_id==client_id)
BllClient().delete(EntityClient.client_id == client_id)
BllMedicamentRecord().delete(EntityMedicamentRecord.client_id == client_id)
BllMedicamentTemplate().delete(EntityMedicamentTemplate.client_id == client_id)
BllHumitureRecord().delete(EntityHumitureRecord.client_id == client_id)
@ -185,6 +189,7 @@ def get_client_drawer():
else:
return jsonify(Utils.false_return(msg="该柜体没有柜子"))
# 分配抽屉权限展示
@client_router.route("/get_drawer_power", methods=["POST"])
@token_auth.login_required
@ -196,7 +201,9 @@ def get_client_drawer_power():
page_param = PageParam(int(page), int(page_size))
data_list = BllClientCell().get_drawer_power_user_list(
drawer_id=drawer_id, client_id=client_id, page_param=page_param)
return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
return jsonify(Utils.true_return(
data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
# 分配抽屉权限
@client_router.route("/set_drawer_power", methods=["POST"])
@ -214,12 +221,12 @@ def set_client_drawer_power():
user_id_list = list(set_drawer_info.keys())
obj_list = cell_user_obj.findList(
and_(
EntityClientCellUser.client_id==client_id,
EntityClientCellUser.client_cell_id==drawer_id,
EntityClientCellUser.user_id.in_(user_id_list)
EntityClientCellUser.client_id == client_id,
EntityClientCellUser.client_cell_id == drawer_id,
EntityClientCellUser.user_id.in_(user_id_list)
)
).all()
#筛选出被删除的用户
# 筛选出被删除的用户
# drawer_del_user_list = []
# obj_list = Utils.msyql_table_model(obj_list)
for i in obj_list:
@ -227,9 +234,9 @@ def set_client_drawer_power():
if str(user_drawer) == "0":
cell_user_obj.delete(
and_(
EntityClientCellUser.client_id==i.client_id,
EntityClientCellUser.client_cell_id==drawer_id,
EntityClientCellUser.user_id==i.user_id
EntityClientCellUser.client_id == i.client_id,
EntityClientCellUser.client_cell_id == drawer_id,
EntityClientCellUser.user_id == i.user_id
)
)
# set_drawer_info.pop(i.user_id)
@ -237,7 +244,7 @@ def set_client_drawer_power():
# cell_user_obj.session.commit()
# 筛选出需要添加的用户
drawer_add_user_list = []
for k,v in set_drawer_info.items():
for k, v in set_drawer_info.items():
if str(v) == "1":
drawer_add_user_list.append(k)
# # 按条件删除
@ -276,7 +283,8 @@ def client_ban_user_list():
seach_user=seach_user, page_param=page_param,
client_id=client_id
)
return jsonify(Utils.true_return(data={"data": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
return jsonify(
Utils.true_return(data={"data": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
# 确认禁用
@ -300,6 +308,7 @@ def client_ban_user_confirm():
else:
return jsonify(Utils.false_return(msg=""))
# 取消禁用试剂
@client_router.route("/user_ban_relieve", methods=["POST"])
@token_auth.login_required
@ -331,14 +340,16 @@ def get_client_place_list():
).fetchall()
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data)))
# 获取柜子层列表
@client_router.route("/get_client_layer", methods=["POST"])
@token_auth.login_required
def get_client_layer_list():
client_id = request.values.get("client_id")
data = BllClientCell().execute(f"select * from rms_client_cell where client_id='{client_id}'").fetchall()
data = BllClientCell().execute(f"select * from rms_client_cell where client_id='{client_id}' order by cell_code asc").fetchall()
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data)))
# 修改柜子层存放试剂数量
@client_router.route("/update_client_storage_quantity", methods=["POST"])
@token_auth.login_required
@ -346,9 +357,27 @@ def update_storage_quantity():
data_info = request.values.get("data_info")
data_dict = json.loads(data_info)
obj = BllClientCell()
for k,v in data_dict.items():
for k, v in data_dict.items():
obj_find = obj.findEntity(EntityClientCell.id == k)
if obj_find:
obj_find.storage_quantity = int(v)
obj.update(obj_find)
return jsonify(Utils.true_return())
return jsonify(Utils.true_return())
@client_router.route("/cell_ratio", methods=["GET"])
def get_client_cell_ratio():
"""
大屏 货位占比情况
:return:
"""
func_type_dict = {
1: "易制毒易制爆品",
2: "一般危化品",
}
ratio_dict = get_all_client_cell_ratio(func_type_dict)
ratio_list = [{
"client_cell": func_type_dict.get(k),
"ratio": v,
} for k, v in ratio_dict.items()]
return jsonify(Utils.true_return(data=ratio_list))

@ -5,6 +5,7 @@
'''
import datetime
import os
import json
from flask import jsonify, request, g, send_from_directory
from flask import Blueprint
from db_logic.client import BllClient
@ -23,6 +24,9 @@ from Common.auth import token_auth
from db_logic.user_temporary_auth import BllUserTemporaryAuth
from Common.GaoPaiYi import GaoPaiYi
from Common.Utils import DooropenUser
from db_logic.meidcament_variety import BllMedicamentVariety
from models.medicament_models import EntityMedicamentVariety
from Common.create_barcode import CreateBarcode
drug_router = Blueprint("drug", __name__)
@ -37,13 +41,14 @@ def drug_collect():
# 获取参数
bar_code = request.values.get("bar_code")
func_type = request.values.get("func_type")
notes = request.values.get("notes","")
# user_id=request.values.get("user_id")
# 默认用户id后续从token 中获取
# user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
# 强制使用默认0不强制1强制
force_use = request.values.get("force_use")
force_use = force_use if force_use != '' else '0'
print(bar_code,'55555555555555555555555555555555555555')
# 获取条码试剂
drug_entity = BllMedicament().findEntity(EntityMedicament.bar_code==bar_code)
# 条码实际逻辑判段
@ -89,8 +94,12 @@ def drug_collect():
BllMedicament().drugUse(
drug_entity,
BllClient().findEntity(EntityClient.client_id==client_id),
user_info
user_info,
notes =notes
)
# 试剂领用后有效期更改
BllMedicament().update_expiration_date(drug_entity)
data = Utils.true_return(msg='领用成功', data=Utils.to_dict(drug_entity))
return jsonify(data)
@ -131,9 +140,11 @@ def drug_return():
user_id_pt = user_id
BllUserTemporaryAuth().create_temporary_auth(user_ids=[user_id, user_id_pt], auth_type=3)
BllMedicament().drugReturn(drug_info, BllClient().findEntity(drug_info.client_id), user_info)
data = Utils.true_return(msg="药剂归还成功", data=Utils.to_dict(drug_info))
result = Utils.to_dict(drug_info)
remain_result = BllMedicament().drugReturn(drug_info, BllClient().findEntity(drug_info.client_id), user_info)
result.update(remain_result)
print("L", result)
data = Utils.true_return(msg="药剂归还成功", data=result)
return jsonify(data)
@ -146,9 +157,53 @@ def drug_use_retur_list():
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data = BllMedicament().drug_use_return(status=status, func_type=func_type, user=g.current_user, page_param=page_param)
# 判断用户是否为管理员(管理员要能看到所有领用/归还列表数据)
# 普通危化品所有人要能看到所有待归还列表
is_admin = True if g.current_user.role_name == "管理员" else False
if str(func_type) == "2" and str(status) == "2":
is_admin = True
data = BllMedicament().drug_use_return(status=status, func_type=func_type, user=g.current_user, page_param=page_param,
is_admin=is_admin)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": Utils.msyql_table_model(data)}))
@drug_router.route("/variety/get_list", methods=["POST"])
@token_auth.login_required
def get_seach_variety():
seach_word = request.values.get("seach_word")
page = request.values.get("page", 1)
func_type = request.values.get("func_type")
page_size = request.values.get("page_size", 10)
page_param = PageParam(int(page), int(page_size))
data_list = BllMedicamentVariety().get_seach_info(seach_word=seach_word, page_param=page_param, func_type=func_type)
return jsonify(
Utils.true_return(
data={
"data_list":Utils.msyql_table_model(data_list),
"total_count": page_param.totalRecords
}
)
)
@drug_router.route("/variety/update", methods=["POST"])
@token_auth.login_required
def update_variety():
variety_id = request.values.get("variety_id")
db_obj = BllMedicamentVariety().findEntity(EntityMedicamentVariety.variety_id == variety_id)
if not db_obj:
return jsonify(Utils.false_return(msg="品类id有误"))
finds_list = dir(EntityMedicamentVariety)
for i in finds_list:
va = request.values.get(i)
if not va:
continue
setattr(db_obj, i, va)
try:
BllMedicamentVariety().update(db_obj)
return jsonify(Utils.true_return(msg="修改成功"))
except Exception:
return jsonify(Utils.false_return(msg="修改有误"))
# 试剂称重展示试剂详细信息
@drug_router.route("/get_drug_info", methods=["GET", "POST"])
@ -159,7 +214,7 @@ def get_drug_info():
bar_code, new_code = Utils.get_bar_code_reverse(bar_code)
data = BllMedicament().execute(
f"select * from rms_medicament where func_type={func_type} and (bar_code like '%{bar_code}%' or bar_code like '%{new_code}%') "
).fetchall()
).fetchall()
data = Utils.msyql_table_model(data)
if data:
return jsonify(Utils.true_return(data=data[0]))
@ -382,6 +437,7 @@ def save_drug_img_info():
"medicament_id": request.values.get("medicament_id"),
}]
file_base64 = request.files.get("file")
# try:
gaopaiyi_obj = GaoPaiYi()
img_path = f"{Utils.UUID()}.jpg"
@ -424,7 +480,6 @@ def use_gaopaiyi():
"variety_id": request.values.get("variety_id"),
"medicament_id": request.values.get("medicament_id"),
}]
pic_data = GaoPaiYi().getPic()
if pic_data['code'] == 0:
for medicament in medicament_list:
@ -487,6 +542,7 @@ def get_stay_putin_list():
page_size = request.values.get("page_size",'10000')
status = request.values.get("status")
page_param = PageParam(int(page), int(page_size))
print(DooropenUser.user_id,status,'*************************************************')
data = BllMedicament().get_drug_type_list(status=int(status), client_id=client_id, page_param=page_param, user_id=DooropenUser.user_id)
data_list = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data={"data_list":data_list, "total_count": page_param.totalRecords}))
@ -505,4 +561,34 @@ def update_drug_status():
return jsonify(Utils.false_return(msg="试剂信息有误"))
obj.status = status
BllMedicament().update(obj)
return jsonify(Utils.true_return(msg="修改成功"))
return jsonify(Utils.true_return(msg="修改成功"))
@drug_router.route("/print_select_drug_code", methods=["POST"])
@token_auth.login_required
def print_select_drug_code():
"""
药剂管理打印已选药剂标签
:return:
"""
drug_list = request.values.get("selected")
for drug in json.loads(drug_list):
medicament_id = drug.get("medicament_id")
drug_obj = BllMedicament().findEntity(EntityMedicament.medicament_id == medicament_id)
if not drug_obj:
return jsonify(Utils.false_return(msg=f"{drug_obj.get('name')}试剂信息有误"))
client_obj = BllClient().findEntity(EntityClient.client_id == drug_obj.client_id)
new_dict = {
"name": drug_obj.name,
"purity": drug_obj.purity,
"standard_code": drug_obj.standard_code,
"remark12": drug_obj.remark12,
"client_name": client_obj.client_name if client_obj else '',
"flow_position_code": drug_obj.flow_position_code,
}
obj = CreateBarcode()
obj.create_drug_lobel_code(**new_dict)
return jsonify(Utils.true_return(msg="打印完成"))

@ -55,8 +55,11 @@ def show_template():
continue
for a in json.loads(i["template_content"]):
all_export_cout += int(a.get("export_count", 0))
# 模板里面的批号列表
standard_code_list = [item.get("standard_code") for item in json.loads(i["template_content"]) if item.get("standard_code")]
new_dic = {
"all_export_count": all_export_cout,
"standard_codes": ",".join(list(set(standard_code_list))),
**i
}
new_data_list.append(new_dic)
@ -159,9 +162,15 @@ def bind_tmp_input_db():
# user_id = user_info.user_id
# user_id_pt = request.values.get("user_id_pt", '34306da6-0f11-11ed-ba01-009027e3906b')
# BllUserTemporaryAuth().create_temporary_auth(user_ids=[user_id, user_id_pt], auth_type=1)
# obj = CreateBarcode()
# obj.create_drug_lobel_code(**new_dict)
# 柜体
client_obj = BllClient().findEntity(EntityClient.client_id == drug_entity.client_id)
new_dict.update({
"client_name": client_obj.client_name
})
# 打印标签
obj = CreateBarcode()
obj.create_drug_lobel_code(**new_dict)
BllMedicament().drugPutIn(
drug_entity,
BllClient().findEntity(EntityClient.client_id==drug_entity.client_id),
@ -208,23 +217,31 @@ def add_tmp_info():
bar_code_count = 0
for i in tmp_content:
bar_code_count += int(i['export_count'])
obj = EntityMedicamentTemplate(
customer_id=client.customer_id,
client_id=client.client_id,
client_name=client.client_name,
template_name=tmp_name,
func_type=func_type,
template_content=json.dumps(tmp_content),
is_wait_export=1,
start_bar_code=start_bar_code,
bar_code_count=bar_code_count,
create_date=Utils.get_str_datetime(),
create_user_id=user.user_id,
create_user_name=user.real_name,
)
BllMedicamentTemplate().insert(obj)
# 同模板名称进行覆盖
temp = BllMedicamentTemplate().findEntity(EntityMedicamentTemplate.template_name == tmp_name)
params = {
"customer_id": client.customer_id,
"client_id": client.client_id,
"client_name": client.client_name,
"template_name": tmp_name,
"func_type": func_type,
"template_content": json.dumps(tmp_content),
"is_wait_export": 1,
"start_bar_code": start_bar_code,
"bar_code_count": bar_code_count,
"create_date": Utils.get_str_datetime(),
"create_user_id": user.user_id,
"create_user_name": user.real_name,
}
if temp:
for k, v in params.items():
setattr(temp, k, v)
BllMedicamentTemplate().update(temp)
else:
obj = EntityMedicamentTemplate(**params)
BllMedicamentTemplate().insert(obj)
return jsonify(Utils.true_return(msg="添加模板成功"))
except Exception as error:

@ -15,6 +15,7 @@ from db_logic.warning import BllWarning
from Common.Utils import PageParam, Utils
from Common.auth import token_auth
from flask import Blueprint
from Common.screen import get_chemicals_total_num_weight, get_other_drug_total_num
home_router = Blueprint('home', __name__, url_prefix="/home")
@ -139,3 +140,45 @@ def get_monitoring_info():
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list)))
# 获取汇总指标
@home_router.route("/summary", methods=["GET", "POST"])
def get_home_summary_report():
"""
大屏 获取汇总指标
:return:
"""
chemicals_total_num, chemicals_total_weight = get_chemicals_total_num_weight()
standard_num, reagent_num, consumables_num = get_other_drug_total_num()
resp_data = {
"chemicals_total_num": chemicals_total_num,
"chemicals_total_weight": chemicals_total_weight,
"standard_num": standard_num,
"reagent_num": reagent_num,
"consumables_num": consumables_num
}
return jsonify(Utils.true_return(data=resp_data))
@home_router.route("/lack_inventory_alarm", methods=["GET", "POST"])
def lack_inventory_alarm():
"""
大屏 库存不足预警
:return:
"""
# 2试剂过期 3余量不足
object_type = 3
page_param = PageParam(1, 30)
warning_list = BllWarning().getWarningList(
pageParam=page_param,
start_time="",
end_time="",
key_word="",
object_type=object_type
)
data = {
"total_count": page_param.totalRecords,
"data_list": Utils.msyql_table_model(warning_list)
}
return jsonify(Utils.true_return(data=data))

@ -11,6 +11,7 @@ from db_logic.medicament_record import BllMedicamentRecord
from db_logic.medicament import BllMedicament
from Common.auth import token_auth
from apps.report.utils_base import download_file
from Common.screen import get_storage_summary, get_drug_operate, get_all_inventory
report_router = Blueprint("report", __name__)
@ -335,17 +336,24 @@ def drug_log_type_info():
download_tp = request.values.get("download_type", 0)
if download_tp:
page_param = None
data_list = BllMedicament().drug_show_type_info(
record_type=record_type,
put_in_user_name=put_in_user_name,
func_type=func_type,
statue_type=statue_type,
name=name,
start_time=start_time, end_time=end_time,
page_param=page_param,
client_place=client_place,
client_id=client_id
)
kwargs = {
"record_type": record_type,
"put_in_user_name": put_in_user_name,
"func_type": func_type,
"statue_type": statue_type,
"name": name,
"start_time": start_time,
"end_time": end_time,
"page_param": page_param,
"client_place": client_place,
"client_id": client_id
}
# 未入库记录
if record_type == "100":
data_list, _ = BllMedicament().drug_show_un_warehoused_type_info(**kwargs)
else:
data_list = BllMedicament().drug_show_type_info(**kwargs)
data_list = Utils.msyql_table_model(data_list)
if not download_tp:
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data_list}))
@ -397,4 +405,57 @@ def get_putin_acceptance_record():
if data:
return data
else:
return jsonify(Utils.false_return())
return jsonify(Utils.false_return())
@report_router.route("/storage", methods=["GET", "POST"])
def get_report_storage():
"""
大屏 获取出入库情况
:return: chemicals: 物品名
day_out_num 今日出库数
day_in_num: 今日入库数
opt_count: 操作次数
"""
storage_report_list = get_storage_summary()
if not storage_report_list:
storage_report_list = [{
"chemicals": "",
"day_out_num": 0,
"day_in_num": 0,
"opt_count": 0
}]
return jsonify(Utils.true_return(data=storage_report_list))
@report_router.route("/operation", methods=["GET", "POST"])
def get_report_operation():
"""
大屏 获取操作情况
:return: [{chemicals_name: 化学品, update_user: 操作人, update_type: 操作类型, update_time:操作时间}]
"""
# 1入库2领用3归还
type_dict = {
1: "入库",
2: "领用",
3: "归还",
}
operate_list = get_drug_operate()
result = [{
"chemicals": item.get("name"),
"update_user": item.get("create_user_name"),
"update_type": type_dict.get(item.get("record_type"), '未知'),
"update_time": item.get("create_date")
} for item in operate_list]
return jsonify(Utils.true_return(data=result))
@report_router.route("/inventory", methods=["GET", "POST"])
def get_report_inventory():
"""
大屏 获取库存情况
:return: [{chemicals: 化学品, total_num: 库存量, total_weight: 总重量}]
"""
inventory_list = get_all_inventory()
return jsonify(Utils.true_return(data=inventory_list))

@ -4,6 +4,7 @@
@Date: 2022/12/14 15:17:57
'''
import sys
sys.path.append('.')
import json
@ -23,6 +24,10 @@ from Common.Utils import DooropenUser
temporary_bp = Blueprint("temporary_auth", __name__)
temp_list=['乌头碱','次乌头碱','新乌头碱','苯甲酰新乌头原碱','苯甲酰乌头原碱','苯甲酰次乌头原碱','盐酸麻黄碱','盐酸伪麻黄碱'
,'黄曲霉毒素B1溶液标准品','黄曲霉毒素B2溶液标准品','黄曲霉毒素G1溶液标准品','黄曲霉毒素混合对照品','黄曲霉毒素G2溶液标准品'
,'麻黄(草麻黄)','咖啡因','咖啡因(熔点用)'
]
# 获取试剂分组列表
@ -35,7 +40,7 @@ def get_use_drug_list():
page_param = PageParam(int(page), int(page_size))
data = BllMedicament().use_drug_info_list(client_id=client_id, seach_word=seach_word, page_param=page_param)
data_list = Utils.msyql_table_model(data_list=data)
return jsonify(Utils.true_return(data={"data_list":data_list, "total_count": page_param.totalRecords}))
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
# 创建申请记录
@ -47,6 +52,7 @@ def user_apply_log():
func_type = request.values.get("func_type")
use_doc = request.values.get("use_doc")
use_content = request.values.get("use_content")
tag =0
# drug_name = request.values.get("drug_name")
# drug_num = request.values.get("drug_num")
@ -57,22 +63,40 @@ def user_apply_log():
# client_code = ''
if not use_content:
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
else:
data_obj= json.loads(use_content)
for i in data_obj:
if i["name"] in temp_list:
tag=1
print(i["client_id"])
client_obj =BllClient().findEntity(EntityClient.client_id ==i["client_id"])
print(client_obj,'11223')
if client_obj:
i["client_name"]=client_obj.client_name
else:
i["client_name"]=''
use_content =json.dumps(data_obj)
solve_user_id_sh ="-"
if tag ==1:
solve_user_id_sh = ''
obj = EntityUserApply(
user_id = g.current_user.user_id,
user_id_pt = user_id_pt,
user_id=g.current_user.user_id,
user_id_pt=user_id_pt,
# drug_name = drug_name,
# drug_num = drug_num,
create_date = Utils.get_str_datetime(),
is_solve = 0,
use_content = use_content,
create_date=Utils.get_str_datetime(),
is_solve=0,
solve_user_id_sh=solve_user_id_sh,
use_content=use_content,
# client_id = client_id,
func_type=func_type,
# client_code=client_code,
use_doc=use_doc
)
)
BllUserApply().insert(obj)
return jsonify(Utils.true_return())
# 修改个人申请
@temporary_bp.route("/update_itself_apply", methods=["POST"])
@token_auth.login_required
@ -88,13 +112,14 @@ def update_itself_apply():
EntityUserApply.id == apply_id,
EntityUserApply.user_id == user.user_id
)
)
)
if not user_apply_obj:
return jsonify(Utils.false_return(msg="只能修改自己的申请!"))
user_apply_obj.use_content=use_content
user_apply_obj.use_content = use_content
BllUserApply().update(user_apply_obj)
return jsonify(Utils.true_return())
# 展示
@temporary_bp.route("/get_list", methods=["POST"])
# @token_auth.login_required
@ -117,10 +142,14 @@ def get_info_list():
# i_dict = dict(zip(i.keys(), [(x if x is not None else '') for x in i.values()]))
i_dict['user_name'] = user_dict.get(i_dict["user_id"])
i_dict["user_name_pt"] = user_dict.get(i_dict["user_id_pt"])
i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '')
i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '')
i_dict["solve_user_pt_name"] = user_dict.get(i_dict["solve_user_id_pt"], '')
i_dict["solve_user_sh_name"] = user_dict.get(i_dict["solve_user_id_sh"], '')
if i_dict["solve_user_id_sh"] =='-':
i_dict["solve_user_sh_name"]='-'
data_list.append(i_dict)
return jsonify(Utils.true_return(data= {"data_list":data_list, "total_count": page_param.totalRecords}))
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
# 删除
@temporary_bp.route("/del", methods=["POST"])
@ -129,14 +158,15 @@ def del_user_apply():
user_json = request.values.get("user_ids")
user_id_list = user_json.split(",")
for i in user_id_list:
BllUserApply().delete(EntityUserApply.id==i)
BllUserApply().delete(EntityUserApply.id == i)
return jsonify(Utils.true_return())
# 处理消息
@temporary_bp.route("/update_solve", methods=["POST"])
@token_auth.login_required
def solve_apply():
apply_id =request.values.get("id")
apply_id = request.values.get("id")
# user_id = request.values.get("user_id")
user_id = g.current_user.user_id
# user_id_pt = request.values.get("user_id_pt")
@ -149,15 +179,22 @@ def solve_apply():
obj.information = request.values.get("information")
obj.is_solve = 2
else:
if not obj.solve_user_id:
obj.solve_user_id = user_id
else:
if user_id == obj.solve_user_id:
return jsonify(Utils.false_return(msg="不能位同一人审批"))
obj.solve_user_id_pt=user_id
obj.is_solve = 1
obj.time_hour=t
BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_id_pt], auth_type=2, t=t)
if user_id == obj.user_id:
return jsonify(Utils.false_return(msg="申请人与审批人不能为同一人"))
if not obj.solve_user_id_sh:
obj.solve_user_id_sh = user_id
else:
if not obj.solve_user_id:
if user_id == obj.solve_user_id_sh:
return jsonify(Utils.false_return(msg="不能位同一人审批"))
obj.solve_user_id = user_id
else:
if user_id == obj.solve_user_id or user_id == obj.solve_user_id_sh:
return jsonify(Utils.false_return(msg="不能位同一人审批"))
obj.solve_user_id_pt = user_id
obj.is_solve = 1
obj.time_hour = t
BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_id_pt], auth_type=2, t=t)
obj.solve_date = Utils.get_str_datetime()
# obj.solve_user_id = user_id
# obj.solve_user_id_pt = user_id_pt
@ -174,7 +211,8 @@ def get_register_drug():
page_size = request.values.get("page_size")
page_param = PageParam(int(page), int(page_size))
data = BllMedicament().get_register_list(user=g.current_user, page_param=page_param)
return jsonify(Utils.true_return(data={"data_list":Utils.msyql_table_model(data), "total_count": page_param.totalRecords}))
return jsonify(
Utils.true_return(data={"data_list": Utils.msyql_table_model(data), "total_count": page_param.totalRecords}))
# 登记接口
@ -213,16 +251,63 @@ def set_register():
BllMedicament().drugRegister(
entityDrug=obj,
entityClient= BllClient().findEntity(EntityClient.client_id==obj.client_id),
entityClient=BllClient().findEntity(EntityClient.client_id == obj.client_id),
entityUser=g.current_user
)
# 试剂有效期更改
BllMedicament().update_expiration_date(obj)
return jsonify(Utils.true_return())
else:
return jsonify(Utils.false_return())
# 获取待领用试剂列表
@temporary_bp.route("/get_stay_use_list", methods=["GET", "POST"])
def get_stay_use_list():
client_id = request.values.get("client_id")
data_list = BllUserApply().get_stay_use_list(client_id=client_id, user_id=DooropenUser.user_id)
return jsonify(Utils.true_return(data=data_list))
return jsonify(Utils.true_return(data=data_list))
@temporary_bp.route("/get_check_last_drug", methods=["GET", "POST"])
@token_auth.login_required
def get_check_last_drug():
"""
检查获取是否为最早入库试剂先进先出
:return {"is_last": True, "medicament": 最早入库试剂信息} True:不存在更早试剂 False:存在更早试剂
"""
medicament_id = request.values.get("medicament_id")
func_type = request.values.get("func_type")
drug_name = request.values.get("name")
put_in_date = request.values.get("put_in_date")
client_id = request.values.get("client_id")
medicament_obj = BllMedicament().get_last_drug(client_id=client_id, drug_name=drug_name,
put_in_date=put_in_date, func_type=func_type)
if not medicament_obj:
return jsonify(Utils.except_return(msg="未查询到相关信息", data={"is_last": True}))
# True: 当前选择试剂为最早入库试剂
# False: 当前选择试剂不是最早入库试剂
data = {
"is_last": True if medicament_obj.medicament_id == medicament_id else False,
"medicament": dict(medicament_obj._mapping)
}
return jsonify(Utils.true_return(data=data))
# 添加未领用说明
@temporary_bp.route("/update_notes", methods=["POST"])
def update_notes():
apply_id = request.values.get("id")
bar_code = request.values.get("bar_code")
info = request.values.get("info")
obj = BllUserApply().findEntity(EntityUserApply.id == apply_id)
if obj:
data_obj =json.loads(obj.use_content)
for i in data_obj:
if i["bar_code"] ==bar_code:
print('5555')
i["info"] =info
obj.use_content =json.dumps(data_obj)
BllUserApply().update(obj)
return jsonify(Utils.true_return(data=obj))

@ -28,6 +28,7 @@ def user_login():
password = request.values.get('password')
# user_name = body.user_name
# password = body.password
print(user_name,password,'**********************************************************')
user_obj, user_info = BllUser().login(user_name=user_name, password=password)
if user_obj:
return jsonify(Utils.true_return(msg="登陆成功", data={"token":user_obj, "user_info": Utils.to_dict(user_info)}))
@ -39,7 +40,7 @@ def user_login():
@token_auth.login_required
def user_update_password():
old_password = request.values.get("old_password")
new_password = request.values.get("new_password")
new_password = request.values.get("new_password")
new_password1 = request.values.get("new_password1")
# user_id = g.current_user.use
if new_password != new_password1:
@ -57,6 +58,7 @@ def user_update_password():
def get_user_info_list():
user_code = request.values.get("user_code")
real_name = request.values.get("real_name")
role_name = request.values.get("role_name")
role_id = request.values.get("role_id")
is_enabled = request.values.get("is_enabled")
if role_id:
@ -66,12 +68,14 @@ def get_user_info_list():
role_name=''
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
print(page_size,'44444444444444444444')
page_param = PageParam(page, page_size)
data_list = BllUser().get_seach_user_list(
user_id = g.current_user.user_id,
user_code=user_code,
real_name=real_name,
role_name=role_name,
role_id=role_id,
is_enabled=is_enabled,
role_name_self=g.current_user.role_name,
page_param=page_param
@ -193,3 +197,15 @@ def opendoorcheck():
if data:
DooropenUser.user_id =user1.user_id
return jsonify(Utils.true_return(msg="请求成功",data=data))
@user_router.route("/get_active_user_list", methods=["GET", "POST"])
def get_active_user_list():
"""
获取所有申通通过有效期内用户与管理员与危化品管理员用户列表
:return: [user_id_list]
"""
data = BllUserApply().get_apply_solve_user_list()
apply_user_id_list = [item.user_id for item in data]
return jsonify(Utils.true_return(msg="请求成功", data=apply_user_id_list))

@ -4,11 +4,13 @@
@Date:2022/07/18 16:54:45
'''
import sys
import datetime
from dateutil.relativedelta import relativedelta
sys.path.append('.')
from sqlalchemy import distinct, or_, and_, desc, asc
from sqlalchemy.sql import func
from db_logic.db_base import Repository
from models.medicament_models import EntityMedicament, EntityMedicamentRecord, EntityMedicamentTemplate, EntityVariety
from models.medicament_models import EntityMedicament, EntityMedicamentRecord, EntityMedicamentTemplate, EntityVariety, EntityMedicamentVariety
from models.client_models import EntityClient
from models.user_models import EntityUser
from db_logic.meidcament_variety import BllMedicamentVariety
@ -26,7 +28,7 @@ class BllMedicament(Repository):
def update(self, entity):
entity.remark30 = '0'
return super().update(entity)
def get_register_list(self, user, page_param):
# sql_all = f"""
@ -35,7 +37,7 @@ class BllMedicament(Repository):
# 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 = []
@ -50,7 +52,7 @@ class BllMedicament(Repository):
# if drugobj:
# data_list.append(j)
# #所有试剂
@ -69,7 +71,7 @@ class BllMedicament(Repository):
# 获取可入库层数据
def get_drug_save_db_info(self, drug_name, func_type):
# sql_all = f"""
# select name, IFNULL(num,0) number, c.client_name, c.client_id, cell_code, cell_speci from (
# select cell_code, a.client_id, cell_speci, client_name from (
# select * from rms_client_cell
@ -81,7 +83,7 @@ class BllMedicament(Repository):
# from rms_medicament where `name` like '%{drug_name}%' and status=1 and func_type={func_type}
# GROUP BY client_id, flow_position_code
# ) d on c.client_id=d.client_id and c.cell_code=d.flow_position_code
# HAVING number < 40
# """
sql_all = f"""
@ -90,9 +92,9 @@ class BllMedicament(Repository):
select a.cell_code,a.client_id, a.cell_speci, IFNULL(a.storage_quantity,0) storage_quantity, count(b.name) num, IFNULL(GROUP_CONCAT(b.name),'') name_json
from (select * from rms_client_cell) a
LEFT JOIN (select * from rms_medicament) b on a.client_id=b.client_id and a.cell_speci=b.place
GROUP BY a.id
GROUP BY a.id order by a.cell_speci asc
) c LEFT JOIN (select * from rms_client where func_type={func_type}) d on c.client_id=d.client_id
where d.client_name is not null
where d.client_name is not null order by d.client_name asc
"""
data = self.execute(sql_all).fetchall()
@ -113,6 +115,7 @@ class BllMedicament(Repository):
"client_cell": [i.cell_speci]
}
data_dict[i.client_id] = client_dict
data_dict[i.client_id]["client_cell"].sort()
# data_dict = {}
# for i in data:
# if i.client_id in data_dict.keys():
@ -253,10 +256,11 @@ class BllMedicament(Repository):
new_code = seach_word[i*2:(i+1)*2] + new_code
else:
new_code = seach_word
new_code = f"%{new_code}%"
if filter_base:
filter_base += " and "
filter_base += f" (bar_code like '{new_code}' or bar_code like '{seach_word}' )"
# TODO 确认下面这段和上面修改b_code代码作用
# new_code = f"%{new_code}%"
# if filter_base:
# filter_base += " or "
# filter_base += f" (bar_code like '{new_code}' or bar_code like '{seach_word}' )"
if func_type:
if filter_base:
filter_base += " and "
@ -274,7 +278,7 @@ class BllMedicament(Repository):
page_param.totalRecords=count_number
page_sql = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(page_sql).fetchall()
# 选择药剂入库--试剂详情
def get_drug_info_distinct_list(self, seach_word, func_type, page_param, client_id=None):
# 动态添加查询条件
@ -299,7 +303,7 @@ class BllMedicament(Repository):
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
count_number = 0
page_param.totalRecords = count_number
# 分页sql
page_sql = Utils.sql_paging_assemble(sql_all, page_param)
@ -317,7 +321,7 @@ class BllMedicament(Repository):
medicament_id=entityDrug.medicament_id,
price=entityDrug.price,
record_type=DrugRecordType.PutIn,
record_remain=float(entityDrug.remain),
record_remain=float(entityDrug.remain) if entityDrug.remain else 0,
is_empty=0,
create_date=Utils.get_str_datetime(),
@ -337,7 +341,7 @@ class BllMedicament(Repository):
return True
return boolean_
# 药剂领用
def drugUse(self, entityDrug=EntityMedicament(), entityClient=EntityClient(), entityUser=EntityUser()):
def drugUse(self, entityDrug=EntityMedicament(), entityClient=EntityClient(), entityUser=EntityUser(),notes=''):
#创建事务
self.beginTrans()
entityDrug.remark30 = '0'
@ -356,6 +360,7 @@ class BllMedicament(Repository):
create_date=Utils.get_str_datetime(),
create_user_id=entityUser.user_id,
create_user_name=entityUser.real_name,
notes = notes
)
self.session.add(entityDrugRecord)
@ -374,8 +379,7 @@ class BllMedicament(Repository):
drug = BllMedicament().findEntity(entityDrug.medicament_id)
lastRemain = float(drug.remain)
if not entityDrug.remain:
entityDrug.remain=0
remain_result = {"is_liquid": False, "use_volume": 0, "use_quality": 0}
if entityClient.client_id not in client_list:
entityDrugRecord = EntityMedicamentRecord(
@ -394,6 +398,15 @@ class BllMedicament(Repository):
create_user_name=entityUser.real_name,
)
# 液体用量 = 用量质量 / 密度
medicament_variety_obj = BllMedicamentVariety().findEntity(
EntityMedicamentVariety.variety_id == entityDrug.variety_id)
if medicament_variety_obj.net_weight_unit == 'ml' and medicament_variety_obj.density:
use_volume = (float(lastRemain) - float(
entityDrug.remain if entityDrug.remain else 0)) / medicament_variety_obj.density
entityDrugRecord.use_volume = use_volume
remain_result["is_liquid"] = True
remain_result["use_volume"] = use_volume
self.session.add(entityDrugRecord)
entityVariety = BllMedicamentVariety().findEntity(entityDrug.variety_id)
if(entityDrug.remain != 0):
@ -404,6 +417,8 @@ class BllMedicament(Repository):
self.session.merge(entityVariety)
self.commitTrans()
remain_result["use_quality"] = float(lastRemain) - float(entityDrug.remain if entityDrug.remain else 0)
return remain_result
# 药剂登记
def drugRegister(self, entityDrug, entityClient=EntityClient(), entityUser=EntityUser()):
@ -434,8 +449,11 @@ class BllMedicament(Repository):
self.session.add(entityDrugRecord)
self.commitTrans()
# 获取领用和归还页面列表
def drug_use_return(self, status, func_type, user, page_param):
# 获取领用和归还页面列表 管理员要能看到所有领用/归还列表数据
def drug_use_return(self, status, func_type, user, page_param, is_admin):
filter_base = f" status={status} and func_type='{func_type}' "
if not is_admin:
filter_base += f"and by_user_id='{user.user_id}' "
sql_all = f"""
select * from rms_medicament where status={status} and func_type='{func_type}' and by_user_id='{user.user_id}' order by by_user_date desc
"""
@ -469,7 +487,7 @@ class BllMedicament(Repository):
filter_base1 = ""
if client_place:
filter_base1 += f"where place='{client_place}'"
# sql_all =f"""
# select DISTINCT
# `name`, speci, cas_number,net_weight_unit, purity,
@ -574,17 +592,19 @@ class BllMedicament(Repository):
count_number= len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
# 进行分页sql拼接
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 drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, func_type, client_id, statue_type, page_param, client_place):
filter_base1 = f" WHERE record_type={record_type} "
filter_base1 = ''
if record_type:
filter_base1 = f" WHERE record_type={record_type} "
if put_in_user_name:
filter_base1 += f" and create_user_name like '%{put_in_user_name}%'"
if start_time and end_time:
@ -596,11 +616,11 @@ class BllMedicament(Repository):
name = f"%{name}%"
filter_base2 += f" (`name` like '{name}' or english_name like '{name}') "
if statue_type:
if statue_type and statue_type != '100':
if filter_base2:
filter_base2 += " and "
filter_base2 = f" `status`={statue_type}"
if func_type:
if filter_base2:
filter_base2 += " and "
@ -613,8 +633,8 @@ class BllMedicament(Repository):
filter_base += f"where place='{client_place}'"
sql_all = f"""
select
`name`, english_name, bar_code, purity,
cas_number, speci, use_quantity, `status`,
record_type, `name`, english_name, bar_code, purity,
cas_number, speci, use_quantity, use_volume, `status`,
create_date, create_user_name, a.client_id, client_code, client_name, unit_code
from (select * from rms_medicament_record {filter_base1}
) as a LEFT JOIN(
@ -637,6 +657,58 @@ class BllMedicament(Repository):
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(sql_all).fetchall()
def drug_show_un_warehoused_type_info(self, **kwargs):
"""
未入库记录未归还
:param kwargs: record_type, start_time, end_time, put_in_user_name, name, func_type, client_id, statue_type,
page_param, client_place
:return:
"""
filter_base1 = " where record_type=2 "
if kwargs.get("put_in_user_name"):
filter_base1 += f" and create_user_name like '%{kwargs.get('put_in_user_name')}%'"
if kwargs.get("start_time") and kwargs.get("end_time"):
filter_base1 += f" and create_date >= '{kwargs.get('start_time')}' and create_date <= '{kwargs.get('end_time')}'"
if kwargs.get("client_id"):
filter_base1 += f" and client_id='{kwargs.get('client_id')}'"
filter_base2 = " `status` = 2 "
if kwargs.get("func_type"):
if filter_base2:
filter_base2 += " and "
filter_base2 += f" func_type='{kwargs.get('func_type')}' "
if filter_base2:
filter_base2 = f" where {filter_base2}"
filter_base = ""
if kwargs.get("client_place"):
filter_base += f"where place='{kwargs.get('client_place')}'"
sql_all = f"""
select
`name`, english_name, bar_code, purity,
cas_number, speci, use_quantity, use_volume, `status`,
create_date, create_user_name, a.client_id, client_code, client_name, unit_code
from (select * from rms_medicament_record {filter_base1}
) as a LEFT JOIN(
select
medicament_id, `name`, english_name,
bar_code, purity, speci, cas_number,
net_weight, remain, `status`,
by_user_date, by_user_name, unit_code
FROM rms_medicament {filter_base2}
) as b on a.medicament_id=b.medicament_id
LEFT JOIN(select client_id,client_name from rms_client {filter_base}) c on a.client_id=c.client_id
where name is not null and client_name is not null GROUP BY b.medicament_id ORDER BY create_date desc
"""
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
if kwargs["page_param"]:
kwargs["page_param"].totalRecords = count_number
sql_all = Utils.sql_paging_assemble(sql_all, kwargs["page_param"])
return self.execute(sql_all).fetchall(), count_number
def client_room_number(self):
sql_all = """
select
@ -663,7 +735,7 @@ class BllMedicament(Repository):
group by `name`, speci, purity
"""
return self.execute(sql_all).fetchall()
# 库存盘点获取分组后的试剂信息数据
def get_drug_stock_info(self, client_id):
sql_all = f"""
@ -685,11 +757,11 @@ class BllMedicament(Repository):
filter_base = f" and {filter_base}"
# sql_all = f"""
# select a.*,b.client_name from (
# select
# select
# `name`, speci, purity, count(*) drug_num, manufacturer, distributor,client_id,medicament_id
# from
# from
# rms_medicament WHERE `status`=1 {filter_base}
# GROUP BY
# GROUP BY
# `name`, speci, purity, client_id
# ) a LEFT JOIN (
# select * from rms_client
@ -697,9 +769,9 @@ class BllMedicament(Repository):
# """
sql_all = f"""
select a.*,b.client_name from (
select * from rms_medicament WHERE `status`=1 {filter_base}
select * from rms_medicament WHERE rms_medicament.func_type=1 and `status`=1 {filter_base}
) a LEFT JOIN (
select * from rms_client
select * from rms_client WHERE rms_client.place =10
) b on a.client_id = b.client_id
"""
try:
@ -734,7 +806,7 @@ class BllMedicament(Repository):
if client_id =='72e70542-b70d-11e8-aea5-448a5bc6c417':
if filter_base:
filter_base += " and "
filter_base += f" client_id in ('72e70542-b70d-11e8-aea5-448a5bc6c417') "
filter_base += f" client_id in ('72e70542-b70d-11e8-aea5-448a5bc6c417') "
if filter_base:
filter_base = f" where {filter_base}"
sql_all = f"""
@ -759,7 +831,7 @@ class BllMedicament(Repository):
if data:
return True
else:
return False
return False
def getDrugSetPotionStorageIn(self,name,clientId=""):
@ -811,6 +883,108 @@ class BllMedicament(Repository):
obj_list.append(obj)
self.insert_many(obj_list)
def get_last_drug(self, client_id, drug_name, put_in_date, func_type):
"""
判断获取最早入库试剂信息
"""
filter_base = ""
if func_type:
filter_base += f"func_type='{func_type}'"
if client_id:
if filter_base:
filter_base += " and "
filter_base += f"client_id='{client_id}'"
if drug_name:
if filter_base:
filter_base += " and "
filter_base += f" `name`='{drug_name}' "
if filter_base:
filter_base = f" and {filter_base}"
sql_all = f"""
select a.*,b.client_name from (
select * from rms_medicament WHERE `status`=1 {filter_base}
) a LEFT JOIN (
select * from rms_client
) b on a.client_id = b.client_id order by a.put_in_date asc
"""
medicament_obj = self.execute(sql_all).fetchone()
return medicament_obj
def get_drug_total_num(self, filter_base):
"""
获取药剂总数
:param filter_base:
:return:
"""
if filter_base:
filter_base = f" and {filter_base}"
sql_all = f"""
select count(medicament_id) count_number from rms_medicament where `status` != 3 {filter_base}
"""
# 查看分组数据
data = self.execute(sql_all).fetchone()
return data.count_number if data.count_number else 0
def get_chemicals_total_num(self):
"""
获取化学品总数量
:return:
"""
num = self.get_drug_total_num('')
return num
def get_chemicals_total_weight(self):
"""
获取化学品总重量
:return:
"""
sql_all = f"""
select sum(remain) total_weight from rms_medicament where `status` != 3
"""
# 查看分组数据
data = self.execute(sql_all).fetchone()
return data.total_weight if data.total_weight else 0
def get_chemicals_other_total_num(self):
"""
获取其他化学品总数量
:return: standard_num 普通危化总数 2
reagent_num 易制毒易制爆总数 1
consumables_num 对照品数量 3
"""
standard_num = self.get_drug_total_num("func_type=2")
reagent_num = self.get_drug_total_num("func_type=1")
consumables_num = self.get_drug_total_num("func_type=3")
return standard_num, reagent_num, consumables_num
def update_expiration_date(self, drug_entry):
"""
更改试剂有效期
液体1年 普通固体5年 易潮解固体2年
:param drug_entry:
:return:
"""
expiration_dict = {
"ml": 1,
"g": 5,
"mg": 5,
}
unit = drug_entry.net_weight_unit
add_year = expiration_dict.get(unit) if expiration_dict.get(unit) else 2
date_now = datetime.datetime.now()
add_expiration_date = (date_now + relativedelta(years=add_year)).strftime("%Y-%m-%d %H:%M:%S")
if add_expiration_date > drug_entry.expiration_date:
return
else:
drug_entry.expiration_date = add_expiration_date
self.beginTrans()
self.session.merge(drug_entry)
self.commitTrans()
if __name__ == '__main__':
data = BllMedicament().getDrugSetPotionStorageIn("2-氨基苯酚", '1c39cb24-07f8-11ed-abd4-f47b094925e1')
print(data)
@ -833,4 +1007,4 @@ if __name__ == '__main__':
# )
# print(typ_dic)

@ -64,6 +64,32 @@ class BllMedicamentVariety(Repository):
self.update(entity)
entity = self.session.merge(entity)
return entity
def get_seach_info(self, seach_word, page_param, func_type):
filter_base = ""
if seach_word:
seach_word = f'%{seach_word}%'
filter_base += f" (`name` like '{seach_word}' or english_name like '{seach_word}')"
if func_type:
if filter_base:
filter_base += " and "
filter_base += f" tp = {func_type}"
if filter_base:
filter_base = f" where {filter_base} "
sql_all = f"""
select * from rms_medicament_variety {filter_base}
"""
try:
count_number = self.execute(f"select count(*) count_num from rms_medicament_variety {filter_base}").fetchone().count_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 getVarietyStatistics(self):
# SQL = """

@ -32,6 +32,10 @@ class BllUserApply(Repository):
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}"
"""
@ -86,20 +90,20 @@ class BllUserApply(Repository):
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
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)
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):
@ -151,4 +155,29 @@ class BllUserApply(Repository):
if data:
return True
else:
return False
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

@ -168,6 +168,7 @@ class EntityMedicamentRecord(Base):
create_date = Column(String(50), comment="创建日期")
create_user_id = Column(String(50), comment="创建人ID")
create_user_name = Column(String(50), comment="创建人名称")
notes = Column(String(1000), comment="用途说明",default='')
is_add = Column(Integer, comment="", default=0)

@ -90,6 +90,7 @@ class EntityUserApply(Base):
is_solve = Column(Integer, comment="是否处理", default=0)
solve_date = Column(String(50), comment="受理时间")
solve_user_id = Column(String(50), comment="受理人")
solve_user_id_sh = Column(String(50), comment="部门审核人")
solve_user_id_pt = Column(String(50), comment="受理人")
func_type = Column(Integer, comment="类型")
use_doc = Column(Text, comment="类型")

Loading…
Cancel
Save