tmp
zhaoqingang
2025-02-13 d4ab4357a4eaf61dcab6bba427e620b9c5333e42
app/service/v2/initialize_data.py
@@ -5,11 +5,12 @@
import yaml
from passlib.context import CryptContext
from Log import logger
# from app.api import pwd_context
from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW
from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \
    cipher_suite
    cipher_suite, UserTokenModel
from app.service.auth import UserAppDao
from app.service.bisheng import BishengService
from app.service.difyService import DifyService
@@ -139,13 +140,15 @@
                dialog.name = agent["name"]
                dialog.description = agent["description"]
                dialog.icon = agent["icon"]
                dialog.mode = agent["mode"]
                dialog.parameters = json.dumps(agent["parameters"])
                db.commit()
            except Exception as e:
                logger.error(e)
        else:
            try:
                dialog = DialogModel(id=agent["id"], name=agent["name"], description=agent["description"],
                                     icon=agent["icon"], tenant_id=user.id if user else "", dialog_type=agent["dialogType"], mode=agent["mode"])
                dialog = DialogModel(id=agent["id"], name=agent["name"], description=agent["description"],
                                     icon=agent["icon"], tenant_id=user.id if user else "", dialog_type=agent["dialogType"], mode=agent["mode"],parameters = json.dumps(agent["parameters"]))
                db.add(dialog)
                db.commit()
                db.refresh(dialog)
@@ -228,6 +231,33 @@
    print({"msg": "User registered successfully", "userFlag": user_id})
async def admin_account_sync(db):
    try:
        config = {}
        now_account  =[]
        with open(os.path.join(ENV_CONF_PATH, "account.yaml"), 'r', encoding='utf-8') as file:
            # 加载JSON数据
            config = yaml.safe_load(file)
        account_list = db.query(UserTokenModel).all()
        for account in account_list:
            if account.id in config:
                if account.account != config[account.id]["account"] or account.password != config[account.id]["password"]:
                    db.query(UserTokenModel).filter_by(id=account.id).update({"account": config[account.id]["account"],
                                                                              "password": config[account.id]["password"],
                                                                              "access_token": ""
                                                                              })
                now_account.append(account.id)
            else:
                db.query(UserTokenModel).filter_by(id=account.id).delete()
        for k, v in config.items():
            if k not in now_account:
                new_account = UserTokenModel(id=k, account=v["account"], password=v["password"])
                db.add(new_account)
        db.commit()
    except Exception as e:
        print(e)
        db.rollback()
async def admin_user_sync(db):
    try:
        config = {}