添加跨域参数配置;

修改入库接口参数问题
duizhaopin
apan 2 years ago
parent a69f5a4085
commit 78c79230e3

@ -33,6 +33,10 @@ class Utils(object):
def get_str_datetime():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def sql_paging_assemble(sql_all, page_param):
sql_all += ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows)
return sql_all
def classify(num, all_num, fl=2):
return str(round(float(round(num / all_num, fl)) * 100)) + "%"

@ -36,7 +36,17 @@ def show_template():
page_param = PageParam(page, page_size)
data = BllMedicamentTemplate().getAllTemplateList(client_id=client_id, page_param=page_param)
data = Utils.msyql_table_model(data)
return jsonify(Utils.true_return(data={"total_count":page_param.totalRecords, "data_list":data}))
new_data_list = []
for i in data:
all_export_cout=0
for a in eval(i["template_content"]):
all_export_cout += int(a.get("export_count", 0))
new_dic = {
"all_export_count": all_export_cout,
**i
}
new_data_list.append(new_dic)
return jsonify(Utils.true_return(data={"total_count":page_param.totalRecords, "data_list":new_data_list}))
@ -245,9 +255,9 @@ def import_tmplate():
# 删除模板
@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)
tmp_id_list = request.values.get("template_id_list")
if tmp_id_list:
BllMedicamentTemplate().del_template_obj(eval(tmp_id_list))
return Utils.true_return(msg='删除药剂模板成功')
return Utils.false_return(msg='删除药剂模板失败')

@ -62,10 +62,10 @@ def drun_input_info():
# manufacturer = request.values.get("manufacturer")
customer_id = request.values.get("customer_id")
client_id = request.values.get("client_id")
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 = BllMedicament.getAllDrugList(
data = BllMedicament().getAllDrugList(
search_word=seach_word,
page_param=page_param,
customer_id=customer_id,

@ -79,7 +79,7 @@ def register_blueprints(app: New_flask):
def create_app():
app = Flask(__name__)
CORS(app)
CORS(app, supports_credentials=True)
# app.config.from_object('setting')
app.config["SECRET_KEY"] = "wYdilHT~TRw7j{lF+Ee5MR3nFBINONPUcObwjwzge&/(~[C?Yz"
register_blueprints(app)

@ -3,4 +3,5 @@ clientid = 000
serverip = 0.0.0.0
port = 9001
# dbconntion = mysql+pymysql://root:123456@127.0.0.1/local_rms_db?charset=utf8
dbconntion = mysql+pymysql://yanyi:tangyan86910282@111.231.67.55/yy_rms_multiple?charset=utf8
# dbconntion = mysql+pymysql://yanyi:tangyan86910282@111.231.67.55/yy_rms_multiple?charset=utf8
dbconntion = mysql+pymysql://root:tangyan86910282@127.0.0.1/yy_rms_multiple?charset=utf8

@ -15,28 +15,16 @@ from models.medicament_models import EntityMedicament, EntityMedicamentRecord, E
from models.client_models import EntityClient
from models.user_models import EntityUser
from db_logic.meidcament_variety import BllMedicamentVariety
from Common.Utils import Utils, DrugStatus, DrugRecordType, PageParam
from Common.Utils import Utils, DrugStatus, DrugRecordType
#药剂流程业务逻辑类
class BllMedicament(Repository):
#_instance_lock = threading.Lock()
##实现单例模式
#def __new__(cls, *args, **kwargs):
# if not hasattr(BllMedicament, "_instance"):
# with BllMedicament._instance_lock:
# if not hasattr(BllMedicament, "_instance"):
# BllMedicament._instance = object.__new__(cls)
# return BllMedicament._instance
def __init__(self, entityType=EntityMedicament):
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):
drugList = self.findList(
@ -67,7 +55,7 @@ class BllMedicament(Repository):
# 组装sql
sql_all = sql_all % where_base
# 调用分页组装sql
sql_all = self.sql_paging_assemble(sql_all, page_param)
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
data_list = self.execute(sql_all).fetchall()
# 查询页总数
count_sql = f"SELECT count(*) FROM rms_medicament %s GROUP BY `name`, cas_number, purity" % where_base
@ -126,7 +114,7 @@ class BllMedicament(Repository):
where_base = "where" + where_base
# 组装最终sql
run_sql = sql_all % ("*", where_base+group_base)
run_sql = self.sql_paging_assemble(run_sql, page_param)
run_sql = Utils.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]
@ -231,10 +219,7 @@ class BllMedicament(Repository):
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}"
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
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_list = self.execute(sql_all).fetchall()
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}"
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
@ -255,42 +240,49 @@ class BllMedicament(Repository):
filter_base += " GROUP BY `name`, cas_number, net_weight_unit"
sql_all = sql_all % filter_base
sql_all = self.sql_paging_assemble(sql_all, page_param)
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 "
page_param.totalRecords = len(self.execute(count_sql).fetchone())
try:
count_number = len(self.execute(count_sql).fetchall())
except Exception:
count_number = 0
page_param.totalRecords = count_number
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`, distributor, net_weight_unit, remain, production_date, expiration_date,
select `name`, 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
"""
# 动态添加查询条件
filter_base = ""
if customer_id:
filter_base = f"customer_id='{customer_id}'"
# filter_base.append(self.entityType.customer_id == customer_id)
if client_id:
if filter_base:
filter_base += " and "
filter_base += f"client_id='{client_id}'"
# filter_base.append(self.entityType.client_id == client_id)
# 模糊搜索
if search_word:
seach_w = f"%{search_word}%"
if filter_base:
filter_base += " and "
filter_base += f" `name` like '{seach_w}' or english_name like '{seach_w}' or english_name like '{seach_w}'"
filter_base += f" `name` like '{seach_w}' or english_name like '{seach_w}' or manufacturer like '{seach_w}'"
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_all = Utils.sql_paging_assemble(sql_all, page_param)
data_list = self.execute(sql_all).fetchall()
count_sql = f"SELECT count(medicament_id) FROM rms_medicament"
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
data_list = Utils.msyql_table_model(data_list)
return data_list
@ -331,12 +323,37 @@ class BllMedicament(Repository):
# EntityMedicament.ByUserId == userId, EntityMedicament.Status == DrugStatus.Out).all()
# return drugList
if __name__ == '__main__':
from db_logic.medicament import BllMedicament
from Common.Utils import PageParam
page_param = PageParam(1, 10)
data = BllMedicament().get_drug_use_classify()
print(data)
def inster_log_shiji(self):
import random
name_list = ["", "硫酸", "氧化钠"]
obj_list = []
for i in range(100):
obj = EntityMedicament(
bar_code= 10000 + i,
client_id='1c39cb24-07f8-11ed-abd4-f47b094925e1',
client_code="12345",
name=random.choice(name_list),
production_date=Utils.get_str_datetime(),
shelf_life=10,
remain=100,
total=500,
net_weight_unit="g",
net_weight=100,
purity="国标",
put_in_date=Utils.get_str_datetime(),
put_in_user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1',
put_in_user_name="admin",
status=random.randint(1,3)
)
obj_list.append(obj)
self.insert_many(obj_list)
# if __name__ == '__main__':
# from db_logic.medicament import BllMedicament
# from Common.Utils import PageParam
# page_param = PageParam(1, 10)
# data = BllMedicament().inster_log_shiji()
# print(data)
# values= {}
# page = values.get("page", 1)
# page_size = values.get("page_size", 10)

@ -35,8 +35,8 @@ class BllMedicamentRecord(Repository):
# 获取流转记录
def get_drug_flow_log(self, page_param):
sql_all = """
select a.`name`, a.bar_code, a.cas_number, a.purity, a.client_id, a.`status`, b.create_date, b.create_user_name from(
select medicament_id, `name`, bar_code, cas_number, purity, client_id, `status` from rms_medicament
select a.`name`, a.speci, a.bar_code, a.cas_number, a.purity, a.client_id, a.`status`, b.create_date, b.create_user_name from(
select medicament_id, `name`, speci, bar_code, cas_number, purity, client_id, `status` from rms_medicament
) a RIGHT JOIN(
select medicament_id, create_date, create_user_id, create_user_name from rms_medicament_record order by create_date desc
) b on b.medicament_id=a.medicament_id
@ -253,10 +253,15 @@ class BllMedicamentRecord(Repository):
else:
sql_all = sql_all % ""
count_sql = "select count(medicament_id) from rms_medicament_record group by create_user_id"
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 += ' 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")
for i in data:
i["ratio"] = str(
@ -294,12 +299,38 @@ class BllMedicamentRecord(Repository):
sql_all = sql_all % f"where {filter_sql}"
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)
# count_sql = "select count(medicament_id) from rms_medicament group by `name`, purity, net_weight_unit"
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, _ = self.default_data_list(sql_all)
return data
def inster_log_list(self):
import random
data = list(self.execute("select medicament_id from rms_medicament").fetchall())
# print(random.choice(data)[0])
#
obj_list = []
for i in range(100):
obj = EntityMedicamentRecord(
client_id='1c39cb24-07f8-11ed-abd4-f47b094925e1',
client_code='12345',
medicament_id=random.choice(data)[0],
record_type=random.randint(1,3),
is_empty=random.randint(0,1),
record_remain=random.randint(1,100),
use_quantity=float(round(random.uniform(0, 50), 2)),
create_date=Utils.get_str_datetime(),
create_user_id="c0858e96-d900-11eb-8209-009027e3906b",
create_user_name="admin"
)
obj_list.append(obj)
self.insert_many(obj_list)
# #获取药剂最后一次使用余量
# def getLastRecordRemain(self, drugId):
# SQL = """
@ -320,12 +351,12 @@ 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'
# sql = f"update rms_medicament_record set use_quantity={round(random.uniform(1,10), 1)}"
from Common.Utils import PageParam
page_param = PageParam(1, 10)
typ_dic = BllMedicamentRecord().report_home_user_use_info()
print(typ_dic)
# if __name__ == '__main__':
# import random
# from db_logic.medicament_record import BllMedicamentRecord
# # customerId, clientId = None, '8db7e540-070f-11ed-a286-f47b094925e1'
# # sql = f"update rms_medicament_record set use_quantity={round(random.uniform(1,10), 1)}"
# from Common.Utils import PageParam
# page_param = PageParam(1, 10)
# typ_dic = BllMedicamentRecord().inster_log_list()
# print(typ_dic)

@ -28,17 +28,26 @@ class BllMedicamentTemplate(Repository):
sql_all = sql_all + f"and client_id='{client_id}'"
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)
sql_all = Utils.sql_paging_assemble(sql_all % "*" + end_sql, page_param)
data = self.execute(sql_all % "*").fetchall()
return data
# 批量或删除单个模板
def del_template_obj(self, tmp_list):
data_list = self.findList(EntityMedicamentTemplate.template_id.in_(tuple(tmp_list))).all()
for i in data_list:
self.session.delete(i)
self.session.commit()
# sql_all = f"DELETE from rms_medicament_template WHERE template_id in {tuple(tmp_list)}"
# return self.execute(sql_all)
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_id="1c39cb24-07f8-11ed-abd4-f47b094925e1",
client_name="测试机器",
template_name=f"测试模板{i}",
template_content=json.dumps(asss),
@ -86,5 +95,6 @@ if __name__ == '__main__':
{"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)

@ -55,14 +55,17 @@ class BllWarning(Repository):
return new_data_list, all_number
def create_bluk_waring(self):
data = list(self.execute(
"select medicament_id, name from rms_medicament").fetchall())
inster_list = []
for i in range(1000):
objs = random.choice(data)
inster_list.append(
EntityWarning(
customer_id='1c39cb2a-07f8-11ed-972d-f47b094925e1',
object_type=random.randint(1, 7),
object_id='1c39cb24-07f8-11ed-abd4-f47b094925e1',
object_name=f'测试对象名称{i}',
object_id=objs[0],
object_name=objs[1],
warning_content=f'测试预警数据{i}',
warning_date=Utils.get_str_datetime()
)
@ -71,8 +74,9 @@ class BllWarning(Repository):
# if __name__ == '__main__':
# a = BllWarning().get_waring_type_classify()
if __name__ == '__main__':
a = BllWarning().create_bluk_waring()
print(a)
# base_ratio = 0
# base_number = 0
# for i in a:

@ -49,6 +49,7 @@ class EntityMedicament(Base):
# SpeciUnit = Column(String(50)) # 规格单位
# Unit = Column(String(50)) # 单位
total = Column(String(50), comment="总量")
speci = Column(String(50), comment="规格")
net_weight_unit = Column(String(50), comment="净含量单位")
net_weight = Column(String(50), comment="净含量")
tp = Column(String(50), comment="类型")

Loading…
Cancel
Save