IM消息功能
This commit is contained in:
parent
54e04be768
commit
73aa36fc69
@ -1,14 +1,17 @@
|
||||
package cn.lili.controller.member;
|
||||
|
||||
import cn.lili.common.enums.ResultUtil;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.member.entity.dto.FootPrintQueryParams;
|
||||
import cn.lili.modules.member.service.FootprintService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -35,8 +38,9 @@ public class FootprintController {
|
||||
|
||||
@ApiOperation(value = "分页获取")
|
||||
@GetMapping
|
||||
public ResultMessage<IPage<EsGoodsIndex>> getByPage(PageVO page) {
|
||||
return ResultUtil.data(footprintService.footPrintPage(page));
|
||||
public ResultMessage<IPage<EsGoodsIndex>> getByPage(FootPrintQueryParams params) {
|
||||
params.setMemberId(UserContext.getCurrentUser().getId());
|
||||
return ResultUtil.data(footprintService.footPrintPage(params));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id删除")
|
||||
|
@ -14,5 +14,5 @@ public interface StoreSettingChangeEvent {
|
||||
*
|
||||
* @param store 店铺信息
|
||||
*/
|
||||
void StoreSettingChange(Store store);
|
||||
void storeSettingChange(Store store);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class ImTalkExecute implements MemberInfoChangeEvent, StoreSettingChangeE
|
||||
}
|
||||
|
||||
@Override
|
||||
public void StoreSettingChange(Store store) {
|
||||
public void storeSettingChange(Store store) {
|
||||
//当与UserId1相等时
|
||||
List<ImTalk> imTalkList1 = imTalkService.list(new LambdaQueryWrapper<ImTalk>().eq(ImTalk::getUserId1, store.getId()));
|
||||
for (ImTalk imTalk : imTalkList1) {
|
||||
|
@ -35,7 +35,7 @@ public class StoreMessageListener implements RocketMQListener<MessageExt> {
|
||||
for (StoreSettingChangeEvent storeSettingChangeEvent : storeSettingChangeEventList) {
|
||||
try {
|
||||
Store store = JSONUtil.toBean(new String(messageExt.getBody()), Store.class);
|
||||
storeSettingChangeEvent.StoreSettingChange(store);
|
||||
storeSettingChangeEvent.storeSettingChange(store);
|
||||
} catch (Exception e) {
|
||||
log.error("会员{},在{}业务中,状态修改事件执行异常",
|
||||
new String(messageExt.getBody()),
|
||||
|
@ -327,7 +327,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
|
||||
//记录用户足迹
|
||||
if (UserContext.getCurrentUser() != null) {
|
||||
FootPrint footPrint = new FootPrint(UserContext.getCurrentUser().getId(), goodsId, skuId);
|
||||
FootPrint footPrint = new FootPrint(UserContext.getCurrentUser().getId(), goodsIndex.getStoreId(), goodsId, skuId);
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.VIEW_GOODS.name();
|
||||
rocketMQTemplate.asyncSend(destination, footPrint, RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
package cn.lili.modules.im.entity.dos;
|
||||
|
||||
import cn.lili.common.utils.SnowFlake;
|
||||
import cn.lili.modules.im.entity.enums.MessageTypeEnum;
|
||||
import cn.lili.modules.im.entity.vo.MessageOperation;
|
||||
import cn.lili.mybatis.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Chopper
|
||||
@ -12,6 +18,8 @@ import lombok.Data;
|
||||
@Data
|
||||
@TableName("li_im_message")
|
||||
@ApiModel(value = "Im消息")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ImMessage extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -46,4 +54,16 @@ public class ImMessage extends BaseEntity {
|
||||
*/
|
||||
private String text;
|
||||
|
||||
|
||||
public ImMessage(MessageOperation messageOperation){
|
||||
this.setFromUser(messageOperation.getFrom());
|
||||
this.setMessageType(messageOperation.getMessageType());
|
||||
this.setIsRead(false);
|
||||
this.setText(messageOperation.getContext());
|
||||
this.setTalkId(messageOperation.getTalkId());
|
||||
this.setCreateTime(new Date());
|
||||
this.setToUser(messageOperation.getTo());
|
||||
this.setId(SnowFlake.getIdStr());
|
||||
}
|
||||
|
||||
}
|
@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
@ -18,64 +20,65 @@ import java.util.Date;
|
||||
@Data
|
||||
@TableName("li_im_talk")
|
||||
@ApiModel(value = "聊天")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ImTalk extends BaseTenantEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户1 id小的排在1
|
||||
*/
|
||||
@ApiModelProperty("用户1 id")
|
||||
private String userId1;
|
||||
/**
|
||||
* 用户1 id大的排在2
|
||||
*/
|
||||
|
||||
@ApiModelProperty("用户2 id")
|
||||
private String userId2;
|
||||
|
||||
/**
|
||||
* 用户1置顶
|
||||
*/
|
||||
@ApiModelProperty("用户1置顶")
|
||||
private Boolean top1;
|
||||
|
||||
/**
|
||||
* 用户2置顶
|
||||
*/
|
||||
@ApiModelProperty("用户2置顶")
|
||||
private Boolean top2;
|
||||
/**
|
||||
* 用户1 不可见
|
||||
*/
|
||||
|
||||
@ApiModelProperty("用户1 不可见")
|
||||
private Boolean disable1;
|
||||
|
||||
/**
|
||||
* 用户2 不可见
|
||||
*/
|
||||
@ApiModelProperty("用户2 不可见")
|
||||
private Boolean disable2;
|
||||
/**
|
||||
* 用户1名字
|
||||
*/
|
||||
|
||||
@ApiModelProperty("用户1名字")
|
||||
private String name1;
|
||||
|
||||
/**
|
||||
* 用户2名字
|
||||
*/
|
||||
@ApiModelProperty("用户2名字")
|
||||
private String name2;
|
||||
/**
|
||||
* 用户1头像
|
||||
*/
|
||||
|
||||
@ApiModelProperty("用户1头像")
|
||||
private String face1;
|
||||
|
||||
/**
|
||||
* 用户2头像
|
||||
*/
|
||||
@ApiModelProperty("用户2头像")
|
||||
private String face2;
|
||||
|
||||
@ApiModelProperty("用户1的店铺标识")
|
||||
private Boolean storeFlag1;
|
||||
|
||||
@ApiModelProperty("用户2的店铺标识")
|
||||
private Boolean storeFlag2;
|
||||
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "最后聊天时间", hidden = true)
|
||||
private Date lastTalkTime;
|
||||
|
||||
public ImTalk() {
|
||||
@ApiModelProperty(value = "最后聊天内容")
|
||||
private String lastTalkMessage;
|
||||
|
||||
@ApiModelProperty(value = "最后发送消息类型")
|
||||
private String lastMessageType;
|
||||
|
||||
@ApiModelProperty(value = "坐席Id")
|
||||
private String tenantId;
|
||||
|
||||
@ApiModelProperty(value = "坐席名称")
|
||||
private String tenantName;
|
||||
|
||||
}
|
||||
|
||||
public ImTalk(String userId1, String userId2,
|
||||
String face1, String face2,
|
||||
@ -87,6 +90,8 @@ public class ImTalk extends BaseTenantEntity {
|
||||
this.top2 = false;
|
||||
this.disable1 = false;
|
||||
this.disable2 = false;
|
||||
this.storeFlag1 = false;
|
||||
this.storeFlag2 = false;
|
||||
this.setId(SnowFlake.getIdStr());
|
||||
this.lastTalkTime = new Date();
|
||||
this.face1 = face1;
|
||||
|
@ -3,6 +3,7 @@ package cn.lili.modules.im.entity.dto;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.im.entity.dos.ImMessage;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.Data;
|
||||
@ -15,7 +16,7 @@ import lombok.Data;
|
||||
* 2022-01-20 17:16
|
||||
*/
|
||||
@Data
|
||||
public class MessageQueryParams {
|
||||
public class MessageQueryParams extends PageVO {
|
||||
/**
|
||||
* 聊天窗口
|
||||
*/
|
||||
@ -42,8 +43,8 @@ public class MessageQueryParams {
|
||||
if (StringUtils.isNotEmpty(lastMessageId)) {
|
||||
lambdaQueryWrapper.lt(ImMessage::getId, lastMessageId);
|
||||
}
|
||||
lambdaQueryWrapper.orderByDesc(ImMessage::getId);
|
||||
lambdaQueryWrapper.last("limit " + num);
|
||||
lambdaQueryWrapper.orderByDesc(ImMessage::getCreateTime);
|
||||
// lambdaQueryWrapper.last("limit " + num);
|
||||
return lambdaQueryWrapper;
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,6 @@ public enum MessageTypeEnum {
|
||||
MESSAGE,
|
||||
PICTURE,
|
||||
VOICE,
|
||||
GOODS,
|
||||
VIDEO
|
||||
}
|
||||
|
@ -19,40 +19,41 @@ public class ImTalkVO extends BaseTenantEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty("id")
|
||||
private String id;
|
||||
/**
|
||||
* 用户 id
|
||||
*/
|
||||
|
||||
@ApiModelProperty("用户 id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 置顶
|
||||
*/
|
||||
@ApiModelProperty("置顶")
|
||||
private Boolean top;
|
||||
|
||||
/**
|
||||
* 用户 不可见
|
||||
*/
|
||||
@ApiModelProperty("用户 不可见")
|
||||
private Boolean disable;
|
||||
|
||||
/**
|
||||
* 用户名字
|
||||
*/
|
||||
@ApiModelProperty("用户名字")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
@ApiModelProperty("用户头像")
|
||||
private String face;
|
||||
|
||||
@ApiModelProperty("店铺标识")
|
||||
private Boolean storeFlag;
|
||||
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "最后聊天时间", hidden = true)
|
||||
private Date lastTalkTime;
|
||||
|
||||
@ApiModelProperty(value = "最后聊天内容")
|
||||
private String lastTalkMessage;
|
||||
|
||||
@ApiModelProperty(value = "最后发送消息类型")
|
||||
private String lastMessageType;
|
||||
|
||||
@ApiModelProperty(value = "未读数量")
|
||||
private Long unread;
|
||||
|
||||
public ImTalkVO() {
|
||||
|
||||
}
|
||||
@ -64,15 +65,18 @@ public class ImTalkVO extends BaseTenantEntity {
|
||||
disable = imTalk.getDisable1();
|
||||
name = imTalk.getName1();
|
||||
face = imTalk.getFace1();
|
||||
storeFlag = imTalk.getStoreFlag1();
|
||||
} else {
|
||||
userId = imTalk.getUserId2();
|
||||
top = imTalk.getTop2();
|
||||
disable = imTalk.getDisable2();
|
||||
name = imTalk.getName2();
|
||||
face = imTalk.getFace2();
|
||||
storeFlag = imTalk.getStoreFlag2();
|
||||
}
|
||||
|
||||
lastTalkMessage = imTalk.getLastTalkMessage();
|
||||
lastTalkTime = imTalk.getLastTalkTime();
|
||||
lastMessageType = imTalk.getLastMessageType();
|
||||
id = imTalk.getId();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cn.lili.modules.im.service;
|
||||
|
||||
import cn.lili.modules.im.entity.dos.ImMessage;
|
||||
import cn.lili.modules.im.entity.dto.MessageQueryParams;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
@ -41,4 +42,22 @@ public interface ImMessageService extends IService<ImMessage> {
|
||||
* @return
|
||||
*/
|
||||
Boolean hasNewMessage(String accessToken);
|
||||
|
||||
/**
|
||||
* 分页获取消息列表
|
||||
* @param messageQueryParams 查询条件
|
||||
* @return 消息列表
|
||||
*/
|
||||
List<ImMessage> getList(MessageQueryParams messageQueryParams);
|
||||
|
||||
/**
|
||||
* 获取所有未读消息
|
||||
* @return
|
||||
*/
|
||||
Long unreadMessageCount();
|
||||
|
||||
/**
|
||||
* 清空所有未读消息
|
||||
*/
|
||||
void cleanUnreadMessage();
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package cn.lili.modules.im.service;
|
||||
|
||||
import cn.lili.modules.im.entity.dos.ImTalk;
|
||||
import cn.lili.modules.im.entity.vo.ImTalkVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 聊天 业务层
|
||||
*
|
||||
@ -33,4 +36,16 @@ public interface ImTalkService extends IService<ImTalk> {
|
||||
* @param id
|
||||
*/
|
||||
void disable(String id);
|
||||
|
||||
/**
|
||||
* 获取用户聊天列表
|
||||
* @return
|
||||
*/
|
||||
List<ImTalkVO> getUserTalkList(String userName);
|
||||
|
||||
/**
|
||||
* 获取商家聊天列表
|
||||
* @return
|
||||
*/
|
||||
List<ImTalkVO> getStoreTalkList();
|
||||
}
|
@ -1,10 +1,15 @@
|
||||
package cn.lili.modules.im.serviceimpl;
|
||||
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.modules.im.entity.dos.ImMessage;
|
||||
import cn.lili.modules.im.entity.dto.MessageQueryParams;
|
||||
import cn.lili.modules.im.mapper.ImMessageMapper;
|
||||
import cn.lili.modules.im.service.ImMessageService;
|
||||
import cn.lili.modules.im.service.ImTalkService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -13,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -66,4 +73,71 @@ public class ImMessageServiceImpl extends ServiceImpl<ImMessageMapper, ImMessage
|
||||
return this.list(queryWrapper).size() > 0;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImMessage> getList(MessageQueryParams messageQueryParams) {
|
||||
List<ImMessage> messageList = this.page(PageUtil.initPage(messageQueryParams), messageQueryParams.initQueryWrapper()).getRecords();
|
||||
ListSort(messageList);
|
||||
readMessage(messageList);
|
||||
return messageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long unreadMessageCount() {
|
||||
AuthUser currentUser = UserContext.getCurrentUser();
|
||||
if(currentUser == null){
|
||||
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
|
||||
}
|
||||
return this.count(new LambdaQueryWrapper<ImMessage>().eq(ImMessage::getToUser,currentUser.getId()).eq(ImMessage::getIsRead,false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUnreadMessage() {
|
||||
AuthUser currentUser = UserContext.getCurrentUser();
|
||||
if(currentUser == null){
|
||||
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
|
||||
}
|
||||
this.update(new LambdaUpdateWrapper<ImMessage>().eq(ImMessage::getToUser,currentUser.getId()).set(ImMessage::getIsRead,true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间倒叙
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
private static void ListSort(List<ImMessage> list) {
|
||||
list.sort(new Comparator<ImMessage>() {
|
||||
@Override
|
||||
public int compare(ImMessage e1, ImMessage e2) {
|
||||
try {
|
||||
if (e1.getCreateTime().before(e2.getCreateTime())) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阅读消息
|
||||
*
|
||||
* @param messageList 消息列表
|
||||
*/
|
||||
private void readMessage(List<ImMessage> messageList) {
|
||||
if (messageList.size() > 0) {
|
||||
for (ImMessage imMessage : messageList) {
|
||||
if(Boolean.FALSE.equals(imMessage.getIsRead())){
|
||||
imMessage.setIsRead(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateBatchById(messageList);
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,14 @@ package cn.lili.modules.im.serviceimpl;
|
||||
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.modules.im.entity.dos.ImMessage;
|
||||
import cn.lili.modules.im.entity.dos.ImTalk;
|
||||
import cn.lili.modules.im.entity.vo.ImTalkVO;
|
||||
import cn.lili.modules.im.mapper.ImTalkMapper;
|
||||
import cn.lili.modules.im.service.ImMessageService;
|
||||
import cn.lili.modules.im.service.ImTalkService;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
import cn.lili.modules.member.service.MemberService;
|
||||
@ -18,6 +23,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.stringtemplate.v4.ST;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 聊天 业务实现
|
||||
*
|
||||
@ -34,24 +42,25 @@ public class ImTalkServiceImpl extends ServiceImpl<ImTalkMapper, ImTalk> impleme
|
||||
@Autowired
|
||||
private StoreService storeService;
|
||||
|
||||
@Autowired
|
||||
private ImMessageService imMessageService;
|
||||
|
||||
@Override
|
||||
public ImTalk getTalkByUser(String userId1, String userId2) {
|
||||
LambdaQueryWrapper<ImTalk> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ImTalk::getUserId2, userId2);
|
||||
queryWrapper.eq(ImTalk::getUserId1, userId1);
|
||||
ImTalk imTalk = this.getOne(queryWrapper);
|
||||
Member self = memberService.getById(userId1);
|
||||
Store selfStore = storeService.getById(userId1);
|
||||
|
||||
|
||||
AuthUser currentUser = UserContext.getCurrentUser();
|
||||
//如果没有聊天,则创建聊天
|
||||
if (imTalk == null) {
|
||||
// 没有登录的这个账户信息
|
||||
if (self == null && selfStore ==null) {
|
||||
if (currentUser == null) {
|
||||
return null;
|
||||
}
|
||||
//当自己为店铺时
|
||||
if(selfStore != null){
|
||||
if(UserEnums.STORE.equals(currentUser.getRole())){
|
||||
Store selfStore = storeService.getById(userId1);
|
||||
//没有这个用户信息
|
||||
Member other = memberService.getById(userId2);
|
||||
if(other == null){
|
||||
@ -59,14 +68,20 @@ public class ImTalkServiceImpl extends ServiceImpl<ImTalkMapper, ImTalk> impleme
|
||||
}
|
||||
//自己为店铺其他人必定为用户
|
||||
imTalk = new ImTalk(userId1, userId2, selfStore.getStoreLogo(), other.getFace(), selfStore.getStoreName(), other.getNickName());
|
||||
}else if(self != null){
|
||||
imTalk.setStoreFlag1(true);
|
||||
}else if(UserEnums.MEMBER.equals(currentUser.getRole())){
|
||||
//没有这个店铺信息
|
||||
Member self = memberService.getById(userId1);
|
||||
Member otherMember = memberService.getById(userId2);
|
||||
Store otherStore = storeService.getById(userId2);
|
||||
if(otherStore == null){
|
||||
if(otherStore != null){
|
||||
imTalk = new ImTalk(userId1, userId2, self.getFace(), otherStore.getStoreLogo(), self.getNickName(), otherStore.getStoreName());
|
||||
imTalk.setStoreFlag2(true);
|
||||
}else if (otherMember != null){
|
||||
imTalk = new ImTalk(userId1, userId2, self.getFace(), otherMember.getFace(), self.getNickName(), otherMember.getNickName());
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
//当自己为用户时 其他人必定为店铺
|
||||
imTalk = new ImTalk(userId1, userId2, self.getFace(), otherStore.getStoreLogo(), self.getNickName(), otherStore.getStoreName());
|
||||
}
|
||||
this.save(imTalk);
|
||||
} else {
|
||||
@ -114,4 +129,59 @@ public class ImTalkServiceImpl extends ServiceImpl<ImTalkMapper, ImTalk> impleme
|
||||
this.updateById(imTalk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImTalkVO> getUserTalkList(String userName) {
|
||||
AuthUser authUser = UserContext.getCurrentUser();
|
||||
if(authUser == null){
|
||||
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
|
||||
}
|
||||
LambdaQueryWrapper<ImTalk> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.and(wq->{
|
||||
wq.like(ImTalk::getName1, userName).or().like(ImTalk::getName2,userName);
|
||||
});
|
||||
queryWrapper.and(wq->{
|
||||
wq.like(ImTalk::getUserId1, authUser.getId()).or().like(ImTalk::getUserId2,authUser.getId());
|
||||
});
|
||||
queryWrapper.orderByDesc(ImTalk::getLastTalkTime);
|
||||
List<ImTalk> imTalks = this.list(queryWrapper);
|
||||
List<ImTalkVO> imTalkVOList = imTalks.stream().map(imTalk -> {
|
||||
return new ImTalkVO(imTalk, authUser.getId());
|
||||
}).collect(Collectors.toList());
|
||||
getUnread(imTalkVOList);
|
||||
return imTalkVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImTalkVO> getStoreTalkList() {
|
||||
AuthUser authUser = UserContext.getCurrentUser();
|
||||
if(authUser == null){
|
||||
throw new ServiceException(ResultCode.STORE_NOT_LOGIN_ERROR);
|
||||
}
|
||||
LambdaQueryWrapper<ImTalk> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.and(wq->{
|
||||
wq.like(ImTalk::getUserId1, authUser.getStoreId()).or().like(ImTalk::getUserId2,authUser.getStoreId());
|
||||
});
|
||||
queryWrapper.orderByDesc(ImTalk::getLastTalkTime);
|
||||
List<ImTalk> imTalks = this.list(queryWrapper);
|
||||
|
||||
List<ImTalkVO> imTalkVOList = imTalks.stream().map(imTalk -> {
|
||||
return new ImTalkVO(imTalk, authUser.getStoreId());
|
||||
}).collect(Collectors.toList());
|
||||
getUnread(imTalkVOList);
|
||||
return imTalkVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读消息数量
|
||||
* @param imTalkVOList
|
||||
*/
|
||||
private void getUnread(List<ImTalkVO> imTalkVOList){
|
||||
if(imTalkVOList.size() > 0){
|
||||
for (ImTalkVO imTalkVO : imTalkVOList) {
|
||||
long count = imMessageService.count(new LambdaQueryWrapper<ImMessage>().eq(ImMessage::getFromUser, imTalkVO.getUserId()).eq(ImMessage::getIsRead, false));
|
||||
imTalkVO.setUnread(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ public class FootPrint extends BaseEntity {
|
||||
@ApiModelProperty(value = "会员ID")
|
||||
private String memberId;
|
||||
|
||||
@ApiModelProperty(value = "店铺Id")
|
||||
private String storeId;
|
||||
|
||||
@ApiModelProperty(value = "商品ID")
|
||||
private String goodsId;
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
package cn.lili.modules.member.entity.dto;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author chc
|
||||
* @since 2022/6/2114:46
|
||||
*/
|
||||
@Data
|
||||
@ApiModel
|
||||
public class FootPrintQueryParams extends PageVO {
|
||||
|
||||
@ApiModelProperty("用户Id")
|
||||
private String memberId;
|
||||
|
||||
@ApiModelProperty("店铺Id")
|
||||
private String storeId;
|
||||
|
||||
public <T> QueryWrapper<T> queryWrapper() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
if (CharSequenceUtil.isNotEmpty(memberId)) {
|
||||
queryWrapper.eq("member_id", memberId);
|
||||
}
|
||||
if (CharSequenceUtil.isNotEmpty(storeId)) {
|
||||
queryWrapper.eq("store_id", storeId);
|
||||
}
|
||||
queryWrapper.eq("delete_flag",false);
|
||||
queryWrapper.orderByDesc("update_time");
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package cn.lili.modules.member.service;
|
||||
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.member.entity.dos.FootPrint;
|
||||
import cn.lili.modules.member.entity.dto.FootPrintQueryParams;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@ -42,10 +43,10 @@ public interface FootprintService extends IService<FootPrint> {
|
||||
/**
|
||||
* 获取会员浏览历史分页
|
||||
*
|
||||
* @param pageVO 分页
|
||||
* @param params 分页
|
||||
* @return 会员浏览历史列表
|
||||
*/
|
||||
IPage<EsGoodsIndex> footPrintPage(PageVO pageVO);
|
||||
IPage<EsGoodsIndex> footPrintPage(FootPrintQueryParams params);
|
||||
|
||||
/**
|
||||
* 获取当前会员的浏览记录数量
|
||||
@ -53,4 +54,5 @@ public interface FootprintService extends IService<FootPrint> {
|
||||
* @return 当前会员的浏览记录数量
|
||||
*/
|
||||
long getFootprintNum();
|
||||
|
||||
}
|
@ -252,7 +252,6 @@ public interface MemberService extends IService<Member> {
|
||||
void logout(UserEnums userEnums);
|
||||
|
||||
/**
|
||||
* <<<<<<< HEAD
|
||||
* 修改会员是否拥有店铺
|
||||
*
|
||||
* @param haveStore 是否拥有店铺
|
||||
|
@ -3,6 +3,7 @@ package cn.lili.modules.member.serviceimpl;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.member.entity.dos.FootPrint;
|
||||
import cn.lili.modules.member.entity.dto.FootPrintQueryParams;
|
||||
import cn.lili.modules.member.mapper.FootprintMapper;
|
||||
import cn.lili.modules.member.service.FootprintService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
@ -74,15 +75,8 @@ public class FootprintServiceImpl extends ServiceImpl<FootprintMapper, FootPrint
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<EsGoodsIndex> footPrintPage(PageVO pageVO) {
|
||||
|
||||
LambdaQueryWrapper<FootPrint> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||
lambdaQueryWrapper.eq(FootPrint::getMemberId, UserContext.getCurrentUser().getId());
|
||||
lambdaQueryWrapper.eq(FootPrint::getDeleteFlag, false);
|
||||
lambdaQueryWrapper.orderByDesc(FootPrint::getCreateTime);
|
||||
IPage<FootPrint> footPrintPages = this.page(PageUtil.initPage(pageVO), lambdaQueryWrapper);
|
||||
|
||||
|
||||
public IPage<EsGoodsIndex> footPrintPage(FootPrintQueryParams params) {
|
||||
IPage<FootPrint> footPrintPages = this.page(PageUtil.initPage(params), params.queryWrapper());
|
||||
//定义结果
|
||||
IPage<EsGoodsIndex> esGoodsIndexIPage = new Page<>();
|
||||
|
||||
@ -90,7 +84,7 @@ public class FootprintServiceImpl extends ServiceImpl<FootprintMapper, FootPrint
|
||||
return esGoodsIndexIPage;
|
||||
} else {
|
||||
List<EsGoodsIndex> list = esGoodsSearchService.getEsGoodsBySkuIds(
|
||||
footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()), pageVO);
|
||||
footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()), params);
|
||||
|
||||
esGoodsIndexIPage.setPages(footPrintPages.getPages());
|
||||
esGoodsIndexIPage.setRecords(list);
|
||||
|
@ -94,7 +94,14 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
List<String> categories = skus.stream().map(GoodsSku::getCategoryPath).collect(Collectors.toList());
|
||||
List<String> skuIds = skus.stream().map(GoodsSku::getId).collect(Collectors.toList());
|
||||
List<String> categoriesPath = new ArrayList<>();
|
||||
categories.forEach(i -> categoriesPath.addAll(Arrays.asList(i.split(","))));
|
||||
for (String category : categories) {
|
||||
if(CharSequenceUtil.isNotEmpty(category) && CharSequenceUtil.isNotBlank(category)){
|
||||
categoriesPath.addAll(Arrays.asList(category.split(",")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// categories.forEach(i -> categoriesPath.addAll(Arrays.asList(i.split(","))));
|
||||
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
queryWrapper.and(i -> i.or(j -> j.in(SKU_ID_COLUMN, skuIds))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lili.modules.store.service;
|
||||
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import cn.lili.modules.member.entity.dto.CollectionDTO;
|
||||
import cn.lili.modules.store.entity.dos.Store;
|
||||
import cn.lili.modules.store.entity.dto.*;
|
||||
@ -9,6 +10,8 @@ import cn.lili.modules.store.entity.vos.StoreVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺业务层
|
||||
*
|
||||
@ -117,5 +120,15 @@ public interface StoreService extends IService<Store> {
|
||||
*/
|
||||
void updateStoreCollectionNum(CollectionDTO collectionDTO);
|
||||
|
||||
/**
|
||||
* 重新生成所有店铺
|
||||
*/
|
||||
void storeToClerk();
|
||||
|
||||
/**
|
||||
* 店铺获取该会员的访问记录
|
||||
* @param memberId 会员Id
|
||||
* @return
|
||||
*/
|
||||
List<GoodsSku> getToMemberHistory(String memberId);
|
||||
}
|
@ -11,12 +11,16 @@ import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.utils.BeanUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
import cn.lili.modules.member.entity.dos.Clerk;
|
||||
import cn.lili.modules.member.entity.dos.FootPrint;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
import cn.lili.modules.member.entity.dto.ClerkAddDTO;
|
||||
import cn.lili.modules.member.entity.dto.CollectionDTO;
|
||||
import cn.lili.modules.member.service.ClerkService;
|
||||
import cn.lili.modules.member.service.FootprintService;
|
||||
import cn.lili.modules.member.service.MemberService;
|
||||
import cn.lili.modules.store.entity.dos.Store;
|
||||
import cn.lili.modules.store.entity.dos.StoreDetail;
|
||||
@ -70,6 +74,9 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
||||
*/
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
/**
|
||||
* 店铺详情
|
||||
*/
|
||||
@ -82,6 +89,9 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
@Autowired
|
||||
private FootprintService footprintService;
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@ -343,6 +353,18 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
||||
clerkService.saveBatch(clerkList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GoodsSku> getToMemberHistory(String memberId) {
|
||||
AuthUser currentUser = UserContext.getCurrentUser();
|
||||
List<String> skuIdList = new ArrayList<>();
|
||||
for (FootPrint footPrint : footprintService.list(new LambdaUpdateWrapper<FootPrint>().eq(FootPrint::getStoreId, currentUser.getStoreId()).eq(FootPrint::getMemberId, memberId))) {
|
||||
if(footPrint.getSkuId() != null){
|
||||
skuIdList.add(footPrint.getSkuId());
|
||||
}
|
||||
}
|
||||
return goodsSkuService.getGoodsSkuByIdFromCache(skuIdList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录操作的店铺
|
||||
*
|
||||
|
@ -0,0 +1,92 @@
|
||||
package cn.lili.controller.goods;
|
||||
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.enums.ResultUtil;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsVO;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsRelatedInfo;
|
||||
import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO;
|
||||
import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import cn.lili.modules.search.service.HotWordsService;
|
||||
import cn.lili.modules.statistics.aop.PageViewPoint;
|
||||
import cn.lili.modules.statistics.aop.enums.PageViewEnum;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 买家端,商品接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2020/11/16 10:06 下午
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "买家端,商品接口")
|
||||
@RestController
|
||||
@RequestMapping("/im/goods/goods")
|
||||
public class GoodsImController {
|
||||
|
||||
/**
|
||||
* 商品
|
||||
*/
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
/**
|
||||
* 商品SKU
|
||||
*/
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
/**
|
||||
* ES商品搜索
|
||||
*/
|
||||
@Autowired
|
||||
private EsGoodsSearchService goodsSearchService;
|
||||
|
||||
@Autowired
|
||||
private HotWordsService hotWordsService;
|
||||
|
||||
@ApiOperation(value = "通过id获取商品信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path"),
|
||||
@ApiImplicitParam(name = "skuId", value = "skuId", required = true, paramType = "path")
|
||||
})
|
||||
@GetMapping(value = "/sku/{goodsId}/{skuId}")
|
||||
@PageViewPoint(type = PageViewEnum.SKU, id = "#id")
|
||||
public ResultMessage<Map<String, Object>> getSku(@NotNull(message = "商品ID不能为空") @PathVariable("goodsId") String goodsId,
|
||||
@NotNull(message = "SKU ID不能为空") @PathVariable("skuId") String skuId) {
|
||||
try {
|
||||
// 读取选中的列表
|
||||
Map<String, Object> map = goodsSkuService.getGoodsSkuDetail(goodsId, skuId);
|
||||
return ResultUtil.data(map);
|
||||
} catch (ServiceException se) {
|
||||
log.info(se.getMsg(), se);
|
||||
throw se;
|
||||
} catch (Exception e) {
|
||||
log.error(ResultCode.GOODS_ERROR.message(), e);
|
||||
return ResultUtil.error(ResultCode.GOODS_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -33,7 +33,7 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "管理员")
|
||||
@RequestMapping("/manager/im/passport/user")
|
||||
@RequestMapping("/im/manager/im/passport/user")
|
||||
@Validated
|
||||
public class ImManagerController {
|
||||
@Autowired
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "Im消息接口")
|
||||
@RequestMapping("/lili/imMessage")
|
||||
@RequestMapping("/im/message")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class ImMessageController {
|
||||
@ -31,7 +31,6 @@ public class ImMessageController {
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation(value = "查看Im消息详情")
|
||||
public ResultMessage<ImMessage> get(@PathVariable String id) {
|
||||
|
||||
ImMessage imMessage = imMessageService.getById(id);
|
||||
return new ResultUtil<ImMessage>().setData(imMessage);
|
||||
}
|
||||
@ -39,14 +38,13 @@ public class ImMessageController {
|
||||
@GetMapping
|
||||
@ApiOperation(value = "分页获取Im消息")
|
||||
public ResultMessage<List<ImMessage>> historyMessage(MessageQueryParams messageQueryParams) {
|
||||
List<ImMessage> data = imMessageService.list(messageQueryParams.initQueryWrapper());
|
||||
List<ImMessage> data = imMessageService.getList(messageQueryParams);
|
||||
return new ResultUtil<List<ImMessage>>().setData(data);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation(value = "新增Im消息")
|
||||
public ResultMessage<ImMessage> save(ImMessage imMessage) {
|
||||
|
||||
if (imMessageService.save(imMessage)) {
|
||||
return new ResultUtil<ImMessage>().setData(imMessage);
|
||||
}
|
||||
@ -65,18 +63,27 @@ public class ImMessageController {
|
||||
@DeleteMapping(value = "/{ids}")
|
||||
@ApiOperation(value = "删除Im消息")
|
||||
public ResultMessage<Object> delAllByIds(@PathVariable List ids) {
|
||||
|
||||
imMessageService.removeByIds(ids);
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/newMessage")
|
||||
@ApiOperation(value = "删除Im消息")
|
||||
@ApiOperation(value = "查看是否有新消息")
|
||||
public ResultMessage<Boolean> hasNewMessage(String accessToken) {
|
||||
|
||||
return ResultUtil.data(imMessageService.hasNewMessage(accessToken));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/unredMessage")
|
||||
@ApiOperation(value = "获取所有未读消息")
|
||||
public ResultMessage<Long> getUnreadMessageCount() {
|
||||
return ResultUtil.data(imMessageService.unreadMessageCount());
|
||||
}
|
||||
|
||||
@PutMapping(value = "/clean/unred")
|
||||
@ApiOperation(value = "清除所有未读消息")
|
||||
public ResultMessage<Object> cleanUnreadMessage() {
|
||||
imMessageService.cleanUnreadMessage();
|
||||
return ResultUtil.success();
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,10 @@ import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.im.entity.dos.ImTalk;
|
||||
import cn.lili.modules.im.entity.vo.ImTalkVO;
|
||||
import cn.lili.modules.im.service.ImTalkService;
|
||||
import cn.lili.modules.store.service.StoreService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -25,13 +27,16 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "聊天接口")
|
||||
@RequestMapping("/lili/imTalk")
|
||||
@RequestMapping("/im/talk")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class ImTalkController {
|
||||
|
||||
private final ImTalkService imTalkService;
|
||||
|
||||
@Autowired
|
||||
private StoreService storeService;
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation(value = "查看聊天详情")
|
||||
public ResultMessage<ImTalk> get(@PathVariable String id) {
|
||||
@ -47,6 +52,13 @@ public class ImTalkController {
|
||||
return ResultUtil.data(imTalkService.getTalkByUser(authUser.getId(), uid));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/by/user/{userId}")
|
||||
@ApiOperation(value = "查看与某人聊天详情")
|
||||
public ResultMessage<ImTalkVO> getByUser(@PathVariable String userId) {
|
||||
AuthUser authUser = UserContext.getCurrentUser();
|
||||
return ResultUtil.data(new ImTalkVO(imTalkService.getTalkByUser(authUser.getId(), userId), authUser.getId()));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/top")
|
||||
@ApiOperation(value = "查看与某人聊天详情")
|
||||
public ResultMessage top(String id, Boolean top) {
|
||||
@ -56,32 +68,15 @@ public class ImTalkController {
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation(value = "分页获取聊天")
|
||||
public ResultMessage<List<ImTalkVO>> getByPage() {
|
||||
AuthUser authUser = UserContext.getCurrentUser();
|
||||
LambdaQueryWrapper<ImTalk> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ImTalk::getUserId1, authUser.getId()).or().eq(ImTalk::getUserId2, authUser.getId());
|
||||
List<ImTalk> imTalks = imTalkService.list(queryWrapper);
|
||||
|
||||
List<ImTalkVO> results = imTalks.stream().map(imTalk -> {
|
||||
return new ImTalkVO(imTalk, authUser.getId());
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return ResultUtil.data(results);
|
||||
@ApiImplicitParam(name = "userName", value = "用户名称", paramType = "query", dataType = "String")
|
||||
public ResultMessage<List<ImTalkVO>> getUserTalkList(String userName) {
|
||||
return ResultUtil.data(imTalkService.getUserTalkList(userName));
|
||||
}
|
||||
|
||||
@GetMapping("/store/list")
|
||||
@ApiOperation(value = "分页获取商家聊天")
|
||||
public ResultMessage<List<ImTalkVO>> getStoreTalkList() {
|
||||
AuthUser authUser = UserContext.getCurrentUser();
|
||||
LambdaQueryWrapper<ImTalk> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ImTalk::getUserId1, authUser.getStoreId()).or().eq(ImTalk::getUserId2, authUser.getStoreId());
|
||||
List<ImTalk> imTalks = imTalkService.list(queryWrapper);
|
||||
|
||||
List<ImTalkVO> results = imTalks.stream().map(imTalk -> {
|
||||
return new ImTalkVO(imTalk, authUser.getStoreId());
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return ResultUtil.data(results);
|
||||
return ResultUtil.data(imTalkService.getStoreTalkList());
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/{id}")
|
||||
|
@ -5,16 +5,23 @@ import cn.lili.common.enums.ResultUtil;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.member.entity.dos.FootPrint;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
import cn.lili.modules.member.entity.dto.FootPrintQueryParams;
|
||||
import cn.lili.modules.member.service.FootprintService;
|
||||
import cn.lili.modules.member.service.MemberService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.store.entity.dos.Store;
|
||||
import cn.lili.modules.store.service.StoreService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -24,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "Im消息接口")
|
||||
@RequestMapping("/lili/imUser")
|
||||
@RequestMapping("/im/user")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class ImUserController {
|
||||
@ -34,6 +41,9 @@ public class ImUserController {
|
||||
@Autowired
|
||||
private StoreService storeService;
|
||||
|
||||
@Autowired
|
||||
private FootprintService footprintService;
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "获取用户信息")
|
||||
public ResultMessage<Member> getImUser() {
|
||||
@ -42,10 +52,30 @@ public class ImUserController {
|
||||
}
|
||||
|
||||
@GetMapping("/store")
|
||||
@ApiOperation(value = "获取用户信息")
|
||||
@ApiOperation(value = "获取店铺信息")
|
||||
public ResultMessage<Store> getStoreUser() {
|
||||
AuthUser authUser = UserContext.getCurrentUser();
|
||||
return ResultUtil.data(storeService.getById(authUser.getStoreId()));
|
||||
}
|
||||
|
||||
@GetMapping("/{memberId}")
|
||||
@ApiImplicitParam(name = "memberId", value = "店铺Id", required = true, dataType = "String", paramType = "path")
|
||||
@ApiOperation(value = "获取用户信息")
|
||||
public ResultMessage<Member> getImUserDetail(@PathVariable String memberId) {
|
||||
return ResultUtil.data(memberService.getById(memberId));
|
||||
}
|
||||
|
||||
@GetMapping("/store/{storeId}")
|
||||
@ApiImplicitParam(name = "storeId", value = "店铺Id", required = true, dataType = "String", paramType = "path")
|
||||
@ApiOperation(value = "获取店铺信息")
|
||||
public ResultMessage<Store> getStoreUserDetail(@PathVariable String storeId) {
|
||||
return ResultUtil.data(storeService.getById(storeId));
|
||||
}
|
||||
|
||||
@GetMapping("/history")
|
||||
@ApiOperation(value = "获取会员的历史足迹")
|
||||
public ResultMessage<IPage<EsGoodsIndex>> getMemberHistory(FootPrintQueryParams params) {
|
||||
return ResultUtil.data(footprintService.footPrintPage(params));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import javax.validation.constraints.NotNull;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "管理端,自定义分词接口")
|
||||
@RequestMapping("/store/qa")
|
||||
@RequestMapping("/im/store/qa")
|
||||
public class QAStoreController {
|
||||
|
||||
@Autowired
|
||||
|
@ -7,16 +7,20 @@ import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.common.utils.SnowFlake;
|
||||
import cn.lili.modules.im.config.CustomSpringConfigurator;
|
||||
import cn.lili.modules.im.entity.dos.ImMessage;
|
||||
import cn.lili.modules.im.entity.dos.ImTalk;
|
||||
import cn.lili.modules.im.entity.enums.MessageResultType;
|
||||
import cn.lili.modules.im.entity.vo.MessageOperation;
|
||||
import cn.lili.modules.im.entity.vo.MessageVO;
|
||||
import cn.lili.modules.im.service.ImMessageService;
|
||||
import cn.lili.modules.im.service.ImTalkService;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
import cn.lili.modules.member.service.MemberService;
|
||||
import cn.lili.modules.store.entity.dos.Store;
|
||||
import cn.lili.modules.store.service.StoreService;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -50,6 +54,9 @@ public class WebSocketServer {
|
||||
@Autowired
|
||||
private StoreService storeService;
|
||||
|
||||
@Autowired
|
||||
private ImTalkService imTalkService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
@ -116,16 +123,12 @@ public class WebSocketServer {
|
||||
break;
|
||||
case MESSAGE:
|
||||
//保存消息
|
||||
ImMessage imMessage = new ImMessage();
|
||||
imMessage.setFromUser(messageOperation.getFrom());
|
||||
imMessage.setMessageType(messageOperation.getMessageType());
|
||||
imMessage.setIsRead(false);
|
||||
imMessage.setText(messageOperation.getContext());
|
||||
imMessage.setTalkId(messageOperation.getTalkId());
|
||||
imMessage.setCreateTime(new Date());
|
||||
imMessage.setToUser(messageOperation.getTo());
|
||||
imMessage.setId(SnowFlake.getIdStr());
|
||||
ImMessage imMessage = new ImMessage(messageOperation);
|
||||
imMessageService.save(imMessage);
|
||||
//修改最后消息信息
|
||||
imTalkService.update(new LambdaUpdateWrapper<ImTalk>().eq(ImTalk::getId,messageOperation.getTalkId()).set(ImTalk::getLastTalkMessage,messageOperation.getContext())
|
||||
.set(ImTalk::getLastTalkTime,imMessage.getCreateTime())
|
||||
.set(ImTalk::getLastMessageType,imMessage.getMessageType()));
|
||||
//发送消息
|
||||
sendMessage(messageOperation.getTo(), new MessageVO(MessageResultType.MESSAGE, imMessage));
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user