管理员和用户功能成功通过Postman测试验收

grs
yjxx 1 month ago
parent 93febaf68e
commit 9c33185231

@ -11,10 +11,6 @@ public class GoodsDTO {
@NotBlank(message = "请选择快递公司") @NotBlank(message = "请选择快递公司")
private String company; private String company;
@JsonSerialize(using = ToStringSerializer.class)
@NotNull
private Long sendUserId;
@NotBlank(message = "收件人名字不能为空") @NotBlank(message = "收件人名字不能为空")
private String getUserName; private String getUserName;
@ -26,4 +22,8 @@ public class GoodsDTO {
@NotBlank(message = "运送地址不能为空") @NotBlank(message = "运送地址不能为空")
private String address; private String address;
@JsonSerialize(using = ToStringSerializer.class)
@NotNull
private Long expressId;
} }

@ -4,16 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data @Data
public class SendMessageDTO implements Serializable { public class SendMessageDTO {
@Serial
private static final long serialVersionUID = 1L;
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long id; private Long Id;
private String content; private String content;
} }

@ -13,6 +13,6 @@ public class WebConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor).excludePathPatterns("/common/login", "/common/loginByAccount"); registry.addInterceptor(loginInterceptor).excludePathPatterns("/common/register", "/common/loginByAccount");
} }
} }

@ -22,7 +22,7 @@ public class AdminController {
private MessageService messageService; private MessageService messageService;
// 管理员查看用户或者快递员信息 // 管理员查看用户或者快递员信息
@GetMapping("/userList") @GetMapping("/infoList")
public Result<Page<User>> getUserList(@RequestParam int page, @RequestParam int pageSize, @RequestParam int mark) { public Result<Page<User>> getUserList(@RequestParam int page, @RequestParam int pageSize, @RequestParam int mark) {
if (page <= 0 || pageSize <= 0) { if (page <= 0 || pageSize <= 0) {
return new Result<>(400, "页码和每页大小必须大于0", null); return new Result<>(400, "页码和每页大小必须大于0", null);
@ -43,7 +43,7 @@ public class AdminController {
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result<String> delete(@PathVariable Long id, @RequestParam String operation) { public Result<String> delete(@PathVariable Long id, @RequestParam String operation) {
User user = userService.getById(id); User user = userService.getById(id);
switch(operation){ switch (operation) {
// 禁用 // 禁用
case "0" -> user.setDisabled(1); case "0" -> user.setDisabled(1);
// 解除禁用 // 解除禁用
@ -61,7 +61,7 @@ public class AdminController {
// 管理员发送消息 // 管理员发送消息
@PostMapping("/sendMessage") @PostMapping("/sendMessage")
public Result<String> sendMessage(@RequestBody SendMessageDTO sendMessageDTO) { public Result<String> sendMessage(@RequestBody SendMessageDTO sendMessageDTO) {
Message message = SendMessageUtil.sendMessage(sendMessageDTO); Message message = SendMessageUtil.sendMessage(sendMessageDTO);
messageService.save(message); messageService.save(message);
return new Result<>(200, "发送成功", ""); return new Result<>(200, "发送成功", "");
} }

@ -67,7 +67,7 @@ public class CommonController {
return new Result<>(401, "账号或者密码错误", ""); return new Result<>(401, "账号或者密码错误", "");
} }
User user = optionalUser.get(); User user = optionalUser.get();
if(user.getDisabled() == 1){ if (user.getDisabled() == 1) {
return new Result<>(403, "该账号已被禁用, 请联系管理员", ""); return new Result<>(403, "该账号已被禁用, 请联系管理员", "");
} }
user.setLoginTime(LocalDateTime.now()); user.setLoginTime(LocalDateTime.now());

@ -14,6 +14,7 @@ import jty.expressdistributionsystem.utils.ClaimCodeUtil;
import jty.expressdistributionsystem.utils.ExpressCodeUtil; import jty.expressdistributionsystem.utils.ExpressCodeUtil;
import jty.expressdistributionsystem.utils.GetIdUtil; import jty.expressdistributionsystem.utils.GetIdUtil;
import jty.expressdistributionsystem.utils.SendMessageUtil; import jty.expressdistributionsystem.utils.SendMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -22,6 +23,7 @@ import java.util.List;
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
@Slf4j
public class UserController { public class UserController {
@Resource @Resource
private UserService userService; private UserService userService;
@ -51,87 +53,44 @@ public class UserController {
// 给快递员点赞 // 给快递员点赞
@PostMapping("/likes") @PostMapping("/likes")
public Result<String> like(Long id) { public Result<String> like(@RequestParam Long id) {
User employee = userService.getById(id); User employee = userService.getById(id);
employee.setLikes(employee.getLikes() + 1); employee.setLikes(employee.getLikes() + 1);
userService.save(employee); userService.updateById(employee);
return new Result<>(200, "点赞成功", ""); return new Result<>(200, "点赞成功", "");
} }
// 用户查看自己的快递记录 // 用户查看发给别人消息
@GetMapping("/history") @GetMapping("/sendToMessage")
public Result<Page<Records>> getHistory(@RequestParam int page, @RequestParam int pageSize) { public Result<Page<Message>> sendToMessage(@RequestParam int page, @RequestParam int pageSize) {
if (page <= 0 || pageSize == 0) { if (page <= 0 || pageSize == 0) {
return new Result<>(400, "页码和每页大小必须大于0", null); return new Result<>(400, "页码和每页大小必须大于0", null);
} }
Long id = GetIdUtil.getId(); Long id = GetIdUtil.getId();
Page<Records> pageInfo = new Page<>(page, pageSize); log.info("当前登录用户的id: {}", id);
LambdaQueryWrapper<Records> queryWrapper = new LambdaQueryWrapper<>(); Page<Message> messagePage = new Page<>(page, pageSize);
queryWrapper.eq(Records::getSendUserId, id); LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(Records::getCreateTime); // 添加查询条件
recordsService.page(pageInfo, queryWrapper); messageLambdaQueryWrapper.eq(Message::getSendUserId, id);
return new Result<>(200, "", pageInfo); // 排序条件:先按 mark 对应值排序,然后按时间排序
} messageLambdaQueryWrapper.orderByDesc(Message::getMark) // mark 值大的排前面
.orderByDesc(Message::getCreateTime); // 时间新的排前面
// 用户收件 messageService.page(messagePage, messageLambdaQueryWrapper);
@PostMapping("/addressee") return new Result<>(200, "获取成功", messagePage);
public Result<String> addressee(@Validated @RequestBody @NotNull AddresseeDTO addresseeDTO) {
Long goodsId = addresseeDTO.getGoodsId();
QueryWrapper<Code> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("goods_id", goodsId);
Code code = codeService.getOne(queryWrapper);
// 判断取件码是否输入正确
if (!code.getClaim().equals(addresseeDTO.getClaimCode())) {
return new Result<>(401, "请输入正确的取件码", "");
}
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
recordsQueryWrapper.eq("goods_id", goodsId);
Records records = recordsService.getOne(recordsQueryWrapper);
records.setMark(1);
// 设置取件人
records.setAddresseeId(GetIdUtil.getId());
recordsService.save(records);
return new Result<>(200, "取件成功", "");
}
// 用户代取快递
@PostMapping("/pickUp")
public Result<String> pickUpExpress(@RequestBody @Validated @NotNull PickUpExpressDTO pickUpExpressDTO) {
// 查询快递原主人信息
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("user_name", pickUpExpressDTO.getMaster());
User master = userService.getOne(userQueryWrapper);
if (master == null) {
return new Result<>(404, "该用户不存在", "");
}
// 查询快递信息
QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
goodsQueryWrapper.eq("express_code", pickUpExpressDTO.getExpressCode());
Goods goods = goodsService.getOne(goodsQueryWrapper);
if (goods == null) {
return new Result<>(404, "快递不存在", "");
}
// 代取
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
recordsQueryWrapper.eq("goods_id", goods.getId());
Records records = recordsService.getOne(recordsQueryWrapper);
records.setMark(1);
records.setAddresseeId(GetIdUtil.getId());
recordsService.save(records);
return new Result<>(200, "待取成功", "");
} }
// 用户查看消息 // 用户查看别人发给自己的消息
@GetMapping("/getMessage") @GetMapping("/getFromMessage")
public Result<Page<Message>> getMessage(@RequestParam int page, @RequestParam int pageSize) { public Result<Page<Message>> getFromMessage(@RequestParam int page, @RequestParam int pageSize) {
if (page <= 0 || pageSize == 0) { if (page <= 0 || pageSize == 0) {
return new Result<>(400, "页码和每页大小必须大于0", null); return new Result<>(400, "页码和每页大小必须大于0", null);
} }
Long id = GetIdUtil.getId(); Long id = GetIdUtil.getId();
log.info("当前登录用户的id: {}", id);
Page<Message> messagePage = new Page<>(page, pageSize); Page<Message> messagePage = new Page<>(page, pageSize);
LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
// 添加查询条件 // 添加查询条件
messageLambdaQueryWrapper.eq(Message::getSendUserId, id); messageLambdaQueryWrapper.eq(Message::getGetUserId, id);
// 排序条件:先按 mark 对应值排序,然后按时间排序 // 排序条件:先按 mark 对应值排序,然后按时间排序
messageLambdaQueryWrapper.orderByDesc(Message::getMark) // mark 值大的排前面 messageLambdaQueryWrapper.orderByDesc(Message::getMark) // mark 值大的排前面
.orderByDesc(Message::getCreateTime); // 时间新的排前面 .orderByDesc(Message::getCreateTime); // 时间新的排前面
@ -142,12 +101,26 @@ public class UserController {
// 用户确认查看消息 // 用户确认查看消息
@PostMapping("/confirmMessage") @PostMapping("/confirmMessage")
public Result<String> confirmMessage(@RequestParam Long id) { public Result<String> confirmMessage(@RequestParam Long id) {
Records records = recordsService.getById(id); Message message = messageService.getById(id);
records.setMark(0); message.setMark(0);
recordsService.save(records); messageService.updateById(message);
return new Result<>(200, "消息查看成功", ""); return new Result<>(200, "消息查看成功", "");
} }
// 用户新建快递地址
@PostMapping("/addAddress")
public Result<String> addAddress(@RequestBody @NotNull Address address) {
// 查询快递地址是否已经存在
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
addressLambdaQueryWrapper.eq(Address::getAddress, address.getAddress());
Address getAddress = addressService.getOne(addressLambdaQueryWrapper);
if (getAddress != null) {
return new Result<>(409, "该地址已存在", "");
}
addressService.save(address);
return new Result<>(200, "地址创建成功", "");
}
// 用户获取自己写过的地址 // 用户获取自己写过的地址
@GetMapping("/getAddress") @GetMapping("/getAddress")
public Result<List<Address>> listAddress() { public Result<List<Address>> listAddress() {
@ -158,6 +131,21 @@ public class UserController {
return new Result<>(200, "", list); return new Result<>(200, "", list);
} }
// 用户查看自己的发送快递记录
@GetMapping("/history")
public Result<Page<Records>> getHistory(@RequestParam int page, @RequestParam int pageSize) {
if (page <= 0 || pageSize == 0) {
return new Result<>(400, "页码和每页大小必须大于0", null);
}
Long id = GetIdUtil.getId();
Page<Records> pageInfo = new Page<>(page, pageSize);
LambdaQueryWrapper<Records> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Records::getSendUserId, id);
queryWrapper.orderByDesc(Records::getCreateTime);
recordsService.page(pageInfo, queryWrapper);
return new Result<>(200, "", pageInfo);
}
// 用户寄件 // 用户寄件
@PostMapping("/shipment") @PostMapping("/shipment")
public Result<String> shipmentExpress(@RequestBody @Validated @NotNull GoodsDTO goodsDTO) { public Result<String> shipmentExpress(@RequestBody @Validated @NotNull GoodsDTO goodsDTO) {
@ -165,9 +153,16 @@ public class UserController {
LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
userLambdaQueryWrapper.eq(User::getUserName, goodsDTO.getGetUserName()); userLambdaQueryWrapper.eq(User::getUserName, goodsDTO.getGetUserName());
User getUser = userService.getOne(userLambdaQueryWrapper); User getUser = userService.getOne(userLambdaQueryWrapper);
if(getUser == null) { if (getUser == null) {
return new Result<>(404, "用户不存在", null); return new Result<>(404, "用户不存在", null);
} }
// 判断地址是否存在
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddress());
Address address = addressService.getOne(addressLambdaQueryWrapper);
if (address == null) {
return new Result<>(404, "地址不存在", null);
}
// 生成快递码 // 生成快递码
String expressCode = ExpressCodeUtil.getExpressCode(goodsDTO.getCompany()); String expressCode = ExpressCodeUtil.getExpressCode(goodsDTO.getCompany());
// 生成取件码 // 生成取件码
@ -183,11 +178,9 @@ public class UserController {
Records records = new Records(); Records records = new Records();
records.setSendUserId(GetIdUtil.getId()); records.setSendUserId(GetIdUtil.getId());
records.setGetUserId(getUser.getId()); records.setGetUserId(getUser.getId());
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); records.setAddressId(address.getId());
addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddress());
Address address = addressService.getOne(addressLambdaQueryWrapper);
records.setAddresseeId(address.getId());
records.setGoodsId(goods.getId()); records.setGoodsId(goods.getId());
records.setExpressId(goodsDTO.getExpressId());
recordsService.save(records); recordsService.save(records);
Code code = new Code(); Code code = new Code();
code.setClaim(claimCode); code.setClaim(claimCode);
@ -195,4 +188,60 @@ public class UserController {
codeService.save(code); codeService.save(code);
return new Result<>(200, "寄件成功", ""); return new Result<>(200, "寄件成功", "");
} }
// 用户收件
@PostMapping("/addressee")
public Result<String> addressee(@Validated @RequestBody @NotNull AddresseeDTO addresseeDTO) {
// 判断是不是自己的快递
Long goodsId = addresseeDTO.getGoodsId();
Goods goods = goodsService.getById(goodsId);
if (goods.getGetUserId().compareTo(GetIdUtil.getId()) != 0) {
return new Result<>(401, "签收他人快递请选择代取功能", "");
}
QueryWrapper<Code> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("goods_id", goodsId);
Code code = codeService.getOne(queryWrapper);
// 判断取件码是否输入正确
if (!code.getClaim().equals(addresseeDTO.getClaimCode())) {
return new Result<>(401, "请输入正确的取件码", "");
}
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
recordsQueryWrapper.eq("goods_id", goodsId);
Records records = recordsService.getOne(recordsQueryWrapper);
records.setMark(1);
// 设置取件人
records.setAddresseeId(GetIdUtil.getId());
recordsService.updateById(records);
return new Result<>(200, "取件成功", "");
}
// 用户代取快递
@PostMapping("/pickUp")
public Result<String> pickUpExpress(@RequestBody @Validated @NotNull PickUpExpressDTO pickUpExpressDTO) {
// 查询快递原主人信息
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("user_name", pickUpExpressDTO.getMaster());
User master = userService.getOne(userQueryWrapper);
if (master == null) {
return new Result<>(404, "该用户不存在", "");
}
// 查询快递信息
QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
goodsQueryWrapper.eq("express_code", pickUpExpressDTO.getExpressCode());
Goods goods = goodsService.getOne(goodsQueryWrapper);
if (goods == null) {
return new Result<>(404, "快递不存在", "");
}
// 代取
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
recordsQueryWrapper.eq("goods_id", goods.getId());
Records records = recordsService.getOne(recordsQueryWrapper);
if(records.getMark() == 1) {
return new Result<>(500, "快递已被签收", "");
}
records.setMark(1);
records.setAddresseeId(GetIdUtil.getId());
recordsService.updateById(records);
return new Result<>(200, "代取成功", "");
}
} }

@ -33,6 +33,10 @@ public class Records implements Serializable {
@NotNull @NotNull
private Long getUserId; private Long getUserId;
@JsonSerialize(using = ToStringSerializer.class)
@NotNull
private Long expressId;
@TableField("goods_id") @TableField("goods_id")
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
@NotNull @NotNull
@ -41,6 +45,10 @@ public class Records implements Serializable {
@TableField("mark") @TableField("mark")
private Integer mark; private Integer mark;
@TableField
@JsonSerialize(using = ToStringSerializer.class)
private Long addressId;
@TableField("addressee_id") @TableField("addressee_id")
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long addresseeId; private Long addresseeId;

@ -21,13 +21,13 @@ public class LoginInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) { public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) {
// 令牌验证 // 令牌验证
String token = request.getHeader("Authorization"); String token = request.getHeader("Authorization");
try { try {
// 从redis获取相同的token // 从redis获取相同的token
ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue(); ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
String redisToken = stringStringValueOperations.get(token); String redisToken = stringStringValueOperations.get(token);
if(redisToken == null){ if (redisToken == null) {
// 说明token失效 // 说明token失效
throw new RuntimeException(); throw new RuntimeException();
} }

Loading…
Cancel
Save