From 42b288d23c17810f0a64dd4ac747f9d1d87ce3a9 Mon Sep 17 00:00:00 2001 From: yjxx <1055683039@qq.com> Date: Wed, 13 Nov 2024 15:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=84=E4=BB=B6=E5=92=8C=E6=94=B6=E4=BB=B6?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E6=98=AF=E5=90=8C=E4=B8=80=E4=B8=AA=E5=9C=B0?= =?UTF-8?q?=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTO/GoodsDTO.java | 4 ---- .../controller/UserController.java | 22 ++++++++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java b/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java index 69fb69b..5f892d5 100644 --- a/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java +++ b/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java @@ -27,8 +27,4 @@ public class GoodsDTO { @NotBlank(message = "运送地址不能为空") private String addressTo; - - @JsonSerialize(using = ToStringSerializer.class) - @NotNull - private Long expressId; } diff --git a/src/main/java/jty/expressdistributionsystem/controller/UserController.java b/src/main/java/jty/expressdistributionsystem/controller/UserController.java index 6ee55b8..4205aaa 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/UserController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/UserController.java @@ -4,7 +4,6 @@ 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 jakarta.validation.constraints.NotBlank; import jty.expressdistributionsystem.DTO.AddresseeDTO; import jty.expressdistributionsystem.DTO.GoodsDTO; import jty.expressdistributionsystem.DTO.PickUpExpressDTO; @@ -19,6 +18,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; @@ -105,9 +105,9 @@ public class UserController { return new Result<>(200, "消息查看成功", ""); } - // 用户新建快递地址 + // 用户新建快递地址(finish) @PostMapping("/addAddress") - public Result addAddress(@RequestBody @NotNull Address address) { + public Result addAddress(@RequestBody @Validated Address address) { // 查询快递地址是否已经存在 LambdaQueryWrapper
addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); addressLambdaQueryWrapper.eq(Address::getAddress, address.getAddress()); @@ -119,11 +119,11 @@ public class UserController { return new Result<>(200, "地址创建成功", ""); } - // 用户获取自己写过的地址 + // 用户获取自己写过的地址(finish) @GetMapping("/getAddress") - public Result> listAddress() { + public Result> listAddress(@RequestParam Long id) { LambdaQueryWrapper
addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); - addressLambdaQueryWrapper.eq(Address::getUserId, GetIdUtil.getId()) + addressLambdaQueryWrapper.eq(Address::getUserId, id) .orderByDesc(Address::getAddress); List
list = addressService.list(addressLambdaQueryWrapper); return new Result<>(200, "", list); @@ -154,6 +154,7 @@ public class UserController { if (getUser == null) { return new Result<>(404, "用户不存在", null); } + userLambdaQueryWrapper.clear(); // 判断地址是否存在 LambdaQueryWrapper
addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddressTo()); @@ -162,7 +163,7 @@ public class UserController { return new Result<>(404, "地址不存在", null); } // 如果寄件和收件是一个地方,禁止 - if(goodsDTO.getAddressFrom().equals(goodsDTO.getAddressTo())) { + if (goodsDTO.getAddressFrom().equals(goodsDTO.getAddressTo())) { return new Result<>(400, "寄件和收件不能是同一个地方", null); } // 生成快递码 @@ -182,7 +183,12 @@ public class UserController { records.setGetUserId(getUser.getId()); records.setAddressId(address.getId()); records.setGoodsId(goods.getId()); - records.setExpressId(goodsDTO.getExpressId()); + // 系统自动分配快递员 + userLambdaQueryWrapper.eq(User::getMark, 1); + List list = userService.list(userLambdaQueryWrapper); + Collections.shuffle(list); + User user = list.get(0); + records.setExpressId(user.getId()); recordsService.save(records); Code code = new Code(); code.setClaim(claimCode);