所有项目完成!

grs
yjxx 2 weeks 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) // 通过账号登录(finish)
@PostMapping("/loginByAccount") @PostMapping("/loginByAccount")
public Result<String> login(@RequestBody @Validated @NotNull UserLoginByAccountDTO userLoginByAccountDTO) { public Result<String> login(@RequestBody @Validated @NotNull UserLoginByAccountDTO userLoginByAccountDTO) {
// 删除ThreadLocal存储信息
ThreadLocalUtil.remove();
// 查询用户是否存在 // 查询用户是否存在
Optional<User> optionalUser = Optional.ofNullable(userService.getOne(new QueryWrapper<User>() Optional<User> optionalUser = Optional.ofNullable(userService.getOne(new QueryWrapper<User>()
.eq("account", userLoginByAccountDTO.getAccount()))); .eq("account", userLoginByAccountDTO.getAccount())));

@ -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, "发送成功", "");
} }
} }

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

Loading…
Cancel
Save