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; } }