#!/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 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.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") page = request.values.get("page") page_size = request.values.get("page_size") page_param = PageParam(int(page), int(page_size)) data = BllMedicament().use_drug_info_list(client_id=client_id, 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"]) def user_apply_log(): user_id = request.values.get("user_id") user_id_pt = request.values.get("user_id_pt") drug_name = request.values.get("drug_name") drug_num = request.values.get("drug_num") client_id = request.values.get("client_id") func_type = request.values.get("func_type") use_doc = request.values.get("use_doc") try: client_code = BllClient().findEntity(EntityClient.client_id==client_id).client_code except: client_code = '' obj = EntityUserApply( user_id = 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, 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("/get_list", methods=["POST"]) # @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") page_param = PageParam(int(page), int(page_size)) data = BllUserApply().get_list_info(client_id=client_id, func_type=func_type, page_param=page_param) 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_pt = request.values.get("user_id_pt") obj = BllUserApply().findEntity(EntityUserApply.id == apply_id) if obj.is_solve == 1: return jsonify(Utils.false_return(msg="已受理,无需重复受理")) obj.is_solve = 1 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], client_id=obj.client_id) BllUserApply().update(obj) return jsonify(Utils.true_return())