def updatechatuserstate(request): result = {} 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为默认值 state = int(request.POST.get("state", None)) # 读取post数据,None为默认值 if request.method == "GET": send_id = int(request.GET.get("send_id", None)) # 读取post数据,None为默认值 receive_id = int(request.GET.get("receive_id", None)) # 读取post数据,None为默认值 state = int(request.POST.get("state", None)) # 读取post数据,None为默认值 page = PageForId() page.send_id = send_id page.receive_id = receive_id page.state = state ChatuserDAO.updatachatuserstateforuser(page) result["message"] = "设置成功" result["data"] = "" result["errorcode"] = ResultCode.SUCCESS result["respcode"] = ResultCode.SUCCESS print("设置成功") return JsonResponse(result)
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)
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)
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)