|
|
|
@ -3,23 +3,22 @@ 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.DTO.EmExpressDTO;
|
|
|
|
|
import jty.expressdistributionsystem.DTO.GoodsEmDTO;
|
|
|
|
|
import jty.expressdistributionsystem.entity.*;
|
|
|
|
|
import jty.expressdistributionsystem.service.AddressService;
|
|
|
|
|
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.*;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/employee")
|
|
|
|
|
public class EmployeeController {
|
|
|
|
|
@Resource
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private RecordsService recordsService;
|
|
|
|
|
|
|
|
|
@ -27,56 +26,85 @@ public class EmployeeController {
|
|
|
|
|
private GoodsService goodsService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MessageService messageService;
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AddressService addressService;
|
|
|
|
|
|
|
|
|
|
// 查询所有自己派送的快递
|
|
|
|
|
// 查询所有自己派送的快递(finish)
|
|
|
|
|
@GetMapping("/express")
|
|
|
|
|
public Result<Page<Records>> getAllExpress(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
|
if (page <= 0 || pageSize == 0) {
|
|
|
|
|
public Result<Page<EmExpressDTO>> 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);
|
|
|
|
|
Long expressId = GetIdUtil.getId(); // 获取当前用户的 ID(假设此方法返回当前用户的 expressId)
|
|
|
|
|
// 根据 expressId 查询 Records 表中的快递记录
|
|
|
|
|
LambdaQueryWrapper<Records> recordsQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
recordsQueryWrapper.eq(Records::getExpressId, expressId)
|
|
|
|
|
.orderByDesc(Records::getCreateTime); // 按时间降序排序
|
|
|
|
|
Page<Records> recordsPage = recordsService.page(new Page<>(page, pageSize), recordsQueryWrapper);
|
|
|
|
|
List<EmExpressDTO> emExpressDTOList = new ArrayList<>();
|
|
|
|
|
for (Records record : recordsPage.getRecords()) {
|
|
|
|
|
EmExpressDTO emExpressDTO = new EmExpressDTO();
|
|
|
|
|
// 查询相关用户(发送者、接收者)
|
|
|
|
|
User sendUser = userService.getById(record.getSendUserId());
|
|
|
|
|
User getUser = userService.getById(record.getGetUserId());
|
|
|
|
|
User addressee = userService.getById(record.getAddresseeId());
|
|
|
|
|
// 查询地址信息
|
|
|
|
|
Address addressFrom = addressService.getById(record.getAddressFrom());
|
|
|
|
|
Address addressTo = addressService.getById(record.getAddressId());
|
|
|
|
|
// 查询商品信息
|
|
|
|
|
Goods goods = goodsService.getById(record.getGoodsId());
|
|
|
|
|
emExpressDTO.setSendUser(sendUser);
|
|
|
|
|
emExpressDTO.setGetUser(getUser);
|
|
|
|
|
emExpressDTO.setAddressee(addressee);
|
|
|
|
|
emExpressDTO.setAddressFrom(addressFrom);
|
|
|
|
|
emExpressDTO.setAddressTo(addressTo);
|
|
|
|
|
emExpressDTO.setGoods(goods);
|
|
|
|
|
emExpressDTO.setRecords(record);
|
|
|
|
|
emExpressDTOList.add(emExpressDTO);
|
|
|
|
|
}
|
|
|
|
|
Page<EmExpressDTO> resultPage = new Page<>(page, pageSize);
|
|
|
|
|
resultPage.setRecords(emExpressDTOList);
|
|
|
|
|
resultPage.setTotal(recordsPage.getTotal());
|
|
|
|
|
return new Result<>(200, "查询成功", resultPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询单件快递信息
|
|
|
|
|
@PostMapping("/expressInfo")
|
|
|
|
|
public Result<Goods> getExpressInfo(@RequestParam Long id) {
|
|
|
|
|
public Result<GoodsEmDTO> getExpressInfo(@RequestParam String expressCode) {
|
|
|
|
|
if (expressCode.isEmpty()) {
|
|
|
|
|
return new Result<>(404, "快递不存在", null);
|
|
|
|
|
}
|
|
|
|
|
LambdaQueryWrapper<Goods> goodsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
goodsLambdaQueryWrapper.eq(Goods::getId, id);
|
|
|
|
|
goodsLambdaQueryWrapper.eq(Goods::getExpressCode, expressCode);
|
|
|
|
|
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());
|
|
|
|
|
recordsLambdaQueryWrapper.eq(Records::getGoodsId, goods.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::getUserName, sendMessageDTO.getToUserName());
|
|
|
|
|
User user = userService.getOne(userLambdaQueryWrapper);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return new Result<>(404, "用户不存在", "");
|
|
|
|
|
User sendUser = userService.getById(goods.getSendUserId());
|
|
|
|
|
User getUser = userService.getById(goods.getGetUserId());
|
|
|
|
|
User employee = userService.getById(records.getExpressId());
|
|
|
|
|
Address addressFrom = addressService.getById(records.getAddressFrom());
|
|
|
|
|
Address addressTo = addressService.getById(records.getAddressId());
|
|
|
|
|
User addressee = userService.getById(records.getAddresseeId());
|
|
|
|
|
// 填充DTO
|
|
|
|
|
GoodsEmDTO goodsEmDTO = new GoodsEmDTO();
|
|
|
|
|
goodsEmDTO.setName(goods.getName());
|
|
|
|
|
goodsEmDTO.setSendUser(sendUser.getUserName());
|
|
|
|
|
goodsEmDTO.setGetUser(getUser.getUserName());
|
|
|
|
|
goodsEmDTO.setQuality(goods.getQuality());
|
|
|
|
|
goodsEmDTO.setAddressFrom(addressFrom.getAddress());
|
|
|
|
|
goodsEmDTO.setAddressTo(addressTo.getAddress());
|
|
|
|
|
goodsEmDTO.setMark(records.getMark());
|
|
|
|
|
goodsEmDTO.setEmployee(employee.getUserName());
|
|
|
|
|
if (addressee != null) {
|
|
|
|
|
goodsEmDTO.setAddressee(addressee.getUserName());
|
|
|
|
|
}
|
|
|
|
|
Message message = SendMessageUtil.sendMessage(sendMessageDTO, userService);
|
|
|
|
|
messageService.save(message);
|
|
|
|
|
return new Result<>(200, "发送成功", "");
|
|
|
|
|
return new Result<>(200, "查询成功", goodsEmDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|