release: 用户收货地址

release-2024-04-25
huangyw 3 months ago
parent 928bb1c436
commit f851ec4f22

@ -12,10 +12,13 @@ import com.luoo.user.dto.bank.UserBankAddDto;
import com.luoo.user.dto.request.LoginReq; import com.luoo.user.dto.request.LoginReq;
import com.luoo.user.dto.request.LogoffReq; import com.luoo.user.dto.request.LogoffReq;
import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.dto.userinfo.UserinfoShippingAddressAddDTO;
import com.luoo.user.dto.userinfo.UserinfoShippingAddressUpdateDTO;
import com.luoo.user.pojo.*; import com.luoo.user.pojo.*;
import com.luoo.user.service.*; import com.luoo.user.service.*;
import com.luoo.user.util.EmojiConverterUtil; import com.luoo.user.util.EmojiConverterUtil;
import com.luoo.user.util.IpUtil; import com.luoo.user.util.IpUtil;
import com.luoo.user.vo.userinfo.UserinfoShippingAddressAppVO;
import constants.Constants; import constants.Constants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import controller.BaseController; import controller.BaseController;
@ -88,6 +91,9 @@ public class MyController extends BaseController {
@Autowired @Autowired
private UserPointLogService userPointLogService; private UserPointLogService userPointLogService;
@Autowired
private UserinfoShippingAddressService userinfoShippingAddressService;
@ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息")
@GetMapping("/userInfo") @GetMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
@ -755,5 +761,43 @@ public class MyController extends BaseController {
return Result.success(userInfoService.createInvitationCode(authorization)); return Result.success(userInfoService.createInvitationCode(authorization));
} }
@ApiOperation(value = "19.1 获取用户收货地址列表")
@GetMapping("/address/list")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<List<UserinfoShippingAddressAppVO>> getUserinfoShippingAddressList(
@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) {
return Result.success(userinfoShippingAddressService.getUserinfoShippingAddressList());
}
@ApiOperation(value = "19.2 添加用户收货地址")
@PostMapping("/address/add")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> addUserinfoShippingAddress(
@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "添加用户收货地址对象", required = true) @Validated @RequestBody UserinfoShippingAddressAddDTO userinfoShippingAddressAddDTO) {
userinfoShippingAddressService.add(userinfoShippingAddressAddDTO);
return Result.success();
}
@ApiOperation(value = "19.3 删除用户收货地址")
@PostMapping("/address/del/{id}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> delUserinfoShippingAddress(
@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "用户收货地址id", required = true) @PathVariable String id) {
userinfoShippingAddressService.delete(id);
return Result.success();
}
@ApiOperation(value = "19.4 修改用户收货地址")
@PostMapping("/address/update")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> updateUserinfoShippingAddress(
@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "修改用户收货地址对象", required = true) @Validated @RequestBody UserinfoShippingAddressUpdateDTO userinfoShippingAddressUpdateDTO) {
userinfoShippingAddressService.update(userinfoShippingAddressUpdateDTO);
return Result.success();
}
} }

@ -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…
Cancel
Save