From 038760b094e58bbe590a9ce45532d776a11b16ac Mon Sep 17 00:00:00 2001 From: yjxx <1055683039@qq.com> Date: Sun, 20 Oct 2024 00:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=80=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E5=92=8C=E4=BA=8C=E9=98=B6=E6=AE=B5=E9=80=9A=E8=BF=87=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=AA=8C=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdminController.java | 8 +++++++- .../jty/expressdistributionsystem/entity/Message.java | 5 +++-- .../jty/expressdistributionsystem/utils/SendMessage.java | 8 ++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java index 2531b5a..b353e00 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java @@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.annotation.Resource; import jty.expressdistributionsystem.DTO.SendMessageDTO; import jty.expressdistributionsystem.config.MyMetaObjectHandler; +import jty.expressdistributionsystem.entity.Message; import jty.expressdistributionsystem.entity.Result; import jty.expressdistributionsystem.entity.User; +import jty.expressdistributionsystem.service.MessageService; import jty.expressdistributionsystem.service.UserService; import jty.expressdistributionsystem.utils.SendMessage; import org.springframework.web.bind.annotation.*; @@ -17,6 +19,9 @@ public class AdminController { @Resource private UserService userService; + @Resource + private MessageService messageService; + // 管理员查看用户或者快递员信息 @GetMapping("/userList") public Result> getUserList(@RequestParam int page, @RequestParam int pageSize, @RequestParam int mark) { @@ -57,7 +62,8 @@ public class AdminController { // 管理员发送消息 @PostMapping("/sendMessage") public Result sendMessage(@RequestBody SendMessageDTO sendMessageDTO) { - SendMessage.sendMessage(sendMessageDTO); + Message message = SendMessage.sendMessage(sendMessageDTO); + messageService.save(message); return new Result<>(200, "发送成功", ""); } } diff --git a/src/main/java/jty/expressdistributionsystem/entity/Message.java b/src/main/java/jty/expressdistributionsystem/entity/Message.java index 70eebb6..bcb599a 100644 --- a/src/main/java/jty/expressdistributionsystem/entity/Message.java +++ b/src/main/java/jty/expressdistributionsystem/entity/Message.java @@ -1,5 +1,6 @@ package jty.expressdistributionsystem.entity; +import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -33,10 +34,10 @@ public class Message implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long getUserId; - @TableField("create_time") + @TableField(value = "create_time", fill = FieldFill.INSERT) private LocalDateTime createTime; - @TableField("update_time") + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) private LocalDateTime updateTime; @TableField("mark") diff --git a/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java b/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java index eebc769..f0f3e94 100644 --- a/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java +++ b/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java @@ -1,21 +1,17 @@ package jty.expressdistributionsystem.utils; -import jakarta.annotation.Resource; import jty.expressdistributionsystem.DTO.SendMessageDTO; import jty.expressdistributionsystem.entity.Message; -import jty.expressdistributionsystem.service.MessageService; import org.jetbrains.annotations.NotNull; public class SendMessage { - @Resource - private static MessageService messageService; - public static void sendMessage(@NotNull SendMessageDTO sendMessageDTO) { + public static Message sendMessage(@NotNull SendMessageDTO sendMessageDTO) { Long sendId = GetIdUtil.getId(); Message message = new Message(); message.setSendUserId(sendId); message.setGetUserId(sendMessageDTO.getId()); message.setContent(sendMessageDTO.getContent()); - messageService.save(message); + return message; } }