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.
137 lines
5.0 KiB
137 lines
5.0 KiB
2 years ago
|
#!/usr/bin/env python
|
||
|
# -*- encoding: utf-8 -*-
|
||
|
'''
|
||
|
@Date: 2023/01/05 14:10:45
|
||
|
'''
|
||
|
import sys
|
||
|
sys.path.append('.')
|
||
|
import os
|
||
|
import json
|
||
|
from flask import Blueprint, request, jsonify, g
|
||
|
from sqlalchemy import and_, or_
|
||
|
from db_logic.medicament_shengou import BllMedicamntShenGou
|
||
|
from models.medicament_models import EntityMedicamntShenGou
|
||
|
from Common.report_shen_gou import ReportData
|
||
|
from db_logic.user import BllUser
|
||
|
from Common.Utils import Utils, PageParam
|
||
|
from Common.auth import token_auth
|
||
|
from apps.report.dows_utils import dows_flie
|
||
|
|
||
|
shengou_bp = Blueprint("shengou", __name__)
|
||
|
|
||
|
# 展示列表,根据用户角色是否展示全部
|
||
|
@shengou_bp.route("/get_list", methods=["POST"])
|
||
|
@token_auth.login_required
|
||
|
def get_shengou_list():
|
||
|
user = g.current_user
|
||
|
page = request.values.get("page")
|
||
|
page_size = request.values.get("page_size")
|
||
|
page_param = PageParam(int(page), int(page_size))
|
||
|
data = BllMedicamntShenGou().get_list(user=user, 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["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}))
|
||
|
|
||
|
|
||
|
# 创建申请记录
|
||
|
@shengou_bp.route("/add", methods=["POST"])
|
||
|
@token_auth.login_required
|
||
|
def add_drug_shengou():
|
||
|
func_type = request.values.get("func_type")
|
||
|
use_doc = request.values.get("use_doc")
|
||
|
use_content = request.values.get("use_content")
|
||
|
|
||
|
if not use_content:
|
||
|
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
|
||
|
obj = EntityMedicamntShenGou(
|
||
|
user_id = g.current_user.user_id,
|
||
|
create_date = Utils.get_str_datetime(),
|
||
|
is_solve = 0,
|
||
|
use_content = use_content,
|
||
|
func_type=func_type,
|
||
|
use_doc=use_doc
|
||
|
)
|
||
|
BllMedicamntShenGou().insert(obj)
|
||
|
return jsonify(Utils.true_return())
|
||
|
|
||
|
# 修改个人申请
|
||
|
@shengou_bp.route("/update", methods=["POST"])
|
||
|
@token_auth.login_required
|
||
|
def update_shengou():
|
||
|
shengou_id = request.values.get("id")
|
||
|
use_content = request.values.get("use_content")
|
||
|
if not use_content:
|
||
|
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
|
||
|
user = g.current_user
|
||
|
user_apply_obj = BllMedicamntShenGou().findEntity(
|
||
|
and_(
|
||
|
EntityMedicamntShenGou.id == shengou_id,
|
||
|
EntityMedicamntShenGou.user_id == user.user_id
|
||
|
)
|
||
|
)
|
||
|
if not user_apply_obj:
|
||
|
return jsonify(Utils.false_return(msg="只能修改自己的申请!"))
|
||
|
user_apply_obj.use_content=use_content
|
||
|
BllMedicamntShenGou().update(user_apply_obj)
|
||
|
return jsonify(Utils.true_return())
|
||
|
|
||
|
|
||
|
# 处理消息
|
||
|
@shengou_bp.route("/solve", methods=["POST"])
|
||
|
@token_auth.login_required
|
||
|
def solve_shengou():
|
||
|
shengou_id =request.values.get("id")
|
||
|
user_id = g.current_user.user_id
|
||
|
obj = BllMedicamntShenGou().findEntity(EntityMedicamntShenGou.id == shengou_id)
|
||
|
if obj.is_solve == 1:
|
||
|
return jsonify(Utils.false_return(msg="已受理,无需重复受理"))
|
||
|
if str(request.values.get('result')) == "0":
|
||
|
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.solve_date = Utils.get_str_datetime()
|
||
|
BllMedicamntShenGou().update(obj)
|
||
|
return jsonify(Utils.true_return())
|
||
|
|
||
|
# 导出申购单
|
||
|
@shengou_bp.route("/dowload", methods=["GET", "POST"])
|
||
|
@token_auth.login_required
|
||
|
def dowload_shengou():
|
||
|
shengou_id = request.values.get("id")
|
||
|
obj = BllMedicamntShenGou().findEntity(EntityMedicamntShenGou.id == shengou_id)
|
||
|
if obj and obj.is_solve == 1:
|
||
|
try:
|
||
|
file_path = os.path.join(os.getcwd(), "report_file")
|
||
|
if not os.path.exists(file_path):
|
||
|
os.makedirs(file_path)
|
||
|
obj_report = ReportData()
|
||
|
obj = obj_report.build_file(json.loads(obj.use_content))
|
||
|
rsp_file_name = f"tem_申购单_{Utils.get_file_name_datetime()}"
|
||
|
obj.save(os.path.join(file_path, rsp_file_name))
|
||
|
# u_path = Utils.getUDiskPath()
|
||
|
# if u_path:
|
||
|
# obj.save(os.path.join(u_path, rsp_file_name))
|
||
|
rep = dows_flie(file_path, rsp_file_name)
|
||
|
return rep
|
||
|
# return jsonify(Utils.true_return())
|
||
|
except Exception as error:
|
||
|
print(error)
|
||
|
return jsonify(Utils.false_return(msg=f"导出错误:{error}"))
|
||
|
return jsonify(Utils.false_return(msg="申购单导出错误"))
|