模板接口调整;

报表接口部分调整
duizhaopin
apan 2 years ago
parent 2d74ff1d59
commit b6ed0329e1

@ -64,7 +64,7 @@ class Utils(object):
# sqlalchemy 原生sql转换实体列表 # sqlalchemy 原生sql转换实体列表
def msyql_table_model(data_list): def msyql_table_model(data_list):
return[i._mapping for i in data_list] return[dict(i._mapping) for i in data_list]
#生成统一格式接口数据 #生成统一格式接口数据
def resultData(status, message, data=""): def resultData(status, message, data=""):

@ -114,7 +114,7 @@ def get_drug_info():
# 试剂管理 # 试剂管理
@drug_router.route("/drug_manage", methods=["GET", "POST"]) @drug_router.route("/drug_manage", methods=["GET", "POST"])
def get_drug_info(): def get_drug_manage():
seach_word = request.values.get("seach_word") seach_word = request.values.get("seach_word")
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
data_list = BllMedicament().get_drug_info_distinct_list(seach_word=seach_word, client_id=client_id) data_list = BllMedicament().get_drug_info_distinct_list(seach_word=seach_word, client_id=client_id)

@ -3,15 +3,16 @@
''' '''
@Date:2022/07/25 09:32:18 @Date:2022/07/25 09:32:18
''' '''
import sys
sys.path.append(".")
import datetime import datetime
import json import json
from flask import jsonify, request from flask import jsonify, request, g
from flask import Blueprint from flask import Blueprint
from common.read_excel import ReadExcel from common.read_excel import ReadExcel
from common.utils import Utils from common.utils import Utils, PageParam
from db_logic.client import BllClient from db_logic.client import BllClient
from db_logic.medicament import BllMedicament from db_logic.medicament import BllMedicament
from db_logic.user import BllUser from db_logic.user import BllUser
@ -30,9 +31,12 @@ tmp_router = Blueprint("drug_tmplate", __name__)
@tmp_router.route("/show_tmp", methods=["GET", "POST"]) @tmp_router.route("/show_tmp", methods=["GET", "POST"])
def show_template(): def show_template():
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
data = BllMedicamentTemplate().getAllTemplateList(client_id=client_id) page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data = BllMedicamentTemplate().getAllTemplateList(client_id=client_id, page_param=page_param)
data = Utils.msyql_table_model(data) data = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data=data)) return jsonify(Utils.true_return(data={"total_count":page_param.totalRecords, "data_list":data}))
@ -42,17 +46,23 @@ def show_template():
@tmp_router.route("/select_drug", methods=["GET", "POST"]) @tmp_router.route("/select_drug", methods=["GET", "POST"])
def select_drug_info(): def select_drug_info():
seach_word =request.values.get("seach_word") seach_word =request.values.get("seach_word")
data_list = BllMedicament().get_drug_info_distinct_list(seach_word) page = int(request.values.get("page", 1))
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list))) page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data_list = BllMedicament().get_drug_info_distinct_list(
seach_word=seach_word, page_param=page_param)
data_list = Utils.msyql_table_model(data_list)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data_list": data_list}))
# 绑定入库 # 绑定入库
@tmp_router.route("/bind_tmp_enter_warehouse", methods=["GET", "POST"]) @tmp_router.route("/bind_tmp_enter_warehouse", methods=["GET", "POST"])
def bind_tmp_input_db(): def bind_tmp_input_db():
tmp_content = request.values.get("tmplate_content") tmp_content = request.values.get("tmplate_content")
customer_id = request.values.get("customer_id", '') customer_id = request.values.get("customer_id", '')
client_id = request.values.get("client_id") # client_id = request.values.get("client_id")
client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1'
bar_code = request.values.get("bar_code") bar_code = request.values.get("bar_code")
user_id = request.values.get("user_id") # user_id = request.values.get("user_id")
if not bar_code: if not bar_code:
return jsonify(Utils.false_return(msg="条码不能为空")) return jsonify(Utils.false_return(msg="条码不能为空"))
drug_obj = BllMedicament().findEntity(EntityMedicament.bar_code==bar_code) drug_obj = BllMedicament().findEntity(EntityMedicament.bar_code==bar_code)
@ -60,7 +70,9 @@ def bind_tmp_input_db():
return jsonify(Utils.false_return(msg="该药剂已被锁定")) return jsonify(Utils.false_return(msg="该药剂已被锁定"))
else: else:
drug_info = eval(tmp_content) drug_info = eval(tmp_content)
user_info = BllUser().findEntity(user_id) user_info = BllUser().findEntity('4cea74ee-0d8b-11ed-943e-f47b094925e1')
# user_info = g.current_user
drug_variety = BllMedicamentVariety().createDrugVariety( drug_variety = BllMedicamentVariety().createDrugVariety(
customer_id=customer_id, customer_id=customer_id,
drug_info=drug_info, user_info=user_info drug_info=drug_info, user_info=user_info
@ -109,9 +121,10 @@ def bind_tmp_input_db():
@tmp_router.route("/add_tmp", methods=["GET", "POST"]) @tmp_router.route("/add_tmp", methods=["GET", "POST"])
def add_tmp_info(): def add_tmp_info():
tmp_name = request.values.get("template_name") tmp_name = request.values.get("template_name")
client_id = request.values.get("client_id") # client_id = request.values.get("client_id")
client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1'
tmp_content = request.values.get("tmplate_content") tmp_content = request.values.get("tmplate_content")
user_id = request.values.get("user_id") user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
user = BllUser().findEntity(user_id) user = BllUser().findEntity(user_id)
client = BllClient().findEntity(client_id) client = BllClient().findEntity(client_id)
sql_all = """ sql_all = """

@ -43,18 +43,14 @@ def get_drug_user_use_number():
@report_router.route("/stock_data_info", methods=["GET", "POST"]) @report_router.route("/stock_data_info", methods=["GET", "POST"])
def get_stock_data_info(): def get_stock_data_info():
name = request.values.get("name", None) name = request.values.get("name", None)
page = request.values.get('page', 1) page = int(request.values.get('page', 1))
page_size = request.values.get('page_size', 15) page_size = int(request.values.get('page_size', 15))
finds = ["name", "cas_number", "net_weight_unit",
"client_id", "count_surplus", "sum_remain"]
page_param = PageParam(page, page_size) page_param = PageParam(page, page_size)
data_list = BllMedicament.get_stock_all_info( data_list = BllMedicament().get_stock_all_info(
name=name, page_param=page_param) name=name, page_param=page_param)
data_list = Utils.msyql_table_model(data_list)
if data_list: if data_list:
data = [] return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data_list}))
for i in data_list:
data.append(dict(zip(finds, list(i))))
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data}))
else: else:
return jsonify(Utils.false_return(msg="无效数据")) return jsonify(Utils.false_return(msg="无效数据"))
@ -98,7 +94,7 @@ def stock_loss_info():
# 试剂用量消耗 # 试剂用量消耗
@report_router.route("/drug_use_expend", methods=["GET", "POST"]) @report_router.route("/drug_use_expend", methods=["GET", "POST"])
def drug_use_expend(): def get_drug_use_expend():
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
page = request.values.get("page", 1) page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10) page_size = request.values.get("page_size", 10)
@ -109,7 +105,7 @@ def drug_use_expend():
# 人员用量消耗 # 人员用量消耗
@report_router.route("/drug_user_use_expend", methods=["GET", "POST"]) @report_router.route("/drug_user_use_expend", methods=["GET", "POST"])
def drug_use_expend(): def get_drug_user_use_expend():
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
page = request.values.get("page", 1) page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10) page_size = request.values.get("page_size", 10)

@ -62,20 +62,20 @@ class JSONEncoder(_JSONEncoder):
class Flask(New_flask): class Flask(New_flask):
json_encoder = JSONEncoder json_encoder = JSONEncoder
def register_blueprints(app: Flask): def register_blueprints(app: New_flask):
""" """
""" """
# from apps import all_router from apps.home.views import home_router
# from apps.home.views import home_router from apps.drug.views import drug_router
from apps.drug_template.views import tmp_router
from apps.user.views import user_router from apps.user.views import user_router
# from apps.report.views import report_router from apps.report.views import report_router
# all_router = Blueprint('all_router', __name__) app.register_blueprint(home_router, url_prefix="/api/home")
# app.register_blueprint(home_router, url_prefix="/api/home") app.register_blueprint(drug_router, url_prefix="/api/drug")
# app.register_blueprint(report_router, url_prefix="/api/report") app.register_blueprint(tmp_router, url_prefix="/api/drug_tmplate")
app.register_blueprint(report_router, url_prefix="/api/report")
app.register_blueprint(user_router, url_prefix="/api/user") app.register_blueprint(user_router, url_prefix="/api/user")
# app.register_blueprint(all_router, url_prefix="/api")
def create_app(): def create_app():

@ -4,6 +4,8 @@
@Date:2022/07/18 16:54:45 @Date:2022/07/18 16:54:45
''' '''
import sys import sys
import sqlalchemy
sys.path.append('.') sys.path.append('.')
import datetime import datetime
from sqlalchemy import distinct, or_, and_, desc, asc from sqlalchemy import distinct, or_, and_, desc, asc
@ -31,6 +33,10 @@ class BllMedicament(Repository):
def __init__(self, entityType=EntityMedicament): def __init__(self, entityType=EntityMedicament):
return super().__init__(entityType) return super().__init__(entityType)
def sql_paging_assemble(self, sql_all, page_param):
sql_all += ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows)
return sql_all
# 获取离保质期最近的同类药剂 # 获取离保质期最近的同类药剂
def getDrugNearExpired(self, varietyId, customerId): def getDrugNearExpired(self, varietyId, customerId):
drugList = self.findList( drugList = self.findList(
@ -52,13 +58,18 @@ class BllMedicament(Repository):
sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) surplus_number sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) surplus_number
from rms_medicament %s GROUP BY `name`, cas_number, purity from rms_medicament %s GROUP BY `name`, cas_number, purity
""" """
# 动态添加查询条件
where_base = "" where_base = ""
if client_id: if client_id:
where_base = f" client_id='{client_id}'" where_base = f" client_id='{client_id}'"
if where_base: if where_base:
where_base = " where " + where_base where_base = " where " + where_base
# 组装sql
sql_all = sql_all % where_base sql_all = sql_all % where_base
# 调用分页组装sql
sql_all = self.sql_paging_assemble(sql_all, page_param)
data_list = self.execute(sql_all).fetchall() data_list = self.execute(sql_all).fetchall()
# 查询页总数
count_sql = f"SELECT count(*) FROM rms_medicament %s GROUP BY `name`, cas_number, purity" % where_base count_sql = f"SELECT count(*) FROM rms_medicament %s GROUP BY `name`, cas_number, purity" % where_base
page_param.totalRecords = self.execute(count_sql).fetchone()[0] page_param.totalRecords = self.execute(count_sql).fetchone()[0]
return data_list return data_list
@ -97,11 +108,13 @@ class BllMedicament(Repository):
return self.queryPage(orm_query, pageParam) return self.queryPage(orm_query, pageParam)
# 选择药剂入库--试剂详情 # 选择药剂入库--试剂详情
def get_drug_info_distinct_list(self, seach_word, client_id=None): def get_drug_info_distinct_list(self, seach_word, page_param, client_id=None):
sql_all = """ sql_all = """
select * from rms_medicament %s select %s from rms_medicament %s
""" """
# 分组查询
group_base = " group by `name`, cas_number, net_weight_unit" group_base = " group by `name`, cas_number, net_weight_unit"
# 动态添加查询条件
where_base = "" where_base = ""
if client_id: if client_id:
where_base += f"client_id='{client_id}'" where_base += f"client_id='{client_id}'"
@ -111,8 +124,14 @@ class BllMedicament(Repository):
where_base += f" `name` like '{seach_word}' or english_name like '{seach_word}'" where_base += f" `name` like '{seach_word}' or english_name like '{seach_word}'"
if where_base: if where_base:
where_base = "where" + where_base where_base = "where" + where_base
sql_all = sql_all % (where_base+group_base, ) # 组装最终sql
return self.execute(sql_all).fetchall() run_sql = sql_all % ("*", where_base+group_base)
run_sql = self.sql_paging_assemble(run_sql, page_param)
run_sql_data = self.execute(run_sql).fetchall()
page_param.totalRecords = self.execute(
sql_all % ("count(*)", where_base + group_base)).fetchone()[0]
return run_sql_data
# 药剂入库 # 药剂入库
def drugPutIn(self, entityDrug=EntityMedicament(), entityClient=EntityClient(), entityUser=EntityUser()): def drugPutIn(self, entityDrug=EntityMedicament(), entityClient=EntityClient(), entityUser=EntityUser()):
@ -224,34 +243,25 @@ class BllMedicament(Repository):
# 获取库存信息总览 # 获取库存信息总览
def get_stock_all_info(self, page_param, name=None): def get_stock_all_info(self, page_param, name=None):
base_case = [ sql_all = """
self.entityType.name, select DISTINCT `name`,cas_number,net_weight_unit, client_id,
self.entityType.cas_number, sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number,
self.entityType.net_weight_unit sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain
] FROM rms_medicament %s
"""
filter_base = ""
if name: if name:
filt = [self.entityType.name.like(f"%{name}%")] filter_base = f"where `name` LIKE %'{name}'%"
else:
filt = [] filter_base += " GROUP BY `name`, cas_number, net_weight_unit"
data = self.session.query( sql_all = sql_all % filter_base
*base_case, sql_all = self.sql_paging_assemble(sql_all, page_param)
self.entityType.client_id, sql_data = self.execute(sql_all).fetchall()
func.count(self.entityType.medicament_id),
func.sum(self.entityType.remain)
).select_from(
self.entityType
).distinct(
*base_case
).filter(
*filt
).group_by(
*base_case
)
count_sql = f"SELECT count(medicament_id) FROM rms_medicament "
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
return self.queryPage(data, page_param) count_sql = f"SELECT count(medicament_id) FROM rms_medicament GROUP BY `name`, cas_number, net_weight_unit "
page_param.totalRecords = len(self.execute(count_sql).fetchone())
return sql_data
#获取所有药剂列表 #获取所有药剂列表
def getAllDrugList(self, search_word, page_param, customer_id=None, client_id=None): def getAllDrugList(self, search_word, page_param, customer_id=None, client_id=None):
# (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord) # (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord)

@ -21,12 +21,16 @@ class BllMedicamentTemplate(Repository):
return super().__init__(entityType) return super().__init__(entityType)
# 获取所有模板列表 # 获取所有模板列表
def getAllTemplateList(self, client_id): def getAllTemplateList(self, client_id, page_param):
sql_all = "select * from rms_medicament_template where is_wait_export=1 " sql_all = "select %s from rms_medicament_template where is_wait_export=1 "
end_sql = "order by create_date desc" end_sql = "order by create_date desc"
if client_id: if client_id:
sql_all = sql_all + f"and client_id='{client_id}'" sql_all = sql_all + f"and client_id='{client_id}'"
data = self.execute(sql_all+end_sql).fetchall()
page_param.totalRecords = self.execute(sql_all% ("count(*)")).fetchone()[0]
sql_all = sql_all + end_sql + ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows)
data = self.execute(sql_all % "*").fetchall()
return data return data
def inster_base_log(self, asss): def inster_base_log(self, asss):

@ -0,0 +1,73 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/07/28 08:37:59
'''
import sys
sys.path.append(".")
from sqlalchemy import Column, String, Integer
from models.models_base import Base
#终端模块实体类
class EntityModule(Base):
__tablename__ = "rms_module"
__table_args__ = (
{
"comment": "终端模块表"
}
)
module_id = Column(String(50), primary_key=True, comment="模块ID")
module_type = Column(String(50), comment="模块类型")
module_code = Column(String(50), comment="")
module_name = Column(String(50), comment="模块名称")
icon = Column(String(50), comment="图片")
url_address = Column(String(50), comment="图片地址")
sort_index = Column(Integer, comment="排序下标")
module_weight = Column(Integer, comment="模块权重")
parent_id = Column(String(50), comment="父id")
is_enabled = Column(Integer, comment="是否启用")
description = Column(String(50), comment="备注")
create_date = Column(String(50), comment="创建时间")
create_user_id = Column(String(50), comment="创建用户id")
create_user_name = Column(String(50), comment="创建用户名")
is_add = Column(Integer, comment="")
# #终端模块权限实体类
class EntityModuleRelation(Base):
__tablename__ = "rms_module_relation"
__table_args__ = (
{
"comment": "模块权限表"
}
)
module_relation_id = Column(String(50), primary_key=True, comment="模块权限id")
customer_id = Column(String(50), comment="客户id")
object_type = Column(String(50), comment="类型")
object_id = Column(String(50), comment="类型id")
module_type = Column(String(50), comment="模块类型")
module_id = Column(String(50), comment="模块id")
create_date = Column(String(50), comment="创建时间")
create_user_id = Column(String(50), comment="创建用户id")
create_user_name = Column(String(50), comment="创建用户名称")
is_add = Column(Integer, comment="")
# if __name__ == '__main__':
# from sqlalchemy import create_engine
# from config.SystemConfig import SystemConfig
# from sqlalchemy.pool import NullPool
# from sqlalchemy.orm import sessionmaker
# engine = create_engine(SystemConfig.getConfig(
# 'dbconntion'), poolclass=NullPool)
# # if not database_exists(engine.url):
# # create_database(engine.url)
# # 创建session工厂
# # DBSession = sessionmaker(bind=engine, expire_on_commit=False)
# # # 创建session对象
# # session = DBSession()
# Base.metadata.create_all(engine)

Binary file not shown.
Loading…
Cancel
Save