试剂入库问题修复;

数据接口返回问题修复
duizhaopin
apan 2 years ago
parent b9a8089d80
commit a593e8dbcd

@ -38,7 +38,7 @@ class Utils(object):
return sql_all
def classify(num, all_num, fl=2):
return str(round(float(round(num / all_num, fl)) * 100)) + "%"
return str(round(float(round(float(num) / all_num, fl)) * 100)) + "%"
#获取唯一识别码
def UUID():

@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/07/29 09:03:39
'''
from flask import Blueprint, jsonify, request
from Common.Utils import Utils
from db_logic.client import BllClient
client_router = Blueprint("client", __name__)
# 查看client列表
@client_router.route("/client_list", methods=["POST"])
def get_client_list():
data = BllClient().get_all_client_list()
data_list = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data={"data_list": data_list}))

@ -87,14 +87,14 @@ def bind_tmp_input_db():
customer_id=customer_id,
drug_info=drug_info, user_info=user_info
)
finds = [
"name", "cas_number", "english_name", "purity", "manufacturer", "distributor",
"production_date", "shelf_life", "net_weight_unit", "net_weight", "tp", "price",
"place", "expiration_date"
]
key_dict = {}
for i in finds:
key_dict[i] = drug_info.get(i)
# finds = [
# "name", "cas_number", "english_name", "purity", "manufacturer", "distributor",
# "production_date", "shelf_life", "net_weight_unit", "net_weight", "tp", "price",
# "place", "expiration_date"
# ]
# key_dict = {}
# for i in finds:
# key_dict[i] = drug_info.get(i)
new_dict = {
"medicament_id": Utils.UUID(),
"variety_id": drug_variety.variety_id,
@ -107,13 +107,18 @@ def bind_tmp_input_db():
"shelf_life_warning_value":10,
"use_days_warning_value":10,
"is_supervise":0,
"remain": drug_info.get("net_weight"),
"put_in_date": Utils.get_str_datetime(),
"put_in_user_id": user_info.user_id,
"put_in_user_name": user_info.real_name,
"status":5
"status":1
}
new_dict.update(**key_dict)
finds_list = dir(EntityMedicament())
for i in finds_list:
if i in new_dict.keys():
continue
value = drug_info.get(i)
if value != None:
new_dict[i] = value
drug_entity = EntityMedicament(**new_dict)
objs = BllMedicament().drugPutIn(
drug_entity,

@ -6,6 +6,7 @@
from flask import jsonify, request
from Common.Utils import PageParam, Utils
from config.SystemConfig import SystemConfig
from db_logic.medicament_record import BllMedicamentRecord
from db_logic.medicament import BllMedicament
@ -33,12 +34,15 @@ def get_drug_use_classify():
data_list = BllMedicamentRecord().report_home_drug_useing_classify()
return jsonify(Utils.true_return(data=data_list))
# 用户试剂消耗
@report_router.route("/drug_user_use_info", methods=["GET", "POST"])
def get_drug_user_use_number():
data_list = BllMedicamentRecord().report_home_user_use_info()
return jsonify(Utils.true_return(data=data_list))
# 库存信息总览
@report_router.route("/stock_data_info", methods=["GET", "POST"])
def get_stock_data_info():
@ -58,35 +62,40 @@ def get_stock_data_info():
# 入库信息查询and 试剂信息查询
@report_router.route("/drug_details_info", methods=["GET", "POST"])
def drun_input_info():
# 获取参数
seach_word = request.values.get('seach_word')
# manufacturer = request.values.get("manufacturer")
customer_id = request.values.get("customer_id")
# customer_id = request.values.get("customer_id")
# 获取配置文件内的客户id
customer_id = SystemConfig.getConfig("customer_id")
client_id = request.values.get("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 = BllMedicament().getAllDrugList(
search_word=seach_word,
page_param=page_param,
customer_id=customer_id,
client_id=client_id
)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data}))
# 数据处理列表keyvalue格式
data_list = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data_list}))
# 库存消耗
# 试剂名称、纯度、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')
page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10)
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
# 获取数据结果
data = BllMedicamentRecord().durg_stock_loss(seach_word, page_param=page_param)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data}))
@ -95,10 +104,12 @@ def stock_loss_info():
# 试剂用量消耗
@report_router.route("/drug_use_expend", methods=["GET", "POST"])
def get_drug_use_expend():
# 参数获取
seach_word = request.values.get('seach_word')
page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10)
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
# 获取数据
data = BllMedicamentRecord().durg_useing_info(seach_word, page_param=page_param)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data}))
@ -106,11 +117,14 @@ def get_drug_use_expend():
# 人员用量消耗
@report_router.route("/drug_user_use_expend", methods=["GET", "POST"])
def get_drug_user_use_expend():
seach_word = request.values.get('seach_word')
page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10)
# 参数获取
seach_user = request.values.get('seach_user')
page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size)
data = BllMedicamentRecord().user_use_info(seach_word, page_param=page_param)
# 获取数据
data = BllMedicamentRecord().user_use_info(
seach_user=seach_user, page_param=page_param)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data}))

@ -69,12 +69,21 @@ def register_blueprints(app: New_flask):
from apps.drug_template.views import tmp_router
from apps.user.views import user_router
from apps.report.views import report_router
from apps.client.views import client_router
# 主概览相关
app.register_blueprint(home_router, url_prefix="/api/home")
# 试剂相关
app.register_blueprint(drug_router, url_prefix="/api/drug")
# 模板相关
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(client_router, url_prefix="/api/client")
def create_app():

@ -1,5 +1,6 @@
[system]
clientid = 000
customer_id = 1
serverip = 0.0.0.0
port = 9001
# dbconntion = mysql+pymysql://root:123456@127.0.0.1/local_rms_db?charset=utf8

@ -22,7 +22,9 @@ class BllClient(Repository):
# 获取客户端列表
def get_all_client_list(self):
return self.findList().order_by(asc(EntityClient.client_code)).all()
# return self.findList().order_by(asc(EntityClient.client_code)).all()
sql_all = """select * from rms_client order by client_code """
return self.execute(sql_all).fetchall()
# 根据条件查询客户端信息
def get_filter_client(self, client_id, customer_id):

@ -150,6 +150,8 @@ class BllMedicament(Repository):
self.session.add(entityDrug)
self.session.add(entityDrugRecord)
boolean_ = self.commitTrans()
if boolean_ is None:
return True
return boolean_
# 药剂领用
def drugUse(self, entityDrug=EntityMedicament(), entityClient=EntityClient(), entityUser=EntityUser()):
@ -234,33 +236,36 @@ class BllMedicament(Repository):
# 获取库存信息总览
def get_stock_all_info(self, page_param, name=None):
sql_all = """
select DISTINCT `name`,cas_number,net_weight_unit, client_id,
select DISTINCT `name`, speci, cas_number,net_weight_unit, purity, client_id,
sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number,
sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain
FROM rms_medicament %s
"""
# 拼接查询条件及分组条件
filter_base = ""
if name:
filter_base = f"where `name` LIKE %'{name}'%"
filter_base += " GROUP BY `name`, cas_number, net_weight_unit"
filter_base += " GROUP BY `name`, speci, purity"
sql_all = sql_all % filter_base
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
sql_data = self.execute(sql_all).fetchall()
count_sql = f"SELECT count(medicament_id) FROM rms_medicament GROUP BY `name`, cas_number, net_weight_unit "
# 首次查询,判断长度,做分页使用
try:
count_number = len(self.execute(count_sql).fetchall())
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords = count_number
# 组件分页参数,返回分页后数据
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
sql_data = self.execute(sql_all).fetchall()
return sql_data
#获取所有药剂列表
def getAllDrugList(self, search_word, page_param, customer_id=None, client_id=None):
# (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord)
sql_all = """
select `name`, manufacturer, distributor, net_weight_unit, remain, production_date, expiration_date,
select `name`,speci, manufacturer, distributor, net_weight_unit, remain, production_date, expiration_date,
shelf_life, put_in_user_name, put_in_date, english_name, purity, is_supervise, by_user_name
from rms_medicament %s
"""
@ -281,15 +286,15 @@ class BllMedicament(Repository):
if filter_base:
filter_base = "where " + filter_base
sql_all = sql_all % filter_base
# 获取数量做分页
try:
count_number= len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords = count_number
# 进行分页sql拼接
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
data_list = self.execute(sql_all).fetchall()
data_list = Utils.msyql_table_model(data_list)
return data_list
return self.execute(sql_all).fetchall()
# 入库、领用、归还记录
def drug_show_type_info(self, record_type, put_in_user_name, name, start_time, end_time, page_param):

@ -150,124 +150,140 @@ class BllMedicamentRecord(Repository):
# 公用方法
def default_data_list(self, sql_all, finds=None):
"""
参数介绍
sql_all = 最终执行sql
finds = 需要聚合的字段
"""
# 获取数据
med_data = self.execute(sql_all).fetchall()
data_list = []
base_num = 0
# 数据格式化
data= Utils.msyql_table_model(med_data)
# 数据处理转换float类型聚合字段返回新列表
for d in data:
new_dic = {}
for k,v in d.items():
v = v if not isinstance(v, Decimal) else float(v)
new_dic[k]=v
new_dic[k] = v if not isinstance(v, Decimal) else float(v)
data_list.append(new_dic)
if finds:
print(base_num)
base_num += float(new_dic.get(finds))
return data_list, base_num
# 获取库存消耗数据
def durg_stock_loss(self, seach_word, page_param):
sql_all = """
select c.`name`, c.cas_number, c.net_weight_unit, c.purity, c.enter_stock,
select c.`name`, c.cas_number,c.speci, 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
select medicament_id, `name`, cas_number, speci, 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
) c GROUP BY `name`, purity, speci
"""
# 拼接搜索条件
if seach_word:
seach_word = f"%{seach_word}%"
sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'"
else:
sql_all = sql_all % ""
finds = [
"name", "cas_number", "net_weight_unit", "purity", "enter_stock", "in_stock", "up_stock", "no_stock"
]
count_sql = "select count(medicament_id) from rms_medicament group by `name`, purity, net_weight_unit"
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
sql_all += ' limit ' + \
str((page_param.curPage - 1) * page_param.pageRows) + \
',' + str(page_param.pageRows)
# 查询获取数据条目数
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords = count_number
# 数据分页处理
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
# 获取处理后的数据
data_list, _ = self.default_data_list(sql_all)
return data_list
# 试剂用量消耗
def durg_useing_info(self, seach_word, page_param):
sql_all = """
select c.`name`, c.purity, c.cas_number, c.net_weight_unit, sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) on_in, c.c_two use_num, c.sum_use use_level from (
select c.`name`, c.purity, c.speci, c.cas_number, c.net_weight_unit,
sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) on_in,
IFNULL(c.c_two,0) use_num,
IFNULL(c.sum_use,0) use_level from (
select a.*, b.c_two, b.sum_use from(
select medicament_id, `name`, cas_number, purity, net_weight_unit, `status` from rms_medicament
select medicament_id, `name`, speci, cas_number, purity, net_weight_unit, `status` from rms_medicament
%s
) a LEFT JOIN(
select medicament_id, FORMAT(sum(use_quantity), 2) sum_use, sum(CASE WHEN record_type=2 THEN 1 ELSE 0 END) c_two from rms_medicament_record GROUP BY medicament_id
select medicament_id, FORMAT(sum(use_quantity),2) sum_use, sum(CASE WHEN record_type=2 THEN 1 ELSE 0 END) c_two from rms_medicament_record GROUP BY medicament_id
) b on a.medicament_id=b.medicament_id
) c GROUP BY `name`, purity, net_weight_unit
) c GROUP BY `name`, purity, speci
"""
# 拼接查询条件
if seach_word:
seach_word = f"%{seach_word}%"
sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'"
else:
sql_all = sql_all % ""
count_sql = "select count(medicament_id) from rms_medicament group by `name`, purity, net_weight_unit"
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
sql_all += ' limit ' + \
str((page_param.curPage - 1) * page_param.pageRows) + \
',' + str(page_param.pageRows)
data, ratio_all = self.default_data_list(sql_all, "use_level")
# 获取数量
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords = count_number
page_sql_all = Utils.sql_paging_assemble(sql_all, page_param)
# 获取组建后的数据结果
data, ratio_all = self.default_data_list(page_sql_all, "use_level")
# 拼接百分比数据
for i in data:
i["ratio"] = str(round(float(i["use_level"]) / ratio_all, 2) * 100) + "%"
i["ratio"] = Utils.classify(i["use_level"], ratio_all)
return data
# 人员用量消耗
def user_use_info(self, page_param, seach_word=None, seach_user=None):
def user_use_info(self, page_param, seach_user=None):
# sql_all = """
# select c.by_user_name, c.by_user_id, c.sum_use use_number, IFNULL(c.c_two, 0) use_level from (
# select a.*, b.c_two, b.sum_use from(
# select medicament_id, by_user_name, by_user_id from rms_medicament %s
# ) a LEFT JOIN(
# select medicament_id, FORMAT(sum(use_quantity), 2) sum_use, sum(CASE WHEN record_type=2 THEN 1 ELSE 0 END) c_two from rms_medicament_record GROUP BY medicament_id
# ) b on a.medicament_id=b.medicament_id
# ) c GROUP BY by_user_name, by_user_id
# """
sql_all = """
select c.by_user_name, c.by_user_id, c.sum_use use_number, c.c_two use_level from (
select a.*, b.c_two, b.sum_use from(
select medicament_id, by_user_name, by_user_id from rms_medicament %s
) a LEFT JOIN(
select medicament_id, FORMAT(sum(use_quantity), 2) sum_use, sum(CASE WHEN record_type=2 THEN 1 ELSE 0 END) c_two from rms_medicament_record GROUP BY medicament_id
) b on a.medicament_id=b.medicament_id
) c GROUP BY by_user_name, by_user_id
select a.*, b.role_name from (
select convert(sum(use_quantity), decimal(10,2)) use_amount,
sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num,
create_user_id,
create_user_name
from rms_medicament_record %s GROUP BY create_user_id
) a LEFT JOIN (
SELECT role_name, user_id FROM rms_user
) b on a.create_user_id = b.user_id
"""
# 查询条件组合
filter_sql = ""
if seach_word:
seach_word = f"%{seach_word}%"
filter_sql = f"`name` like '{seach_word}' or english_name like '{seach_word}'"
if seach_user:
if filter_sql:
filter_sql += " and "
seach_user = f"%{seach_user}%"
filter_sql += f"by_user_name like '{seach_user}'"
filter_sql += f"where by_user_name like '%{seach_user}%'"
if filter_sql:
sql_all = sql_all % f"where {filter_sql}"
sql_all = sql_all % filter_sql
else:
sql_all = sql_all % ""
count_sql = "select count(medicament_id) from rms_medicament_record group by create_user_id"
# 分页总数
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords = count_number
# sql_all += ' limit ' + \
# str((page_param.curPage - 1) * page_param.pageRows) + \
# ',' + str(page_param.pageRows)
# 数据分页
sql_all=Utils.sql_paging_assemble(sql_all, page_param)
data, ratio_all = self.default_data_list(sql_all, "use_level")
data, ratio_all = self.default_data_list(sql_all, "use_amount")
# 数据处理
for i in data:
i["ratio"] = str(
round(float(i["use_level"]) / ratio_all, 2) * 100) + "%"
print(i)
i["ratio"] = Utils.classify(i["use_amount"], ratio_all)
return data
# 使用频率

@ -64,17 +64,6 @@ class BllMedicamentTemplate(Repository):
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

@ -46,8 +46,8 @@ class BllMedicamentVariety(Repository):
net_weight_unit=drug_info.get("net_weight_unit"),
net_weight=drug_info.get("net_weight"),
create_date=Utils.get_str_datetime(),
create_user_id=user_info.get("user_id"),
create_user_name=user_info.get("real_name"),
create_user_id=user_info.user_id,
create_user_name=user_info.real_name,
shelf_life_warning_value=10,
inventory_warning_value=10,
use_days_warning_value=10,

Loading…
Cancel
Save