|
|
@ -4,12 +4,16 @@ import com.luoo.user.dao.RegionDao;
|
|
|
|
import com.luoo.user.dao.UserinfoShippingAddressDao;
|
|
|
|
import com.luoo.user.dao.UserinfoShippingAddressDao;
|
|
|
|
import com.luoo.user.dto.userinfo.UserinfoShippingAddressAddDTO;
|
|
|
|
import com.luoo.user.dto.userinfo.UserinfoShippingAddressAddDTO;
|
|
|
|
import com.luoo.user.dto.userinfo.UserinfoShippingAddressUpdateDTO;
|
|
|
|
import com.luoo.user.dto.userinfo.UserinfoShippingAddressUpdateDTO;
|
|
|
|
|
|
|
|
import com.luoo.user.pojo.QRegion;
|
|
|
|
import com.luoo.user.pojo.QUserinfoShippingAddress;
|
|
|
|
import com.luoo.user.pojo.QUserinfoShippingAddress;
|
|
|
|
import com.luoo.user.pojo.UserinfoShippingAddress;
|
|
|
|
import com.luoo.user.pojo.UserinfoShippingAddress;
|
|
|
|
import com.luoo.user.vo.userinfo.UserinfoShippingAddressAppVO;
|
|
|
|
import com.luoo.user.vo.userinfo.UserinfoShippingAddressAppVO;
|
|
|
|
import com.querydsl.core.types.Projections;
|
|
|
|
import com.querydsl.core.types.Projections;
|
|
|
|
|
|
|
|
import com.querydsl.jpa.JPAExpressions;
|
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
|
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
|
|
|
import enums.UserInfoShippingAddressEnums;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@ -18,6 +22,7 @@ import util.JwtUtil;
|
|
|
|
import util.PropertyUtils;
|
|
|
|
import util.PropertyUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @program: luoo_parent
|
|
|
|
* @program: luoo_parent
|
|
|
@ -55,8 +60,9 @@ public class UserinfoShippingAddressService {
|
|
|
|
UserLoginDto user = jwtUtil.getUser();
|
|
|
|
UserLoginDto user = jwtUtil.getUser();
|
|
|
|
|
|
|
|
|
|
|
|
QUserinfoShippingAddress qUserinfoShippingAddress = QUserinfoShippingAddress.userinfoShippingAddress;
|
|
|
|
QUserinfoShippingAddress qUserinfoShippingAddress = QUserinfoShippingAddress.userinfoShippingAddress;
|
|
|
|
|
|
|
|
QRegion qRegion = QRegion.region;
|
|
|
|
|
|
|
|
|
|
|
|
List<UserinfoShippingAddressAppVO> fetch = jpaQueryFactory.select(Projections.constructor(UserinfoShippingAddressAppVO.class,
|
|
|
|
return jpaQueryFactory.select(Projections.constructor(UserinfoShippingAddressAppVO.class,
|
|
|
|
qUserinfoShippingAddress.id,
|
|
|
|
qUserinfoShippingAddress.id,
|
|
|
|
qUserinfoShippingAddress.address,
|
|
|
|
qUserinfoShippingAddress.address,
|
|
|
|
qUserinfoShippingAddress.acquiesce,
|
|
|
|
qUserinfoShippingAddress.acquiesce,
|
|
|
@ -64,16 +70,13 @@ public class UserinfoShippingAddressService {
|
|
|
|
qUserinfoShippingAddress.cityId,
|
|
|
|
qUserinfoShippingAddress.cityId,
|
|
|
|
qUserinfoShippingAddress.districtId,
|
|
|
|
qUserinfoShippingAddress.districtId,
|
|
|
|
qUserinfoShippingAddress.consignee,
|
|
|
|
qUserinfoShippingAddress.consignee,
|
|
|
|
qUserinfoShippingAddress.phone
|
|
|
|
qUserinfoShippingAddress.phone,
|
|
|
|
)).from(qUserinfoShippingAddress).
|
|
|
|
JPAExpressions.select(qRegion).from(qRegion).where(qRegion.id.eq(qUserinfoShippingAddress.provinceId)),
|
|
|
|
where(qUserinfoShippingAddress.userId.eq(user.getUserId()))
|
|
|
|
JPAExpressions.select(qRegion).from(qRegion).where(qRegion.id.eq(qUserinfoShippingAddress.cityId)),
|
|
|
|
|
|
|
|
JPAExpressions.select(qRegion).from(qRegion).where(qRegion.id.eq(qUserinfoShippingAddress.districtId))
|
|
|
|
|
|
|
|
)).from(qUserinfoShippingAddress)
|
|
|
|
|
|
|
|
.where(qUserinfoShippingAddress.userId.eq(user.getUserId()))
|
|
|
|
.fetch();
|
|
|
|
.fetch();
|
|
|
|
fetch.forEach(item -> {
|
|
|
|
|
|
|
|
item.setProvinceRegion(item.getProvinceId() != null ? regionDao.getOne(item.getProvinceId()) : null);
|
|
|
|
|
|
|
|
item.setCityRegion(item.getCityId() != null ? regionDao.getOne(item.getCityId()) : null);
|
|
|
|
|
|
|
|
item.setDistrictRegion(item.getDistrictId() != null ? regionDao.getOne(item.getDistrictId()) : null);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return fetch;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@ -84,7 +87,14 @@ public class UserinfoShippingAddressService {
|
|
|
|
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUser();
|
|
|
|
UserLoginDto user = jwtUtil.getUser();
|
|
|
|
userinfoShippingAddress.setUserId(user.getUserId());
|
|
|
|
userinfoShippingAddress.setUserId(user.getUserId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<UserinfoShippingAddress> checkList = userinfoShippingAddressDao.findByUserIdAndAcquiesce(user.getUserId(), UserInfoShippingAddressEnums.DEFAULT_ADDRESS.getCode());
|
|
|
|
|
|
|
|
if(checkList.isEmpty()) {
|
|
|
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
|
|
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 请勿重复添加默认地址!
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.DEFAULT_ADDRESS_CANNOT_BE_ADDED_AGAIN);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@ -97,7 +107,20 @@ public class UserinfoShippingAddressService {
|
|
|
|
UserLoginDto user = jwtUtil.getUser();
|
|
|
|
UserLoginDto user = jwtUtil.getUser();
|
|
|
|
userinfoShippingAddress.setUserId(user.getUserId());
|
|
|
|
userinfoShippingAddress.setUserId(user.getUserId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(UserInfoShippingAddressEnums.NORMAL_ADDRESS.getCode(), userinfoShippingAddress.getAcquiesce())) {
|
|
|
|
|
|
|
|
// 如果是非默认地址,直接保存即可
|
|
|
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
|
|
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果是默认地址,将原先的默认地址改为非默认地址
|
|
|
|
|
|
|
|
List<UserinfoShippingAddress> checkList = userinfoShippingAddressDao.findByUserIdAndAcquiesceAndIdIsNot(user.getUserId(), UserInfoShippingAddressEnums.DEFAULT_ADDRESS.getCode(), userinfoShippingAddress.getId());
|
|
|
|
|
|
|
|
if(!checkList.isEmpty()) {
|
|
|
|
|
|
|
|
checkList.forEach(item -> {
|
|
|
|
|
|
|
|
item.setAcquiesce(UserInfoShippingAddressEnums.NORMAL_ADDRESS.getCode());
|
|
|
|
|
|
|
|
userinfoShippingAddressDao.save(item);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|