diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index e6b0547..3466952 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -12,10 +12,13 @@ import com.luoo.user.dto.bank.UserBankAddDto; import com.luoo.user.dto.request.LoginReq; import com.luoo.user.dto.request.LogoffReq; 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.service.*; import com.luoo.user.util.EmojiConverterUtil; import com.luoo.user.util.IpUtil; +import com.luoo.user.vo.userinfo.UserinfoShippingAddressAppVO; import constants.Constants; import constants.TaskPointIdConstants; import controller.BaseController; @@ -88,6 +91,9 @@ public class MyController extends BaseController { @Autowired private UserPointLogService userPointLogService; + @Autowired + private UserinfoShippingAddressService userinfoShippingAddressService; + @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @GetMapping("/userInfo") @GlobalInterceptor(checkAppUserLogin = true) @@ -110,7 +116,7 @@ public class MyController extends BaseController { userRespDTO.setPoint(user.getPoint()); String invitationUserId = user.getInvitationUserId(); - if(StringUtils.isNotEmpty(invitationUserId)) { + if (StringUtils.isNotEmpty(invitationUserId)) { UserInfo myInvitationUser = userInfoService.findById(invitationUserId); userRespDTO.setInvitationUserId(myInvitationUser.getId()); userRespDTO.setInvitationCode(myInvitationUser.getInvitationCode()); @@ -129,7 +135,7 @@ public class MyController extends BaseController { @PutMapping("/userInfo") @GlobalInterceptor(checkAppUserLogin = true) public Result> updateUserInfo(@RequestHeader(value = "Authorization", required = true) String authorization, - @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) { + @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) { UserLoginDto userLoginDto = getUserLoginDto(authorization); UserInfo user = userInfoService.findById(userLoginDto.getUserId()); String nickName = EmojiConverterUtil.encode(userInfoUpdateDto.getNickName()); @@ -157,7 +163,7 @@ public class MyController extends BaseController { // 修改了性别 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()); } @@ -184,22 +190,22 @@ public class MyController extends BaseController { userInfoService.update(user); List resultList = new ArrayList<>(); - if(isChangeNickName) { + if (isChangeNickName) { // 修改了昵称 Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_NICKNAME, authorization); resultList.add("修改了昵称,积分增加" + point + "分"); } - if(isChangeSignature) { + if (isChangeSignature) { // 修改了签名 Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_SIGNATURE, authorization); resultList.add("修改了签名,积分增加" + point + "分"); } - if(isChangeBirthDay) { + if (isChangeBirthDay) { // 修改了生日 Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_BIRTHDAY, authorization); resultList.add("修改了签名,积分增加" + point + "分"); } - if(isChangeSex) { + if (isChangeSex) { // 修改了性别 Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_SEX, authorization); resultList.add("修改了签名,积分增加" + point + "分"); @@ -632,7 +638,7 @@ public class MyController extends BaseController { } String userId = userLoginDto.getUserId(); 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); userInfoService.update(userInfo); return Result.success(); @@ -755,5 +761,43 @@ public class MyController extends BaseController { return Result.success(userInfoService.createInvitationCode(authorization)); } + @ApiOperation(value = "19.1 获取用户收货地址列表") + @GetMapping("/address/list") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> 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 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 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 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(); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserinfoShippingAddressDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserinfoShippingAddressDao.java new file mode 100644 index 0000000..37219c7 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserinfoShippingAddressDao.java @@ -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, JpaSpecificationExecutor { + + +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/userinfo/UserinfoShippingAddressAddDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/userinfo/UserinfoShippingAddressAddDTO.java new file mode 100644 index 0000000..c7dab5c --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/userinfo/UserinfoShippingAddressAddDTO.java @@ -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; + +} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/dto/userinfo/UserinfoShippingAddressUpdateDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/userinfo/UserinfoShippingAddressUpdateDTO.java new file mode 100644 index 0000000..50e911f --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/userinfo/UserinfoShippingAddressUpdateDTO.java @@ -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; + +} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserinfoShippingAddress.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserinfoShippingAddress.java new file mode 100644 index 0000000..1647582 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserinfoShippingAddress.java @@ -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; + +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java b/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java new file mode 100644 index 0000000..463155d --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java @@ -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 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); + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/vo/userinfo/UserinfoShippingAddressAppVO.java b/luoo_user/src/main/java/com/luoo/user/vo/userinfo/UserinfoShippingAddressAppVO.java new file mode 100644 index 0000000..5fbd8fe --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/vo/userinfo/UserinfoShippingAddressAppVO.java @@ -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; + +}