Ejemplo n.º 1
0
def update_data(record, record_id, attrs):
    """
    更新记录的attrs字段,不允许为空
    :param record: 已经赋值的对象
    :param record_id: 需要更新的对象主键
    :param attrs: 需要更新的字段名的 list, 如["product_count","product_name"]
    :return:
    """
    son = DBSession()
    # record_id = getattr(record, get_pk(record))
    print "========update_data record_id===========", record_id
    if int(record_id) > 0:
        if len(attrs) == 0:
            return
        update_columns = {}
        for a in attrs:
            update_columns[a] = getattr(record, a)
        if update_columns:
            son.query(record.__class__).filter_by(**{
                get_pk(record): record_id
            }).update(update_columns)
            son.commit()
            son.close()
        return record_id
    else:
        return False
Ejemplo n.º 2
0
def find_school_class_by_org_id(org_id):
    """
    通过org_id 查询返回班级信息
    :param org_id:
    :return:object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class).filter_by(org_id=org_id).first()
    son.close()
    return ob
Ejemplo n.º 3
0
def find_school_class_by_uin(uin):
    """
    通过uin查询返回班级信息
    :param uin:
    :return: object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class).filter_by(uin=uin).first()
    son.close()
    return ob
Ejemplo n.º 4
0
def find_edu_robot_by_uin(robot_uin):
    """
    通过机器人uin查询返回机器人信息
    :param robot_uin:
    :return: object
    """
    son = DBSession()
    ob = son.query(EduWxRobot).filter_by(robot_uin=robot_uin).first()
    son.close()
    return ob
Ejemplo n.º 5
0
def find_school_class_user_by_user_id(user_id):
    """
    通过发起者的user_id查询返回用户信息
    :param user_id:
    :return: object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class_User).filter_by(user_id=user_id).first()
    son.close()
    return ob
Ejemplo n.º 6
0
def find_class_by_group_id(group_id):
    """
    通过班级group_id查询返回所有当前班级信息
    :param group_id:
    :return: object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class).filter_by(group_id=group_id).first()
    son.close()
    return ob
Ejemplo n.º 7
0
def find_class_user_by_id(school_class_id):
    """
    通过班级id查询返回所有当前班级用户信息
    :param school_class_id:
    :return: objects
    """
    son = DBSession()
    obs = son.query(Edu_School_Class_User).filter_by(
        school_class_id=school_class_id).all()
    son.close()
    return obs
Ejemplo n.º 8
0
def find_room_by_room_uin(room_uin):
    """
    通过room_uin查询返回群信息
    :param user_name:
    :param school_class_id:
    :return: object
    """
    son = DBSession()
    ob = son.query(EduWxRobotChatRoom).filter_by(room_uin=room_uin).first()
    son.close()
    return ob
Ejemplo n.º 9
0
def find_class_user_by_weixin(weixin):
    """
    通过用户微信号查询返回当前班级用户信息
    :param weixin:
    :return: objects
    """
    son = DBSession()
    obs = son.query(Edu_School_Class_User).filter_by(weixin=weixin).order_by(
        Edu_School_Class_User.school_class_id.desc()).all()
    son.close()
    return obs
Ejemplo n.º 10
0
def find_school_class_by_id(school_class_id):
    """
    通过班级id查询返回当前班级信息
    :param school_class_id:
    :return: object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class).filter_by(
        school_class_id=school_class_id).first()
    son.close()
    return ob
Ejemplo n.º 11
0
def find_class_user_by_user_name_and_class_id(user_name, school_class_id):
    """
    通过姓名和班级id查询返回用户信息
    :param user_name:
    :param school_class_id:
    :return: object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class_User).filter_by(
        school_class_id=school_class_id, user_name=user_name).first()
    son.close()
    return ob
Ejemplo n.º 12
0
def find_school_class_by_class_name(school_class_name):
    """
    通过班级名称查询返回班级信息
    :param schoo_class_name:
    :return:object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class).filter_by(
        school_class_name=school_class_name).order_by(
            Edu_School_Class.school_class_id.desc()).first()
    son.close()
    return ob
Ejemplo n.º 13
0
def find_school_class_user_by_weixin_and_class_id(weixin, school_class_id):
    """
    通过微信号班级id查询返回单个用户信息
    :param weixin:
    :param school_class_id:
    :return:object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class_User).filter_by(
        weixin=weixin, school_class_id=school_class_id).first()
    son.close()
    return ob
Ejemplo n.º 14
0
def find_school_class_user_by_nick_name(nick_name):
    """
    通过用户的个人昵称查询返回当前班级的信息
    :param nick_name:
    :return:object
    """
    son = DBSession()
    obs = son.query(Edu_School_Class_User).filter_by(
        nick_name=nick_name).order_by(
            Edu_School_Class_User.school_class_id.desc()).all()
    son.close()
    return obs
Ejemplo n.º 15
0
def find_class_user_by_user_name(user_name):
    """
    通过用户名称查询返回所有当前班级用户信息
    :param user_name:
    :return: objects
    """
    son = DBSession()
    obs = son.query(Edu_School_Class_User).filter_by(
        user_name=user_name).order_by(
            Edu_School_Class_User.school_class_id.desc()).all()
    son.close()
    return obs
Ejemplo n.º 16
0
def find_school_class_by_org_id_nick_name(org_id, school_class_name):
    """
    通过org_id,nick_name查询返回班级信息
    :param org_id:
    :param nick_name:
    :return:object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class).filter_by(
        org_id=org_id, school_class_name=school_class_name).first()
    son.close()
    return ob
Ejemplo n.º 17
0
def find_school_class_by_name(school_class_name):
    """

    :param school_class_name:
    :return:
    """
    son = DBSession()
    obs = son.query(Edu_School_Class).filter_by(
        school_class_name=school_class_name).order_by(
            Edu_School_Class.school_class_id.desc()).all()
    son.close()
    return obs
Ejemplo n.º 18
0
def find_school_class_user_by_displayname_and_class_id(displayname,
                                                       school_class_id):
    """
    通过微信号班级id查询返回单个用户信息
    :param displayname:
    :param school_class_id:
    :return:object
    """
    son = DBSession()
    ob = son.query(Edu_School_Class_User).filter_by(
        displayname=displayname, school_class_id=school_class_id).first()
    son.close()
    return ob
Ejemplo n.º 19
0
def find_school_class_user_by_nick_name_and_id(nick_name, school_class_id):
    """
    通过用户nick_name 和所在班级的id返回用户信息
    :param nick_name:
    :param school_class_id:
    :return:object
    """
    son = DBSession()
    obs = son.query(Edu_School_Class_User).filter_by(
        nick_name=nick_name, school_class_id=school_class_id).order_by(
            Edu_School_Class_User.school_class_id.desc()).all()
    son.close()
    return obs
Ejemplo n.º 20
0
def into_q_memberlist(new_instance_b, memberlist):
    print "##memberlist#", memberlist
    no_alias_list = []  # 没有微信号用户列表
    # invite_code = uuid.uuid1()
    own_user_Alias=""
    own_user_AttrStatus=""
    own_user_NickName=""
    user_list = memberlist["MemberList"]
    q_username = memberlist["UserName"]
    uin = memberlist["Uin"]
    EncryChatRoomId = memberlist["EncryChatRoomId"]

    """获取当前群信息"""
    xcv = new_instance_b.update_chatroom(userName=EncryChatRoomId)

    KeyWord=xcv["KeyWord"]
    print "########KeyWord#######",KeyWord
    KeyWord = KeyWord
    print "###qun_uin###", uin
    self_user = memberlist["self"]
    chatroomowner = ""

    if "ChatRoomOwner" in memberlist:
        print "%%%%%%%%%%%%%%@@@@@@@@@@@@@", memberlist["ChatRoomOwner"]
        chatroomowner = memberlist["ChatRoomOwner"]

        """获取群创建者信息"""
        own_user = new_instance_b.search_friends(userName=chatroomowner)

        print "own_userown_userown_user@@@@@@@@@@@", own_user["Alias"], own_user["AttrStatus"], own_user["NickName"]
        own_user_Alias=own_user["Alias"]
        own_user_AttrStatus=own_user["AttrStatus"]
        own_user_NickName=own_user["NickName"]
    else:
        print "%%%%%%%%%%%%%%@@@@@@@@@@@@@"

    # chatroomowner = memberlist["ChatRoomOwner"]  # 房间创建者的user_name_id
      # 房间创建者的user_name_id
    q_nickname = memberlist["NickName"]

    if uin and uin != 0 and uin != "0":
        q_ = dao_find.find_school_class_by_uin(uin)
    else:
        q_ = dao_find.find_school_class_by_group_id(q_username)

    if not q_:
        # q_ = dao_base.find_school_class_by_org_id(KeyWord)
        q_ = dao_find.find_school_class_by_org_id_nick_name(KeyWord, q_nickname)
    session = DBSession()
    if not q_:
        data = dict()
        data['group_id'] = q_username
        data['uin'] = uin
        data['chatroomowner'] = chatroomowner
        data['org_id'] = KeyWord
        data['school_class_name'] = q_nickname
        data['invite_code'] = json.dumps({"Alias": own_user_Alias, "AttrStatus": own_user_AttrStatus,
                                          "NickName": own_user_NickName})

        q_ = Edu_School_Class(group_id=q_username, uin=uin, chatroomowner=chatroomowner, org_id=KeyWord,
                              school_class_name=q_nickname,
                              invite_code=json.dumps({"Alias": own_user_Alias,
                                                      "AttrStatus": own_user_AttrStatus,
                                                      "NickName": own_user_NickName}))
        session.add(q_)
        session.commit()

    if q_username:
        q_.group_id = q_username
    if uin and len(uin) >= 3:
        q_.uin = uin
    if chatroomowner:
        q_.chatroomowner = chatroomowner
    if q_nickname:
        q_.school_class_name = q_nickname
    q_.invite_code = json.dumps({"Alias": own_user_Alias, "AttrStatus": own_user_AttrStatus, "NickName": own_user_NickName})
    q_.org_id = KeyWord
    q_.chatroomowner = chatroomowner

    session.add(q_)
    session.commit()
    school_class_id = q_.school_class_id
    session.close()
    for i in user_list:
        if i["Alias"]:
            print "####Alias####", i["Alias"]
        else:
            print "####notAlias ####", i
        q_user = None
        username = i["UserName"]  # userid
        nickname = i["NickName"]  # 昵称
        displayname = i["DisplayName"]  # 群昵称
        alias = i["Alias"]  # 微信号
        province = i["Province"]  # 省份
        city = i["City"]  # 城市
        sex = i["Sex"]  # 性别
        signature = i["Signature"]  # 签名
        KeyWord = i["KeyWord"]  # 关键字
        #headimgurl = i["HeadImgUrl"]  # 头像地址
        headimgurl = ""  # 头像地址
        from robot.util.oss import itchat_upload_images_to_oss
        if username:
            """获取微信头像存入数据库"""
            avatar = new_instance_b.get_head_img(userName=username)
            headimgurl = itchat_upload_images_to_oss(avatar)

        session = DBSession()
        if alias:
            q_user = session.query(Edu_School_Class_User).filter_by(school_class_id=school_class_id).filter_by(weixin=alias).first()
            #q_user = dao_base.find_school_class_user_by_weixin_and_class_id(alias, school_class_id)
            if q_user:
                q_user.displayname = displayname
                q_user.nickname = nickname
                q_user.username = username
                q_user.headimgurl = headimgurl
                q_user.signature = signature
                session.add(q_user)
                session.commit()
            elif displayname:
                q_user = session.query(Edu_School_Class_User).filter_by(school_class_id=school_class_id).filter_by(displayname=displayname).first()
                #q_user = dao_base.find_school_class_user_by_displayname_and_class_id(displayname, school_class_id)
                if q_user:
                    q_user.weixin = alias
                    q_user.nickname = nickname
                    q_user.username = username
                    q_user.headimgurl = headimgurl
                    q_user.signature = signature
                    session.add(q_user)
                    session.commit()
            else:
                #当群用户没修改群昵称时
                q_user = Edu_School_Class_User(user_name=username, headimgurl=headimgurl, displayname=displayname,
                                           weixin=alias, signature=signature, school_class_id=school_class_id,
                                           province=province, city=city, sex=sex, nick_name=nickname)
                session.add(q_user)
                session.commit()
        elif displayname:
            q_user = session.query(Edu_School_Class_User).filter_by(school_class_id=school_class_id).filter_by(displayname=displayname).first()
            #q_user = dao_base.find_school_class_user_by_displayname_and_class_id(displayname, school_class_id)
            if q_user:
                if KeyWord:
                    q_user.weixin = KeyWord
                q_user.username = username
                q_user.headimgurl = headimgurl
                q_user.signature = signature
                session.add(q_user)
                session.commit()
        else:
            q_user = None  # 没有设置微信号
            no_alias_list.append({"username": username, "nickname": nickname, "displayname": displayname})
        if not q_user and displayname:
            q_user = Edu_School_Class_User(user_name=username, headimgurl=headimgurl, displayname=displayname,
                                           weixin=alias, signature=signature, school_class_id=school_class_id,
                                           province=province, city=city, sex=sex, nick_name=nickname)
            session.add(q_user)
            session.commit()
        if q_user and q_user != "error":
            q_user.username = username
            q_user.nickname = nickname
            q_user.headimgurl = headimgurl
            q_user.displayname = displayname
            q_user.alias = alias
            q_user.province = province
            q_user.sex = sex
            q_user.headimgurl = ""
            q_user.signature = signature
            session.add(q_user)
            session.commit()
        session.close()
    return school_class_id