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
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 result #设置聊天关系为已读 #获取聊天数目 page = PageForId() page.pageNo = pageNo page.receive_id = receive_id page.send_id = qunid totalPage = 0 try: page.abid = chatuser1.abid totalPage = Chat_MessageDAO.querysixinnumwithhe( chatuser1.abid) #查询Aid_Bid except Exception as e1: # TODO Auto-generated catch block print(e1) page.totalPage = totalPage 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 = qun allmessage_back.add(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 result
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 result #设置聊天关系为已读 #获取聊天数目 page = PageForId() page.pageNo = pageNo page.receive_id = receive_id page.send_id = send_id totalPage = 0 try: page.abid = chatuser1.abid totalPage = Chat_MessageDAO.querysixinnumwithhe(chatuser1.abid) #查询Aid_Bid except Exception as e: print(e) page.totalPage = totalPage page.pageSize = 10 page.start = 10 * (pageNo - 1) #数据库本来就是从后向前查询的 在数据库中第0条记录就是最默认的记录 print("共有聊天记录" + totalPage + "abid:" + page.abid) try: allMessage = Chat_MessageDAO.queryAllsixinwithhe( page.abid, page.start, page.pageSize) #通过abid查询 if (allMessage != None 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.add(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 result