新增聊天模块
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.service.ChatConversationService;
|
||||
import com.gxwebsoft.common.system.vo.ChatConversationVO;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -20,7 +21,7 @@ import java.util.List;
|
||||
* 聊天消息表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-15 21:26:48
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Api(tags = "聊天消息表管理")
|
||||
@RestController
|
||||
@@ -29,74 +30,46 @@ public class ChatConversationController extends BaseController {
|
||||
@Resource
|
||||
private ChatConversationService chatConversationService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@ApiOperation("查询全部聊天消息表")
|
||||
@GetMapping("/app")
|
||||
public ApiResult<List<ChatConversationVO>> appList() {
|
||||
ChatConversationParam param = new ChatConversationParam();
|
||||
param.setUserId(getLoginUserId());
|
||||
return success(chatConversationService.getFriendList(param));
|
||||
}
|
||||
|
||||
@ApiOperation("标记已读")
|
||||
@PostMapping("/app/read")
|
||||
public ApiResult<Boolean> read(@RequestBody ChatConversationParam param) {
|
||||
return success(chatConversationService.update(
|
||||
new LambdaUpdateWrapper<ChatConversation>().eq(ChatConversation::getId, param.getId()).set(ChatConversation::getUnRead, 0)
|
||||
));
|
||||
// 使用关联查询
|
||||
//return success(chatConversationService.pageRel(param));
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询聊天消息表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<ChatConversationVO>> page(ChatConversationParam param) {
|
||||
PageParam<ChatConversation, ChatConversationParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// return success(chatConversationService.page(page, page.getWrapper()));
|
||||
public ApiResult<PageResult<ChatConversation>> page(ChatConversationParam param) {
|
||||
// 使用关联查询
|
||||
return success(chatConversationService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部聊天消息表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<ChatConversation>> list(ChatConversationParam param) {
|
||||
PageParam<ChatConversation, ChatConversationParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// return success(chatConversationService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
return success(chatConversationService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询聊天消息表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<ChatConversation> get(@PathVariable("id") Integer id) {
|
||||
return success(chatConversationService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(chatConversationService.getByIdRel(id));
|
||||
return success(chatConversationService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:save')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加聊天消息表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody ChatConversation chatConversation) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
chatConversation.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (chatConversationService.save(chatConversation)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:update')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改聊天消息表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody ChatConversation chatConversation) {
|
||||
@@ -106,6 +79,8 @@ public class ChatConversationController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除聊天消息表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
@@ -115,7 +90,8 @@ public class ChatConversationController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:save')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加聊天消息表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<ChatConversation> list) {
|
||||
@@ -125,7 +101,8 @@ public class ChatConversationController extends BaseController {
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:update')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改聊天消息表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<ChatConversation> batchParam) {
|
||||
@@ -135,7 +112,8 @@ public class ChatConversationController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:remove')")
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除聊天消息表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.enums.GreenWebType;
|
||||
import com.gxwebsoft.common.core.socketio.cache.ClientCache;
|
||||
import com.gxwebsoft.common.core.utils.GreenWebUtils;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.ChatMessageService;
|
||||
import com.gxwebsoft.common.system.entity.ChatMessage;
|
||||
import com.gxwebsoft.common.system.param.ChatMessageParam;
|
||||
import com.gxwebsoft.common.system.service.ChatConversationService;
|
||||
import com.gxwebsoft.common.system.service.ChatMessageService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -26,7 +22,7 @@ import java.util.List;
|
||||
* 聊天消息表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-10 18:27:25
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Api(tags = "聊天消息表管理")
|
||||
@RestController
|
||||
@@ -35,95 +31,46 @@ public class ChatMessageController extends BaseController {
|
||||
@Resource
|
||||
private ChatMessageService chatMessageService;
|
||||
|
||||
@Resource
|
||||
private ChatConversationService chatConversationService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
|
||||
@Resource
|
||||
private ClientCache clientCache;
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("发送消息:app端使用")
|
||||
@PostMapping("/app/send")
|
||||
public ApiResult<?> sendMessage(@RequestBody ChatMessage message) {
|
||||
|
||||
String type = message.getType();
|
||||
if ("text".equals(type) && !GreenWebUtils.testText(message.getContent(), GreenWebType.chat_detection)) {
|
||||
return fail("您的内容存在违规行为,请您重新编辑!");
|
||||
} else if ("image".equals(type) && !GreenWebUtils.testImage(message.getContent(), GreenWebType.baselineCheck)) {
|
||||
return fail("您的内容存在违规行为,请您重新编辑!");
|
||||
}
|
||||
|
||||
User loginUser = getLoginUser();
|
||||
message.setFormUserId(getLoginUserId());
|
||||
message.setFormUserInfo(loginUser);
|
||||
chatMessageService.sendMessage(message);
|
||||
return success(message.getId());
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("消息列表")
|
||||
@GetMapping("/app/list")
|
||||
public ApiResult<List<ChatMessage>> listApp(Integer friendId, Integer lastMessageId) {
|
||||
|
||||
return success(chatMessageService.getFriendMessage(getLoginUserId(), friendId, lastMessageId));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:list')")
|
||||
@ApiOperation("分页查询聊天消息表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<ChatMessage>> page(ChatMessageParam param) {
|
||||
PageParam<ChatMessage, ChatMessageParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// return success(chatMessageService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
return success(chatMessageService.pageRel(param));
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:list')")
|
||||
@ApiOperation("查询全部聊天消息表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<ChatMessage>> list(ChatMessageParam param) {
|
||||
PageParam<ChatMessage, ChatMessageParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(chatMessageService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(chatMessageService.listRel(param));
|
||||
return success(chatMessageService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:list')")
|
||||
@ApiOperation("根据id查询聊天消息表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<ChatMessage> get(@PathVariable("id") Integer id) {
|
||||
return success(chatMessageService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(chatMessageService.getByIdRel(id));
|
||||
return success(chatMessageService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加聊天消息表 管理员使用")
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:save')")
|
||||
@ApiOperation("添加聊天消息表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody ChatMessage message) {
|
||||
public ApiResult<?> save(@RequestBody ChatMessage chatMessage) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
User fromUser = userService.getById(message.getFormUserId());
|
||||
message.setFormUserInfo(fromUser);
|
||||
if (chatMessageService.sendMessage(message)) {
|
||||
return success("发送成功");
|
||||
if (loginUser != null) {
|
||||
chatMessage.setFormUserId(loginUser.getUserId());
|
||||
if (chatMessageService.save(chatMessage)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:update')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:update')")
|
||||
@ApiOperation("修改聊天消息表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody ChatMessage chatMessage) {
|
||||
@@ -133,7 +80,7 @@ public class ChatMessageController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:remove')")
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除聊天消息表")
|
||||
@DeleteMapping("/{id}")
|
||||
@@ -144,8 +91,7 @@ public class ChatMessageController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:save')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:save')")
|
||||
@ApiOperation("批量添加聊天消息表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<ChatMessage> list) {
|
||||
@@ -155,8 +101,7 @@ public class ChatMessageController extends BaseController {
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:update')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:update')")
|
||||
@ApiOperation("批量修改聊天消息表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<ChatMessage> batchParam) {
|
||||
@@ -166,8 +111,7 @@ public class ChatMessageController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:remove')")
|
||||
@OperationLog
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:remove')")
|
||||
@ApiOperation("批量删除聊天消息表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
@@ -177,73 +121,4 @@ public class ChatMessageController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("屏蔽消息")
|
||||
@PutMapping("/sideMessage")
|
||||
public ApiResult<?> sideMessage(@RequestBody ChatMessage chatMessage) {
|
||||
ChatMessage msg = chatMessageService.getById(chatMessage.getId());
|
||||
Integer loginUserId = getLoginUserId();
|
||||
Integer toUserId = chatMessage.getToUserId();
|
||||
|
||||
if (msg.getToUserId().equals(loginUserId)) {
|
||||
msg.setSideTo(true);
|
||||
} else if (msg.getFormUserId().equals(loginUserId)) {
|
||||
msg.setSideFrom(true);
|
||||
}
|
||||
chatMessageService.updateById(msg);
|
||||
|
||||
|
||||
ChatConversation conversation1 = chatConversationService.getByBothId(loginUserId, toUserId);
|
||||
List<ChatMessage> friendMessage = chatMessageService.getFriendMessage(loginUserId, toUserId, null);
|
||||
conversation1.setUpdateTime(DateUtil.date());
|
||||
if(CollectionUtils.isEmpty(friendMessage)){
|
||||
conversation1.setContent("");
|
||||
}else {
|
||||
String lastContent;
|
||||
ChatMessage lastMessage = friendMessage.get(0);
|
||||
if (GreenWebType.ChatMessageType.IMAGE.getName().equals(lastMessage.getType())) {
|
||||
lastContent = "[图片]";
|
||||
} else if (GreenWebType.ChatMessageType.VOICE.getName().equals(lastMessage.getType())) {
|
||||
lastContent = "[语音]";
|
||||
} else if (GreenWebType.ChatMessageType.CARD.getName().equals(lastMessage.getType())) {
|
||||
lastContent = "[卡片]";
|
||||
} else {
|
||||
lastContent = lastMessage.getContent();
|
||||
}
|
||||
conversation1.setContent(lastContent);
|
||||
}
|
||||
|
||||
return success("屏蔽成功");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation("撤回消息")
|
||||
@PutMapping("/withdraw")
|
||||
public ApiResult<?> withdraw(@RequestBody ChatMessage chatMessage) {
|
||||
|
||||
|
||||
Integer loginUserId = getLoginUserId();
|
||||
Integer toUserId = chatMessage.getToUserId();
|
||||
|
||||
chatMessage.setWithdraw(1);
|
||||
|
||||
if (chatMessageService.updateById(chatMessage)) {
|
||||
clientCache.sendUserEvent(toUserId + "", "withdrawMessage", chatMessage);
|
||||
|
||||
}
|
||||
|
||||
ChatConversation conversation1 = chatConversationService.getByBothId(loginUserId, toUserId);
|
||||
conversation1.setContent("您撤回了一条消息");
|
||||
conversation1.setUpdateTime(DateUtil.date());
|
||||
ChatConversation conversation2 = chatConversationService.getByBothId(toUserId, loginUserId);
|
||||
conversation2.setContent("对方撤回了一条消息");
|
||||
conversation2.setUpdateTime(DateUtil.date());
|
||||
|
||||
chatConversationService.updateById(conversation1);
|
||||
chatConversationService.updateById(conversation2);
|
||||
|
||||
|
||||
return success("您撤回了一条消息");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 聊天消息表
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-15 21:26:48
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -32,10 +36,6 @@ public class ChatConversation implements Serializable {
|
||||
@ApiModelProperty(value = "好友ID")
|
||||
private Integer friendId;
|
||||
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "好友信息")
|
||||
private User friendInfo;
|
||||
|
||||
@ApiModelProperty(value = "消息类型")
|
||||
private Integer type;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ChatConversation implements Serializable {
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "未读消息")
|
||||
private int unRead;
|
||||
private Integer unRead;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0未读, 1已读")
|
||||
private Integer status;
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 聊天消息表
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-10 18:27:25
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "ChatMessage对象", description = "聊天消息表")
|
||||
@TableName(value = "sys_chat_message",autoResultMap = true)
|
||||
@TableName("sys_chat_message")
|
||||
public class ChatMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -27,38 +28,36 @@ public class ChatMessage implements Serializable {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "发送用户ID")
|
||||
@ApiModelProperty(value = "发送人ID")
|
||||
private Integer formUserId;
|
||||
|
||||
@ApiModelProperty(value = "接收人ID")
|
||||
private Integer toUserId;
|
||||
|
||||
@ApiModelProperty(value = "发送人")
|
||||
@TableField(exist = false)
|
||||
private User formUserInfo;
|
||||
|
||||
@ApiModelProperty(value = "接收人")
|
||||
@TableField(exist = false)
|
||||
private User toUserInfo;
|
||||
|
||||
@ApiModelProperty(value = "消息类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "消息内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "文件信息")
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private FileInfo fileInfo;
|
||||
@ApiModelProperty(value = "屏蔽接收方")
|
||||
private Integer sideTo;
|
||||
|
||||
@ApiModelProperty(value = "屏蔽发送方")
|
||||
private Integer sideFrom;
|
||||
|
||||
@ApiModelProperty(value = "是否撤回")
|
||||
private Integer withdraw;
|
||||
|
||||
@ApiModelProperty(value = "文件信息")
|
||||
private String fileInfo;
|
||||
|
||||
@ApiModelProperty(value = "存在联系方式")
|
||||
private Integer hasContact;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0未读, 1已读")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "撤回")
|
||||
private Integer withdraw;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
@@ -72,19 +71,20 @@ public class ChatMessage implements Serializable {
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
private Boolean sideTo;
|
||||
private Boolean sideFrom;
|
||||
@ApiModelProperty(value = "发送人昵称")
|
||||
@TableField(exist = false)
|
||||
private String formUserName;
|
||||
|
||||
@ApiModelProperty(value = "发送人头像")
|
||||
@TableField(exist = false)
|
||||
private String formUserAvatar;
|
||||
|
||||
@Data
|
||||
public static class FileInfo {
|
||||
|
||||
private Integer width;
|
||||
private Integer height;
|
||||
private String type;
|
||||
|
||||
|
||||
}
|
||||
@ApiModelProperty(value = "接收人昵称")
|
||||
@TableField(exist = false)
|
||||
private String toUserName;
|
||||
|
||||
@ApiModelProperty(value = "接收人头像")
|
||||
@TableField(exist = false)
|
||||
private String toUserAvatar;
|
||||
|
||||
}
|
||||
|
||||
@@ -182,6 +182,9 @@ public class Company implements Serializable {
|
||||
@ApiModelProperty("是否推荐")
|
||||
private Boolean recommend;
|
||||
|
||||
@ApiModelProperty("商户ID")
|
||||
private Integer merchantId;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.gxwebsoft.common.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -13,9 +12,9 @@ import java.util.List;
|
||||
* 聊天消息表Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-18 18:42:17
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
public interface ChatConversationMapper extends MPJBaseMapper<ChatConversation> {
|
||||
public interface ChatConversationMapper extends BaseMapper<ChatConversation> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
* 聊天消息表Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-18 18:42:17
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
SELECT a.*,b.nickname as formUserName,b.avatar as formUserAvatar,c.nickname as toUserName,c.avatar as toUserAvatar
|
||||
FROM sys_chat_message a
|
||||
LEFT JOIN sys_user b ON a.form_user_id = b.user_id
|
||||
LEFT JOIN sys_user c ON a.to_user_id = c.user_id
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
@@ -34,6 +36,9 @@
|
||||
<if test="param.fileInfo != null">
|
||||
AND a.file_info LIKE CONCAT('%', #{param.fileInfo}, '%')
|
||||
</if>
|
||||
<if test="param.hasContact != null">
|
||||
AND a.has_contact = #{param.hasContact}
|
||||
</if>
|
||||
<if test="param.status != null">
|
||||
AND a.status = #{param.status}
|
||||
</if>
|
||||
|
||||
@@ -110,6 +110,9 @@
|
||||
<if test="param.email != null">
|
||||
AND a.email = #{param.email}
|
||||
</if>
|
||||
<if test="param.merchantId != null">
|
||||
AND a.merchant_id = #{param.merchantId}
|
||||
</if>
|
||||
<if test="param.keywords != null">
|
||||
AND (a.company_name LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR a.short_name LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
|
||||
@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
|
||||
* 聊天消息表查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-15 21:26:48
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -41,6 +41,10 @@ public class ChatConversationParam extends BaseParam {
|
||||
@ApiModelProperty(value = "消息内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "未读消息")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer unRead;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0未读, 1已读")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer status;
|
||||
@@ -49,8 +53,4 @@ public class ChatConversationParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "是否只要僵尸, 0否, 1是")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean onlyFake;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
|
||||
* 聊天消息表查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-10 18:27:25
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -26,25 +26,40 @@ public class ChatMessageParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "发送用户ID")
|
||||
@ApiModelProperty(value = "发送人ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer formUserId;
|
||||
|
||||
@ApiModelProperty(value = "接受用户ID")
|
||||
@ApiModelProperty(value = "接收人ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer toUserId;
|
||||
|
||||
@ApiModelProperty(value = "屏蔽消息的用户")
|
||||
private Integer sideUserId;
|
||||
|
||||
@ApiModelProperty(value = "消息类型")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "消息内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0在线, 1离线")
|
||||
@ApiModelProperty(value = "屏蔽接收方")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer sideTo;
|
||||
|
||||
@ApiModelProperty(value = "屏蔽发送方")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer sideFrom;
|
||||
|
||||
@ApiModelProperty(value = "是否撤回")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer withdraw;
|
||||
|
||||
@ApiModelProperty(value = "文件信息")
|
||||
private String fileInfo;
|
||||
|
||||
@ApiModelProperty(value = "存在联系方式")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer hasContact;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0未读, 1已读")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer status;
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ public class CompanyParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty("商户ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer merchantId;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer deleted;
|
||||
|
||||
@@ -77,4 +77,10 @@ public class NoticeParam extends BaseParam {
|
||||
@TableField(exist = false)
|
||||
private String nickname;
|
||||
|
||||
@ApiModelProperty(value = "是否已查阅")
|
||||
private Integer isRead;
|
||||
|
||||
@ApiModelProperty(value = "任务状态")
|
||||
private Integer progress;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import com.gxwebsoft.common.system.vo.ChatConversationVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,7 +11,7 @@ import java.util.List;
|
||||
* 聊天消息表Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-15 21:26:48
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
public interface ChatConversationService extends IService<ChatConversation> {
|
||||
|
||||
@@ -22,7 +21,7 @@ public interface ChatConversationService extends IService<ChatConversation> {
|
||||
* @param param 查询参数
|
||||
* @return PageResult<ChatConversation>
|
||||
*/
|
||||
PageResult<ChatConversationVO> pageRel(ChatConversationParam param);
|
||||
PageResult<ChatConversation> pageRel(ChatConversationParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
@@ -40,8 +39,4 @@ public interface ChatConversationService extends IService<ChatConversation> {
|
||||
*/
|
||||
ChatConversation getByIdRel(Integer id);
|
||||
|
||||
ChatConversation getByBothId(Integer formUserId, Integer toUserId);
|
||||
|
||||
List<ChatConversationVO> getFriendList(ChatConversationParam param);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
* 聊天消息表Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-10 18:27:25
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
public interface ChatMessageService extends IService<ChatMessage> {
|
||||
|
||||
@@ -39,10 +39,4 @@ public interface ChatMessageService extends IService<ChatMessage> {
|
||||
*/
|
||||
ChatMessage getByIdRel(Integer id);
|
||||
|
||||
List<ChatMessage> getUnreadMessage(Integer fromUserId, Integer toUserId);
|
||||
|
||||
boolean sendMessage(ChatMessage message);
|
||||
|
||||
List<ChatMessage> getFriendMessage(Integer userId, Integer friendId, Integer lastMessageId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,75 +1,31 @@
|
||||
package com.gxwebsoft.common.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.gxwebsoft.common.system.mapper.ChatConversationMapper;
|
||||
import com.gxwebsoft.common.system.service.ChatConversationService;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.entity.ChatMessage;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.mapper.ChatConversationMapper;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import com.gxwebsoft.common.system.service.ChatConversationService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.common.system.vo.ChatConversationVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 聊天消息表Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-15 21:26:48
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Service
|
||||
public class ChatConversationServiceImpl extends ServiceImpl<ChatConversationMapper, ChatConversation> implements ChatConversationService {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
|
||||
@Override
|
||||
public PageResult<ChatConversationVO> pageRel(ChatConversationParam param) {
|
||||
|
||||
MPJLambdaWrapper<ChatConversation> wrapper = JoinWrappers.lambda("t",ChatConversation.class)
|
||||
.selectAll(ChatConversation.class)
|
||||
// 查询用户
|
||||
// .eq(ObjectUtils.isNotEmpty(param.getUserId()), ChatConversation::getUserId, param.getUserId())
|
||||
.and(ObjectUtils.isNotEmpty(param.getUserId()), w2-> {
|
||||
w2.eq(ChatConversation::getUserId, param.getUserId()).or(w3->{
|
||||
w3.eq(ChatConversation::getFriendId, param.getUserId());
|
||||
});
|
||||
} )
|
||||
// 查询未读
|
||||
.gt(param.getStatus()!= null &¶m.getStatus() == 1, ChatConversation::getUnRead, 0)
|
||||
//
|
||||
.selectAssociation("t1",User.class, ChatConversationVO::getFriendInfo)
|
||||
.selectAssociation("t2",User.class, ChatConversationVO::getUserInfo)
|
||||
.innerJoin(User.class,"t1", User::getUserId, ChatConversation::getFriendId)
|
||||
.innerJoin(User.class, "t2", wrapper1 -> wrapper1.notLike(param.getOnlyFake(),User::getUsername, "wx_%").eq(User::getUserId, ChatConversation::getUserId))
|
||||
// 消息列表 影响分页 暂时无解User::getUserId, ChatConversation::getUserId,
|
||||
// .selectCollection(ChatMessage.class, ChatConversationVO::getMessages)
|
||||
// .leftJoin(ChatMessage.class, on ->
|
||||
// on.and(w -> {
|
||||
// w.eq(ChatMessage::getFormUserId, ChatConversation::getUserId).eq(ChatMessage::getToUserId, ChatConversation::getFriendId);
|
||||
// })
|
||||
// .or(w -> {
|
||||
// w.eq(ChatMessage::getFormUserId, ChatConversation::getFriendId).eq(ChatMessage::getToUserId, ChatConversation::getUserId);
|
||||
// })
|
||||
// .orderByDesc(ChatMessage::getCreateTime)
|
||||
// )
|
||||
|
||||
.orderByDesc(ChatConversation::getUpdateTime);
|
||||
|
||||
|
||||
Page<ChatConversationVO> chatConversationVOPage = baseMapper.selectJoinPage(new Page<>(param.getPage(), param.getLimit()), ChatConversationVO.class, wrapper);
|
||||
|
||||
return new PageResult<>(chatConversationVOPage.getRecords(), chatConversationVOPage.getTotal());
|
||||
public PageResult<ChatConversation> pageRel(ChatConversationParam param) {
|
||||
PageParam<ChatConversation, ChatConversationParam> page = new PageParam<>(param);
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
List<ChatConversation> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +34,6 @@ public class ChatConversationServiceImpl extends ServiceImpl<ChatConversationMap
|
||||
// 排序
|
||||
PageParam<ChatConversation, ChatConversationParam> page = new PageParam<>();
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@@ -89,35 +44,4 @@ public class ChatConversationServiceImpl extends ServiceImpl<ChatConversationMap
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatConversation getByBothId(Integer formUserId, Integer toUserId) {
|
||||
ChatConversationParam param = new ChatConversationParam();
|
||||
param.setUserId(formUserId);
|
||||
param.setFriendId(toUserId);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatConversationVO> getFriendList(ChatConversationParam param) {
|
||||
MPJLambdaWrapper<ChatConversation> wrapper = JoinWrappers.lambda(ChatConversation.class)
|
||||
.selectAll(ChatConversation.class)
|
||||
.eq(ChatConversation::getUserId, param.getUserId())
|
||||
.selectAssociation(User.class, ChatConversationVO::getFriendInfo)
|
||||
.leftJoin(User.class, User::getUserId, ChatConversation::getFriendId)
|
||||
.selectCollection(ChatMessage.class, ChatConversationVO::getMessages)
|
||||
.leftJoin(ChatMessage.class, on ->
|
||||
on.and(w -> {
|
||||
w.eq(ChatMessage::getFormUserId, param.getUserId()).eq(ChatMessage::getToUserId, ChatConversation::getFriendId);
|
||||
})
|
||||
.or(w -> {
|
||||
w.eq(ChatMessage::getFormUserId, ChatConversation::getFriendId).eq(ChatMessage::getToUserId, param.getUserId());
|
||||
})
|
||||
.orderByDesc(ChatMessage::getCreateTime)
|
||||
)
|
||||
.orderByDesc(ChatConversation::getUpdateTime);
|
||||
|
||||
|
||||
return baseMapper.selectJoinList(ChatConversationVO.class, wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,85 +1,31 @@
|
||||
package com.gxwebsoft.common.system.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.core.enums.ChatMessageType;
|
||||
import com.gxwebsoft.common.core.socketio.cache.ClientCache;
|
||||
import com.gxwebsoft.common.core.utils.PushUtil;
|
||||
import com.gxwebsoft.common.system.mapper.ChatMessageMapper;
|
||||
import com.gxwebsoft.common.system.service.ChatMessageService;
|
||||
import com.gxwebsoft.common.system.entity.ChatMessage;
|
||||
import com.gxwebsoft.common.system.param.ChatMessageParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.core.enums.GreenWebType;
|
||||
import com.gxwebsoft.common.system.entity.ChatMessage;
|
||||
import com.gxwebsoft.common.system.mapper.ChatMessageMapper;
|
||||
import com.gxwebsoft.common.system.param.ChatMessageParam;
|
||||
import com.gxwebsoft.common.system.service.ChatConversationService;
|
||||
import com.gxwebsoft.common.system.service.ChatMessageService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 聊天消息表Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-10 18:27:25
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Service
|
||||
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage> implements ChatMessageService {
|
||||
|
||||
@Resource
|
||||
private ChatConversationService conversationService;
|
||||
|
||||
@Resource
|
||||
private ClientCache clientCache;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private PushUtil pushUtil;
|
||||
|
||||
@Override
|
||||
public PageResult<ChatMessage> pageRel(ChatMessageParam param) {
|
||||
LambdaQueryWrapper<ChatMessage> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.and(w -> {
|
||||
w.eq(ChatMessage::getFormUserId, param.getToUserId()).eq(ChatMessage::getToUserId, param.getFormUserId());
|
||||
})
|
||||
.or(w -> {
|
||||
w.eq(ChatMessage::getFormUserId, param.getFormUserId()).eq(ChatMessage::getToUserId, param.getToUserId());
|
||||
})
|
||||
.orderByAsc(ChatMessage::getCreateTime);
|
||||
|
||||
Page<ChatMessage> chatMessagePage = new Page<>(param.getPage(), param.getLimit());
|
||||
Page<ChatMessage> result = baseMapper.selectPage(chatMessagePage, wrapper);
|
||||
List<ChatMessage> list = result.getRecords();
|
||||
Set<Integer> userIds = new HashSet<>();
|
||||
if (param.getFormUserId() != null && param.getToUserId() != null) {
|
||||
userIds.add(param.getToUserId());
|
||||
userIds.add(param.getFormUserId());
|
||||
} else {
|
||||
list.stream().forEach(d -> {
|
||||
userIds.add(d.getToUserId());
|
||||
userIds.add(d.getFormUserId());
|
||||
});
|
||||
}
|
||||
List<User> users = userService.list(Wrappers.lambdaQuery(User.class).in(User::getUserId, userIds));
|
||||
Map<Integer, List<User>> collect = users.stream().collect(Collectors.groupingBy(User::getUserId));
|
||||
list.stream().forEach(d -> {
|
||||
d.setFormUserInfo(collect.get(d.getFormUserId()).get(0));
|
||||
});
|
||||
return new PageResult<>(list, result.getTotal());
|
||||
PageParam<ChatMessage, ChatMessageParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
List<ChatMessage> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,82 +44,4 @@ public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatM
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatMessage> getUnreadMessage(Integer fromUserId, Integer toUserId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean sendMessage(ChatMessage message) {
|
||||
Integer userId = message.getFormUserId();
|
||||
Integer toUserId = message.getToUserId();
|
||||
|
||||
User toUser = userService.getById(toUserId);
|
||||
User fromUser = userService.getById(userId);
|
||||
message.setToUserInfo(toUser);
|
||||
// 判断双方是否是好友(有消息记录),没有就添加两条记录 后续可以做拉黑什么的处理
|
||||
ChatConversation conversation1 = conversationService.getByBothId(userId, toUserId);
|
||||
ChatConversation conversation2 = conversationService.getByBothId(toUserId, userId);
|
||||
if (conversation1 == null) {
|
||||
conversation1 = new ChatConversation();
|
||||
conversation1.setUserId(Integer.valueOf(userId));
|
||||
conversation1.setFriendId(toUserId);
|
||||
}
|
||||
if (conversation2 == null) {
|
||||
conversation2 = new ChatConversation();
|
||||
conversation2.setUserId(toUserId);
|
||||
conversation2.setFriendId(Integer.valueOf(userId));
|
||||
}
|
||||
String lastContent;
|
||||
if (ChatMessageType.IMAGE.getName().equals(message.getType())) {
|
||||
lastContent = "[图片]";
|
||||
} else if (ChatMessageType.VOICE.getName().equals(message.getType())) {
|
||||
lastContent = "[语音]";
|
||||
} else if (ChatMessageType.CARD.getName().equals(message.getType())) {
|
||||
lastContent = "[卡片]";
|
||||
} else {
|
||||
lastContent = message.getContent();
|
||||
}
|
||||
conversation1.setContent(lastContent);
|
||||
conversation1.setUpdateTime(DateUtil.date());
|
||||
//未读+1
|
||||
|
||||
conversation2.setUnRead(conversation2.getUnRead() + 1);
|
||||
conversation2.setContent(lastContent);
|
||||
conversation2.setUpdateTime(DateUtil.date());
|
||||
this.save(message);
|
||||
// 发送到接收方
|
||||
clientCache.sendUserEvent(message.getToUserId() + "", "message", message);
|
||||
if(lastContent.length() > 20) {
|
||||
lastContent = lastContent.substring(0, 20);
|
||||
}
|
||||
pushUtil.toSingle(message.getToUserId(),fromUser.getNickname(), lastContent,"message", message.getFormUserId());
|
||||
// 发送到管理员
|
||||
if (!toUser.getUsername().startsWith("wx_")) {
|
||||
clientCache.sendUserEvent("admin", "message", message);
|
||||
}
|
||||
|
||||
|
||||
conversationService.saveOrUpdate(conversation1);
|
||||
conversationService.saveOrUpdate(conversation2);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatMessage> getFriendMessage(Integer userId, Integer friendId, Integer lastMessageId) {
|
||||
LambdaQueryWrapper<ChatMessage> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.lt(lastMessageId != null && lastMessageId != 0, ChatMessage::getId, lastMessageId)
|
||||
.and(w2 -> {
|
||||
w2
|
||||
.or(w -> { w.eq(ChatMessage::getFormUserId, userId).eq(ChatMessage::getToUserId, friendId).ne(ChatMessage::getSideFrom, true);})
|
||||
.or(w -> {w.eq(ChatMessage::getFormUserId, friendId).eq(ChatMessage::getToUserId, userId).ne(ChatMessage::getSideTo, true);});
|
||||
})
|
||||
|
||||
.orderByDesc(ChatMessage::getCreateTime)
|
||||
.last("limit 30");
|
||||
|
||||
return baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SysGenerator {
|
||||
// "sys_app_renew"
|
||||
// "sys_version",
|
||||
// "sys_website",
|
||||
"sys_website_field",
|
||||
// "sys_website_field",
|
||||
// "sys_white_domain"
|
||||
// "sys_order"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user