parent
928bb1c436
commit
f851ec4f22
@ -0,0 +1,16 @@
|
|||||||
|
package com.luoo.user.dao;
|
||||||
|
|
||||||
|
import com.luoo.user.pojo.UserinfoShippingAddress;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @program: luoo_parent
|
||||||
|
* @description: 用户收货地址
|
||||||
|
* @author: yawei.huang
|
||||||
|
* @create: 2024-08-19 09:51
|
||||||
|
**/
|
||||||
|
public interface UserinfoShippingAddressDao extends JpaRepository<UserinfoShippingAddress, String>, JpaSpecificationExecutor<UserinfoShippingAddress> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.luoo.user.dto.userinfo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DTO for {@link com.luoo.user.pojo.UserinfoShippingAddress}
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UserinfoShippingAddressAddDTO implements Serializable {
|
||||||
|
private static final long serialVersionUID = -8566097448639271806L;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "收货地址")
|
||||||
|
@NotBlank
|
||||||
|
String address;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否默认地址 1-是 2-否")
|
||||||
|
Integer acquiesce;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.luoo.user.dto.userinfo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DTO for {@link com.luoo.user.pojo.UserinfoShippingAddress}
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UserinfoShippingAddressUpdateDTO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6209553882050635563L;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
@NotBlank
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "收货地址")
|
||||||
|
@NotBlank
|
||||||
|
String address;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否默认地址 1-是 2-否")
|
||||||
|
Integer acquiesce;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.luoo.user.pojo;
|
||||||
|
|
||||||
|
import com.luoo.user.config.JPABasePojo;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @program: luoo_parent
|
||||||
|
* @description: 用户收货地址
|
||||||
|
* @author: yawei.huang
|
||||||
|
* @create: 2024-08-19 09:49
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@DynamicUpdate
|
||||||
|
@Where(clause = "del_flag = 0")
|
||||||
|
@Table(name = "tb_userinfo_shipping_address")
|
||||||
|
public class UserinfoShippingAddress extends JPABasePojo {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1087882778774562914L;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "收货地址")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否默认地址 1-是 2-否")
|
||||||
|
private Integer acquiesce;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
package com.luoo.user.service;
|
||||||
|
|
||||||
|
import com.luoo.user.dao.UserinfoShippingAddressDao;
|
||||||
|
import com.luoo.user.dto.userinfo.UserinfoShippingAddressAddDTO;
|
||||||
|
import com.luoo.user.dto.userinfo.UserinfoShippingAddressUpdateDTO;
|
||||||
|
import com.luoo.user.pojo.QUserinfoShippingAddress;
|
||||||
|
import com.luoo.user.pojo.UserinfoShippingAddress;
|
||||||
|
import com.luoo.user.vo.userinfo.UserinfoShippingAddressAppVO;
|
||||||
|
import com.querydsl.core.types.Projections;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import dto.UserLoginDto;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import util.IdWorker;
|
||||||
|
import util.JwtUtil;
|
||||||
|
import util.PropertyUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @program: luoo_parent
|
||||||
|
* @description: 用户收货地址
|
||||||
|
* @author: yawei.huang
|
||||||
|
* @create: 2024-08-19 09:53
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class UserinfoShippingAddressService {
|
||||||
|
|
||||||
|
private final UserinfoShippingAddressDao userinfoShippingAddressDao;
|
||||||
|
|
||||||
|
private final IdWorker idWorker;
|
||||||
|
|
||||||
|
private final JwtUtil jwtUtil;
|
||||||
|
|
||||||
|
private final JPAQueryFactory jpaQueryFactory;
|
||||||
|
|
||||||
|
public UserinfoShippingAddressService(JwtUtil jwtUtil, IdWorker idWorker, UserinfoShippingAddressDao userinfoShippingAddressDao, JPAQueryFactory jpaQueryFactory) {
|
||||||
|
this.jwtUtil = jwtUtil;
|
||||||
|
this.idWorker = idWorker;
|
||||||
|
this.userinfoShippingAddressDao = userinfoShippingAddressDao;
|
||||||
|
this.jpaQueryFactory = jpaQueryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前登录用户的收货地址
|
||||||
|
*
|
||||||
|
* @return 收货地址
|
||||||
|
*/
|
||||||
|
public List<UserinfoShippingAddressAppVO> getUserinfoShippingAddressList() {
|
||||||
|
UserLoginDto user = jwtUtil.getUser();
|
||||||
|
|
||||||
|
QUserinfoShippingAddress qUserinfoShippingAddress = QUserinfoShippingAddress.userinfoShippingAddress;
|
||||||
|
|
||||||
|
return jpaQueryFactory.select(Projections.constructor(UserinfoShippingAddressAppVO.class,
|
||||||
|
qUserinfoShippingAddress.id,
|
||||||
|
qUserinfoShippingAddress.address,
|
||||||
|
qUserinfoShippingAddress.acquiesce
|
||||||
|
)).from(qUserinfoShippingAddress).
|
||||||
|
where(qUserinfoShippingAddress.userId.eq(user.getUserId()))
|
||||||
|
.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void add(UserinfoShippingAddressAddDTO userinfoShippingAddressAddDTO) {
|
||||||
|
UserinfoShippingAddress userinfoShippingAddress = new UserinfoShippingAddress();
|
||||||
|
BeanUtils.copyProperties(userinfoShippingAddressAddDTO, userinfoShippingAddress);
|
||||||
|
userinfoShippingAddress.setId(idWorker.nextId() + "");
|
||||||
|
|
||||||
|
UserLoginDto user = jwtUtil.getUser();
|
||||||
|
userinfoShippingAddress.setUserId(user.getUserId());
|
||||||
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void update(UserinfoShippingAddressUpdateDTO userinfoShippingAddressUpdateDTO) {
|
||||||
|
UserinfoShippingAddress userinfoShippingAddress = userinfoShippingAddressDao.findById(userinfoShippingAddressUpdateDTO.getId()).get();
|
||||||
|
// 拷贝时忽略null
|
||||||
|
String[] names = PropertyUtils.getNullPropertyNamesForJpa(userinfoShippingAddress);
|
||||||
|
BeanUtils.copyProperties(userinfoShippingAddressUpdateDTO, userinfoShippingAddress);
|
||||||
|
|
||||||
|
UserLoginDto user = jwtUtil.getUser();
|
||||||
|
userinfoShippingAddress.setUserId(user.getUserId());
|
||||||
|
|
||||||
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void delete(String id) {
|
||||||
|
UserinfoShippingAddress userinfoShippingAddress = userinfoShippingAddressDao.findById(id).get();
|
||||||
|
userinfoShippingAddress.setDelFlag(2);
|
||||||
|
userinfoShippingAddressDao.save(userinfoShippingAddress);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.luoo.user.vo.userinfo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DTO for {@link com.luoo.user.pojo.UserinfoShippingAddress}
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UserinfoShippingAddressAppVO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6980350918589532593L;
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
String id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "收货地址")
|
||||||
|
String address;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否默认地址 1-是 2-否")
|
||||||
|
Integer acquiesce;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue