diff --git a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java new file mode 100644 index 0000000..000bbfb --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java @@ -0,0 +1,37 @@ +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.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; + +@RestController +@RequestMapping("/admin") +public class AdminController { + @Resource + private UserService userService; + + // 管理员查看用户信息 + @GetMapping("/userList") + public Result> getUserList(@RequestParam int page, @RequestParam int pageSize){ + 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.orderByDesc(User::getLoginTime) + .orderByDesc(User::getCreateTime); + userService.page(pageInfo, queryWrapper); + return new Result<>(200, "", pageInfo); + } +} diff --git a/src/main/java/jty/expressdistributionsystem/controller/UserController.java b/src/main/java/jty/expressdistributionsystem/controller/UserController.java index 7d6952e..7e74468 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/UserController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/UserController.java @@ -9,7 +9,7 @@ import jty.expressdistributionsystem.DTO.UserModifyPassword; import jty.expressdistributionsystem.config.MyMetaObjectHandler; import jty.expressdistributionsystem.entity.Result; import jty.expressdistributionsystem.entity.User; -import jty.expressdistributionsystem.mapper.UserMapper; +import jty.expressdistributionsystem.service.UserService; import jty.expressdistributionsystem.utils.GetIdUtil; import jty.expressdistributionsystem.utils.JwtUtil; import jty.expressdistributionsystem.utils.Md5Util; @@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit; @RequestMapping("/user") public class UserController { @Resource - private UserMapper userMapper; + private UserService userService; @Resource private StringRedisTemplate stringRedisTemplate; @@ -43,14 +43,14 @@ public class UserController { queryWrapper.eq("user_name", user.getUserName()) .or() .eq("account", user.getAccount()); - User u = userMapper.selectOne(queryWrapper); + User u = userService.getOne(queryWrapper); if (u != null) { return new Result<>(409, "用户已存在", ""); } // 密码加密 user.setPassword(Md5Util.getMD5String(user.getPassword())); // 用户数据入库 - userMapper.insert(user); + userService.save(user); return new Result<>(200, "注册成功", ""); } @@ -58,7 +58,7 @@ public class UserController { @PostMapping("/loginByAccount") public Result login(@RequestBody @Validated @NotNull UserLoginByAccountDTO userLoginByAccountDTO) { // 查询用户是否存在 - Optional optionalUser = Optional.ofNullable(userMapper.selectOne(new QueryWrapper() + Optional optionalUser = Optional.ofNullable(userService.getOne(new QueryWrapper() .eq("account", userLoginByAccountDTO.getAccount()))); if (optionalUser.isEmpty() || !Md5Util.getMD5String(userLoginByAccountDTO.getPassword()).equals(optionalUser.get().getPassword())) { return new Result<>(401, "账号或者密码错误", ""); @@ -70,7 +70,7 @@ public class UserController { // 禁用自动填充 MyMetaObjectHandler.setSkipUpdateFill(true); user.setLoginTime(LocalDateTime.now()); - userMapper.update(user, new UpdateWrapper().eq("id", user.getId())); + userService.update(user, new UpdateWrapper().eq("id", user.getId())); // 校验通过 Map claims = new HashMap<>(); claims.put("id", user.getId()); @@ -92,7 +92,7 @@ public class UserController { public Result modifyMessage(@RequestBody @Validated @NotNull UserModifyMessageDTO userModifyMessageDTO) { // 获取登录用户id Long id = GetIdUtil.getId(); - User user = userMapper.selectById(id); + User user = userService.getById(id); // 检查phone和userName是否与当前用户信息一致 boolean isPhoneSame = user.getPhone().equals(userModifyMessageDTO.getPhone()); boolean isUserNameSame = user.getUserName().equals(userModifyMessageDTO.getUserName()); @@ -102,7 +102,7 @@ public class UserController { QueryWrapper queryWrapper = new QueryWrapper<>(); if (!isPhoneSame) { queryWrapper.eq("phone", userModifyMessageDTO.getPhone()); - if (userMapper.selectOne(queryWrapper) != null) { + if (userService.getOne(queryWrapper) != null) { return new Result<>(400, "该手机号已被注册", ""); } user.setPhone(userModifyMessageDTO.getPhone()); @@ -110,12 +110,12 @@ public class UserController { queryWrapper.clear(); if (!isUserNameSame) { queryWrapper.eq("user_name", userModifyMessageDTO.getUserName()); - if (userMapper.selectOne(queryWrapper) != null) { + if (userService.getOne(queryWrapper) != null) { return new Result<>(400, "该用户名已被使用", ""); } user.setUserName(userModifyMessageDTO.getUserName()); } - userMapper.updateById(user); + userService.updateById(user); return new Result<>(200, "用户信息修改成功", user); } @@ -131,12 +131,12 @@ public class UserController { return new Result<>(409, "两次输入密码不相同", ""); } Long id = GetIdUtil.getId(); - User user = userMapper.selectById(id); + User user = userService.getById(id); if (!user.getIdentity().equals(userModifyPassword.getIdentity())) { return new Result<>(409, "请输入您的身份证", ""); } user.setPassword(Md5Util.getMD5String(userModifyPassword.getNewPassword())); - userMapper.updateById(user); + userService.updateById(user); // 删除redis当中的token stringRedisTemplate.delete(token); // 删除当前线程的存储信息 @@ -148,7 +148,7 @@ public class UserController { @GetMapping("/info") public Result getInfo() { Long id = GetIdUtil.getId(); - User user = userMapper.selectById(id); + User user = userService.getById(id); return new Result<>(200, "", user); } } diff --git a/src/main/java/jty/expressdistributionsystem/entity/Message.java b/src/main/java/jty/expressdistributionsystem/entity/Message.java new file mode 100644 index 0000000..63885f3 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/entity/Message.java @@ -0,0 +1,37 @@ +package jty.expressdistributionsystem.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; +import org.jetbrains.annotations.NotNull; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class Message implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @TableId("id") + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + @TableField("content") + private String content; + + @TableField("send_user_id") + @NotNull + @JsonSerialize(using = ToStringSerializer.class) + private Long sendUserId; + + @TableField("get_user_id") + @NotNull + @JsonSerialize(using = ToStringSerializer.class) + private Long getUserId; + + @TableField("mark") + private Integer mark; +}