parent
6826648699
commit
12cfcd6bed
@ -0,0 +1,123 @@
|
||||
#!/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='删除药剂模板失败')
|
||||
|
||||
|
||||
|
@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@Date:2022/07/25 09:38:05
|
||||
'''
|
||||
import sys
|
||||
|
||||
sys.path.append(".")
|
||||
|
||||
from common.utils import Utils
|
||||
from sqlalchemy import desc, Table
|
||||
|
||||
from db_logic.db_base import Repository
|
||||
from models.medicament_models import EntityMedicamentTemplate
|
||||
|
||||
|
||||
#药剂品种业务逻辑类
|
||||
class BllMedicamentTemplate(Repository):
|
||||
|
||||
def __init__(self, entityType=EntityMedicamentTemplate):
|
||||
return super().__init__(entityType)
|
||||
|
||||
# 获取所有模板列表
|
||||
def getAllTemplateList(self, client_id):
|
||||
sql_all = "select * from rms_medicament_template where is_wait_export=1 "
|
||||
end_sql = "order by create_date desc"
|
||||
if client_id:
|
||||
sql_all = sql_all + f"and client_id='{client_id}'"
|
||||
data = self.execute(sql_all+end_sql).fetchall()
|
||||
return data
|
||||
|
||||
def inster_base_log(self, asss):
|
||||
import random, json
|
||||
li_ba = []
|
||||
for i in range(1, 5):
|
||||
obj = EntityMedicamentTemplate(
|
||||
client_id="8db7e540-070f-11ed-a286-f47b094925e1",
|
||||
client_name="测试机器",
|
||||
template_name=f"测试模板{i}",
|
||||
template_content=json.dumps(asss),
|
||||
is_wait_export=1,
|
||||
start_bar_code=random.randint(100001, 100111),
|
||||
bar_code_count=len(asss),
|
||||
create_date=Utils.get_str_datetime(),
|
||||
create_user_id="c0858e96-d900-11eb-8209-009027e3906b",
|
||||
create_user_name="admin",
|
||||
)
|
||||
li_ba.append(obj)
|
||||
self.insert_many(li_ba)
|
||||
|
||||
def to_dict(c, data_list):
|
||||
# li = []
|
||||
# for i in self.__table__.columns:
|
||||
# li.append(i.name)
|
||||
data = []
|
||||
key_list = [i for i in c.__table__.columns]
|
||||
for i in data_list:
|
||||
data.append(
|
||||
dict(zip(key_list, i))
|
||||
)
|
||||
return data
|
||||
|
||||
if __name__ == '__main__':
|
||||
# import json
|
||||
# data = BllMedicamentTemplate().getAllTemplateList("")
|
||||
# # data = Utils.resultAlchemyData(json.loads(data))
|
||||
|
||||
|
||||
# # data =BllMedicamentTemplate().entityType.to_dict(data_list=data)
|
||||
# print(data)
|
||||
asss = [
|
||||
{"variety_id": "f8442a6e-9950-11ec-a502-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u6613\u5236\u6bd2", "remark4": "", "name": "\u7532\u82ef", "english_name": "", "purity": "AR\uff08\u6caa\u8bd5\uff09\uff0c\u2265 99.5%", "cas_number": "108-88-3", "remark5": "",
|
||||
"speci": "500", "speci_unit": "ml", "export_count": "1", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "683", "manufacturer": "\u56fd\u836f", "remark8": "", "remark9": "\u70f7\u57fa\u6c5e", "remark10": ""},
|
||||
{"variety_id": "f8442a6f-9950-11ec-9253-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u5371\u5316\u54c1", "remark4": "", "name": "\u82ef\u915a", "english_name": "", "purity": "AR\uff08\u6caa\u8bd5\uff09\uff0c\u2265 99.0%", "cas_number": "108-95-2", "remark5": "",
|
||||
"speci": "500", "speci_unit": "ml", "export_count": "1", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "848", "manufacturer": "\u56fd\u836f", "remark8": "", "remark9": "\u6325\u53d1\u915a", "remark10": ""},
|
||||
{"variety_id": "f8442a70-9950-11ec-a157-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u5371\u5316\u54c1", "remark4": "", "name": "\u82ef", "english_name": "", "purity": "AR\uff08\u6caa\u8bd5\uff09\uff0c\u2265 99.5%", "cas_number": "71-43-2", "remark5": "",
|
||||
"speci": "500", "speci_unit": "ml", "export_count": "1", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "640", "manufacturer": "\u56fd\u836f", "remark8": "", "remark9": "\u6cb9", "remark10": ""},
|
||||
{"variety_id": "f8442a71-9950-11ec-9894-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u5371\u5316\u54c1", "remark4": "", "name": "\u4e59\u9178\uff0836%\uff09", "english_name": "", "purity": "AR", "cas_number": "64-19-7", "remark5": "", "speci": "500",
|
||||
"speci_unit": "ml", "export_count": "1", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "734", "manufacturer": "\u56fd\u836f", "remark8": "", "remark9": "\u70f7\u57fa\u6c5e", "remark10": ""},
|
||||
{"variety_id": "f84451a6-9950-11ec-8925-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u5371\u5316\u54c1", "remark4": "", "name": "\u4e59\u9178\u9150", "english_name": "", "purity": "AR", "cas_number": "106-24-7", "remark5": "", "speci": "500",
|
||||
"speci_unit": "ml", "export_count": "1", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "749", "manufacturer": "\u56fd\u836f", "remark8": "", "remark9": "\u70f7\u57fa\u6c5e", "remark10": ""},
|
||||
{"variety_id": "f84451a7-9950-11ec-9b4e-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u5371\u5316\u54c1", "remark4": "", "name": "\u56db\u6c2f\u4e59\u70ef", "english_name": "", "purity": "\u73af\u4fdd\u7ea7", "cas_number": "127-18-4", "remark5": "", "speci": "500",
|
||||
"speci_unit": "ml", "export_count": "28", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "1207", "manufacturer": "\u5929\u6d25\u50b2\u7136", "remark8": "", "remark9": "\u6cb9", "remark10": ""},
|
||||
{"variety_id": "f84451a8-9950-11ec-96ca-e2052a1045e4", "remark1": "", "remark2": "", "remark3": "\u5371\u5316\u54c1", "remark4": "", "name": "\u56db\u6c2f\u5316\u78b3", "english_name": "", "purity": "\u7ea2\u5916\u6d4b\u6cb9\u4eea\u4e13\u7528", "cas_number": "56-23-5", "remark5": "", "speci": "500", "speci_unit": "ml", "export_count": "31", "remark6": "\u74f6", "production_date": "2022-03-01", "shelf_life": 10529, "price": "0", "is_supervise": 0, "remain": "1126", "manufacturer": "\u5b89\u8c31", "remark8": "", "remark9": "\u77ff\u7269\u6cb9", "remark10": ""}]
|
||||
rsp = BllMedicamentTemplate().inster_base_log(asss)
|
||||
print(rsp)
|
Binary file not shown.
Loading…
Reference in new issue