试剂入库问题修复;

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

@ -38,7 +38,7 @@ class Utils(object):
return sql_all return sql_all
def classify(num, all_num, fl=2): 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(): 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, customer_id=customer_id,
drug_info=drug_info, user_info=user_info drug_info=drug_info, user_info=user_info
) )
finds = [ # finds = [
"name", "cas_number", "english_name", "purity", "manufacturer", "distributor", # "name", "cas_number", "english_name", "purity", "manufacturer", "distributor",
"production_date", "shelf_life", "net_weight_unit", "net_weight", "tp", "price", # "production_date", "shelf_life", "net_weight_unit", "net_weight", "tp", "price",
"place", "expiration_date" # "place", "expiration_date"
] # ]
key_dict = {} # key_dict = {}
for i in finds: # for i in finds:
key_dict[i] = drug_info.get(i) # key_dict[i] = drug_info.get(i)
new_dict = { new_dict = {
"medicament_id": Utils.UUID(), "medicament_id": Utils.UUID(),
"variety_id": drug_variety.variety_id, "variety_id": drug_variety.variety_id,
@ -107,13 +107,18 @@ def bind_tmp_input_db():
"shelf_life_warning_value":10, "shelf_life_warning_value":10,
"use_days_warning_value":10, "use_days_warning_value":10,
"is_supervise":0, "is_supervise":0,
"remain": drug_info.get("net_weight"),
"put_in_date": Utils.get_str_datetime(), "put_in_date": Utils.get_str_datetime(),
"put_in_user_id": user_info.user_id, "put_in_user_id": user_info.user_id,
"put_in_user_name": user_info.real_name, "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) drug_entity = EntityMedicament(**new_dict)
objs = BllMedicament().drugPutIn( objs = BllMedicament().drugPutIn(
drug_entity, drug_entity,

@ -6,6 +6,7 @@
from flask import jsonify, request from flask import jsonify, request
from Common.Utils import PageParam, Utils from Common.Utils import PageParam, Utils
from config.SystemConfig import SystemConfig
from db_logic.medicament_record import BllMedicamentRecord from db_logic.medicament_record import BllMedicamentRecord
from db_logic.medicament import BllMedicament from db_logic.medicament import BllMedicament
@ -33,12 +34,15 @@ def get_drug_use_classify():
data_list = BllMedicamentRecord().report_home_drug_useing_classify() data_list = BllMedicamentRecord().report_home_drug_useing_classify()
return jsonify(Utils.true_return(data=data_list)) return jsonify(Utils.true_return(data=data_list))
# 用户试剂消耗
@report_router.route("/drug_user_use_info", methods=["GET", "POST"]) @report_router.route("/drug_user_use_info", methods=["GET", "POST"])
def get_drug_user_use_number(): def get_drug_user_use_number():
data_list = BllMedicamentRecord().report_home_user_use_info() data_list = BllMedicamentRecord().report_home_user_use_info()
return jsonify(Utils.true_return(data=data_list)) return jsonify(Utils.true_return(data=data_list))
# 库存信息总览 # 库存信息总览
@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():
@ -58,35 +62,40 @@ def get_stock_data_info():
# 入库信息查询and 试剂信息查询 # 入库信息查询and 试剂信息查询
@report_router.route("/drug_details_info", methods=["GET", "POST"]) @report_router.route("/drug_details_info", methods=["GET", "POST"])
def drun_input_info(): def drun_input_info():
# 获取参数
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
# manufacturer = request.values.get("manufacturer") # 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") client_id = request.values.get("client_id")
# 分页处理
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10)) page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size) page_param = PageParam(page, page_size)
# 获取数据
data = BllMedicament().getAllDrugList( data = BllMedicament().getAllDrugList(
search_word=seach_word, search_word=seach_word,
page_param=page_param, page_param=page_param,
customer_id=customer_id, customer_id=customer_id,
client_id=client_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 分组后获取 # 试剂名称、纯度、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"]) @report_router.route("/stock_loss_info", methods=["GET", "POST"])
def stock_loss_info(): def stock_loss_info():
# 获取参数
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
page = request.values.get("page", 1) page = int(request.values.get("page", 1))
page_size = request.values.get("page_size", 10) page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size) page_param = PageParam(page, page_size)
# 获取数据结果
data = BllMedicamentRecord().durg_stock_loss(seach_word, page_param=page_param) data = BllMedicamentRecord().durg_stock_loss(seach_word, page_param=page_param)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) 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"]) @report_router.route("/drug_use_expend", methods=["GET", "POST"])
def get_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 = int(request.values.get("page", 1))
page_size = request.values.get("page_size", 10) page_size = int(request.values.get("page_size", 10))
page_param = PageParam(page, page_size) page_param = PageParam(page, page_size)
# 获取数据
data = BllMedicamentRecord().durg_useing_info(seach_word, page_param=page_param) data = BllMedicamentRecord().durg_useing_info(seach_word, page_param=page_param)
return jsonify(Utils.true_return(data={"total_count": page_param.totalRecords, "data": data})) 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"]) @report_router.route("/drug_user_use_expend", methods=["GET", "POST"])
def get_drug_user_use_expend(): def get_drug_user_use_expend():
seach_word = request.values.get('seach_word') # 参数获取
page = request.values.get("page", 1) seach_user = request.values.get('seach_user')
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) 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})) 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.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
from apps.client.views import client_router
# 主概览相关
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(drug_router, url_prefix="/api/drug")
# 模板相关
app.register_blueprint(tmp_router, url_prefix="/api/drug_tmplate") app.register_blueprint(tmp_router, url_prefix="/api/drug_tmplate")
# 报表相关
app.register_blueprint(report_router, url_prefix="/api/report") 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(client_router, url_prefix="/api/client")
def create_app(): def create_app():

@ -1,5 +1,6 @@
[system] [system]
clientid = 000 clientid = 000
customer_id = 1
serverip = 0.0.0.0 serverip = 0.0.0.0
port = 9001 port = 9001
# dbconntion = mysql+pymysql://root:123456@127.0.0.1/local_rms_db?charset=utf8 # 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): 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): def get_filter_client(self, client_id, customer_id):

@ -150,6 +150,8 @@ class BllMedicament(Repository):
self.session.add(entityDrug) self.session.add(entityDrug)
self.session.add(entityDrugRecord) self.session.add(entityDrugRecord)
boolean_ = self.commitTrans() boolean_ = self.commitTrans()
if boolean_ is None:
return True
return boolean_ return boolean_
# 药剂领用 # 药剂领用
def drugUse(self, entityDrug=EntityMedicament(), entityClient=EntityClient(), entityUser=EntityUser()): 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): def get_stock_all_info(self, page_param, name=None):
sql_all = """ 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 1 ELSE 0 END) count_number,
sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain
FROM rms_medicament %s FROM rms_medicament %s
""" """
# 拼接查询条件及分组条件
filter_base = "" filter_base = ""
if name: if name:
filter_base = f"where `name` LIKE %'{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 = 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: try:
count_number = len(self.execute(count_sql).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number 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 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)
sql_all = """ 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 shelf_life, put_in_user_name, put_in_date, english_name, purity, is_supervise, by_user_name
from rms_medicament %s from rms_medicament %s
""" """
@ -281,15 +286,15 @@ class BllMedicament(Repository):
if filter_base: if filter_base:
filter_base = "where " + filter_base filter_base = "where " + filter_base
sql_all = sql_all % filter_base sql_all = sql_all % filter_base
# 获取数量做分页
try: try:
count_number= len(self.execute(sql_all).fetchall()) count_number= len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number page_param.totalRecords = count_number
# 进行分页sql拼接
sql_all = Utils.sql_paging_assemble(sql_all, page_param) sql_all = Utils.sql_paging_assemble(sql_all, page_param)
data_list = self.execute(sql_all).fetchall() return self.execute(sql_all).fetchall()
data_list = Utils.msyql_table_model(data_list)
return data_list
# 入库、领用、归还记录 # 入库、领用、归还记录
def drug_show_type_info(self, record_type, put_in_user_name, name, start_time, end_time, page_param): 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): def default_data_list(self, sql_all, finds=None):
"""
参数介绍
sql_all = 最终执行sql
finds = 需要聚合的字段
"""
# 获取数据
med_data = self.execute(sql_all).fetchall() med_data = self.execute(sql_all).fetchall()
data_list = [] data_list = []
base_num = 0 base_num = 0
# 数据格式化
data= Utils.msyql_table_model(med_data) data= Utils.msyql_table_model(med_data)
# 数据处理转换float类型聚合字段返回新列表
for d in data: for d in data:
new_dic = {} new_dic = {}
for k,v in d.items(): for k,v in d.items():
v = v if not isinstance(v, Decimal) else float(v) new_dic[k] = v if not isinstance(v, Decimal) else float(v)
new_dic[k]=v
data_list.append(new_dic) data_list.append(new_dic)
if finds: if finds:
print(base_num)
base_num += float(new_dic.get(finds)) base_num += float(new_dic.get(finds))
return data_list, base_num return data_list, base_num
# 获取库存消耗数据 # 获取库存消耗数据
def durg_stock_loss(self, seach_word, page_param): def durg_stock_loss(self, seach_word, page_param):
sql_all = """ 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`=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`=2 THEN 1 ELSE 0 END) up_stock,
sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock sum(CASE WHEN c.`status`=3 THEN 1 ELSE 0 END) no_stock
from ( from (
select a.*, b.enter_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 %s
) a LEFT JOIN( ) 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 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 ) 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: if seach_word:
seach_word = f"%{seach_word}%" seach_word = f"%{seach_word}%"
sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'" sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'"
else: else:
sql_all = sql_all % "" sql_all = sql_all % ""
# 查询获取数据条目数
finds = [ try:
"name", "cas_number", "net_weight_unit", "purity", "enter_stock", "in_stock", "up_stock", "no_stock" count_number = len(self.execute(sql_all).fetchall())
] except Exception:
count_sql = "select count(medicament_id) from rms_medicament group by `name`, purity, net_weight_unit" count_number = 0
page_param.totalRecords = self.execute(count_sql).fetchone()[0] page_param.totalRecords = count_number
sql_all += ' limit ' + \ # 数据分页处理
str((page_param.curPage - 1) * page_param.pageRows) + \ sql_all = Utils.sql_paging_assemble(sql_all, page_param)
',' + str(page_param.pageRows) # 获取处理后的数据
data_list, _ = self.default_data_list(sql_all) data_list, _ = self.default_data_list(sql_all)
return data_list return data_list
# 试剂用量消耗 # 试剂用量消耗
def durg_useing_info(self, seach_word, page_param): def durg_useing_info(self, seach_word, page_param):
sql_all = """ 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 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 %s
) a LEFT JOIN( ) 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 ) 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: if seach_word:
seach_word = f"%{seach_word}%" seach_word = f"%{seach_word}%"
sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'" sql_all = sql_all % f"where `name` like '{seach_word}' or english_name like '{seach_word}'"
else: else:
sql_all = sql_all % "" 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] try:
sql_all += ' limit ' + \ count_number = len(self.execute(sql_all).fetchall())
str((page_param.curPage - 1) * page_param.pageRows) + \ except Exception:
',' + str(page_param.pageRows) count_number = 0
page_param.totalRecords = count_number
data, ratio_all = self.default_data_list(sql_all, "use_level") 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: 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 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 = """ 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.role_name from (
select a.*, b.c_two, b.sum_use from( select convert(sum(use_quantity), decimal(10,2)) use_amount,
select medicament_id, by_user_name, by_user_id from rms_medicament %s sum( CASE WHEN record_type = 2 THEN 1 ELSE 0 END ) use_num,
) a LEFT JOIN( create_user_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 create_user_name
) b on a.medicament_id=b.medicament_id from rms_medicament_record %s GROUP BY create_user_id
) c GROUP BY by_user_name, by_user_id ) a LEFT JOIN (
SELECT role_name, user_id FROM rms_user
) b on a.create_user_id = b.user_id
""" """
# 查询条件组合
filter_sql = "" 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 seach_user:
if filter_sql: filter_sql += f"where by_user_name like '%{seach_user}%'"
filter_sql += " and "
seach_user = f"%{seach_user}%"
filter_sql += f"by_user_name like '{seach_user}'"
if filter_sql: if filter_sql:
sql_all = sql_all % f"where {filter_sql}" sql_all = sql_all % filter_sql
else: else:
sql_all = sql_all % "" sql_all = sql_all % ""
count_sql = "select count(medicament_id) from rms_medicament_record group by create_user_id" # 分页总数
try: try:
count_number = len(self.execute(sql_all).fetchall()) count_number = len(self.execute(sql_all).fetchall())
except Exception: except Exception:
count_number = 0 count_number = 0
page_param.totalRecords = count_number 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) 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: for i in data:
i["ratio"] = str( i["ratio"] = Utils.classify(i["use_amount"], ratio_all)
round(float(i["use_level"]) / ratio_all, 2) * 100) + "%"
print(i)
return data return data
# 使用频率 # 使用频率

@ -64,17 +64,6 @@ class BllMedicamentTemplate(Repository):
li_ba.append(obj) li_ba.append(obj)
self.insert_many(li_ba) 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__': if __name__ == '__main__':
# import json # import json

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

Loading…
Cancel
Save