diff --git a/commom/pom.xml b/commom/pom.xml
index c269593..bec5ea0 100644
--- a/commom/pom.xml
+++ b/commom/pom.xml
@@ -58,5 +58,10 @@
velocity
${velocity.version}
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-joda
+ 2.9.10
+
\ No newline at end of file
diff --git a/commom/src/main/java/com/bx/common/model/im/GroupMessageInfo.java b/commom/src/main/java/com/bx/common/model/im/GroupMessageInfo.java
index caaab76..67f08a7 100644
--- a/commom/src/main/java/com/bx/common/model/im/GroupMessageInfo.java
+++ b/commom/src/main/java/com/bx/common/model/im/GroupMessageInfo.java
@@ -1,5 +1,7 @@
package com.bx.common.model.im;
+import com.bx.common.serializer.DateToLongSerializer;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import java.util.Date;
@@ -20,5 +22,6 @@ public class GroupMessageInfo {
private Integer type;
+ @JsonSerialize(using = DateToLongSerializer.class)
private Date sendTime;
}
diff --git a/commom/src/main/java/com/bx/common/model/im/PrivateMessageInfo.java b/commom/src/main/java/com/bx/common/model/im/PrivateMessageInfo.java
index fbc4b49..1a20b3f 100644
--- a/commom/src/main/java/com/bx/common/model/im/PrivateMessageInfo.java
+++ b/commom/src/main/java/com/bx/common/model/im/PrivateMessageInfo.java
@@ -1,5 +1,7 @@
package com.bx.common.model.im;
+import com.bx.common.serializer.DateToLongSerializer;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import java.util.Date;
@@ -17,5 +19,6 @@ public class PrivateMessageInfo {
private Integer type;
+ @JsonSerialize(using = DateToLongSerializer.class)
private Date sendTime;
}
diff --git a/commom/src/main/java/com/bx/common/serializer/DateToLongSerializer.java b/commom/src/main/java/com/bx/common/serializer/DateToLongSerializer.java
new file mode 100644
index 0000000..ad97b82
--- /dev/null
+++ b/commom/src/main/java/com/bx/common/serializer/DateToLongSerializer.java
@@ -0,0 +1,28 @@
+package com.bx.common.serializer;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.core.type.WritableTypeId;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
+
+import java.io.IOException;
+import java.util.Date;
+
+public class DateToLongSerializer extends JsonSerializer {
+
+ @Override
+ public void serialize(Date date, JsonGenerator jsonGenerator,
+ SerializerProvider serializerProvider) throws IOException {
+ jsonGenerator.writeNumber(date.getTime());
+ }
+
+ @Override
+ public void serializeWithType(Date value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
+ WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen,
+ typeSer.typeId(value, JsonToken.VALUE_STRING));
+ serialize(value, gen, serializers);
+ typeSer.writeTypeSuffix(gen, typeIdDef);
+ }
+}
diff --git a/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java b/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java
index 99bac42..68b882b 100644
--- a/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java
+++ b/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java
@@ -1,6 +1,7 @@
package com.bx.implatform.controller;
+import com.bx.common.model.im.GroupMessageInfo;
import com.bx.common.result.Result;
import com.bx.common.result.ResultUtils;
import com.bx.implatform.service.IGroupMessageService;
@@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
+import java.util.List;
@Api(tags = "群聊消息")
@@ -43,5 +45,12 @@ public class GroupMessageController {
return ResultUtils.success();
}
+ @GetMapping("/history")
+ @ApiOperation(value = "查询聊天记录",notes="查询聊天记录")
+ public Result> recallMessage(@NotNull(message = "群聊id不能为空") @RequestParam Long groupId,
+ @NotNull(message = "页码不能为空") @RequestParam Long page,
+ @NotNull(message = "size不能为空") @RequestParam Long size){
+ return ResultUtils.success( groupMessageService.findHistoryMessage(groupId,page,size));
+ }
}
diff --git a/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java b/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java
index 5fd0286..662c2d8 100644
--- a/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java
+++ b/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java
@@ -1,6 +1,7 @@
package com.bx.implatform.controller;
+import com.bx.common.model.im.PrivateMessageInfo;
import com.bx.common.result.Result;
import com.bx.common.result.ResultUtils;
import com.bx.implatform.service.IPrivateMessageService;
@@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
+import java.util.List;
@Api(tags = "私聊消息")
@RestController
@@ -42,5 +44,15 @@ public class PrivateMessageController {
privateMessageService.pullUnreadMessage();
return ResultUtils.success();
}
+
+
+ @GetMapping("/history")
+ @ApiOperation(value = "查询聊天记录",notes="查询聊天记录")
+ public Result> recallMessage(@NotNull(message = "好友id不能为空") @RequestParam Long friendId,
+ @NotNull(message = "页码不能为空") @RequestParam Long page,
+ @NotNull(message = "size不能为空") @RequestParam Long size){
+ return ResultUtils.success( privateMessageService.findHistoryMessage(friendId,page,size));
+ }
+
}
diff --git a/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java b/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java
index 0bd85fb..7bb582e 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java
@@ -1,9 +1,12 @@
package com.bx.implatform.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.bx.common.model.im.GroupMessageInfo;
import com.bx.implatform.entity.GroupMessage;
import com.bx.implatform.vo.GroupMessageVO;
+import java.util.List;
+
public interface IGroupMessageService extends IService {
@@ -13,4 +16,6 @@ public interface IGroupMessageService extends IService {
void recallMessage(Long id);
void pullUnreadMessage();
+
+ List findHistoryMessage(Long groupId, Long page, Long size);
}
diff --git a/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java b/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java
index e6c8069..0b1cc37 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java
@@ -1,9 +1,12 @@
package com.bx.implatform.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.bx.common.model.im.PrivateMessageInfo;
import com.bx.implatform.entity.PrivateMessage;
import com.bx.implatform.vo.PrivateMessageVO;
+import java.util.List;
+
public interface IPrivateMessageService extends IService {
@@ -11,6 +14,8 @@ public interface IPrivateMessageService extends IService {
void recallMessage(Long id);
+ List findHistoryMessage(Long friendId, Long page,Long size);
+
void pullUnreadMessage();
}
diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
index 89faeca..f5df55a 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
@@ -13,6 +13,7 @@ import com.bx.implatform.service.IUserService;
import com.bx.implatform.session.SessionContext;
import com.bx.implatform.session.UserSession;
import com.bx.implatform.vo.FriendVO;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+@Slf4j
@CacheConfig(cacheNames= RedisKey.IM_CACHE_FRIEND)
@Service
public class FriendServiceImpl extends ServiceImpl implements IFriendService {
@@ -63,6 +65,7 @@ public class FriendServiceImpl extends ServiceImpl impleme
FriendServiceImpl proxy = (FriendServiceImpl)AopContext.currentProxy();
proxy.bindFriend(userId,friendId);
proxy.bindFriend(friendId,userId);
+ log.info("添加好友,用户id:{},好友id:{}",userId,friendId);
}
@@ -80,6 +83,7 @@ public class FriendServiceImpl extends ServiceImpl impleme
FriendServiceImpl proxy = (FriendServiceImpl)AopContext.currentProxy();
proxy.unbindFriend(userId,friendId);
proxy.unbindFriend(friendId,userId);
+ log.info("删除好友,用户id:{},好友id:{}",userId,friendId);
}
diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java
index 3036dab..f2f40c6 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java
@@ -46,7 +46,7 @@ public class GroupMessageServiceImpl extends ServiceImpl findHistoryMessage(Long groupId, Long page, Long size) {
+ page = page > 0 ? page:1;
+ size = size > 0 ? size:10;
+ Long userId = SessionContext.getSession().getId();
+ Long stIdx = (page-1)* size;
+ // 群聊成员信息
+ GroupMember member = groupMemberService.findByGroupAndUserId(groupId,userId);
+ if(member == null || member.getQuit()){
+ throw new GlobalException(ResultCode.PROGRAM_ERROR,"您已不在群聊中");
+ }
+ // 查询聊天记录,只查询加入群聊时间之后的消息
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.lambda().eq(GroupMessage::getGroupId,groupId)
+ .gt(GroupMessage::getSendTime,member.getCreatedTime())
+ .ne(GroupMessage::getStatus,MessageStatusEnum.RECALL.getCode())
+ .orderByDesc(GroupMessage::getId)
+ .last("limit "+stIdx + ","+size);
+
+ List messages = this.list(wrapper);
+ List messageInfos = messages.stream().map(m->{
+ GroupMessageInfo info = BeanUtils.copyProperties(m, GroupMessageInfo.class);
+ return info;
+ }).collect(Collectors.toList());
+ log.info("拉取群聊记录,用户id:{},群聊id:{},数量:{}",userId,groupId,messageInfos.size());
+ return messageInfos;
+ }
+
private void sendMessage(List userIds, GroupMessageInfo msgInfo){
// 根据群聊每个成员所连的IM-server,进行分组
Map> serverMap = new ConcurrentHashMap<>();
diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java
index 65da723..d286a43 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java
@@ -21,6 +21,7 @@ import com.bx.implatform.session.UserSession;
import com.bx.implatform.vo.GroupInviteVO;
import com.bx.implatform.vo.GroupMemberVO;
import com.bx.implatform.vo.GroupVO;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -36,6 +37,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
+@Slf4j
@CacheConfig(cacheNames = RedisKey.IM_CACHE_GROUP)
@Service
public class GroupServiceImpl extends ServiceImpl implements IGroupService {
@@ -79,6 +81,7 @@ public class GroupServiceImpl extends ServiceImpl implements
GroupVO vo = BeanUtils.copyProperties(group, GroupVO.class);
vo.setAliasName(user.getNickName());
vo.setRemark(groupName);
+ log.info("创建群聊,群聊id:{},群聊名称:{}",group.getId(),group.getName());
return vo;
}
@@ -109,6 +112,7 @@ public class GroupServiceImpl extends ServiceImpl implements
member.setAliasName(StringUtils.isEmpty(vo.getAliasName())?session.getNickName():vo.getAliasName());
member.setRemark(StringUtils.isEmpty(vo.getRemark())?group.getName():vo.getRemark());
groupMemberService.updateById(member);
+ log.info("修改群聊,群聊id:{},群聊名称:{}",group.getId(),group.getName());
return vo;
}
@@ -131,6 +135,7 @@ public class GroupServiceImpl extends ServiceImpl implements
// 逻辑删除群数据
group.setDeleted(true);
this.updateById(group);
+ log.info("删除群聊,群聊id:{},群聊名称:{}",group.getId(),group.getName());
}
@@ -142,13 +147,14 @@ public class GroupServiceImpl extends ServiceImpl implements
*/
@Override
public void quitGroup(Long groupId) {
- UserSession session = SessionContext.getSession();
+ Long userId = SessionContext.getSession().getId();
Group group = this.getById(groupId);
- if(group.getOwnerId() == session.getId()){
+ if(group.getOwnerId() == userId){
throw new GlobalException(ResultCode.PROGRAM_ERROR,"您是群主,不可退出群聊");
}
// 删除群聊成员
- groupMemberService.removeByGroupAndUserId(groupId,session.getId());
+ groupMemberService.removeByGroupAndUserId(groupId,userId);
+ log.info("退出群聊,群聊id:{},群聊名称:{},用户id:{}",group.getId(),group.getName(),userId);
}
@@ -171,6 +177,7 @@ public class GroupServiceImpl extends ServiceImpl implements
}
// 删除群聊成员
groupMemberService.removeByGroupAndUserId(groupId,userId);
+ log.info("踢出群聊,群聊id:{},群聊名称:{},用户id:{}",group.getId(),group.getName(),userId);
}
@Override
@@ -281,6 +288,7 @@ public class GroupServiceImpl extends ServiceImpl implements
if(!groupMembers.isEmpty()) {
groupMemberService.saveOrUpdateBatch(group.getId(),groupMembers);
}
+ log.info("邀请进入群聊,群聊id:{},群聊名称:{},被邀请用户id:{}",group.getId(),group.getName(),vo.getFriendIds());
}
/**
diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java
index 95265a3..5bfdcb1 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java
@@ -32,7 +32,7 @@ public class PrivateMessageServiceImpl extends ServiceImpl redisTemplate;
+ private RedisTemplate redisTemplate;
/**
* 发送私聊消息
@@ -43,9 +43,9 @@ public class PrivateMessageServiceImpl extends ServiceImpl Constant.ALLOW_RECALL_SECOND * 1000){
- throw new GlobalException(ResultCode.PROGRAM_ERROR,"消息已发送超过5分钟,无法撤回");
+ if (System.currentTimeMillis() - msg.getSendTime().getTime() > Constant.ALLOW_RECALL_SECOND * 1000) {
+ throw new GlobalException(ResultCode.PROGRAM_ERROR, "消息已发送超过5分钟,无法撤回");
}
// 修改消息状态
msg.setStatus(MessageStatusEnum.RECALL.getCode());
this.updateById(msg);
// 获取对方连接的channelId
- String key = RedisKey.IM_USER_SERVER_ID+msg.getRecvId();
- Integer serverId = (Integer)redisTemplate.opsForValue().get(key);
+ String key = RedisKey.IM_USER_SERVER_ID + msg.getRecvId();
+ Integer serverId = (Integer) redisTemplate.opsForValue().get(key);
// 如果对方在线,将数据存储至redis,等待拉取推送
- if(serverId != null){
- String sendKey = RedisKey.IM_UNREAD_PRIVATE_MESSAGE + serverId;
+ if (serverId != null) {
+ String sendKey = RedisKey.IM_UNREAD_PRIVATE_MESSAGE + serverId;
PrivateMessageInfo msgInfo = BeanUtils.copyProperties(msg, PrivateMessageInfo.class);
msgInfo.setType(MessageTypeEnum.TIP.getCode());
msgInfo.setSendTime(new Date());
msgInfo.setContent("对方撤回了一条消息");
- redisTemplate.opsForList().rightPush(sendKey,msgInfo);
+ redisTemplate.opsForList().rightPush(sendKey, msgInfo);
}
- log.info("撤回私聊消息,发送id:{},接收id:{},内容:{}",msg.getSendId(),msg.getRecvId(),msg.getContent());
+ log.info("撤回私聊消息,发送id:{},接收id:{},内容:{}", msg.getSendId(), msg.getRecvId(), msg.getContent());
+ }
+
+
+ /**
+ * 拉取历史聊天记录
+ *
+ * @param friendId 好友id
+ * @param page 页码
+ * @param size 页码大小
+ * @return 聊天记录列表
+ */
+ @Override
+ public List findHistoryMessage(Long friendId, Long page, Long size) {
+ page = page > 0 ? page : 1;
+ size = size > 0 ? size : 10;
+ Long userId = SessionContext.getSession().getId();
+ Long stIdx = (page - 1) * size;
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.lambda().and(wrap -> wrap.and(
+ wp -> wp.eq(PrivateMessage::getSendId, userId)
+ .eq(PrivateMessage::getRecvId, friendId))
+ .or(wp -> wp.eq(PrivateMessage::getRecvId, userId)
+ .eq(PrivateMessage::getSendId, friendId)))
+ .ne(PrivateMessage::getStatus, MessageStatusEnum.RECALL.getCode())
+ .orderByDesc(PrivateMessage::getId)
+ .last("limit " + stIdx + "," + size);
+
+ List messages = this.list(wrapper);
+ List messageInfos = messages.stream().map(m -> {
+ PrivateMessageInfo info = BeanUtils.copyProperties(m, PrivateMessageInfo.class);
+ return info;
+ }).collect(Collectors.toList());
+
+ log.info("拉取聊天记录,用户id:{},好友id:{},数量:{}", userId, friendId, messageInfos.size());
+ return messageInfos;
}
/**
@@ -111,25 +146,25 @@ public class PrivateMessageServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(PrivateMessage::getRecvId,userId)
- .eq(PrivateMessage::getStatus,MessageStatusEnum.UNREAD);
+ queryWrapper.lambda().eq(PrivateMessage::getRecvId, userId)
+ .eq(PrivateMessage::getStatus, MessageStatusEnum.UNREAD);
List messages = this.list(queryWrapper);
// 上传至redis,等待推送
- if(!messages.isEmpty()){
- List infos = messages.stream().map(m->{
+ if (!messages.isEmpty()) {
+ List infos = messages.stream().map(m -> {
PrivateMessageInfo msgInfo = BeanUtils.copyProperties(m, PrivateMessageInfo.class);
- return msgInfo;
+ return msgInfo;
}).collect(Collectors.toList());
- String sendKey = RedisKey.IM_UNREAD_PRIVATE_MESSAGE + serverId;
- redisTemplate.opsForList().rightPushAll(sendKey,infos.toArray());
- log.info("拉取未读私聊消息,用户id:{},数量:{}",userId,infos.size());
+ String sendKey = RedisKey.IM_UNREAD_PRIVATE_MESSAGE + serverId;
+ redisTemplate.opsForList().rightPushAll(sendKey, infos.toArray());
+ log.info("拉取未读私聊消息,用户id:{},数量:{}", userId, infos.size());
}
}
}
diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
index 8f1945e..70e7ce0 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
@@ -17,6 +17,7 @@ import com.bx.implatform.session.SessionContext;
import com.bx.implatform.session.UserSession;
import com.bx.implatform.vo.RegisterVO;
import com.bx.implatform.vo.UserVO;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -28,6 +29,7 @@ import java.util.List;
import java.util.stream.Collectors;
+@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl implements IUserService {
@@ -58,6 +60,7 @@ public class UserServiceImpl extends ServiceImpl implements IU
user = BeanUtils.copyProperties(vo,User.class);
user.setPassword(passwordEncoder.encode(user.getPassword()));
this.save(user);
+ log.info("注册用户,用户id:{},用户名:{},昵称:{}",user.getId(),vo.getUserName(),vo.getNickName());
}
/**
@@ -116,6 +119,7 @@ public class UserServiceImpl extends ServiceImpl implements IU
user.setHeadImage(vo.getHeadImage());
user.setHeadImageThumb(vo.getHeadImageThumb());
this.updateById(user);
+ log.info("用户信息更新,用户:{}}",user.toString());
}
diff --git a/im-platform/src/main/java/com/bx/implatform/service/thirdparty/FileService.java b/im-platform/src/main/java/com/bx/implatform/service/thirdparty/FileService.java
index ee503ed..404f54a 100644
--- a/im-platform/src/main/java/com/bx/implatform/service/thirdparty/FileService.java
+++ b/im-platform/src/main/java/com/bx/implatform/service/thirdparty/FileService.java
@@ -4,6 +4,7 @@ import com.bx.common.contant.Constant;
import com.bx.common.enums.FileTypeEnum;
import com.bx.common.enums.ResultCode;
import com.bx.implatform.exception.GlobalException;
+import com.bx.implatform.session.SessionContext;
import com.bx.implatform.util.FileUtil;
import com.bx.implatform.util.ImageUtil;
import com.bx.implatform.util.MinioUtil;
@@ -50,6 +51,7 @@ public class FileService {
public String uploadFile(MultipartFile file){
+ Long userId = SessionContext.getSession().getId();
// 大小校验
if(file.getSize() > Constant.MAX_FILE_SIZE){
throw new GlobalException(ResultCode.PROGRAM_ERROR,"文件大小不能超过10M");
@@ -59,11 +61,14 @@ public class FileService {
if(StringUtils.isEmpty(fileName)){
throw new GlobalException(ResultCode.PROGRAM_ERROR,"文件上传失败");
}
- return generUrl(FileTypeEnum.FILE,fileName);
+ String url = generUrl(FileTypeEnum.FILE,fileName);
+ log.info("文件文件成功,用户id:{},url:{}",userId,url);
+ return url;
}
public UploadImageVO uploadImage(MultipartFile file){
try {
+ Long userId = SessionContext.getSession().getId();
// 大小校验
if(file.getSize() > Constant.MAX_IMAGE_SIZE){
throw new GlobalException(ResultCode.PROGRAM_ERROR,"图片大小不能超过5M");
@@ -86,6 +91,7 @@ public class FileService {
throw new GlobalException(ResultCode.PROGRAM_ERROR,"图片上传失败");
}
vo.setThumbUrl(generUrl(FileTypeEnum.IMAGE,fileName));
+ log.info("文件图片成功,用户id:{},url:{}",userId,vo.getOriginUrl());
return vo;
} catch (IOException e) {
log.error("上传图片失败,{}",e.getMessage(),e);
diff --git a/im-platform/src/main/java/com/bx/implatform/util/FileUtil.java b/im-platform/src/main/java/com/bx/implatform/util/FileUtil.java
index b83d45d..8e7347a 100644
--- a/im-platform/src/main/java/com/bx/implatform/util/FileUtil.java
+++ b/im-platform/src/main/java/com/bx/implatform/util/FileUtil.java
@@ -21,7 +21,7 @@ public class FileUtil {
*/
public static boolean isImage(String fileName) {
String extension = getFileExtension(fileName);
- String[] imageExtension = new String[]{"jpeg", "jpg", "bmp", "png","webp"};
+ String[] imageExtension = new String[]{"jpeg", "jpg", "bmp", "png","webp","gif"};
for (String e : imageExtension){
if (extension.toLowerCase().equals(e)) {
return true;
diff --git a/im-platform/src/main/resources/application.yml b/im-platform/src/main/resources/application.yml
index bb22378..71a18c9 100644
--- a/im-platform/src/main/resources/application.yml
+++ b/im-platform/src/main/resources/application.yml
@@ -23,7 +23,7 @@ mybatis-plus:
configuration:
# 是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN(下划线命名) 到经典 Java 属性名 aColumn(驼峰命名) 的类似映射
map-underscore-to-camel-case: false
- # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+ log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# mapper
mapper-locations:
# *.xml的具体路径
diff --git a/im-server/src/main/java/com/bx/imserver/websocket/endecode/MessageProtocolEncoder.java b/im-server/src/main/java/com/bx/imserver/websocket/endecode/MessageProtocolEncoder.java
index 328f02a..4ecf528 100644
--- a/im-server/src/main/java/com/bx/imserver/websocket/endecode/MessageProtocolEncoder.java
+++ b/im-server/src/main/java/com/bx/imserver/websocket/endecode/MessageProtocolEncoder.java
@@ -14,6 +14,7 @@ public class MessageProtocolEncoder extends MessageToMessageEncoder {
protected void encode(ChannelHandlerContext channelHandlerContext, SendInfo sendInfo, List