Exemple #1
0
def queryAllchatuser(request):
    #第一层的结果集
    result = {}
    allchatuser_back = []

    if request.method == "POST":
        receive_id = request.POST.get("receive_id", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        receive_id = request.GET.get("receive_id", None)  # 读取post数据,None为默认值
    print("查询所有聊天用户接口参数:接收者ID", receive_id)

    try:
        allchatuser = ChatuserDAO.queryallchatuser(receive_id)

        if (allchatuser and len(allchatuser) > 0):
            userreceive = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for chatuser in allchatuser:
                print("查询到总数为", len(allchatuser))
                if (chatuser.state != ResultCode.CHATUSER_HIDE):  #如果不隐藏该关系的话
                    chatuser_back = fun.chatuser2back(chatuser)
                    #如果是私信
                    if (chatuser_back['usertype']
                            == ResultCode.CHATUSER_TYPE_SEND
                            or chatuser_back['usertype']
                            == ResultCode.CHATUSER_TYPE_RECEIVE):
                        usertemp = UserDAO.getUserInfoId(
                            chatuser_back['send_id'])
                        chatuser_back['send_user'] = fun.user2else_back(
                            usertemp)
                        chatuser_back['receive_user'] = userreceive
                        allchatuser_back.append(chatuser_back)
                        #如果是群聊
                    if (chatuser_back['usertype'] ==
                            ResultCode.CHATUSER_TYPE_QUN):
                        quntemp = QunDAO.getqunInfoqunid(chatuser_back.send_id)
                        chatuser_back['qun'] = model_to_dict(quntemp)
                        chatuser_back['receive_user'] = userreceive
                        allchatuser_back.append(chatuser_back)

        result["message"] = "查询成功"
        result["data"] = allchatuser_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS
        print("查询成功数目", len(allchatuser_back))

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)
Exemple #2
0
def queryAllsixin(request):
    #第一层的结果集
    result = {}
    allmessage_back = []

    if request.method == "POST":
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询某人的所有接收私信接口参数:接收者ID", receive_id, "page", pageNo)

    #获取聊天数目
    page = PageForId()
    page.pageno = pageNo
    page.receive_id = receive_id

    page.pagesize = 10
    page.start = 10 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = Chat_MessageDAO.queryAllsixin(page.receive_id, page.start,
                                                   page.pagesize)  #通过abid查询
        if (allMessage and len(allMessage) > 0):
            receiveuser = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for message in allMessage:
                senduser = fun.user2else_back(
                    UserDAO.getUserInfoId(message.getSend_id()))
                message_back = fun.chatmessage2back(message)
                message_back['send_user'] = senduser
                message_back['receive_user'] = receiveuser

                allmessage_back.append(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)
Exemple #3
0
def getallqunuser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值

    print("查询用户所在群下所有用户:用户ID:", userid)

    result = {}

    page = PageForId()
    page.pageno = pageNo
    page.userid = userid
    page.pagesize = 20  # 一次查询100个
    page.start = 20 * (int(pageNo) - 1)  # 数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    allUsers = UserDAO.queryallqunuser(page)
    alluserback = []
    for i in range(len(allUsers)):
        alluserback.append(fun.user2else_back(allUsers[i]))

    result["respcode"] = ResultCode.SUCCESS
    result["message"] = "查询用户成功!"
    result["data"] = alluserback
    result["errorcode"] = ResultCode.SUCCESS
    print("查询到用户,数目为", len(alluserback))
    return JsonResponse(result)
Exemple #4
0
def getalluser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值

    print("分页查询所有用户page:", pageNo)

    result = {}
    alluserback = []

    page = PageForId()
    page.pageno = pageNo
    page.pagesize = 100  # 一次查询100个

    page.start = 100 * (pageNo - 1)  # 数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录

    alluser = UserDAO.queryalluser(page)

    if (alluser and len(alluser) != 0):
        for i in range(len(alluser)):
            user_back = fun.user2else_back(alluser[i])
            alluserback.append(user_back)

    result["respcode"] = ResultCode.SUCCESS
    result["message"] = "查询用户成功!"
    result["data"] = alluserback
    result["errorcode"] = ResultCode.SUCCESS
    print("查询用户成功!")
    return JsonResponse(result)
Exemple #5
0
def getUserInfoId(request):
    result = {}
    if request.method == "POST":
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值

    print("查询用户资料接口参数:用户id:", userid)

    user = UserDAO.getUserInfoId(userid)
    if (user):
        user_else = fun.user2else_back(user)
        result["message"] = "查询成功"
        result["respcode"] = ResultCode.SUCCESS
        result["data"] = user_else
        result["errorcode"] = ""
        print("查询成功")
    else:
        # 没有查询到该用户
        result["message"] = "用户不存在"
        result["respcode"] = ResultCode.FAIL
        result["data"] = ""
        result["errorcode"] = ResultCode.UNUSEREXIST
        print("用户不存在")

    return JsonResponse(result)
def getalldealdiaryforqunid(request):
    returnData={}
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取get数据,None为默认值

    print("查询指定群日志处理接口参数:群ID" + qunid+"pageNo:"+pageNo)

    qun = QunDAO.getqunInfoqunid(qunid)

    page = PageForId()
    page.pageNo(pageNo)
    page.qunid(qunid)
    page.pageSize(10)
    page.start(10*(pageNo-1))
    try:
        alluserdeal_back = []
        alluserdeal = UserDealDAO.selectuserdealforqunid(page)
        print("查询到数目"+len(alluserdeal))
        for i in range(len(alluserdeal)):
            userDeal_back = fun.userdeal2back(alluserdeal[i])
            userelse = fun.user2else_back(UserDAO.getUserInfoId(alluserdeal[i].userid))
            userDeal_back.user=userelse
            userDeal_back.qun=qun

            alldealdiary_back =[]
            alldealdiary = DiaryDealDAO.selectdealdiaryfordealid(userDeal_back.id)
            for t in range(len(alldealdiary)):

                dealDiary_Back = fun.dealdiary2back(alldealdiary[t])
                diary=DiaryDAO.selectDiary(alldealdiary[t].id)
                diaryback=fun.diary2back(diary)
                dealDiary_Back.diary(diaryback)
                alldealdiary_back.add(dealDiary_Back)

            userDeal_back.alldealdiary(alldealdiary_back)
            alluserdeal_back.add(userDeal_back)

        returnData["respcode"]=ResultCode.SUCCESS
        returnData["message"]="查询所有日志处理成功!"
        returnData["data"]=alluserdeal_back
        returnData["errorcode"]=ResultCode.SUCCESS
        print("查询成功数目"+len(alluserdeal_back))

    except Exception as e:
        returnData["respcode"]=ResultCode.FAIL
        returnData["message"]="查询所有日志处理失败!"
        returnData["errorcode"]=ResultCode.FAIL
        returnData["data"]=""
        print("查询失败")

    return returnData
Exemple #7
0
def getdifuser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值
        showtype = request.POST.get("showtype", None)  # 读取get数据,None为默认值
    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值
        showtype = request.GET.get("showtype", None)  # 读取get数据,None为默认值

    print("查询各种各样的用户:用户ID:" + userid+"类型"+showtype)

    result = {}
    alluser =[]

    me = UserDAO.getUserInfoId(userid)
    if(not me):
        result["respcode"]= ResultCode.FAIL
        result["message"]= "用户不存在!请先注册登陆"
        result["data"]= ""
        result["errorcode"]= ResultCode.FAIL
        print("用户不存在")
        return result

    page = PageForId()
    page.pageNo=pageNo
    page.userId=userid
    page.pageSize=100  #一次查询100个
    page.deal=showtype
    totalPage = 0
    try:
        totalPage = MoreDAO.selectmorelistnumInfopage(page)
    except Exception as e1:
        print(e1)

    page.totalPage=totalPage
    page.pageSize=10
    page.start=10*(pageNo-1)   #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    allmore = MoreDAO.selectmorelistInfopage(page)
    if(allmore  and  len(allmore) !=0):
        for i in range(len(allmore)):
            user1 = UserDAO.getUserInfoId(allmore[i].userid_destination)
            user_back = fun.user2else_back(user1)
            more = getuserdeal(userid,user1.id, ResultCode.USER_ZAN)
            if(more):
                user_back.ideal=ResultCode.USER_ZAN
            alluser.add(user_back)


    print("查询各种各样用户,数目为" ,len(alluser))
    result["respcode"]= ResultCode.SUCCESS
    result["message"]= "查询用户成功!"
    result["data"]= alluser
    result["errorcode"]= ResultCode.SUCCESS
    return result
Exemple #8
0
def queryqunchat(request):
    #第一层的结果集
    result = {}
    allmessage_back = []

    if request.method == "POST":
        qunid = int(request.POST.get("qunid", None))  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        qunid = int(request.GET.get("qunid", None))  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询群聊接口参数:接收者ID", receive_id, "page", pageNo)

    #首先查询是否存在聊天关系
    chatuser1 = Chatuser()
    chatuser1.send_id = qunid
    chatuser1.receive_id = receive_id
    chatuser1.usertype = ResultCode.CHATUSER_TYPE_QUN
    chatuser1 = ChatuserDAO.querychatqunexist(chatuser1)
    if (chatuser1 == None):
        result["message"] = "暂无聊天信息"
        result["data"] = ""
        result["errorcode"] = ""
        result["respcode"] = ResultCode.FAIL
        print("不存在聊天关系")
        return JsonResponse(result)

    #设置聊天关系为已读
    #获取聊天数目
    page = PageForId()
    page.pageno = pageNo
    page.receive_id = receive_id
    page.send_id = qunid
    page.abid = chatuser1.abid
    page.pagesize = 20
    page.start = 20 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = Chat_MessageDAO.queryAllsixinwithhe(
            page.abid, page.start, page.pagesize)  #通过abid查询
        if (len(allMessage) > 0):
            #修改聊天用户的状态   在群聊中
            page.state = ResultCode.CHATUSER_OLD
            ChatuserDAO.updatachatuserstateforuser(page)
            qun = QunDAO.getqunInfoqunid(qunid)
            for message in allMessage:
                message_back = fun.chatmessage2back(message)
                #获取消息发送者信息
                senduser = fun.user2else_back(
                    UserDAO.getUserInfoId(message_back['send_id']))
                message_back['send_user'] = senduser
                message_back['qun'] = model_to_dict(qun)

                allmessage_back.append(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)
Exemple #9
0
def queryAllsixinwithhe(request):
    #第一层的结果集
    result = {}
    allmessage_back = []
    if request.method == "POST":
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询和某人的所有私信接口参数:接收者ID", receive_id, "发送者id", send_id, "page", pageNo)

    #首先查询是否存在聊天关系
    chatuser1 = Chatuser()
    chatuser1.send_id = send_id
    chatuser1.receive_id = receive_id
    chatuser1.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
    chatuser1 = ChatuserDAO.querychatuserexist(chatuser1)
    if (chatuser1 == None):
        chatuser1 = Chatuser()
        chatuser1.send_id = send_id
        chatuser1.receive_id = receive_id
        chatuser1.usertype = ResultCode.CHATUSER_TYPE_SEND
        chatuser1 = ChatuserDAO.querychatuserexist(chatuser1)
        if (chatuser1 == None):
            result["message"] = "不存在聊天关系"
            result["data"] = allmessage_back
            result["errorcode"] = ""
            result["respcode"] = ResultCode.SUCCESS
            print("不存在聊天关系")
            return JsonResponse(result)

    #设置聊天关系为已读
#获取聊天数目
    page = PageForId()
    page.pageno = pageNo
    page.receive_id = receive_id
    page.send_id = send_id

    page.pagesize = 10
    page.start = 10 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录

    try:
        allMessage = Chat_MessageDAO.queryAllsixinwithhe(
            page.abid, page.start, page.pagesize)  #通过abid查询
        if (allMessage and len(allMessage) > 0):
            page.state = ResultCode.CHATUSER_OLD
            ChatuserDAO.updatachatuserstateforuser(chatuser1)  #修改聊天用户的状态
            senduser = fun.user2else_back(UserDAO.getUserInfoId(send_id))
            receiveuser = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for message in allMessage:
                print("查询聊天记录" + message.content)
                message_back = fun.chatmessage2back(message)
                if (message_back['send_id'] == send_id):
                    message_back['send_user'] = senduser
                    message_back['receive_user'] = receiveuser
                else:
                    message_back['send_user'] = receiveuser
                    message_back['receive_user'] = senduser

                allmessage_back.append(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)