项目阶段二:管理员功能

grs
yjxx 1 month ago
parent c202b4f240
commit bdaec402ed

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

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

@ -17,8 +17,10 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
if (skipUpdateFill.get() == null || !skipUpdateFill.get()) {
this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
}
}
@Override
public void updateFill(MetaObject metaObject) {

@ -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<Page<User>> getUserList(@RequestParam int page, @RequestParam int pageSize){
if(page <= 0 || pageSize <= 0) {
public Result<Page<User>> getUserList(@RequestParam int page, @RequestParam int pageSize, @RequestParam int mark) {
if (page <= 0 || pageSize <= 0) {
return new Result<>(400, "页码和每页大小必须大于0", null);
}
// 分页
Page<User> pageInfo = new Page<>(page, pageSize);
LambdaQueryWrapper<User> 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<String> 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<String> sendMessage(@RequestBody SendMessageDTO sendMessageDTO) {
SendMessage.sendMessage(sendMessageDTO);
return new Result<>(200, "发送成功", "");
}
}

@ -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<String> 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);

@ -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() {
}
}

@ -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<Message> {
}

@ -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<Message> {
}

@ -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<MessageMapper, Message> implements MessageService {
}

@ -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);
}
}
Loading…
Cancel
Save