优化用户收货地址修改默认属性业务,一个地址设置为默认其他地址同步设置非默认
This commit is contained in:
@@ -79,11 +79,8 @@
|
||||
@OperationLog
|
||||
@Operation(summary = "修改收货地址")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody ShopUserAddress shopUserAddress) {
|
||||
if (shopUserAddressService.updateById(shopUserAddress)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
public ApiResult<Boolean> update(@RequestBody ShopUserAddress shopUserAddress) {
|
||||
return success(shopUserAddressService.updateInfo(shopUserAddress));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:shopUserAddress:remove')")
|
||||
|
||||
@@ -55,4 +55,11 @@ public interface ShopUserAddressService extends IService<ShopUserAddress> {
|
||||
*/
|
||||
List<ShopUserAddress> getUserAddresses(Integer userId);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
* @param shopUserAddress
|
||||
* @return
|
||||
*/
|
||||
Boolean updateInfo(ShopUserAddress shopUserAddress);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,11 @@ import com.gxwebsoft.shop.entity.ShopUserAddress;
|
||||
import com.gxwebsoft.shop.param.ShopUserAddressParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -65,4 +68,25 @@ public class ShopUserAddressServiceImpl extends ServiceImpl<ShopUserAddressMappe
|
||||
return list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean updateInfo(ShopUserAddress shopUserAddress) {
|
||||
ShopUserAddress address = baseMapper.selectById(shopUserAddress.getId());
|
||||
if(address != null){
|
||||
if(shopUserAddress.getIsDefault()){
|
||||
List<ShopUserAddress> list = lambdaQuery().eq(ShopUserAddress::getIsDefault, true).eq(ShopUserAddress::getUserId, address.getUserId())
|
||||
.ne(ShopUserAddress::getId, address.getId()).list();
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
list.forEach(userAddress ->{
|
||||
userAddress.setIsDefault(false);
|
||||
});
|
||||
}
|
||||
updateBatchById(list);
|
||||
}
|
||||
shopUserAddress.setUpdateTime(LocalDateTime.now());
|
||||
return baseMapper.updateById(shopUserAddress) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user