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.

124 lines
4.2 KiB

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/07/25 09:32:18
'''
from flask import jsonify, request
from flask import Blueprint
from common.read_excel import ReadExcel
from common.utils import Utils
from db_logic.client import BllClient
from db_logic.user import BllUser
from db_logic.medicament_template import BllMedicamentTemplate
from models.medicament_models import EntityMedicamentTemplate
tmp_router = Blueprint("drug_tmplate", __name__)
# 试剂入库-模板展示
@tmp_router.route("/show_tmp", methods=["GET", "POST"])
def show_template():
client_id = request.values.get("client_id")
data = BllMedicamentTemplate().getAllTemplateList(client_id=client_id)
data = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data=data))
# 选择药剂入库
# 编辑试剂信息
# # 编辑试剂模板
# @tmp_router.route("/update_tmp", methods=["GET", "POST"])
# def modify_tmp():
# tmp_id = request.values.get("template_id")
# 导入入库模板
@tmp_router.route("/put_in_tmp", methods=["GET", "POST"])
def import_tmplate():
try:
file_path = Utils.getUDiskPath()
if not file_path:
return jsonify(msg="请插入U盘")
else:
client_id = request.values.get("cliet_id", '')
template_name = request.values.get("template_name", '')
user_id = request.values.get("user_id")
read_excel = ReadExcel(file_path + "/" + template_name)
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 = tmp_obj.start_bar_code
bar_code_count = tmp_obj.bar_code_count
max_barcode = int(max_barcode) + int(bar_code_count)
else:
max_barcode = 100001
start_bar_code = max_barcode
result_list = read_excel.read()
client_obj = BllClient().findEntity(client_id)
user_obj = BllUser().findEntity(user_id)
if result_list:
inster_obj_list = []
for value in result_list:
total_count = 0
template_content_list = eval(value)
for template_content in template_content_list:
total_count += int(template_content['export_cout'])
obj = EntityMedicamentTemplate(
customer_id=client_obj.customer_id,
client_id=client_obj.client_id,
client_name=client_obj.client_name,
template_name=f'入库模板_{Utils.getFileName()}',
template_content=value,
is_wait_export = 1,
start_bar_code=str(start_bar_code),
bar_code_count=total_count,
create_date=Utils.get_str_datetime(),
create_user_id=user_obj.user_id,
create_user_name=user_obj.real_name
)
inster_obj_list.append(obj)
status = BllMedicamentTemplate().insert_many(inster_obj_list)
if status:
return jsonify(Utils.true_return(msg='导入成功'))
else:
return jsonify(Utils.false_return(msg="入库单异常,导入失败"))
else:
return jsonify(Utils.false_return(msg="入库单格式不正确,请检查之后重新导入"))
except FileNotFoundError as e:
return jsonify(Utils.false_return(msg='当前U盘下暂无reagentTemplate.xlsx文件'))
except Exception as error:
return jsonify(Utils.false_return(msg=f"模板错误:{error}"))
# 删除模板
@tmp_router.route("/del_tmp", methods=["GET", "POST"])
def remove_tmp():
tmp_id = request.values.get("template_id")
if tmp_id:
BllMedicamentTemplate().delete(EntityMedicamentTemplate.template_id==tmp_id)
return Utils.true_return(msg='删除药剂模板成功')
return Utils.false_return(msg='删除药剂模板失败')