Ejemplo n.º 1
0
def do_login(telephone=None, email=None, u_id=None, pwd=""):
    """
    根据 账号信息 及 密码 查询用户信息
    :param telephone: 手机号
    :param email: 邮箱
    :param u_id: 用户id
    :param pwd: 密码(32位字符串)
    :return: 用户信息 : (ID,NAME,TYPE)or None
    """
    # 连接服务器
    # client = pymongo.MongoClient("mongodb://" + MongoDB_CONFIG["ip"] + ":" + MongoDB_CONFIG["port"])
    mongo_operator = MongoOperator(**MongoDB_CONFIG)
    # TODO: 目前查询最多有一个查询该用户的日程安排
    # 条件
    condition = {'password': pwd}

    if telephone:
        condition['tel_number'] = telephone
    elif email:
        condition['email'] = email
    elif u_id:
        condition['id'] = u_id

    result = mongo_operator.find_one(condition, 'user')
    # 删除mongo的id
    if result:
        del result['_id']

    return result
Ejemplo n.º 2
0
def visit_record():
    mongo_operator = MongoOperator(**MongoDB_CONFIG)
    # 获取用户的uid
    uid = session['uid']
    # TODO: 目前查询最多有一个查询该用户的日程安排
    result = mongo_operator.find_one({'user_id': uid}, 'visited_record')
    return render_template('visitRecode.html', visited_records=result['visited_record'])
Ejemplo n.º 3
0
def upsert_relation_of_visited(user_id, teacher_id, teacher_name):
    """
    by chen
    在图数据库中添加拜访关系
    添加拜访信息到 mongoDB 的user 表中
    :param user_id:
    :param teacher_id:
    :param teacher_name:
    :return: None
    """
    # 操作neo4j
    try:
        # back ==> {success: True / False, message:xxxx}
        back = upsert_relation_of_agent2teacher(user_id, teacher_id)
        if not back['success']:
            print("更新拜访记录到图数据库失败,原因:%s" % back['message'])

    except Exception as e:
        print("更新拜访记录到图数据库失败,原因:%s" % e)

    # TODO 后期剔除该部分
    # 操作mongo
    try:
        collection_user = MongoOperator(**MongoDB_CONFIG).get_collection("user")
        # back => None or dict{"_id":ObjectId("xxx"), "related_teacher":[{id:xx, name, visited_count:12, acitve_count: 123}]}
        visited_record = collection_user.find_one({"id": user_id, "related_teacher.id": teacher_id}, {"related_teacher.$": 1})

        if visited_record:
            info = visited_record['related_teacher'][0]
            count = int(info['visited_count'] + 1)
            collection_user.update_one({"_id": visited_record["_id"], "related_teacher.id": teacher_id},
                                       {"$set": {"related_teacher.$.visited_count": count}})
        else:
            insert_data = {
                "id": teacher_id,
                "name": teacher_name,
                "visited_count": int(1),
                "acitve_count": int(0)
            }
            collection_user.update_one({"id": user_id}, {"$set": {"related_teacher": [insert_data]}})

    except Exception as e:
        print("更新拜访记录到mongo失败, 原因:%s" % e)