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.
206 lines
8.0 KiB
206 lines
8.0 KiB
#!/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 db_logic.medicament_template import BllMedicamentTemplate
|
|
from db_logic.client import BllClient
|
|
from models.medicament_models import EntityMedicamentTemplate
|
|
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 = 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["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")
|
|
func_type = request.values.get("func_type")
|
|
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":
|
|
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 = 2
|
|
obj.information = request.values.get("information")
|
|
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
|
|
|
|
|
|
tmp_name=''
|
|
data = BllClient().get_all_client_list(func_type=func_type)
|
|
data_list = Utils.msyql_table_model(data)
|
|
tmp_content = obj.use_content
|
|
user = BllUser().findEntity(obj.user_id)
|
|
client = data_list[0]
|
|
sql_all = """
|
|
select bar_code_count, start_bar_code from rms_medicament_template where start_bar_code=(select max(start_bar_code) max_start from rms_medicament_template)
|
|
"""
|
|
# 获取最大的条形码和条形码数量
|
|
tmp_obj = BllMedicamentTemplate().execute(sql_all).fetchone()
|
|
if tmp_obj:
|
|
max_barcode = int(tmp_obj.start_bar_code) + int(tmp_obj.bar_code_count)
|
|
else:
|
|
max_barcode = 100001
|
|
start_bar_code = max_barcode
|
|
|
|
try:
|
|
if not tmp_content or tmp_content == 'null':
|
|
return jsonify(Utils.false_return(msg="模板内容有误"))
|
|
if not tmp_name:
|
|
tmp_name = f'入库模板_{Utils.getFileName()}'
|
|
if isinstance(tmp_content, str):
|
|
# tmp_content = eval(tmp_content)
|
|
tmp_content = json.loads(tmp_content)
|
|
bar_code_count = 0
|
|
for i in tmp_content:
|
|
bar_code_count += int(i['export_count'])
|
|
|
|
obj1 = EntityMedicamentTemplate(
|
|
customer_id='1002437b-debf-46d6-b186-3e16bcf0cc0f',
|
|
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,
|
|
is_add=1
|
|
)
|
|
BllMedicamentTemplate().insert(obj1)
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
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="申购单导出错误"))
|
|
|
|
|
|
# 删除消息
|
|
@shengou_bp.route("/del", methods=["POST"])
|
|
@token_auth.login_required
|
|
def del_shengou():
|
|
shengou_id =request.values.get("id")
|
|
BllMedicamntShenGou().delete(EntityMedicamntShenGou.id==shengou_id)
|
|
return jsonify(Utils.true_return()) |