Skip to content

Commit

Permalink
IM消息功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Sectet1ove committed Dec 27, 2022
1 parent 54e04be commit 73aa36f
Show file tree
Hide file tree
Showing 29 changed files with 542 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -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.*;

Expand All @@ -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删除")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface StoreSettingChangeEvent {
*
* @param store 店铺信息
*/
void StoreSettingChange(Store store);
void storeSettingChange(Store store);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void memberInfoChange(Member member) {
}

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onMessage(MessageExt 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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public Map<String, Object> getGoodsSkuDetail(String goodsId, String skuId) {

//记录用户足迹
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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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
*/
@Data
@TableName("li_im_message")
@ApiModel(value = "Im消息")
@NoArgsConstructor
@AllArgsConstructor
public class ImMessage extends BaseEntity {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -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());
}

}
69 changes: 37 additions & 32 deletions framework/src/main/java/cn/lili/modules/im/entity/dos/ImTalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
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;
Expand All @@ -18,64 +20,65 @@
@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,
Expand All @@ -87,6 +90,8 @@ public ImTalk(String userId1, String userId2,
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -15,7 +16,7 @@
* 2022-01-20 17:16
*/
@Data
public class MessageQueryParams {
public class MessageQueryParams extends PageVO {
/**
* 聊天窗口
*/
Expand All @@ -42,8 +43,8 @@ public LambdaQueryWrapper<ImMessage> initQueryWrapper() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public enum MessageTypeEnum {
MESSAGE,
PICTURE,
VOICE,
GOODS,
VIDEO
}
42 changes: 23 additions & 19 deletions framework/src/main/java/cn/lili/modules/im/entity/vo/ImTalkVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

}
Expand All @@ -64,15 +65,18 @@ public ImTalkVO(ImTalk imTalk, String currentUser) {
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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
Loading

0 comments on commit 73aa36f

Please sign in to comment.