# -*- coding: utf_8 -*-
# 表名: experience_hosts_type
# 作者: 陈磊
# 时间: 2019-12-03


from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, VARCHAR, SMALLINT, DATETIME, DECIMAL, BigInteger, FLOAT, NUMERIC, TEXT
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
from sqlalchemy import or_

from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase

import time

Base = declarative_base()


class ExperienceHostsType(Base):
    """
    经验手册与资产类型关系
    """
    __tablename__ = "experience_hosts_type"

    id = Column(BigInteger, primary_key=True)
    experienceid = Column(BigInteger, comment="经验手册ID")
    hosts_type = Column(BigInteger, comment="资产类型ID")


class DataExperienceHostsType(object):
    def __init__(self):
        self.log = UtilsLog()
        self.log.info(self.__class__)

        self.table = ExperienceHostsType

    def select_all_from_allKeys(self, session, experienceid=None):
        """
        :param session: 指针
        :param experienceid:
        :return: 查询结果
        """
        self.log.debug("查询数据库:")
        try:
            base = UtilsDataBase()
            base.add_param(_key="experienceid", value=experienceid)
            sql_rep = session.query(self.table).filter_by(**base.param).all()
            self.log.debug(sql_rep)
            session.close()
            return sql_rep
        except UtilsDataBase().errors as error:
            self.log.error("异常:")
            self.log.error(error)
            session.close()
            return error
