forked from fdzcxy212206413/jty
parent
9c33185231
commit
c1766f3259
@ -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, "发送成功", "");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue