mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
fix: 新增和修改会员地址问题修复
This commit is contained in:
parent
a2b4f38526
commit
eebfdd48e4
@ -1,13 +1,6 @@
|
||||
package com.youlai.mall.ums.dto;
|
||||
|
||||
import com.youlai.common.constraint.CheckCityValid;
|
||||
import com.youlai.common.constraint.CityType;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Positive;
|
||||
|
||||
/**
|
||||
* 会员地址传输层对象
|
||||
@ -18,25 +11,20 @@ import javax.validation.constraints.Positive;
|
||||
@Data
|
||||
public class MemberAddressDTO {
|
||||
|
||||
@NotNull(message = "{id.positive}")
|
||||
@Positive(message = "{id.positive}")
|
||||
private Long id;
|
||||
|
||||
private Long memberId;
|
||||
|
||||
private String consigneeName;
|
||||
|
||||
@Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "{phone.valid}")
|
||||
private String consigneeMobile;
|
||||
|
||||
@CheckCityValid(CityType.PROVINCE)
|
||||
private String province;
|
||||
|
||||
@CheckCityValid(CityType.CITY)
|
||||
private String city;
|
||||
|
||||
@CheckCityValid(CityType.AREA)
|
||||
private String area;
|
||||
|
||||
@Length(min = 1, max = 100, message = "{text.length.min},{text.length.max}")
|
||||
private String detailAddress;
|
||||
|
||||
private Integer defaulted;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.youlai.mall.ums.controller.app;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.web.util.MemberUtils;
|
||||
import com.youlai.mall.ums.dto.MemberAddressDTO;
|
||||
import com.youlai.mall.ums.pojo.entity.UmsAddress;
|
||||
import com.youlai.mall.ums.pojo.form.AddressForm;
|
||||
import com.youlai.mall.ums.service.IUmsAddressService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -43,9 +42,9 @@ public class AddressController {
|
||||
@ApiOperation(value = "新增地址")
|
||||
@PostMapping
|
||||
public Result addAddress(
|
||||
@RequestBody @Validated UmsAddress address
|
||||
@RequestBody @Validated AddressForm addressForm
|
||||
) {
|
||||
boolean result = addressService.addAddress(address);
|
||||
boolean result = addressService.addAddress(addressForm);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ -53,9 +52,9 @@ public class AddressController {
|
||||
@PutMapping("/{addressId}")
|
||||
public Result updateAddress(
|
||||
@ApiParam(value = "地址ID") @PathVariable Long addressId,
|
||||
@RequestBody @Validated UmsAddress address
|
||||
@RequestBody @Validated AddressForm addressForm
|
||||
) {
|
||||
boolean result = addressService.updateAddress(address);
|
||||
boolean result = addressService.updateAddress(addressForm);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.youlai.mall.ums.pojo.form;
|
||||
|
||||
import com.youlai.common.constraint.CheckCityValid;
|
||||
import com.youlai.common.constraint.CityType;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Positive;
|
||||
|
||||
/**
|
||||
* 地址表单对象
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2022/2/12 15:57
|
||||
*/
|
||||
@ApiModel("地址表单对象")
|
||||
@Data
|
||||
public class AddressForm {
|
||||
|
||||
@ApiModelProperty("地址ID")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("收货人姓名")
|
||||
private String consigneeName;
|
||||
|
||||
@ApiModelProperty("收货人手机号")
|
||||
@Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "{phone.valid}")
|
||||
private String consigneeMobile;
|
||||
|
||||
@ApiModelProperty("省")
|
||||
@CheckCityValid(CityType.PROVINCE)
|
||||
private String province;
|
||||
|
||||
@ApiModelProperty("市")
|
||||
@CheckCityValid(CityType.CITY)
|
||||
private String city;
|
||||
|
||||
@ApiModelProperty("区")
|
||||
@CheckCityValid(CityType.AREA)
|
||||
private String area;
|
||||
|
||||
@ApiModelProperty("详细地址")
|
||||
@Length(min = 1, max = 100, message = "{text.length.min},{text.length.max}")
|
||||
private String detailAddress;
|
||||
|
||||
@ApiModelProperty("是否默认地址(1:是;0:否)")
|
||||
private Integer defaulted;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ package com.youlai.mall.ums.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.mall.ums.dto.MemberAddressDTO;
|
||||
import com.youlai.mall.ums.pojo.entity.UmsAddress;
|
||||
import com.youlai.mall.ums.pojo.form.AddressForm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -16,20 +17,20 @@ import java.util.List;
|
||||
public interface IUmsAddressService extends IService<UmsAddress> {
|
||||
|
||||
/**
|
||||
* 添加地址
|
||||
* 新增地址
|
||||
*
|
||||
* @param address
|
||||
* @param addressForm
|
||||
* @return
|
||||
*/
|
||||
boolean addAddress(UmsAddress address);
|
||||
boolean addAddress(AddressForm addressForm);
|
||||
|
||||
/**
|
||||
* 修改地址
|
||||
*
|
||||
* @param address
|
||||
* @param addressForm
|
||||
* @return
|
||||
*/
|
||||
boolean updateAddress(UmsAddress address);
|
||||
boolean updateAddress(AddressForm addressForm);
|
||||
|
||||
/**
|
||||
* 获取当前登录会员的地址列表
|
||||
|
@ -9,9 +9,10 @@ import com.youlai.common.web.util.MemberUtils;
|
||||
import com.youlai.mall.ums.dto.MemberAddressDTO;
|
||||
import com.youlai.mall.ums.mapper.UmsAddressMapper;
|
||||
import com.youlai.mall.ums.pojo.entity.UmsAddress;
|
||||
import com.youlai.mall.ums.pojo.form.AddressForm;
|
||||
import com.youlai.mall.ums.service.IUmsAddressService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -28,43 +29,59 @@ import java.util.stream.Collectors;
|
||||
public class UmsAddressServiceImpl extends ServiceImpl<UmsAddressMapper, UmsAddress> implements IUmsAddressService {
|
||||
|
||||
/**
|
||||
* 添加地址
|
||||
* 新增地址
|
||||
*
|
||||
* @param address
|
||||
* @param addressForm
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean addAddress(UmsAddress address) {
|
||||
@Transactional
|
||||
public boolean addAddress(AddressForm addressForm) {
|
||||
Long memberId = MemberUtils.getMemberId();
|
||||
address.setMemberId(memberId);
|
||||
if (GlobalConstants.STATUS_YES.equals(address.getDefaulted())) { // 修改其他默认地址为非默认
|
||||
|
||||
UmsAddress umsAddress = new UmsAddress();
|
||||
BeanUtil.copyProperties(addressForm, umsAddress);
|
||||
umsAddress.setMemberId(memberId);
|
||||
boolean result = this.save(umsAddress);
|
||||
if (result) {
|
||||
// 修改其他默认地址为非默认
|
||||
if (GlobalConstants.STATUS_YES.equals(addressForm.getDefaulted())) {
|
||||
this.update(new LambdaUpdateWrapper<UmsAddress>()
|
||||
.eq(UmsAddress::getMemberId, memberId)
|
||||
.eq(UmsAddress::getDefaulted, 1)
|
||||
.set(UmsAddress::getDefaulted, 0)
|
||||
);
|
||||
}
|
||||
return this.save(address);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改地址
|
||||
*
|
||||
* @param address
|
||||
* @param addressForm
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updateAddress(UmsAddress address) {
|
||||
public boolean updateAddress(AddressForm addressForm) {
|
||||
Long memberId = MemberUtils.getMemberId();
|
||||
|
||||
UmsAddress umsAddress = new UmsAddress();
|
||||
BeanUtil.copyProperties(addressForm, umsAddress);
|
||||
|
||||
boolean result = this.updateById(umsAddress);
|
||||
|
||||
if(result){
|
||||
// 修改其他默认地址为非默认
|
||||
if (GlobalConstants.STATUS_YES.equals(address.getDefaulted())) {
|
||||
if (GlobalConstants.STATUS_YES.equals(addressForm.getDefaulted())) {
|
||||
this.update(new LambdaUpdateWrapper<UmsAddress>()
|
||||
.eq(UmsAddress::getMemberId, memberId)
|
||||
.eq(UmsAddress::getDefaulted, 1)
|
||||
.set(UmsAddress::getDefaulted, 0)
|
||||
);
|
||||
}
|
||||
return this.updateById(address);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user