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.

217 lines
8.0 KiB

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date: 2022/12/14 15:17:57
'''
import sys
sys.path.append('.')
import json
from flask import Blueprint, request, jsonify, g
from sqlalchemy import and_, or_
from db_logic.user_temporary_auth import BllUserTemporaryAuth
from db_logic.user_apply import BllUserApply
from db_logic.medicament import BllMedicament
from db_logic.client import BllClient
from db_logic.user import BllUser
from models.client_models import EntityClient
from models.medicament_models import EntityMedicament
from models.power_models import EntityUserApply, EntityUserTemporaryAuth
from Common.Utils import Utils, PageParam
from Common.auth import token_auth
temporary_bp = Blueprint("temporary_auth", __name__)
# 获取试剂分组列表
@temporary_bp.route("/get_drug_group_list", methods=["POST"])
def get_use_drug_list():
client_id = request.values.get("client_id")
2 years ago
seach_word = request.values.get("seach_word")
page = request.values.get("page")
page_size = request.values.get("page_size")
page_param = PageParam(int(page), int(page_size))
2 years ago
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}))
# 创建申请记录
@temporary_bp.route("/add", methods=["POST"])
2 years ago
@token_auth.login_required
def user_apply_log():
2 years ago
# user_id = request.values.get("user_id")
user_id_pt = request.values.get("user_id_pt")
func_type = request.values.get("func_type")
use_doc = request.values.get("use_doc")
use_content = request.values.get("use_content")
# drug_name = request.values.get("drug_name")
# drug_num = request.values.get("drug_num")
# client_id = request.values.get("client_id")
# try:
# client_code = BllClient().findEntity(EntityClient.client_id==client_id).client_code
# except:
# client_code = ''
if not use_content:
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
obj = EntityUserApply(
2 years ago
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,
# 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
def update_itself_apply():
apply_id = request.values.get("id")
# func_type = request.values.get("func_type")
use_content = request.values.get("use_content")
if not use_content:
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
user = g.current_user
user_apply_obj = BllUserApply().findEntity(
and_(
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
BllUserApply().update(user_apply_obj)
return jsonify(Utils.true_return())
# 展示
@temporary_bp.route("/get_list", methods=["POST"])
# @token_auth.login_required
@token_auth.login_required
def get_info_list():
# client_id = request.values.get("client_id")
func_type = request.values.get("func_type")
page = request.values.get("page")
page_size = request.values.get("page_size")
user = g.current_user
page_param = PageParam(int(page), int(page_size))
data = BllUserApply().get_list_info(func_type=func_type, page_param=page_param, user=user)
user_list = BllUser().findList()
user_dict = {}
for i in user_list:
user_dict[i.user_id] = i.real_name
data_list = []
for i in data:
i_dict = dict(i._mapping)
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_pt_name"] = user_dict.get(i_dict["solve_user_id_pt"], '')
data_list.append(i_dict)
return jsonify(Utils.true_return(data= {"data_list":data_list, "total_count": page_param.totalRecords}))
# 删除
@temporary_bp.route("/del", methods=["POST"])
@token_auth.login_required
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)
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")
# user_id = request.values.get("user_id")
user_id = g.current_user.user_id
# user_id_pt = request.values.get("user_id_pt")
2 years ago
t = request.values.get("t")
obj = BllUserApply().findEntity(EntityUserApply.id == apply_id)
if obj.is_solve == 1:
return jsonify(Utils.false_return(msg="已受理,无需重复受理"))
# obj.is_solve = 1
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
2 years ago
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
# BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_pt], auth_type=2)
BllUserApply().update(obj)
return jsonify(Utils.true_return())
# 展示待登记列表
@temporary_bp.route("/register_drug_list", methods=["GET", "POST"])
2 years ago
@token_auth.login_required
def get_register_drug():
2 years ago
page = request.values.get("page")
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}))
# 登记接口
@temporary_bp.route("/set_register", methods=["POST"])
@token_auth.login_required
def set_register():
bar_code = request.values.get("bar_code")
bar_code, new_code = Utils.get_bar_code_reverse(bar_code)
obj = BllMedicament().findEntity(
or_(
EntityMedicament.bar_code == bar_code,
EntityMedicament.bar_code == new_code
)
)
if not obj:
return jsonify(Utils.false_return())
# drug_id = request.values.get("medicament_id")
remain = request.values.get("remain")
# obj = BllMedicament().findEntity(EntityMedicament.medicament_id==drug_id)
if obj:
2 years ago
# 开瓶日期
if not obj.remark13:
setattr(obj, "remark13", Utils.get_str_datetime())
setattr(obj, "remain", remain)
setattr(obj, "status", 2)
BllMedicament().update(obj)
# 登记
BllUserApply().update_use_content(client_id=obj.client_id, user=g.current_user, drug_info=obj)
BllMedicament().drugRegister(
entityDrug=obj,
entityClient= BllClient().findEntity(EntityClient.client_id==obj.client_id),
entityUser=g.current_user
)
return jsonify(Utils.true_return())
else:
return jsonify(Utils.false_return())
# 获取待领用试剂列表
@temporary_bp.route("/get_stay_use_list", methods=["GET", "POST"])
@token_auth.login_required
def get_stay_use_list():
client_id = request.values.get("client_id")
data_list = BllUserApply().get_stay_use_list(client_id=client_id, user=g.current_user)
return jsonify(Utils.true_return(data=data_list))