报表相关数据接口base

duizhaopin
apan 3 years ago
parent 64de5e4ba8
commit d870c0d9cf

@ -1,11 +0,0 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/07/18 16:28:44
'''
from flask import Blueprint
from apps.home import home_router
all_router = Blueprint('all_router', __name__)
all_router.register_blueprint(home_router, url_prefix="/home")

@ -1,4 +0,0 @@
from flask import Blueprint
home_router = Blueprint('home', __name__)

@ -7,13 +7,18 @@ from flask import jsonify, request
from models.warning_models import EntityWarning
from . import home_router
# from apps.home import home_router
from db_logic.medicament_record import BllMedicamentRecord
from db_logic.warning import BllWarning
from common.utils import PageParam, Utils
from flask import Blueprint
home_router = Blueprint('home', __name__, url_prefix="/home")
# 获取页面主概览数据 --- 查询条件缺少柜体id客户id
@home_router.route('/home_number', methods=["GET", "POST"])
# def getRecordTypeDrugRecordListJson():
@ -33,7 +38,7 @@ def get_record_type_drug_record_json():
# 获取预警信息列表接口
@home_router.router('/home_warning_list', methods=["GET", "POST"])
@home_router.route('/home_warning_list', methods=["GET", "POST"])
def get_warning_list():
customer_id = request.values.get('customer_id', '')
page = request.values.get('page', 1)
@ -51,7 +56,7 @@ def get_warning_list():
# 修改预警状态根据预警id进行
@home_router.router("/update_warning_tp", methods=["GET", "POST"])
@home_router.route("/update_warning_tp", methods=["GET", "POST"])
def update_warning_type():
warning_id = request.values.get('warning_id')
obj = BllWarning().findEntity(EntityWarning.warning_id == warning_id)

@ -1,9 +0,0 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/07/19 17:12:29
'''
from flask import Blueprint
report_router = Blueprint("report", __name__)

@ -5,13 +5,16 @@
'''
from flask import jsonify, request
from . import report_router
from common.utils import Utils
from db_logic.medicament_record import BllMedicamentRecord
from db_logic.medicament import BllMedicament
from flask import Blueprint
report_router = Blueprint("report", __name__)
# 获取报表统计页面展示
@report_router.router('/report_home', methods=["GET", "POST"])
@report_router.route('/report_home', methods=["GET", "POST"])
def report_home_info():
# 试剂使用统计
base_data = BllMedicamentRecord().get_drug_record_count()
@ -29,7 +32,7 @@ def report_home_info():
# 库存信息总览
@report_router.router("/stock_data_info", methods=["GET", "POST"])
@report_router.route("/stock_data_info", methods=["GET", "POST"])
def get_stock_data_info():
name = request.values.get("name", None)
page = request.values.get('page', 1)
@ -45,14 +48,33 @@ def get_stock_data_info():
else:
return jsonify(Utils.false_return(msg="无效数据"))
# 入库信息查询and 试剂信息查询
@report_router.router("/input_info")
@report_router.route("/drug_details_info", methods=["GET", "POST"])
def drun_input_info():
seach_word = request.values.get('seach_word')
page = request.values.get('page', 1)
page_size = request.values.get('page_size', 10)
manufacturer = request.values.get("manufacturer")
# manufacturer = request.values.get("manufacturer")
customer_id = request.values.get("customer_id")
client_id = request.values.get("client_id")
data = BllMedicament.getAllDrugList(search_word=seach_word, page=page, page_size=page_size, customer_id=customer_id, client_id=client_id)
return jsonify(Utils.true_return(data=data))
# 库存消耗
# 试剂名称、纯度、cas码 查询rms_medicament 分组后获取
# 入库数量 根据 medicament_id查询rms_medicament_record record_type == 1 count(id)
# 当前在库数量 查询 rms_medicament 分组后 status=1 count(id)
# 当前借出数量:查询 rms_medicament 分组后 status=2 count(id)
# 当前借出数量:查询 rms_medicament 分组后 status=3 count(id)
@report_router.route("/stock_loss_info", methods=["GET", "POST"])
def stock_loss_info():
seach_word = request.values.get('seach_word')
data = BllMedicamentRecord().durg_stock_loss(seach_word)
return jsonify(Utils.true_return(data=data))
# 试剂用量消耗

@ -3,6 +3,7 @@
'''
@Date:2022/07/18 15:02:28
'''
from csv import unregister_dialect
import json
import datetime
import decimal
@ -60,11 +61,19 @@ class JSONEncoder(_JSONEncoder):
class Flask(New_flask):
json_encoder = JSONEncoder
def register_blueprints(app):
def register_blueprints(app: Flask):
"""
"""
from apps import all_router
app.register_blueprint(all_router, url_prefix="/api")
# from apps import all_router
from apps.home.views import home_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(report_router, url_prefix="/api/report")
# app.register_blueprint(all_router, url_prefix="/api")
def create_app():

@ -212,12 +212,24 @@ class BllMedicament(Repository):
self.entityType.expiration_date,
self.entityType.shelf_life,
self.entityType.put_in_user_name,
self.entityType.put_in_date
self.entityType.put_in_date,
# 试剂详细信息数据展示
self.entityType.english_name,
self.entityType.purity,
self.entityType.is_supervise,
self.entityType.by_user_name,
).filter(*filter_base)
fields = [
"name", "distributor", "net_weight_unit", "remain",
"production_date", "expiration_date", "shelf_life",
"put_in_user_name", "put_in_date"
"put_in_user_name", "put_in_date",
"english_name",
"purity",
"is_supervise",
"by_user_name"
]
data_list = []
page_data = self.queryPage(data, page_param)

@ -3,15 +3,18 @@
'''
@Date:2022/07/19 10:49:15
'''
from decimal import Decimal
import sys
sys.path.append('.')
import json
import datetime
from sqlalchemy import or_, and_, asc, desc
from sqlalchemy.sql import func
from db_logic.db_base import Repository
from models.medicament_models import EntityMedicamentRecord
from common.utils import Utils
# from common.utils import Utils
#药剂流转记录业务逻辑类
@ -76,6 +79,53 @@ class BllMedicamentRecord(Repository):
).select_from(self.entityType).group_by(EntityMedicamentRecord.record_type).all()
return data
# 获取库存消耗数据
def durg_stock_loss(self, seach_word):
sql_all = """
select c.`name`, c.cas_number, c.net_weight_unit, c.purity, c.enter_stock,
sum(CASE WHEN c.`status`=1 THEN 1 ELSE 0 END) in_stock,
sum(CASE WHEN c.`status`=2 THEN 1 ELSE 0 END) up_stock,
sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock
from (
select a.*, b.enter_stock from (
select medicament_id, `name`, cas_number, purity, net_weight_unit, `status` from rms_medicament
%s
) a LEFT JOIN(
SELECT medicament_id, sum(CASE WHEN record_type=1 THEN 1 ELSE 0 END) enter_stock from rms_medicament_record GROUP BY medicament_id
) b on b.medicament_id = a.medicament_id) c GROUP BY `name`, purity, net_weight_unit
"""
if seach_word:
sql_all = sql_all % f"where name link {seach_word} or english_name link {seach_word}"
else:
sql_all = sql_all % ''
finds = [
"name", "cas_number", "net_weight_unit", "purity", "enter_stock", "in_stock", "up_stock", "no_stock"
]
med_data = self.execute(sql_all).fetchall()
data_list = []
for med in med_data:
new_med = []
for n in med:
if isinstance(n, Decimal):
n = float(n)
new_med.append(n)
data_list.append(dict(zip(finds, new_med)))
return data_list
# 试剂用量消耗
def update_db(self):
import random
typ_dic = BllMedicamentRecord().findList().all()
for a in typ_dic:
a.use_quantity = round(random.uniform(1, 10), 2)
self.session.merge(a)
self.session.commit()
# #获取药剂最后一次使用余量
# def getLastRecordRemain(self, drugId):
@ -97,10 +147,10 @@ class BllMedicamentRecord(Repository):
# result = BllMedicamentRecord().executeNoParam(SQL)
# return result
if __name__ == '__main__':
import random
from db_logic.medicament_record import BllMedicamentRecord
customerId, clientId = None, '8db7e540-070f-11ed-a286-f47b094925e1'
typ_dic = BllMedicamentRecord().get_drug_record_count()
# typ_dic[4] = typ_dic[2] - typ_dic[3]
sql = f"update rms_medicament_record set use_quantity={round(random.uniform(1,10), 1)}"
typ_dic = BllMedicamentRecord().update_db()
print(typ_dic)

@ -64,7 +64,9 @@
库存消耗: rms_medicament rms_medicament_variety
入库数量 查询类型等于书库的数量
入库数量 记录表record_type = 1 数量
借出 记录表record_type = 2 数量
借出 记录表record_type = 2 数量
当前库存总量
rms_medicament_record record_type=1 count(id)?
当前库存数量 status=1的count(id)?
@ -94,25 +96,35 @@
# for i in range(30):
# print(f"remark{i+1} = Column(String(50), comment='扩展字段{i+1}')")
import random
from string import digits, ascii_letters, punctuation
aaa = digits + ascii_letters+ punctuation
# ccc = 'l4wu&yj@=ed^ybmw&#6m&vh0cglcqwagu8&($r5@qsmf(bb93='
# print(len(ccc))
print(aaa)
a = ''
# while True:
# c = random.choice(aaa)
# if c in ["'", '"', ",", ";", "."]:
# continue
# # print(c)
# a += c
# import random
# from string import digits, ascii_letters, punctuation
# aaa = digits + ascii_letters+ punctuation
# # ccc = 'l4wu&yj@=ed^ybmw&#6m&vh0cglcqwagu8&($r5@qsmf(bb93='
# # print(len(ccc))
# print(aaa)
# a = ''
# # while True:
# # c = random.choice(aaa)
# # if c in ["'", '"', ",", ";", "."]:
# # continue
# # # print(c)
# # a += c
# # # print(a)
# # if len(a) >= 50:
# # break
# # print(a)
# if len(a) >= 50:
# break
# print(a)
import random
# import random
print(random.choice([1,2,3]))
# # print(random.choice([1,2,3]))
a = """12342525436 %s freqwrqwercqwe"""
b = ''
if b:
a = a % f"ccccc{b}ccccccc"
else:
a = a % ''
print(a)

@ -10,7 +10,7 @@ sys.path.append('.')
# from common.utils import Utils
from sqlalchemy import Column, String, Integer, Text, Float
from models.models_base import Base, get_uuid, ModelBase
from models.models_base import Base, get_uuid
# from sqlalchemy.ext.declarative import declarative_base
@ -223,46 +223,46 @@ class EntityMedicamentExtend(Base):
field_table_type = Column(Integer, comment="字段所在表")
if __name__ == '__main__':
# from db_logic.medicament_record import BllMedicamentRecord
# customerId, clientId = None, '8db7e540-070f-11ed-a286-f47b094925e1'
# aaa = BllMedicamentRecord().getTodayDrugRecordCount(customerId, clientId)
# print(aaa)
import random
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config.SystemConfig import SystemConfig
from sqlalchemy.pool import NullPool
engine = create_engine(SystemConfig.getConfig(
'dbconntion'), poolclass=NullPool)
DBSession = sessionmaker(bind=engine, expire_on_commit=False)
# 创建session对象
session = DBSession()
client_id= get_uuid()
variety_id_list = [get_uuid() for i in range(5)]
bar_code_list = [i for i in range(10001, 10110)]
customer_id= get_uuid()
for i in range(100):
db_mo = EntityMedicament(
bar_code=random.choice(bar_code_list),
variety_id=random.choice(variety_id_list),
client_id=client_id,
client_code=6,
customer_id=customer_id,
cas_number='',
name='',
english_name='',
shelf_life=5170,
inventory_warning_value=10,
shelf_life_warning_value=10,
use_days_warning_value=10,
remain=500,
total=500,
purity="国标",
status=random.randint(1,3)
# create_date=Utils.get_str_datetime()
)
session.add(db_mo)
session.commit()
# if __name__ == '__main__':
# # from db_logic.medicament_record import BllMedicamentRecord
# # customerId, clientId = None, '8db7e540-070f-11ed-a286-f47b094925e1'
# # aaa = BllMedicamentRecord().getTodayDrugRecordCount(customerId, clientId)
# # print(aaa)
# import random
# from sqlalchemy import create_engine
# from sqlalchemy.orm import sessionmaker
# from config.SystemConfig import SystemConfig
# from sqlalchemy.pool import NullPool
# engine = create_engine(SystemConfig.getConfig(
# 'dbconntion'), poolclass=NullPool)
# DBSession = sessionmaker(bind=engine, expire_on_commit=False)
# # 创建session对象
# session = DBSession()
# client_id= get_uuid()
# variety_id_list = [get_uuid() for i in range(5)]
# bar_code_list = [i for i in range(10001, 10110)]
# customer_id= get_uuid()
# for i in range(100):
# db_mo = EntityMedicament(
# bar_code=random.choice(bar_code_list),
# variety_id=random.choice(variety_id_list),
# client_id=client_id,
# client_code=6,
# customer_id=customer_id,
# cas_number='',
# name='砷',
# english_name='',
# shelf_life=5170,
# inventory_warning_value=10,
# shelf_life_warning_value=10,
# use_days_warning_value=10,
# remain=500,
# total=500,
# purity="国标",
# status=random.randint(1,3)
# # create_date=Utils.get_str_datetime()
# )
# session.add(db_mo)
# session.commit()
# Base.metadata.create_all(engine)
# # Base.metadata.create_all(engine)

@ -9,24 +9,6 @@ from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class ModelBase(object):
fields = None
def __init__(self):
if not self.__class__.fields:
self.__class__.fields = [x.key for x in self.__mapper__.attrs]
def __iter__(self):
if not self.__class__.fields:
self.__class__.fields = [x.key for x in self.__mapper__.attrs]
return next(self)
def __next__(self):
for key in self.__class__.fields:
value = getattr(self, key)
def get_uuid():
return str(uuid.uuid1())

Loading…
Cancel
Save