From 6c2e9ba62c418185361179e7014862c481f34e17 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Wed, 09 Mar 2022 14:22:09 +0800 Subject: [PATCH] conflect merge --- src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcMsgServiceImpl.java | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 252 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcMsgServiceImpl.java b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcMsgServiceImpl.java new file mode 100644 index 0000000..67a62fa --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcMsgServiceImpl.java @@ -0,0 +1,252 @@ +package com.xcong.excoin.modules.otc.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.xcong.excoin.common.LoginUserUtils; +import com.xcong.excoin.common.response.Result; +import com.xcong.excoin.modules.member.dao.MemberDao; +import com.xcong.excoin.modules.member.dao.MemberSettingDao; +import com.xcong.excoin.modules.member.entity.MemberEntity; +import com.xcong.excoin.modules.member.entity.MemberSettingEntity; +import com.xcong.excoin.modules.otc.dao.OtcMsgHistoryDao; +import com.xcong.excoin.modules.otc.dao.OtcMsgUserListDao; +import com.xcong.excoin.modules.otc.dao.OtcOrderDao; +import com.xcong.excoin.modules.otc.dto.*; +import com.xcong.excoin.modules.otc.entity.OtcMsgHistoryEntity; +import com.xcong.excoin.modules.otc.entity.OtcMsgUserListEntity; +import com.xcong.excoin.modules.otc.service.OtcMsgService; +import com.xcong.excoin.modules.otc.vo.ChatBoxVo; +import com.xcong.excoin.modules.otc.vo.ChatOrderVo; +import com.xcong.excoin.modules.otc.vo.MsgListVo; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class OtcMsgServiceImpl extends ServiceImpl<OtcMsgUserListDao, OtcMsgUserListEntity> implements OtcMsgService { + + private final OtcMsgUserListDao otcMsgUserListDao; + private final OtcMsgHistoryDao otcMsgHistoryDao; + private final OtcOrderDao otcOrderDao; + + private final MemberSettingDao memberSettingDao; + private final MemberDao memberDao; + + + @Override + public IPage<MsgListVo> getMsgList(MsgListDto msgListDto) { + MemberEntity member = LoginUserUtils.getAppLoginUser(); + Long memberId = member.getId(); +// Long memberId = 444L; +// MemberEntity member = memberDao.selectById(memberId); + + Page<MsgListVo> page = new Page<>(msgListDto.getPageNum(), msgListDto.getPageSize()); + + OtcMsgUserListEntity otcMsgUserListEntity = new OtcMsgUserListEntity(); + otcMsgUserListEntity.setMemberId(memberId); + otcMsgUserListEntity.setNickname(msgListDto.getNickname()); + IPage<MsgListVo> msgList = otcMsgUserListDao.getMsgList(otcMsgUserListEntity, page); + List<MsgListVo> records = msgList.getRecords(); + //更新最外层的消息提醒 + boolean flag = true; + if(CollUtil.isNotEmpty(records)){ + for(MsgListVo msgListVo : records){ + long targetId = msgListVo.getTargetId(); +// MemberEntity memberEntity = memberDao.selectById(targetId); +// msgListVo.setNickname(memberEntity.getName()); + + ChatOrderVo chatOrderVo = new ChatOrderVo(); + List<ChatOrderVo> chatOrderVos = otcOrderDao.selectOneByMemberIdAndTargetId(memberId,targetId); + if(CollUtil.isNotEmpty(chatOrderVos)){ + for(ChatOrderVo chatOrderVodone : chatOrderVos){ + Long memberIdDone = chatOrderVodone.getMemberId(); + if(memberId.equals(memberIdDone) || memberId == memberIdDone){ + chatOrderVo = chatOrderVodone; + } + } + } + msgListVo.setChatOrderVo(chatOrderVo); + + Integer isRead = msgListVo.getIsRead(); + if(OtcMsgUserListEntity.ISREAD_ONE == isRead){ + flag = false; + } + } + if(flag){ + MemberSettingEntity memberSettingEntity = memberSettingDao.selectMemberSettingByMemberId(member.getId()); + memberSettingEntity.setMessageReminder(0); + memberSettingDao.updateById(memberSettingEntity); + } + } + return msgList; + } + + @Override + @Transactional + public Result getChatBox(ChatBoxDto chatBoxDto) { + MemberEntity member = LoginUserUtils.getAppLoginUser(); +// MemberEntity member = memberDao.selectById(443L); + //对话是否存在 + long id = chatBoxDto.getId(); + if(ObjectUtil.isEmpty(id)){ + return Result.fail("请下拉刷新"); + } + OtcMsgUserListEntity otcMsgUserListEntity = otcMsgUserListDao.selectById(id); + if(ObjectUtil.isEmpty(otcMsgUserListEntity)){ + return Result.fail("请下拉刷新"); + } + //更新为已读 + otcMsgUserListEntity.setIsRead(OtcMsgUserListEntity.ISREAD_TWO); + otcMsgUserListDao.updateById(otcMsgUserListEntity); + + long memberId = otcMsgUserListEntity.getMemberId(); + long targetId = otcMsgUserListEntity.getTargetId(); + Page<ChatBoxVo> page = new Page<>(chatBoxDto.getPageNum(), chatBoxDto.getPageSize()); + OtcMsgHistoryEntity otcMsgHistoryEntity = new OtcMsgHistoryEntity(); + otcMsgHistoryEntity.setMemberId(memberId); + otcMsgHistoryEntity.setTargetId(targetId); + IPage<ChatBoxVo> chatBoxVos= otcMsgHistoryDao.getChatBoxMsgList(page,otcMsgHistoryEntity); + return Result.ok(chatBoxVos); + } + + @Override + @Transactional + public Result sendMsg(SendMsgDto sendMsgDto) { + MemberEntity member = LoginUserUtils.getAppLoginUser(); + Long memberId = member.getId(); +// Long memberId = 449L; + long targetId = sendMsgDto.getTargetId(); + if(ObjectUtil.isEmpty(targetId)){ + return Result.fail("对话用户不存在"); + } + MemberEntity memberEntity = memberDao.selectById(targetId); + if(ObjectUtil.isEmpty(memberEntity)){ + return Result.fail("对话用户不存在"); + } + String msg = sendMsgDto.getMsg(); + if(StrUtil.isEmpty(msg)){ + return Result.fail("请输入发送消息"); + } + Integer msgType = sendMsgDto.getMsgType(); + if(ObjectUtil.isEmpty(msgType)){ + return Result.fail("请输入发送消息"); + } + //发送方 + List<OtcMsgUserListEntity> otcMsgUserListEntityFrom = otcMsgUserListDao.selectListByMemberIdAndTargetId(memberId,targetId); + if(CollUtil.isEmpty(otcMsgUserListEntityFrom)){ + OtcMsgUserListEntity otcMsgUserListEntity = new OtcMsgUserListEntity(); + otcMsgUserListEntity.setMemberId(memberId); + otcMsgUserListEntity.setTargetId(targetId); + otcMsgUserListEntity.setIsRead(OtcMsgUserListEntity.ISREAD_TWO); + otcMsgUserListEntity.setLastMsgTime(DateUtil.date()); + otcMsgUserListDao.insert(otcMsgUserListEntity); + }else{ + OtcMsgUserListEntity otcMsgUserListEntity = otcMsgUserListEntityFrom.get(0); + otcMsgUserListEntity.setMemberId(memberId); + otcMsgUserListEntity.setTargetId(targetId); + otcMsgUserListEntity.setIsRead(OtcMsgUserListEntity.ISREAD_TWO); + otcMsgUserListEntity.setLastMsgTime(DateUtil.date()); + otcMsgUserListDao.updateById(otcMsgUserListEntity); + } + //历史消息中增加新纪录 + OtcMsgHistoryEntity otcMsgHistoryEntityFrom = new OtcMsgHistoryEntity(); + otcMsgHistoryEntityFrom.setMemberId(memberId); + otcMsgHistoryEntityFrom.setFromMemberId(memberId); + otcMsgHistoryEntityFrom.setTargetId(targetId); + otcMsgHistoryEntityFrom.setMsg(msg); + otcMsgHistoryEntityFrom.setMsgType(msgType); + otcMsgHistoryEntityFrom.setIsSelf(OtcMsgHistoryEntity.ISSELF_ONE); + otcMsgHistoryDao.insert(otcMsgHistoryEntityFrom); + //接受方 + List<OtcMsgUserListEntity> otcMsgUserListEntityTo = otcMsgUserListDao.selectListByMemberIdAndTargetId(targetId,memberId); + if(CollUtil.isEmpty(otcMsgUserListEntityTo)){ + OtcMsgUserListEntity otcMsgUserListEntity = new OtcMsgUserListEntity(); + otcMsgUserListEntity.setMemberId(targetId); + otcMsgUserListEntity.setTargetId(memberId); + otcMsgUserListEntity.setIsRead(OtcMsgUserListEntity.ISREAD_ONE); + otcMsgUserListEntity.setLastMsgTime(DateUtil.date()); + otcMsgUserListDao.insert(otcMsgUserListEntity); + }else{ + OtcMsgUserListEntity otcMsgUserListEntity = otcMsgUserListEntityTo.get(0); + otcMsgUserListEntity.setMemberId(targetId); + otcMsgUserListEntity.setTargetId(memberId); + otcMsgUserListEntity.setIsRead(OtcMsgUserListEntity.ISREAD_ONE); + otcMsgUserListEntity.setLastMsgTime(DateUtil.date()); + otcMsgUserListDao.updateById(otcMsgUserListEntity); + } + //历史消息中增加新纪录 + OtcMsgHistoryEntity otcMsgHistoryEntityTo = new OtcMsgHistoryEntity(); + otcMsgHistoryEntityTo.setMemberId(targetId); + otcMsgHistoryEntityTo.setFromMemberId(memberId); + otcMsgHistoryEntityTo.setTargetId(targetId); + otcMsgHistoryEntityTo.setMsg(msg); + otcMsgHistoryEntityTo.setMsgType(msgType); + otcMsgHistoryEntityTo.setIsSelf(OtcMsgHistoryEntity.ISSELF_TWO); + otcMsgHistoryDao.insert(otcMsgHistoryEntityTo); + + //增加一个提醒的 + MemberSettingEntity memberSettingEntity = memberSettingDao.selectMemberSettingByMemberId(targetId); + memberSettingEntity.setMessageReminder(1); + memberSettingDao.updateById(memberSettingEntity); + return Result.ok("发送成功"); + } + + @Override + public Result getChatBoxConnect(ConnectDto connectDto) { + + MemberEntity member = LoginUserUtils.getAppLoginUser(); + Long memberId = member.getId(); +// Long memberId = 443L; + long targetId = connectDto.getTargetId(); + if(ObjectUtil.isEmpty(targetId)){ + return Result.fail("请返回重试"); + } + IPage<ChatBoxVo> chatBoxVos= new Page<>(); + List<OtcMsgUserListEntity> otcMsgUserListEntitys = otcMsgUserListDao.selectListByMemberIdAndTargetId(memberId,targetId); + if(CollUtil.isNotEmpty(otcMsgUserListEntitys)){ + Page<ChatBoxVo> page = new Page<>(connectDto.getPageNum(), connectDto.getPageSize()); + OtcMsgHistoryEntity otcMsgHistoryEntity = new OtcMsgHistoryEntity(); + otcMsgHistoryEntity.setMemberId(memberId); + otcMsgHistoryEntity.setTargetId(targetId); + chatBoxVos = otcMsgHistoryDao.getChatBoxMsgList(page,otcMsgHistoryEntity); + } + return Result.ok(chatBoxVos); + } + + @Override + public Result getChatOrder(ChatOrderDto chatOrderDto) { + + MemberEntity member = LoginUserUtils.getAppLoginUser(); + Long memberId = member.getId(); +// Long memberId = 443L; + + long targetId = chatOrderDto.getTargetId(); + if(ObjectUtil.isEmpty(targetId)){ + return Result.fail("请返回重试"); + } + ArrayList<ChatOrderVo> chatOrderVoList = new ArrayList<>(); + List<ChatOrderVo> chatOrderVos = otcOrderDao.selectByMemberIdAndTargetId(memberId,targetId); + if(CollUtil.isNotEmpty(chatOrderVos)){ + for(ChatOrderVo chatOrderVo : chatOrderVos){ + Long memberIdDone = chatOrderVo.getMemberId(); + if(memberId.equals(memberIdDone) || memberId == memberIdDone){ + chatOrderVoList.add(chatOrderVo); + } + } + } + return Result.ok(chatOrderVoList); + } + + +} -- Gitblit v1.9.1