# Path: models/application_access.py
# class ApplicationAccessModel(BaseModel):
#     table = "applications_access"
#     db = "console"
#     
#     fields={
#         "access_type":True,
#         "access_content":True,
#         "container_id":True,
#         "container_host":True,
#         "container_name":True,
#         "user_id":True,
#         "response":True,
#         "status":True,
#         "logs":True,
#         "update_time":True,
#         'create_time':True
#     }


from models.application_access import ApplicationAccessModel
from tornado import gen

class ApplicationAccessService():
    m_application_access = ApplicationAccessModel()
    
    @gen.coroutine
    def access_application(self,access,callback=None):
        access_id = access.get("access_id",None)
        model = {}
        id = ""
        if access_id is None:
            model = yield self.m_application_access.insert_one(access)
            access_id = str(model.inserted_id)
        else:
            model = yield self.m_application_access.update_one({"_id":access_id},{"$set":access})
        raise gen.Return(access_id)
    
    @gen.coroutine
    def exist_access(self,access_id,callback=None):
        result = yield self.m_application_access.find_one(access_id)
        if result==None or not isinstance(result,dict):
            raise gen.Return(False)
        else:
            raise gen.Return(True)
    
    @gen.coroutine
    def find_one(self,access_id,callback=None):
        result = yield self.m_application_access.find_one(access_id)
        if result==None or not isinstance(result,dict):
            raise gen.Return(None)

# Path: models/application_access.py
# class ApplicationAccessModel(BaseModel):
#     table = "applications_access"
#     db = "console"
#     
#     fields={
#         "access_type":True,
#         "access_content":True,
#         "container_id":True,
#         "container_host":True,
#         "container_name":True,
#         "user_id":True,
#         "response":True,
#         "status":True,
#         "logs":True,
#         "update_time":True,
#         'create_time':True
#     }


# Path: services/application_access.py
from models.application_access import ApplicationAccessModel
from tornado import gen


class ApplicationAccessService():
    m_application_access = ApplicationAccessModel()
    
    @gen.coroutine
    def access_application(self,access,callback=None):
        access_id = access.get("access_id",None)
        model = {}
        id = ""
        if access_id is None:
            model = yield self.m_application_access.insert_one(access)
            access_id = str(model.inserted_id)
        else:
            model = yield self.m_application_access.update_one({"_id":access_id},{"$set":access})
        raise gen.Return(access_id)
    
    @gen.coroutine
    def exist_access(self,access_id,callback=None):
        result = yield self.m_application_access.find_one(access_id)
        if result==None or not isinstance(result,dict):
            raise gen.Return(False)
        else:
            raise gen.Return(True)
    
    @gen.coroutine
    def find_one(self,access_id,callback=None):
        result = yield self.m_application_access.find_one(access_id)
        if result==None or not isinstance(result,dict):
            raise gen.Return(None)

        else: