From bdaec402edceeea438649223fd35fb15411f5449 Mon Sep 17 00:00:00 2001 From: yjxx <1055683039@qq.com> Date: Sat, 19 Oct 2024 13:02:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=98=B6=E6=AE=B5=E4=BA=8C?= =?UTF-8?q?=EF=BC=9A=E7=AE=A1=E7=90=86=E5=91=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTO/SendMessageDTO.java | 19 ++++++++ ...ssword.java => UserModifyPasswordDTO.java} | 2 +- .../config/MyMetaObjectHandler.java | 4 +- .../controller/AdminController.java | 46 +++++++++++++++---- .../controller/UserController.java | 12 ++--- .../entity/Message.java | 10 ++++ .../mapper/MessageMapper.java | 7 +++ .../service/MessageService.java | 7 +++ .../service/impl/MessageServiceImpl.java | 11 +++++ .../utils/SendMessage.java | 21 +++++++++ 10 files changed, 123 insertions(+), 16 deletions(-) create mode 100644 src/main/java/jty/expressdistributionsystem/DTO/SendMessageDTO.java rename src/main/java/jty/expressdistributionsystem/DTO/{UserModifyPassword.java => UserModifyPasswordDTO.java} (95%) create mode 100644 src/main/java/jty/expressdistributionsystem/mapper/MessageMapper.java create mode 100644 src/main/java/jty/expressdistributionsystem/service/MessageService.java create mode 100644 src/main/java/jty/expressdistributionsystem/service/impl/MessageServiceImpl.java create mode 100644 src/main/java/jty/expressdistributionsystem/utils/SendMessage.java diff --git a/src/main/java/jty/expressdistributionsystem/DTO/SendMessageDTO.java b/src/main/java/jty/expressdistributionsystem/DTO/SendMessageDTO.java new file mode 100644 index 0000000..1bf6a1c --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/DTO/SendMessageDTO.java @@ -0,0 +1,19 @@ +package jty.expressdistributionsystem.DTO; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class SendMessageDTO implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + private String content; +} diff --git a/src/main/java/jty/expressdistributionsystem/DTO/UserModifyPassword.java b/src/main/java/jty/expressdistributionsystem/DTO/UserModifyPasswordDTO.java similarity index 95% rename from src/main/java/jty/expressdistributionsystem/DTO/UserModifyPassword.java rename to src/main/java/jty/expressdistributionsystem/DTO/UserModifyPasswordDTO.java index a0de9c9..61a8783 100644 --- a/src/main/java/jty/expressdistributionsystem/DTO/UserModifyPassword.java +++ b/src/main/java/jty/expressdistributionsystem/DTO/UserModifyPasswordDTO.java @@ -5,7 +5,7 @@ import jakarta.validation.constraints.Pattern; import lombok.Data; @Data -public class UserModifyPassword { +public class UserModifyPasswordDTO { @NotBlank(message = "旧密码不能为空") @Pattern(regexp = "^.+$") private String OldPassword; diff --git a/src/main/java/jty/expressdistributionsystem/config/MyMetaObjectHandler.java b/src/main/java/jty/expressdistributionsystem/config/MyMetaObjectHandler.java index bf5df5c..e1653c2 100644 --- a/src/main/java/jty/expressdistributionsystem/config/MyMetaObjectHandler.java +++ b/src/main/java/jty/expressdistributionsystem/config/MyMetaObjectHandler.java @@ -17,7 +17,9 @@ public class MyMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class); - this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); + if (skipUpdateFill.get() == null || !skipUpdateFill.get()) { + this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); + } } @Override diff --git a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java index 000bbfb..fda8c58 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java @@ -3,13 +3,13 @@ package jty.expressdistributionsystem.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.Result; import jty.expressdistributionsystem.entity.User; import jty.expressdistributionsystem.service.UserService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import jty.expressdistributionsystem.utils.SendMessage; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/admin") @@ -17,21 +17,51 @@ public class AdminController { @Resource private UserService userService; - // 管理员查看用户信息 + // 管理员查看用户或者快递员信息 @GetMapping("/userList") - public Result> getUserList(@RequestParam int page, @RequestParam int pageSize){ - if(page <= 0 || pageSize <= 0) { + public Result> getUserList(@RequestParam int page, @RequestParam int pageSize, @RequestParam int mark) { + if (page <= 0 || pageSize <= 0) { return new Result<>(400, "页码和每页大小必须大于0", null); } // 分页 Page pageInfo = new Page<>(page, pageSize); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); // 添加查询条件 - queryWrapper.eq(User::getMark, 0); + queryWrapper.eq(User::getMark, mark); // 排序 queryWrapper.orderByDesc(User::getLoginTime) .orderByDesc(User::getCreateTime); userService.page(pageInfo, queryWrapper); return new Result<>(200, "", pageInfo); } + + // 拉黑删除快递员或者用户 + @DeleteMapping("/delete/{id}") + public Result delete(@PathVariable Long id, @RequestParam String operation) { + User user = userService.getById(id); + switch(operation){ + // 禁用 + case "0" -> user.setDisabled(1); + // 解除禁用 + case "1" -> user.setDisabled(0); + // 直接删除 + case "2" -> { + userService.removeById(id); + return new Result<>(200, "删除成功", ""); + } + } + // 禁用自动填充 + MyMetaObjectHandler.setSkipUpdateFill(true); + userService.updateById(user); + // 开启自动填充 + MyMetaObjectHandler.setSkipUpdateFill(false); + return new Result<>(200, "操作成功", ""); + } + + // 管理员发送消息 + @PostMapping("/sendMessage") + public Result sendMessage(@RequestBody SendMessageDTO sendMessageDTO) { + SendMessage.sendMessage(sendMessageDTO); + return new Result<>(200, "发送成功", ""); + } } diff --git a/src/main/java/jty/expressdistributionsystem/controller/UserController.java b/src/main/java/jty/expressdistributionsystem/controller/UserController.java index 7e74468..ff13fdd 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/UserController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/UserController.java @@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import jakarta.annotation.Resource; import jty.expressdistributionsystem.DTO.UserLoginByAccountDTO; import jty.expressdistributionsystem.DTO.UserModifyMessageDTO; -import jty.expressdistributionsystem.DTO.UserModifyPassword; +import jty.expressdistributionsystem.DTO.UserModifyPasswordDTO; import jty.expressdistributionsystem.config.MyMetaObjectHandler; import jty.expressdistributionsystem.entity.Result; import jty.expressdistributionsystem.entity.User; @@ -122,20 +122,20 @@ public class UserController { // 修改个人密码 @PutMapping("/rePassword") public Result modifyPassword(@RequestHeader("Authorization") String token, - @RequestBody @Validated @NotNull UserModifyPassword userModifyPassword) { + @RequestBody @Validated @NotNull UserModifyPasswordDTO userModifyPasswordDTO) { // 判断密码 - if (userModifyPassword.getOldPassword().equals(userModifyPassword.getNewPassword())) { + if (userModifyPasswordDTO.getOldPassword().equals(userModifyPasswordDTO.getNewPassword())) { return new Result<>(409, "新密码不得和旧密码一致", ""); } - if (!userModifyPassword.getNewPassword().equals(userModifyPassword.getReNewPassword())) { + if (!userModifyPasswordDTO.getNewPassword().equals(userModifyPasswordDTO.getReNewPassword())) { return new Result<>(409, "两次输入密码不相同", ""); } Long id = GetIdUtil.getId(); User user = userService.getById(id); - if (!user.getIdentity().equals(userModifyPassword.getIdentity())) { + if (!user.getIdentity().equals(userModifyPasswordDTO.getIdentity())) { return new Result<>(409, "请输入您的身份证", ""); } - user.setPassword(Md5Util.getMD5String(userModifyPassword.getNewPassword())); + user.setPassword(Md5Util.getMD5String(userModifyPasswordDTO.getNewPassword())); userService.updateById(user); // 删除redis当中的token stringRedisTemplate.delete(token); diff --git a/src/main/java/jty/expressdistributionsystem/entity/Message.java b/src/main/java/jty/expressdistributionsystem/entity/Message.java index 63885f3..70eebb6 100644 --- a/src/main/java/jty/expressdistributionsystem/entity/Message.java +++ b/src/main/java/jty/expressdistributionsystem/entity/Message.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; import java.io.Serial; import java.io.Serializable; +import java.time.LocalDateTime; @Data public class Message implements Serializable { @@ -32,6 +33,15 @@ public class Message implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long getUserId; + @TableField("create_time") + private LocalDateTime createTime; + + @TableField("update_time") + private LocalDateTime updateTime; + @TableField("mark") private Integer mark; + + public Message() { + } } diff --git a/src/main/java/jty/expressdistributionsystem/mapper/MessageMapper.java b/src/main/java/jty/expressdistributionsystem/mapper/MessageMapper.java new file mode 100644 index 0000000..06c53a8 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/mapper/MessageMapper.java @@ -0,0 +1,7 @@ +package jty.expressdistributionsystem.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import jty.expressdistributionsystem.entity.Message; + +public interface MessageMapper extends BaseMapper { +} diff --git a/src/main/java/jty/expressdistributionsystem/service/MessageService.java b/src/main/java/jty/expressdistributionsystem/service/MessageService.java new file mode 100644 index 0000000..c9d6025 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/service/MessageService.java @@ -0,0 +1,7 @@ +package jty.expressdistributionsystem.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import jty.expressdistributionsystem.entity.Message; + +public interface MessageService extends IService { +} diff --git a/src/main/java/jty/expressdistributionsystem/service/impl/MessageServiceImpl.java b/src/main/java/jty/expressdistributionsystem/service/impl/MessageServiceImpl.java new file mode 100644 index 0000000..64fa4be --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/service/impl/MessageServiceImpl.java @@ -0,0 +1,11 @@ +package jty.expressdistributionsystem.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import jty.expressdistributionsystem.entity.Message; +import jty.expressdistributionsystem.mapper.MessageMapper; +import jty.expressdistributionsystem.service.MessageService; +import org.springframework.stereotype.Service; + +@Service +public class MessageServiceImpl extends ServiceImpl implements MessageService { +} diff --git a/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java b/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java new file mode 100644 index 0000000..eebc769 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java @@ -0,0 +1,21 @@ +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) { + Long sendId = GetIdUtil.getId(); + Message message = new Message(); + message.setSendUserId(sendId); + message.setGetUserId(sendMessageDTO.getId()); + message.setContent(sendMessageDTO.getContent()); + messageService.save(message); + } +}