寄件和收件不能是同一个地方

grs
yjxx 1 week ago
parent ce7718f68c
commit 42b288d23c

@ -27,8 +27,4 @@ public class GoodsDTO {
@NotBlank(message = "运送地址不能为空") @NotBlank(message = "运送地址不能为空")
private String addressTo; private String addressTo;
@JsonSerialize(using = ToStringSerializer.class)
@NotNull
private Long expressId;
} }

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 jakarta.validation.constraints.NotBlank;
import jty.expressdistributionsystem.DTO.AddresseeDTO; import jty.expressdistributionsystem.DTO.AddresseeDTO;
import jty.expressdistributionsystem.DTO.GoodsDTO; import jty.expressdistributionsystem.DTO.GoodsDTO;
import jty.expressdistributionsystem.DTO.PickUpExpressDTO; import jty.expressdistributionsystem.DTO.PickUpExpressDTO;
@ -19,6 +18,7 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -105,9 +105,9 @@ public class UserController {
return new Result<>(200, "消息查看成功", ""); return new Result<>(200, "消息查看成功", "");
} }
// 用户新建快递地址 // 用户新建快递地址(finish)
@PostMapping("/addAddress") @PostMapping("/addAddress")
public Result<String> addAddress(@RequestBody @NotNull Address address) { public Result<String> addAddress(@RequestBody @Validated Address address) {
// 查询快递地址是否已经存在 // 查询快递地址是否已经存在
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
addressLambdaQueryWrapper.eq(Address::getAddress, address.getAddress()); addressLambdaQueryWrapper.eq(Address::getAddress, address.getAddress());
@ -119,11 +119,11 @@ public class UserController {
return new Result<>(200, "地址创建成功", ""); return new Result<>(200, "地址创建成功", "");
} }
// 用户获取自己写过的地址 // 用户获取自己写过的地址(finish)
@GetMapping("/getAddress") @GetMapping("/getAddress")
public Result<List<Address>> listAddress() { public Result<List<Address>> listAddress(@RequestParam Long id) {
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
addressLambdaQueryWrapper.eq(Address::getUserId, GetIdUtil.getId()) addressLambdaQueryWrapper.eq(Address::getUserId, id)
.orderByDesc(Address::getAddress); .orderByDesc(Address::getAddress);
List<Address> list = addressService.list(addressLambdaQueryWrapper); List<Address> list = addressService.list(addressLambdaQueryWrapper);
return new Result<>(200, "", list); return new Result<>(200, "", list);
@ -154,6 +154,7 @@ public class UserController {
if (getUser == null) { if (getUser == null) {
return new Result<>(404, "用户不存在", null); return new Result<>(404, "用户不存在", null);
} }
userLambdaQueryWrapper.clear();
// 判断地址是否存在 // 判断地址是否存在
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddressTo()); addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddressTo());
@ -182,7 +183,12 @@ public class UserController {
records.setGetUserId(getUser.getId()); records.setGetUserId(getUser.getId());
records.setAddressId(address.getId()); records.setAddressId(address.getId());
records.setGoodsId(goods.getId()); records.setGoodsId(goods.getId());
records.setExpressId(goodsDTO.getExpressId()); // 系统自动分配快递员
userLambdaQueryWrapper.eq(User::getMark, 1);
List<User> list = userService.list(userLambdaQueryWrapper);
Collections.shuffle(list);
User user = list.get(0);
records.setExpressId(user.getId());
recordsService.save(records); recordsService.save(records);
Code code = new Code(); Code code = new Code();
code.setClaim(claimCode); code.setClaim(claimCode);

Loading…
Cancel
Save