封装快递记录查询

grs
yjxx 2 weeks ago
parent e8d409bd38
commit 7101d6b7d2

@ -0,0 +1,17 @@
package jty.expressdistributionsystem.DTO;
import jty.expressdistributionsystem.entity.Address;
import jty.expressdistributionsystem.entity.Goods;
import jty.expressdistributionsystem.entity.User;
import lombok.Data;
@Data
public class RecordsListDTO {
private Goods goods; // 查看货物名称
private Address addressFrom; // 查看发货地
private Address addressTo; // 查看发到哪里
private User employee; // 查看快递员
private User addressee; // 查看谁签收的
private User sendUser; // 查看谁发的
private User getUserId; // 查看发给谁的
}

@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import jty.expressdistributionsystem.DTO.AddresseeDTO;
import jty.expressdistributionsystem.DTO.GoodsDTO;
import jty.expressdistributionsystem.DTO.PickUpExpressDTO;
import jty.expressdistributionsystem.DTO.SendMessageDTO;
import jty.expressdistributionsystem.DTO.*;
import jty.expressdistributionsystem.entity.*;
import jty.expressdistributionsystem.service.*;
import jty.expressdistributionsystem.utils.ClaimCodeUtil;
@ -18,9 +15,7 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
@RestController
@RequestMapping("/user")
@ -78,7 +73,7 @@ public class UserController {
return new Result<>(200, "获取成功", messagePage);
}
// 用户查看别人发给自己的消息
// 用户查看别人发给自己的消息(finish)
@GetMapping("/getFromMessage")
public Result<List<Message>> getFromMessage(@RequestParam Long id) {
LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -120,19 +115,58 @@ public class UserController {
return new Result<>(200, "", list);
}
// 用户查看自己的发送快递记录
// 用户获取自己所有的快递记录
@GetMapping("/history")
public Result<Page<Records>> getHistory(@RequestParam int page, @RequestParam int pageSize) {
if (page <= 0 || pageSize == 0) {
public Result<Page<RecordsListDTO>> getHistory(@RequestParam int page, @RequestParam int pageSize) {
if (page <= 0 || pageSize <= 0) {
return new Result<>(400, "页码和每页大小必须大于0", null);
}
Long id = GetIdUtil.getId();
Page<Records> pageInfo = new Page<>(page, pageSize);
LambdaQueryWrapper<Records> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Records::getSendUserId, id);
queryWrapper.orderByDesc(Records::getCreateTime);
recordsService.page(pageInfo, queryWrapper);
return new Result<>(200, "", pageInfo);
Long userId = GetIdUtil.getId(); // 获取当前用户的ID
List<Records> recordsList = new ArrayList<>();
// 查询作为收件人的快递记录
LambdaQueryWrapper<Records> recordsLambdaQueryWrapper = new LambdaQueryWrapper<>();
recordsLambdaQueryWrapper.eq(Records::getGetUserId, userId);
// 添加排序条件
recordsLambdaQueryWrapper.orderByAsc(Records::getMark)
.orderByDesc(Records::getCreateTime);
List<Records> receivedRecords = recordsService.list(recordsLambdaQueryWrapper);
recordsLambdaQueryWrapper.clear();
recordsList.addAll(receivedRecords);
// 查询作为寄件人的快递记录
recordsLambdaQueryWrapper.eq(Records::getSendUserId, userId);
// 添加排序条件
recordsLambdaQueryWrapper.orderByAsc(Records::getMark)
.orderByDesc(Records::getCreateTime);
List<Records> sentRecords = recordsService.list(recordsLambdaQueryWrapper);
recordsList.addAll(sentRecords);
// 分页处理
int totalRecords = recordsList.size();
int fromIndex = Math.min(pageSize * (page - 1), totalRecords);
int toIndex = Math.min(fromIndex + pageSize, totalRecords);
List<Records> pagedRecords = recordsList.subList(fromIndex, toIndex);
// 封装成GoodsListDTO
List<RecordsListDTO> recordsListDTOList = new ArrayList<>();
for (Records records : pagedRecords) {
Goods goods = goodsService.getById(records.getGoodsId());
User sender = userService.getById(records.getSendUserId());
User recipient = userService.getById(records.getGetUserId());
User addressee = userService.getById(records.getAddresseeId());
User courier = userService.getById(records.getExpressId());
Address addressFrom = addressService.getById(records.getAddressFrom());
Address addressTo = addressService.getById(records.getAddressId());
RecordsListDTO recordsListDTO = new RecordsListDTO();
recordsListDTO.setGoods(goods);
recordsListDTO.setAddressFrom(addressFrom);
recordsListDTO.setAddressTo(addressTo);
recordsListDTO.setEmployee(courier);
recordsListDTO.setAddressee(addressee);
recordsListDTO.setSendUser(sender);
recordsListDTO.setGetUserId(recipient);
recordsListDTOList.add(recordsListDTO);
}
Page<RecordsListDTO> goodsDTOPage = new Page<>(page, pageSize, totalRecords);
goodsDTOPage.setRecords(recordsListDTOList);
return new Result<>(200, "", goodsDTOPage);
}
// 用户寄件(完成)

Loading…
Cancel
Save