自定义表单

duizhaopin
apan_youxiang@163.com 2 years ago
parent 469a7d634e
commit 986cbc308c

@ -0,0 +1,76 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/08/12 15:08:24
'''
import sys
sys.path.append('.')
from flask import jsonify, request, g
from flask import Blueprint
from Common.auth import token_auth
from Common.Utils import Utils, PageParam
from models.medicament_models import EntityMedicamentExtend
from db_logic.medicament_extend import BllMedicamentExtend
drug_form_router = Blueprint("drug_form", __name__)
@drug_form_router.route("/getlist", methods=["GET", "POST"])
# @token_auth.login_required
def get_drug_form():
page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10)
page_param = PageParam(int(page), int(page_size))
data_list = BllMedicamentExtend().get_list(page_param=page_param)
return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
@drug_form_router.route("/add_update", methods=["GET", "POST"])
# @token_auth.login_required
def add_update_drug_form():
drug_form_id = request.values.get("drug_form_id")
bll_obj = BllMedicamentExtend()
finds = [
"name", "description", "key_lenth", "is_use"
]
if drug_form_id:
obj = bll_obj.findEntity(EntityMedicamentExtend.id == drug_form_id)
if obj:
for i in finds:
setattr(obj, i, request.values.get(i))
bll_obj.update(obj)
return jsonify(Utils.true_return())
else:
return jsonify(Utils.false_return(msg="表单id有误"))
else:
del_obj = bll_obj.execute(
"select id, min(sort_index) from rms_medicament_extend where is_del=1").first()
if del_obj[0]:
obj = bll_obj.findEntity(EntityMedicamentExtend.id == del_obj[0])
for i in finds:
setattr(obj, i, request.values.get(i))
setattr(obj, 'is_del', 0)
bll_obj.update(obj)
else:
obj = EntityMedicamentExtend()
for i in finds:
setattr(obj, i, request.values.get(i))
sort_index = bll_obj.execute(
"select max(sort_index) sort_index from rms_medicament_extend").fetchone()
setattr(obj, "sort_index", int(sort_index.sort_index or '0') + 1)
bll_obj.insert(obj)
return jsonify(Utils.true_return())
@drug_form_router.route("/del", methods=["GET", "POST"])
# @token_auth.login_required
def del_drug_form():
drug_form_id = request.values.get("drug_form_id")
obj = BllMedicamentExtend().findEntity(EntityMedicamentExtend.id==drug_form_id)
if obj:
obj.is_del=1
BllMedicamentExtend().update(obj)
return jsonify(Utils.true_return(msg="删除成功"))
else:
return jsonify(Utils.false_return(msg="该表单不存在"))

@ -72,6 +72,7 @@ def register_blueprints(app: New_flask):
from apps.client.views import client_router
from apps.power.views import power_router
from apps.monitor.views import monitor_router
from apps.drug_form.views import drug_form_router
# 主概览相关
app.register_blueprint(home_router, url_prefix="/api/home")
@ -92,6 +93,9 @@ def register_blueprints(app: New_flask):
# 获取温湿度监控
app.register_blueprint(monitor_router, url_prefix="/api/monitor")
# 获取自定义表单
app.register_blueprint(drug_form_router, url_prefix="/api/drug_form")
def create_app():
app = Flask(__name__)

@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date:2022/08/12 15:12:42
'''
import sys
sys.path.append('.')
from db_logic.db_base import Repository
from models.medicament_models import EntityMedicamentExtend
from Common.Utils import Utils
#药剂品种业务逻辑类
class BllMedicamentExtend(Repository):
sql_name = 'rms_medicament_extend'
def __init__(self, entityType=EntityMedicamentExtend):
super().__init__(entityType)
def get_list(self, page_param):
sql_all = """
select * from rms_medicament_extend where is_del=0 order by sort_index
"""
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords=count_number
page_sql = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(page_sql)

@ -22,18 +22,19 @@ class BllMedicamentTemplate(Repository):
# 获取所有模板列表
def getAllTemplateList(self, client_id, page_param):
sql_all = "select * from rms_medicament_template where is_wait_export=1 "
end_sql = "order by create_date desc"
filter_base = ""
if client_id:
sql_all = sql_all + f"and client_id='{client_id}'"
filter_base += f" client_id='{client_id}' "
if filter_base:
filter_base = f" where {filter_base} "
sql_all = f"select * from rms_medicament_template {client_id} order by create_date desc"
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 + end_sql, page_param)
data = self.execute(sql_all).fetchall()
return data
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(sql_all).fetchall()
# 批量或删除单个模板
def del_template_obj(self, tmp_list):

@ -211,9 +211,12 @@ class EntityMedicamentExtend(Base):
}
)
id = Column(String(50), primary_key=True, comment="ID", default=get_uuid)
field_key = Column(String(50), comment="字段名称")
field_value = Column(String(50), comment="字段含义")
field_table_type = Column(Integer, comment="字段所在表")
name = Column(String(50), comment="名称")
description = Column(Text, comment="描述")
key_lenth = Column(String(50), comment="字段长度")
sort_index = Column(Integer, comment="顺序")
is_use = Column(Integer, default=1, comment="是否启用")
is_del = Column(Integer, default=0, comment="是否删除")
if __name__ == '__main__':
@ -283,4 +286,17 @@ if __name__ == '__main__':
# session.add(db_mo)
# session.commit()
# # Base.metadata.create_all(engine)
# # Base.metadata.create_all(engine)
if __name__ == '__main__':
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()
Base.metadata.create_all(engine)

Loading…
Cancel
Save