urban-investment-research/init.py

41 lines
1.1 KiB
Python

# 初始化数据创建、只需要调用一次的接口
import json
from Context.common import common_db
from Mods.CommonInformation.Mods.IndustryMain.Models import IndustryMain
from Mods.CommonInformation.Mods.ProductMain.Models import ProductMain
from Utils.PrintUtils import print_error
from Utils.SqlAlchemyUtils import tree_table_to_json
def save_industry_main_json():
"""
保存行业分类数据
"""
db = common_db.get_db_i()
try:
tree = tree_table_to_json(db, IndustryMain, key_str='code')
json.dump({'data': tree}, open('static/industry_main.json', 'w', encoding="utf-8"), ensure_ascii=False, )
except Exception as e:
print_error(e)
finally:
db.close()
def save_product_main_json():
"""
保存产品分类数据
"""
db = common_db.get_db_i()
try:
tree = tree_table_to_json(db, ProductMain, key_str='code')
json.dump({'data': tree}, open('static/product_main.json', 'w', encoding="utf-8"), ensure_ascii=False, )
except Exception as e:
print_error(e)
finally:
db.close()
save_industry_main_json()
save_product_main_json()