|
|
@@ -52,6 +52,7 @@ public class AddressController {
|
|
|
if(address.getIsDefault() != null && address.getIsDefault() ){
|
|
|
addressService.update(Wrappers.lambdaUpdate(Address.class).in(Address::getUserId,userIdList).set(Address::getIsDefault,false));
|
|
|
}
|
|
|
+ address.setId(null);
|
|
|
address.setUserId(userId);
|
|
|
addressService.save(address);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(address);
|
|
|
@@ -63,11 +64,34 @@ public class AddressController {
|
|
|
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- if(address.getIsDefault() != null && address.getIsDefault() ){
|
|
|
- addressService.update(Wrappers.lambdaUpdate(Address.class).in(Address::getUserId,userIdList).set(Address::getIsDefault,false));
|
|
|
+ if (address.getId() == null || userIdList == null || userIdList.isEmpty()) {
|
|
|
+ throw new BusinessRuntimeException("地址不存在或无权操作");
|
|
|
}
|
|
|
-
|
|
|
- addressService.updateById(address);
|
|
|
+ Address existing = addressService.getOne(Wrappers.lambdaQuery(Address.class)
|
|
|
+ .eq(Address::getId, address.getId()).in(Address::getUserId, userIdList));
|
|
|
+ if (existing == null) {
|
|
|
+ throw new BusinessRuntimeException("地址不存在或无权操作");
|
|
|
+ }
|
|
|
+ // 只复制允许编辑的字段,拒绝userId和BaseEntity字段的批量赋值。
|
|
|
+ Address changes = new Address();
|
|
|
+ changes.setReceiver(address.getReceiver());
|
|
|
+ changes.setPhone(address.getPhone());
|
|
|
+ changes.setProvince(address.getProvince());
|
|
|
+ changes.setCity(address.getCity());
|
|
|
+ changes.setDistrict(address.getDistrict());
|
|
|
+ changes.setAddress(address.getAddress());
|
|
|
+ changes.setCode(address.getCode());
|
|
|
+ changes.setIsDefault(address.getIsDefault());
|
|
|
+ if (!addressService.update(changes, Wrappers.lambdaUpdate(Address.class)
|
|
|
+ .eq(Address::getId, existing.getId()).in(Address::getUserId, userIdList))) {
|
|
|
+ throw new BusinessRuntimeException("地址不存在或无权操作");
|
|
|
+ }
|
|
|
+ if (Boolean.TRUE.equals(address.getIsDefault())) {
|
|
|
+ addressService.update(Wrappers.lambdaUpdate(Address.class)
|
|
|
+ .in(Address::getUserId, userIdList).ne(Address::getId, existing.getId())
|
|
|
+ .set(Address::getIsDefault, false));
|
|
|
+ }
|
|
|
+ address = addressService.getById(existing.getId());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(address);
|
|
|
}
|
|
|
|