终于尼玛调试完了用户,就差代取和快递员了!!!!

grs
yjxx 1 week ago
parent 0abbaab6f8
commit 83e365d75d

@ -1,18 +1,12 @@
package jty.expressdistributionsystem.DTO; package jty.expressdistributionsystem.DTO;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
@Data @Data
public class SendMessageDTO implements Serializable { public class SendMessageDTO {
@JsonSerialize(using = ToStringSerializer.class) @NotBlank(message = "请选择你的聊天对象")
@NotNull(message = "请选择你的聊天对象") private String toUserName;
private Long Id;
@NotBlank(message = "消息不能为空") @NotBlank(message = "消息不能为空")
private String content; private String content;

@ -80,7 +80,7 @@ public class AdminController {
// 管理员发送消息(finish) // 管理员发送消息(finish)
@PostMapping("/sendMessage") @PostMapping("/sendMessage")
public Result<String> sendMessage(@RequestBody @Validated SendMessageDTO sendMessageDTO) { public Result<String> sendMessage(@RequestBody @Validated SendMessageDTO sendMessageDTO) {
Message message = SendMessageUtil.sendMessage(sendMessageDTO); Message message = SendMessageUtil.sendMessage(sendMessageDTO, userService);
messageService.save(message); messageService.save(message);
return new Result<>(200, "发送成功", ""); return new Result<>(200, "发送成功", "");
} }

@ -70,12 +70,12 @@ public class EmployeeController {
@PostMapping("/sendMessage") @PostMapping("/sendMessage")
public Result<String> sendMessageToUser(@RequestBody @NotNull SendMessageDTO sendMessageDTO) { public Result<String> sendMessageToUser(@RequestBody @NotNull SendMessageDTO sendMessageDTO) {
LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
userLambdaQueryWrapper.eq(User::getId, sendMessageDTO.getId()); userLambdaQueryWrapper.eq(User::getUserName, sendMessageDTO.getToUserName());
User user = userService.getOne(userLambdaQueryWrapper); User user = userService.getOne(userLambdaQueryWrapper);
if (user == null) { if (user == null) {
return new Result<>(404, "用户不存在", ""); return new Result<>(404, "用户不存在", "");
} }
Message message = SendMessageUtil.sendMessage(sendMessageDTO); Message message = SendMessageUtil.sendMessage(sendMessageDTO, userService);
messageService.save(message); messageService.save(message);
return new Result<>(200, "发送成功", ""); return new Result<>(200, "发送成功", "");
} }

@ -39,15 +39,15 @@ public class UserController {
@Resource @Resource
private AddressService addressService; private AddressService addressService;
// 用户给快递员发消息 // 用户发消息(finish)
@PostMapping("/sendMessage") @PostMapping("/sendMessage")
public Result<String> sendMessage(@Validated @RequestBody SendMessageDTO sendMessageDTO) { public Result<String> sendMessage(@Validated @RequestBody SendMessageDTO sendMessageDTO) {
Message message = SendMessageUtil.sendMessage(sendMessageDTO); Message message = SendMessageUtil.sendMessage(sendMessageDTO, userService);
messageService.save(message); messageService.save(message);
return new Result<>(200, "发送成功", ""); return new Result<>(200, "发送成功", "");
} }
// 给快递员点赞 // 给快递员点赞(finish)
@PostMapping("/likes") @PostMapping("/likes")
public Result<String> like(@RequestParam Long id) { public Result<String> like(@RequestParam Long id) {
User employee = userService.getById(id); User employee = userService.getById(id);
@ -56,22 +56,18 @@ public class UserController {
return new Result<>(200, "点赞成功", ""); return new Result<>(200, "点赞成功", "");
} }
// 用户查看发给别人消息 // 用户查看发给别人消息(finish)
@GetMapping("/sendToMessage") @GetMapping("/sendToMessage")
public Result<Page<Message>> sendToMessage(@RequestParam int page, @RequestParam int pageSize) { public Result<List<Message>> sendToMessage(@RequestParam String toUserName) {
if (page <= 0 || pageSize == 0) { LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
return new Result<>(400, "页码和每页大小必须大于0", null); userLambdaQueryWrapper.eq(User::getUserName, toUserName);
} User toUser = userService.getOne(userLambdaQueryWrapper);
Long id = GetIdUtil.getId(); Long userId = GetIdUtil.getId();
Page<Message> messagePage = new Page<>(page, pageSize);
LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
// 添加查询条件 messageLambdaQueryWrapper.eq(Message::getSendUserId, userId)
messageLambdaQueryWrapper.eq(Message::getSendUserId, id); .eq(Message::getGetUserId, toUser.getId());
// 排序条件:先按 mark 对应值排序,然后按时间排序 List<Message> list = messageService.list(messageLambdaQueryWrapper);
messageLambdaQueryWrapper.orderByDesc(Message::getMark) // mark 值大的排前面 return new Result<>(200, "", list);
.orderByDesc(Message::getCreateTime); // 时间新的排前面
messageService.page(messagePage, messageLambdaQueryWrapper);
return new Result<>(200, "获取成功", messagePage);
} }
// 用户查看别人发给自己的消息(finish) // 用户查看别人发给自己的消息(finish)

@ -1,16 +1,22 @@
package jty.expressdistributionsystem.utils; package jty.expressdistributionsystem.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jty.expressdistributionsystem.DTO.SendMessageDTO; import jty.expressdistributionsystem.DTO.SendMessageDTO;
import jty.expressdistributionsystem.entity.Message; import jty.expressdistributionsystem.entity.Message;
import jty.expressdistributionsystem.entity.User;
import jty.expressdistributionsystem.service.UserService;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class SendMessageUtil { public class SendMessageUtil {
public static Message sendMessage(@NotNull SendMessageDTO sendMessageDTO) { public static Message sendMessage(@NotNull SendMessageDTO sendMessageDTO, UserService userService) {
Long sendId = GetIdUtil.getId(); Long sendId = GetIdUtil.getId();
Message message = new Message(); Message message = new Message();
message.setSendUserId(sendId); message.setSendUserId(sendId);
message.setGetUserId(sendMessageDTO.getId()); LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
userLambdaQueryWrapper.eq(User::getUserName, sendMessageDTO.getToUserName());
User user = userService.getOne(userLambdaQueryWrapper);
message.setGetUserId(user.getId());
message.setContent(sendMessageDTO.getContent()); message.setContent(sendMessageDTO.getContent());
return message; return message;
} }

Loading…
Cancel
Save