From 5d53806ca7a3d4ea79e78b472d206681e69e5bd6 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Mon, 5 Aug 2024 14:40:05 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E5=90=AF=E7=94=A8/=E5=81=9C?= =?UTF-8?q?=E7=94=A8=20=E7=A7=81=E4=BF=A1=E5=92=8C=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/MyController.java | 34 +++++++++++++++++++ .../controller/UserMessageController.java | 22 +++++++----- .../com/luoo/user/dao/MembershipCodeDao.java | 2 ++ .../luoo/user/dto/response/UserRespDTO.java | 12 +++++++ .../java/com/luoo/user/pojo/UserInfo.java | 10 ++++++ .../user/service/MembershipCodeService.java | 15 +++++--- luoo_user/src/main/resources/sql/20240802.sql | 4 +++ 7 files changed, 85 insertions(+), 14 deletions(-) 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 2442cda..c36be09 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 @@ -592,6 +592,40 @@ public class MyController extends BaseController { return Result.success(); } + @ApiOperation(value = "14.3 启用/停用 私信, 0为停用,1为启用", notes = "启用/停用 私信, 0为停用,1为启用") + @PutMapping("/enableChat/{flag}") + public Result updateEnableChat(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setEnableChat(flag); + userInfoService.update(userInfo); + return Result.success(); + } + + @ApiOperation(value = "14.4 是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论", notes = "是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论") + @PutMapping("/enableComment/{flag}") + public Result updateEnableComment(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + if(Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.ACTIVE.getCode()) || Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { + userInfo.setEnableComment(flag); + userInfoService.update(userInfo); + return Result.success(); + } else { + return Result.failed("会员专享,非会员不允许修改"); + } + } + private Integer getIndex(UserInfo u) { return Integer.valueOf(Arrays.stream(u.getBadges().split(",")).filter(s -> s.startsWith(String.valueOf(UserBadgeEnum.CONTRIBUTOR.getCode()))).findFirst().get().split("_")[1]); } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java index b96aa7b..866f55d 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java @@ -49,15 +49,19 @@ public class UserMessageController extends BaseController { } String userId = userLoginDto.getUserId(); UserInfo userInfo = userInfoService.findById(userId); - UserMessageDto userMessageDto = new UserMessageDto(); - userMessageDto.setType(MessageTypeEnum.PRIVATE_MESSAGE.getType()); - userMessageDto.setSendUserId(userId); - userMessageDto.setTitle(userInfo.getNickName()+" 给您发了新消息"); - userMessageDto.setContent(content); - userMessageDto.setUserId(receiveUserId); - userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar()); - userMessageDto.setSendUserNickName(userInfo.getNickName()); - userMessageService.sendUserMessage(userMessageDto); + + if(userInfo.getEnableChat() == 1) { + // 如果允许私信的话 + UserMessageDto userMessageDto = new UserMessageDto(); + userMessageDto.setType(MessageTypeEnum.PRIVATE_MESSAGE.getType()); + userMessageDto.setSendUserId(userId); + userMessageDto.setTitle(userInfo.getNickName()+" 给您发了新消息"); + userMessageDto.setContent(content); + userMessageDto.setUserId(receiveUserId); + userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar()); + userMessageDto.setSendUserNickName(userInfo.getNickName()); + userMessageService.sendUserMessage(userMessageDto); + } return Result.success(); } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/MembershipCodeDao.java b/luoo_user/src/main/java/com/luoo/user/dao/MembershipCodeDao.java index 2624342..def7944 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/MembershipCodeDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/MembershipCodeDao.java @@ -15,4 +15,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; public interface MembershipCodeDao extends JpaRepository, JpaSpecificationExecutor { public MembershipCode findMembershipCodeByCodeAndStatus(String code, Integer status); + + public MembershipCode findMembershipCodeByCode(String code); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index ec78785..a72eb79 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -74,6 +74,18 @@ public class UserRespDTO implements Serializable { @ApiModelProperty(value = "是否启用推送,0为关闭,1为启用,默认启用") private Integer enablePush; + /** + * 是否关闭评论 + */ + @ApiModelProperty(value = "是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论") + private Integer enableComment; + + /** + * 是否允许私信 + */ + @ApiModelProperty(value = "是否允许私信,0为关闭,1为启用,默认启用") + private Integer enableChat; + /** * 会员状态 0-未开通 1-生效中 2-已过期 3-永久会员 */ diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java index 7b6ced6..4ec2529 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java @@ -180,6 +180,16 @@ public class UserInfo implements Serializable { */ private Integer enablePush; + /** + * 是否关闭评论 + */ + private Integer enableComment; + + /** + * 是否允许私信 + */ + private Integer enableChat; + /** * 登录用户名 */ diff --git a/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java b/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java index dc4e9da..af11b1d 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java @@ -23,6 +23,7 @@ import javax.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -81,8 +82,12 @@ public class MembershipCodeService { public String generateMembershipCode(String token, Integer duration, Integer life) { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - // UUID作为会员码 - String code = UUID.randomUUID().toString(); + // 8位随机数字作为会员码 + String code = RandomStringUtils.randomNumeric(8); + while (membershipCodeDao.findMembershipCodeByCode(code) != null) { + code = RandomStringUtils.randomNumeric(8); + } + MembershipCode build = MembershipCode.builder() .id(String.valueOf(idWorker.nextId())) .code(code) @@ -146,7 +151,7 @@ public class MembershipCodeService { UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); String result = ""; - if (userInfo.getVipStatus() == UserVipStatusEnum.INITIAL.getCode()) { + if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.INITIAL.getCode())) { // 首次开通会员 Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.BUY_MEMBER, token); result = "首次开通会员,积分增加" + point + "分"; @@ -159,8 +164,8 @@ public class MembershipCodeService { // 非永久会员码 // 计算会员到期时间 LocalDate vipExpireTime; - if (Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) { - vipExpireTime = userInfo.getVipExpireTime().plusDays(membershipCode.getDuration()); + if (!Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) { + vipExpireTime = (userInfo.getVipExpireTime() == null ? LocalDate.now() : userInfo.getVipExpireTime()).plusDays(membershipCode.getDuration()); } else { // 从今天开始,增加membershipCode的duration天 userInfo.setVipStatus(UserVipStatusEnum.INITIAL.getCode()); diff --git a/luoo_user/src/main/resources/sql/20240802.sql b/luoo_user/src/main/resources/sql/20240802.sql index df8c2cc..7ede2ae 100644 --- a/luoo_user/src/main/resources/sql/20240802.sql +++ b/luoo_user/src/main/resources/sql/20240802.sql @@ -13,5 +13,9 @@ create index tb_user_point_log_task_point_id_index create index tb_user_point_log_user_id_index on tb_user_point_log (user_id); +alter table tb_user_info + add enable_comment int null comment '是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论'; +alter table tb_user_info + add enable_chat int null comment '是否允许私信 0为关闭 1为启用 默认启用';