所有项目完成!

grs
yjxx 1 week ago
parent 8f3c97fa52
commit 6b54e769fd

@ -0,0 +1,19 @@
package jty.expressdistributionsystem.DTO;
import jty.expressdistributionsystem.entity.Address;
import jty.expressdistributionsystem.entity.Goods;
import jty.expressdistributionsystem.entity.Records;
import jty.expressdistributionsystem.entity.User;
import lombok.Data;
@Data
public class EmExpressDTO {
private User sendUser;
private User getUser;
private User addressee;
private User express;
private Address addressTo;
private Goods goods;
private Address addressFrom;
private Records records;
}

@ -0,0 +1,16 @@
package jty.expressdistributionsystem.DTO;
import lombok.Data;
@Data
public class GoodsEmDTO {
private String name;
private String sendUser;
private String getUser;
private String employee;
private Double quality;
private String addressFrom;
private String addressTo;
private Integer mark;
private String addressee;
}

@ -61,6 +61,8 @@ public class CommonController {
// 通过账号登录(finish)
@PostMapping("/loginByAccount")
public Result<String> login(@RequestBody @Validated @NotNull UserLoginByAccountDTO userLoginByAccountDTO) {
// 删除ThreadLocal存储信息
ThreadLocalUtil.remove();
// 查询用户是否存在
Optional<User> optionalUser = Optional.ofNullable(userService.getOne(new QueryWrapper<User>()
.eq("account", userLoginByAccountDTO.getAccount())));

@ -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);
}
}

@ -264,7 +264,7 @@ public class UserController {
return new Result<>(200, "取件成功", "");
}
// 用户代取快递
// 用户代取快递(finish)
@PostMapping("/pickUp")
public Result<String> pickUpExpress(@RequestBody @Validated PickUpExpressDTO pickUpExpressDTO) {
// 查询快递原主人信息
@ -286,7 +286,7 @@ public class UserController {
recordsQueryWrapper.eq("goods_id", goods.getId());
Records records = recordsService.getOne(recordsQueryWrapper);
if (records.getMark() == 1) {
return new Result<>(500, "快递已被签收", "");
return new Result<>(404, "快递已被签收", "");
}
records.setMark(1);
records.setAddresseeId(GetIdUtil.getId());

Loading…
Cancel
Save