阶段四:快递员功能

grs
yjxx 1 month ago
parent 9c33185231
commit c1766f3259

@ -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<String> sendMessage(@RequestBody SendMessageDTO sendMessageDTO) {
public Result<String> sendMessage(@RequestBody @NotNull SendMessageDTO sendMessageDTO) {
LambdaQueryWrapper<User> 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, "发送成功", "");

@ -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<Page<Records>> getAllExpress(@RequestParam int page, @RequestParam int pageSize) {
if (page <= 0 || pageSize == 0) {
return new Result<>(400, "页码和每页大小必须大于0", null);
}
Long id = GetIdUtil.getId();
Page<Records> recordsPage = new Page<>(page, pageSize);
LambdaQueryWrapper<Records> 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<Goods> getExpressInfo(@RequestParam Long id) {
LambdaQueryWrapper<Goods> goodsLambdaQueryWrapper = new LambdaQueryWrapper<>();
goodsLambdaQueryWrapper.eq(Goods::getId, id);
Goods goods = goodsService.getOne(goodsLambdaQueryWrapper);
if (goods == null) {
return new Result<>(404, "快递不存在", null);
}
LambdaQueryWrapper<Records> 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<String> sendMessageToUser(@RequestBody @NotNull SendMessageDTO sendMessageDTO) {
LambdaQueryWrapper<User> 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, "发送成功", "");
}
}

@ -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<Message> messagePage = new Page<>(page, pageSize);
LambdaQueryWrapper<Message> 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<Message> messagePage = new Page<>(page, pageSize);
LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
// 添加查询条件

Loading…
Cancel
Save