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)
@ -110,7 +116,7 @@ public class MyController extends BaseController {
userRespDTO.setPoint(user.getPoint()); userRespDTO.setPoint(user.getPoint());
String invitationUserId = user.getInvitationUserId(); String invitationUserId = user.getInvitationUserId();
if(StringUtils.isNotEmpty(invitationUserId)) { if (StringUtils.isNotEmpty(invitationUserId)) {
UserInfo myInvitationUser = userInfoService.findById(invitationUserId); UserInfo myInvitationUser = userInfoService.findById(invitationUserId);
userRespDTO.setInvitationUserId(myInvitationUser.getId()); userRespDTO.setInvitationUserId(myInvitationUser.getId());
userRespDTO.setInvitationCode(myInvitationUser.getInvitationCode()); userRespDTO.setInvitationCode(myInvitationUser.getInvitationCode());
@ -129,7 +135,7 @@ public class MyController extends BaseController {
@PutMapping("/userInfo") @PutMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<List<String>> updateUserInfo(@RequestHeader(value = "Authorization", required = true) String authorization, public Result<List<String>> updateUserInfo(@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) { @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId()); UserInfo user = userInfoService.findById(userLoginDto.getUserId());
String nickName = EmojiConverterUtil.encode(userInfoUpdateDto.getNickName()); String nickName = EmojiConverterUtil.encode(userInfoUpdateDto.getNickName());
@ -157,7 +163,7 @@ public class MyController extends BaseController {
// 修改了性别 // 修改了性别
boolean isChangeSex = !Objects.equals(userInfoUpdateDto.getSex(), user.getSex()); boolean isChangeSex = !Objects.equals(userInfoUpdateDto.getSex(), user.getSex());
if(StringUtils.isNotBlank(userInfoUpdateDto.getInvitationCode()) && StringUtils.isBlank(user.getInvitationUserId())) { if (StringUtils.isNotBlank(userInfoUpdateDto.getInvitationCode()) && StringUtils.isBlank(user.getInvitationUserId())) {
// 只有没有被邀请过的才会触发,再次修改无效 // 只有没有被邀请过的才会触发,再次修改无效
userInfoService.bindInvitationCode(user, userInfoUpdateDto.getInvitationCode()); userInfoService.bindInvitationCode(user, userInfoUpdateDto.getInvitationCode());
} }
@ -184,22 +190,22 @@ public class MyController extends BaseController {
userInfoService.update(user); userInfoService.update(user);
List<String> resultList = new ArrayList<>(); List<String> resultList = new ArrayList<>();
if(isChangeNickName) { if (isChangeNickName) {
// 修改了昵称 // 修改了昵称
Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_NICKNAME, authorization); Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_NICKNAME, authorization);
resultList.add("修改了昵称,积分增加" + point + "分"); resultList.add("修改了昵称,积分增加" + point + "分");
} }
if(isChangeSignature) { if (isChangeSignature) {
// 修改了签名 // 修改了签名
Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_SIGNATURE, authorization); Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_SIGNATURE, authorization);
resultList.add("修改了签名,积分增加" + point + "分"); resultList.add("修改了签名,积分增加" + point + "分");
} }
if(isChangeBirthDay) { if (isChangeBirthDay) {
// 修改了生日 // 修改了生日
Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_BIRTHDAY, authorization); Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_BIRTHDAY, authorization);
resultList.add("修改了签名,积分增加" + point + "分"); resultList.add("修改了签名,积分增加" + point + "分");
} }
if(isChangeSex) { if (isChangeSex) {
// 修改了性别 // 修改了性别
Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_SEX, authorization); Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_SEX, authorization);
resultList.add("修改了签名,积分增加" + point + "分"); resultList.add("修改了签名,积分增加" + point + "分");
@ -632,7 +638,7 @@ public class MyController extends BaseController {
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
UserInfo userInfo = userInfoService.findById(userId); UserInfo userInfo = userInfoService.findById(userId);
if(Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.ACTIVE.getCode()) || Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.ACTIVE.getCode()) || Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) {
userInfo.setEnableComment(flag); userInfo.setEnableComment(flag);
userInfoService.update(userInfo); userInfoService.update(userInfo);
return Result.success(); return Result.success();
@ -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