release: 启用/停用 私信和评论

release-2024-08-08
huangyw 4 months ago
parent b9c84e8840
commit 5d53806ca7

@ -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<Void> 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<Void> 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]);
}

@ -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();
}

@ -15,4 +15,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface MembershipCodeDao extends JpaRepository<MembershipCode, String>, JpaSpecificationExecutor<MembershipCode> {
public MembershipCode findMembershipCodeByCodeAndStatus(String code, Integer status);
public MembershipCode findMembershipCodeByCode(String code);
}

@ -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-
*/

@ -180,6 +180,16 @@ public class UserInfo implements Serializable {
*/
private Integer enablePush;
/**
*
*/
private Integer enableComment;
/**
*
*/
private Integer enableChat;
/**
*
*/

@ -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());

@ -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为启用 默认启用';

Loading…
Cancel
Save