Пример #1
0
async def create(validate_model):
    question = validate_model.question
    answer = validate_model.answer
    remark = validate_model.remark
    kind = validate_model.kind
    create_by = validate_model.create_by

    id = Tools.uid()
    status = CommonSQL.check_repeat(db, CommonSQL.IQ_VALIDATE_CHECK, question)
    if status:
        db.insert(CommonSQL.IQ_VALIDATE_CREATE, id, question, answer, remark,
                  kind, create_by)
    else:
        code = ErrorCode.select_already_exists
        raise UnicornException(code, ErrorINFO[code])
Пример #2
0
async def login_service(login_model):
    _username = login_model.username
    _password = login_model.password
    access_id = login_model.access_id

    # rsa校验
    private_key = r.hget(name=access_id, key="public_key")
    if private_key:
        orsa = OperateRSA()
        reduction_username = orsa.private_b64(_username, private_key)
        reduction_password = orsa.private_b64(_password, private_key)
        # print(f"rsa解析账号:{reduction_username}")
        # print(f"rsa解析密码:{reduction_password}")
        if reduction_username and reduction_password:
            r.delete(access_id)
            user_dict = user_sql.check_auth_record(reduction_username)
            if user_dict:
                username = user_dict.get("identifier")
                password = user_dict.get("password")
                # print(f"数据库存储账号:{username}")
                # print(f"数据库存储密码:{password}")
                if all({
                        reduction_username == username,
                        reduction_password == password
                }):
                    u_dict = user_sql.get_user_record(username)
                    if u_dict:
                        uid, nickname = u_dict.get('id'), u_dict.get(
                            'nick_name')
                        access_token = create_token(uid)
                        return {
                            "token": access_token,
                            "nickname": nickname,
                            "user_id": uid
                        }
                    else:
                        code = ErrorCode.user_unknown_exception
                else:
                    code = ErrorCode.user_passwd_error
            else:
                code = ErrorCode.not_user
        else:
            code = ErrorCode.secret_error
    else:
        code = ErrorCode.access_error

    raise UnicornException(code, ErrorINFO[code])
Пример #3
0
 def fetch_all(self, sql, args=None):
     '''
     批量查询记录
     :param sql:
     :param args:条件,可以为空
     :return:list
     '''
     cursor, conn, count = self.execute(sql, param=args, is_dict=True)
     try:
         result = cursor.fetchall()
         self.close(cursor, conn)
         return result
     except Exception as e:
         logger.error(e)
         self.close(cursor, conn)
         raise UnicornException(StatusCode.C10005['code'],
                                StatusCode.C10005['msg'])
Пример #4
0
 def insert(self, sql, *args):
     '''
     插入数据
     :param sql:
     :param args:字段
     :return:
     '''
     cursor, conn, count = self.execute(sql, args)
     try:
         conn.commit()
         self.close(cursor, conn)
     except Exception as e:
         conn.rollback()
         self.close(cursor, conn)
         logger.error(e)
         raise UnicornException(StatusCode.C10001['code'],
                                StatusCode.C10001['msg'])
Пример #5
0
    def fetch_one(self, sql, *args):
        '''
        查询单条记录
        :param sql:
        :param args:条件,可以多个条件
        :return:dict
        '''
        cursor, conn, count = self.execute(sql, param=args, is_dict=True)

        try:
            result = cursor.fetchone()
            self.close(cursor, conn)
            return result if result else {}
        except Exception as e:
            self.close(cursor, conn)
            logger.error(e)
            raise UnicornException(StatusCode.C10004['code'],
                                   StatusCode.C10004['msg'])
Пример #6
0
 def update(self, sql, *args):
     """
     更新记录
     :param sql:
     :param args: 条件,可以有多个条件
     :return:
     """
     cursor, conn, count = self.execute(sql, args)
     try:
         conn.commit()
         self.close(cursor, conn)
         return count
     except Exception as e:
         conn.rollback()
         self.close(cursor, conn)
         logger.error(e)
         raise UnicornException(StatusCode.C10002['code'],
                                StatusCode.C10002['msg'])
Пример #7
0
 def delete_many(self, sql, args):
     """
     删除多条记录
     :param sql:
     :param args: 条件
     :return:
     """
     cursor, conn = self.db.get_conn()
     try:
         cursor.executemany(sql, args)
         conn.commit()
         self.close(cursor, conn)
     except Exception as e:
         logger.exception(e)
         conn.rollback()
         self.close(cursor, conn)
         raise UnicornException(StatusCode.C10003['code'],
                                StatusCode.C10003['msg'])
Пример #8
0
async def create_host_server(host_server_model):
    server_name = host_server_model.name
    server_ip = host_server_model.ip
    version = host_server_model.version
    memory = host_server_model.memory
    cpu = host_server_model.cpu
    sys_status = host_server_model.status
    effect = host_server_model.effect
    sys_check = host_server_model.sys_check
    remarks = host_server_model.remarks

    id = Tools.uid()
    status = host_server_sql.check_host_server_record(server_name, server_ip)
    if status:
        host_server_sql.create_host_server_record(id, server_name, server_ip,
                                                  version, memory, cpu,
                                                  sys_status, effect,
                                                  sys_check, remarks)
    else:
        code = ErrorCode.select_already_exists
        raise UnicornException(code, ErrorINFO[code])
    return
Пример #9
0
async def delete(script_id):
    script_info =  db.fetch_one(CommonSQL.AGENT_SCRIPT_ONE, script_id)
    if script_info:
        db.delete(CommonSQL.AGENT_SCRIPT_DEL,script_id)
    else:
        raise UnicornException(StatusCode.R20006["code"], StatusCode.R20006["msg"])
Пример #10
0
async def delete(id):
    if db.delete(CommonSQL.IQ_VALIDATE_DEL_ONE, id):
        return ErrorCode.success
    code = ErrorCode.sql_execute_error
    raise UnicornException(code, ErrorINFO[code])