diff --git a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java index 4d197aa..aa61bd5 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java @@ -10,6 +10,7 @@ import jty.expressdistributionsystem.entity.User; import jty.expressdistributionsystem.service.MessageService; import jty.expressdistributionsystem.service.UserService; import jty.expressdistributionsystem.utils.SendMessageUtil; +import org.jetbrains.annotations.NotNull; import org.springframework.web.bind.annotation.*; @RestController @@ -60,7 +61,13 @@ public class AdminController { // 管理员发送消息 @PostMapping("/sendMessage") - public Result sendMessage(@RequestBody SendMessageDTO sendMessageDTO) { + public Result sendMessage(@RequestBody @NotNull SendMessageDTO sendMessageDTO) { + LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); + userLambdaQueryWrapper.eq(User::getId, sendMessageDTO.getId()); + User user = userService.getOne(userLambdaQueryWrapper); + if(user == null) { + return new Result<>(404, "用户不存在", ""); + } Message message = SendMessageUtil.sendMessage(sendMessageDTO); messageService.save(message); return new Result<>(200, "发送成功", ""); diff --git a/src/main/java/jty/expressdistributionsystem/controller/EmployeeController.java b/src/main/java/jty/expressdistributionsystem/controller/EmployeeController.java new file mode 100644 index 0000000..c215297 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/controller/EmployeeController.java @@ -0,0 +1,82 @@ +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.entity.*; +import jty.expressdistributionsystem.service.GoodsService; +import jty.expressdistributionsystem.service.MessageService; +import jty.expressdistributionsystem.service.RecordsService; +import jty.expressdistributionsystem.service.UserService; +import jty.expressdistributionsystem.utils.GetIdUtil; +import jty.expressdistributionsystem.utils.SendMessageUtil; +import org.jetbrains.annotations.NotNull; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/employee") +public class EmployeeController { + @Resource + private UserService userService; + + @Resource + private RecordsService recordsService; + + @Resource + private GoodsService goodsService; + + @Resource + private MessageService messageService; + + // 查询所有自己派送的快递 + @GetMapping("/express") + public Result> getAllExpress(@RequestParam int page, @RequestParam int pageSize) { + if (page <= 0 || pageSize == 0) { + return new Result<>(400, "页码和每页大小必须大于0", null); + } + Long id = GetIdUtil.getId(); + Page recordsPage = new Page<>(page, pageSize); + LambdaQueryWrapper recordsLambdaQueryWrapper = new LambdaQueryWrapper<>(); + // 添加查询条件 + recordsLambdaQueryWrapper.eq(Records::getExpressId, id); + // 排序条件:先按 mark 对应值排序,然后按时间排序 + recordsLambdaQueryWrapper.orderByDesc(Records::getMark) // mark 值大的排前面 + .orderByDesc(Records::getCreateTime); // 时间新的排前面 + recordsService.page(recordsPage, recordsLambdaQueryWrapper); + return new Result<>(200, "获取成功", recordsPage); + } + + // 查询单件快递信息 + @PostMapping("/expressInfo") + public Result getExpressInfo(@RequestParam Long id) { + LambdaQueryWrapper goodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); + goodsLambdaQueryWrapper.eq(Goods::getId, id); + Goods goods = goodsService.getOne(goodsLambdaQueryWrapper); + if (goods == null) { + return new Result<>(404, "快递不存在", null); + } + LambdaQueryWrapper recordsLambdaQueryWrapper = new LambdaQueryWrapper<>(); + recordsLambdaQueryWrapper.eq(Records::getGoodsId, goods.getId()) + .eq(Records::getExpressId, GetIdUtil.getId()); + Records records = recordsService.getOne(recordsLambdaQueryWrapper); + if (records == null) { + return new Result<>(401, "这不是你派送的快递, 无权查看", null); + } + return new Result<>(200, "", goods); + } + + // 联系用户 + @PostMapping("/sendMessage") + public Result sendMessageToUser(@RequestBody @NotNull SendMessageDTO sendMessageDTO) { + LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); + userLambdaQueryWrapper.eq(User::getId, sendMessageDTO.getId()); + User user = userService.getOne(userLambdaQueryWrapper); + if (user == null) { + return new Result<>(404, "用户不存在", ""); + } + Message message = SendMessageUtil.sendMessage(sendMessageDTO); + messageService.save(message); + 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 610fe90..24fac8f 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/UserController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/UserController.java @@ -14,7 +14,6 @@ import jty.expressdistributionsystem.utils.ClaimCodeUtil; import jty.expressdistributionsystem.utils.ExpressCodeUtil; import jty.expressdistributionsystem.utils.GetIdUtil; import jty.expressdistributionsystem.utils.SendMessageUtil; -import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -23,7 +22,6 @@ import java.util.List; @RestController @RequestMapping("/user") -@Slf4j public class UserController { @Resource private UserService userService; @@ -67,7 +65,6 @@ public class UserController { return new Result<>(400, "页码和每页大小必须大于0", null); } Long id = GetIdUtil.getId(); - log.info("当前登录用户的id: {}", id); Page messagePage = new Page<>(page, pageSize); LambdaQueryWrapper messageLambdaQueryWrapper = new LambdaQueryWrapper<>(); // 添加查询条件 @@ -86,7 +83,6 @@ public class UserController { return new Result<>(400, "页码和每页大小必须大于0", null); } Long id = GetIdUtil.getId(); - log.info("当前登录用户的id: {}", id); Page messagePage = new Page<>(page, pageSize); LambdaQueryWrapper messageLambdaQueryWrapper = new LambdaQueryWrapper<>(); // 添加查询条件