|
|
@ -3,23 +3,22 @@ package jty.expressdistributionsystem.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
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.entity.*;
|
|
|
|
|
|
|
|
import jty.expressdistributionsystem.service.AddressService;
|
|
|
|
import jty.expressdistributionsystem.service.GoodsService;
|
|
|
|
import jty.expressdistributionsystem.service.GoodsService;
|
|
|
|
import jty.expressdistributionsystem.service.MessageService;
|
|
|
|
|
|
|
|
import jty.expressdistributionsystem.service.RecordsService;
|
|
|
|
import jty.expressdistributionsystem.service.RecordsService;
|
|
|
|
import jty.expressdistributionsystem.service.UserService;
|
|
|
|
import jty.expressdistributionsystem.service.UserService;
|
|
|
|
import jty.expressdistributionsystem.utils.GetIdUtil;
|
|
|
|
import jty.expressdistributionsystem.utils.GetIdUtil;
|
|
|
|
import jty.expressdistributionsystem.utils.SendMessageUtil;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/employee")
|
|
|
|
@RequestMapping("/employee")
|
|
|
|
public class EmployeeController {
|
|
|
|
public class EmployeeController {
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RecordsService recordsService;
|
|
|
|
private RecordsService recordsService;
|
|
|
|
|
|
|
|
|
|
|
@ -27,56 +26,85 @@ public class EmployeeController {
|
|
|
|
private GoodsService goodsService;
|
|
|
|
private GoodsService goodsService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private MessageService messageService;
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private AddressService addressService;
|
|
|
|
|
|
|
|
|
|
|
|
// 查询所有自己派送的快递
|
|
|
|
// 查询所有自己派送的快递(finish)
|
|
|
|
@GetMapping("/express")
|
|
|
|
@GetMapping("/express")
|
|
|
|
public Result<Page<Records>> getAllExpress(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
public Result<Page<EmExpressDTO>> getAllExpress(@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 expressId = GetIdUtil.getId(); // 获取当前用户的 ID(假设此方法返回当前用户的 expressId)
|
|
|
|
Page<Records> recordsPage = new Page<>(page, pageSize);
|
|
|
|
// 根据 expressId 查询 Records 表中的快递记录
|
|
|
|
LambdaQueryWrapper<Records> recordsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
LambdaQueryWrapper<Records> recordsQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
// 添加查询条件
|
|
|
|
recordsQueryWrapper.eq(Records::getExpressId, expressId)
|
|
|
|
recordsLambdaQueryWrapper.eq(Records::getExpressId, id);
|
|
|
|
.orderByDesc(Records::getCreateTime); // 按时间降序排序
|
|
|
|
// 排序条件:先按 mark 对应值排序,然后按时间排序
|
|
|
|
Page<Records> recordsPage = recordsService.page(new Page<>(page, pageSize), recordsQueryWrapper);
|
|
|
|
recordsLambdaQueryWrapper.orderByDesc(Records::getMark) // mark 值大的排前面
|
|
|
|
List<EmExpressDTO> emExpressDTOList = new ArrayList<>();
|
|
|
|
.orderByDesc(Records::getCreateTime); // 时间新的排前面
|
|
|
|
for (Records record : recordsPage.getRecords()) {
|
|
|
|
recordsService.page(recordsPage, recordsLambdaQueryWrapper);
|
|
|
|
EmExpressDTO emExpressDTO = new EmExpressDTO();
|
|
|
|
return new Result<>(200, "获取成功", recordsPage);
|
|
|
|
// 查询相关用户(发送者、接收者)
|
|
|
|
|
|
|
|
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")
|
|
|
|
@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<>();
|
|
|
|
LambdaQueryWrapper<Goods> goodsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
goodsLambdaQueryWrapper.eq(Goods::getId, id);
|
|
|
|
goodsLambdaQueryWrapper.eq(Goods::getExpressCode, expressCode);
|
|
|
|
Goods goods = goodsService.getOne(goodsLambdaQueryWrapper);
|
|
|
|
Goods goods = goodsService.getOne(goodsLambdaQueryWrapper);
|
|
|
|
if (goods == null) {
|
|
|
|
if (goods == null) {
|
|
|
|
return new Result<>(404, "快递不存在", null);
|
|
|
|
return new Result<>(404, "快递不存在", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LambdaQueryWrapper<Records> recordsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
LambdaQueryWrapper<Records> recordsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
recordsLambdaQueryWrapper.eq(Records::getGoodsId, goods.getId())
|
|
|
|
recordsLambdaQueryWrapper.eq(Records::getGoodsId, goods.getId());
|
|
|
|
.eq(Records::getExpressId, GetIdUtil.getId());
|
|
|
|
|
|
|
|
Records records = recordsService.getOne(recordsLambdaQueryWrapper);
|
|
|
|
Records records = recordsService.getOne(recordsLambdaQueryWrapper);
|
|
|
|
if (records == null) {
|
|
|
|
User sendUser = userService.getById(goods.getSendUserId());
|
|
|
|
return new Result<>(401, "这不是你派送的快递, 无权查看", null);
|
|
|
|
User getUser = userService.getById(goods.getGetUserId());
|
|
|
|
}
|
|
|
|
User employee = userService.getById(records.getExpressId());
|
|
|
|
return new Result<>(200, "", goods);
|
|
|
|
Address addressFrom = addressService.getById(records.getAddressFrom());
|
|
|
|
}
|
|
|
|
Address addressTo = addressService.getById(records.getAddressId());
|
|
|
|
|
|
|
|
User addressee = userService.getById(records.getAddresseeId());
|
|
|
|
// 联系用户
|
|
|
|
// 填充DTO
|
|
|
|
@PostMapping("/sendMessage")
|
|
|
|
GoodsEmDTO goodsEmDTO = new GoodsEmDTO();
|
|
|
|
public Result<String> sendMessageToUser(@RequestBody @NotNull SendMessageDTO sendMessageDTO) {
|
|
|
|
goodsEmDTO.setName(goods.getName());
|
|
|
|
LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
goodsEmDTO.setSendUser(sendUser.getUserName());
|
|
|
|
userLambdaQueryWrapper.eq(User::getUserName, sendMessageDTO.getToUserName());
|
|
|
|
goodsEmDTO.setGetUser(getUser.getUserName());
|
|
|
|
User user = userService.getOne(userLambdaQueryWrapper);
|
|
|
|
goodsEmDTO.setQuality(goods.getQuality());
|
|
|
|
if (user == null) {
|
|
|
|
goodsEmDTO.setAddressFrom(addressFrom.getAddress());
|
|
|
|
return new Result<>(404, "用户不存在", "");
|
|
|
|
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);
|
|
|
|
return new Result<>(200, "查询成功", goodsEmDTO);
|
|
|
|
messageService.save(message);
|
|
|
|
|
|
|
|
return new Result<>(200, "发送成功", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|