Merge branch 'feature/community-center' into preview
commit
b1b884a82e
|
@ -2,13 +2,16 @@ package com.mcwl.web.controller.communityCenter;
|
||||||
|
|
||||||
|
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
import com.mcwl.communityCenter.service.InviteMappingService;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.communityCenter.service.InviteService;
|
import com.mcwl.communityCenter.service.InviteService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邀请
|
* 邀请
|
||||||
*/
|
*/
|
||||||
|
@ -23,11 +26,28 @@ public class InviteController {
|
||||||
* 邀请码链接
|
* 邀请码链接
|
||||||
*/
|
*/
|
||||||
@GetMapping("inviteCode")
|
@GetMapping("inviteCode")
|
||||||
public AjaxResult inviteCode(){
|
public AjaxResult inviteCode(Long communityId) {
|
||||||
// 获取邀请码链接
|
// 获取邀请码链接
|
||||||
String inviteCode = inviteService.getInviteCode();
|
String inviteCode = inviteService.getInviteCode(communityId);
|
||||||
|
if (StringUtils.isBlank(inviteCode)) {
|
||||||
|
return AjaxResult.warn("获取邀请码失败");
|
||||||
|
}
|
||||||
return AjaxResult.success(inviteCode);
|
return AjaxResult.success(inviteCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接受邀请
|
||||||
|
*/
|
||||||
|
@GetMapping("acceptInvite")
|
||||||
|
public AjaxResult acceptInvite(@NotNull(message = "communityId不能为空") Long communityId,
|
||||||
|
@NotBlank(message = "inviteCode不能为空") String inviteCode) {
|
||||||
|
// 接受邀请
|
||||||
|
boolean result = inviteService.acceptInvite(communityId, inviteCode);
|
||||||
|
if (result) {
|
||||||
|
return AjaxResult.success("接受邀请成功");
|
||||||
|
}
|
||||||
|
return AjaxResult.warn("接受邀请失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.mcwl.communityCenter.constant;
|
||||||
|
|
||||||
|
public class InviteConstant {
|
||||||
|
/**
|
||||||
|
* 邀请类型 0普通用户
|
||||||
|
*/
|
||||||
|
public static final int INVITE_ADMIN = 1;
|
||||||
|
/**
|
||||||
|
* 邀请类型 1管理员
|
||||||
|
*/
|
||||||
|
public static final int INVITE_COMMON = 0;
|
||||||
|
/**
|
||||||
|
* 费用类型 0免费
|
||||||
|
*/
|
||||||
|
public static final int INVITE_FREE = 0;
|
||||||
|
/**
|
||||||
|
* 费用类型 1付费
|
||||||
|
*/
|
||||||
|
public static final int INVITE_FEE = 1;
|
||||||
|
}
|
|
@ -26,9 +26,13 @@ public class Invite extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private Long inviteeUserId;
|
private Long inviteeUserId;
|
||||||
/**
|
/**
|
||||||
* 受邀类型
|
* 受邀类型 0普通 1管理员
|
||||||
*/
|
*/
|
||||||
private String type;
|
private Integer type;
|
||||||
|
/**
|
||||||
|
* 费用类型 0免费 1付费
|
||||||
|
*/
|
||||||
|
private Integer feeType;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,27 +8,27 @@ import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邀请映射
|
* 邀请码映射
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("cc_invite_mapping")
|
@TableName("cc_invite_code_mapping")
|
||||||
public class InviteMapping extends BaseEntity {
|
public class InviteCodeMapping extends BaseEntity {
|
||||||
|
|
||||||
@TableId
|
@TableId
|
||||||
private String id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 用户id - 租户id
|
* 用户id
|
||||||
*/
|
*/
|
||||||
private String tenantId;
|
private Long userId;
|
||||||
/**
|
/**
|
||||||
* 邀请链接
|
* 邀请码
|
||||||
*/
|
*/
|
||||||
private String inviteUrl;
|
private String inviteCode;
|
||||||
/**
|
/**
|
||||||
* 状态
|
* 状态 1 可用 0 不可用
|
||||||
*/
|
*/
|
||||||
private String status;
|
private Integer status;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.mcwl.communityCenter.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.communityCenter.domain.InviteCodeMapping;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface InviteCodeMappingMapper extends BaseMapper<InviteCodeMapping> {
|
||||||
|
}
|
|
@ -1,9 +1,7 @@
|
||||||
package com.mcwl.communityCenter.mapper;
|
package com.mcwl.communityCenter.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.mcwl.communityCenter.domain.Community;
|
|
||||||
import com.mcwl.communityCenter.domain.Invite;
|
import com.mcwl.communityCenter.domain.Invite;
|
||||||
import com.mcwl.communityCenter.domain.InviteMapping;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package com.mcwl.communityCenter.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.mcwl.communityCenter.domain.Invite;
|
|
||||||
import com.mcwl.communityCenter.domain.InviteMapping;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface InviteMappingMapper extends BaseMapper<InviteMapping> {
|
|
||||||
}
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.mcwl.communityCenter.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.communityCenter.domain.InviteCodeMapping;
|
||||||
|
|
||||||
|
public interface InviteCodeMappingService extends IService<InviteCodeMapping> {
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
package com.mcwl.communityCenter.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.mcwl.communityCenter.domain.Invite;
|
|
||||||
import com.mcwl.communityCenter.domain.InviteMapping;
|
|
||||||
|
|
||||||
public interface InviteMappingService extends IService<InviteMapping> {
|
|
||||||
String getInviteCode();
|
|
||||||
}
|
|
|
@ -7,6 +7,23 @@ import com.mcwl.communityCenter.domain.Invite;
|
||||||
import com.mcwl.communityCenter.domain.Publish;
|
import com.mcwl.communityCenter.domain.Publish;
|
||||||
import com.mcwl.communityCenter.domain.vo.PublishVo;
|
import com.mcwl.communityCenter.domain.vo.PublishVo;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public interface InviteService extends IService<Invite> {
|
public interface InviteService extends IService<Invite> {
|
||||||
String getInviteCode();
|
|
||||||
|
/**
|
||||||
|
* 获取邀请码
|
||||||
|
* @param communityId 社区id
|
||||||
|
* @return 邀请码
|
||||||
|
*/
|
||||||
|
String getInviteCode(@NotNull(message = "communityId不能为空") Long communityId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接受邀请
|
||||||
|
* @param communityId 社区id
|
||||||
|
* @param inviteCode 邀请码
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean acceptInvite(@NotNull(message = "communityId不能为空") Long communityId, @NotBlank(message = "inviteCode不能为空") String inviteCode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mcwl.communityCenter.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.communityCenter.domain.InviteCodeMapping;
|
||||||
|
import com.mcwl.communityCenter.mapper.InviteCodeMappingMapper;
|
||||||
|
import com.mcwl.communityCenter.service.InviteCodeMappingService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class InviteCodeMappingServiceImpl extends ServiceImpl<InviteCodeMappingMapper, InviteCodeMapping>
|
||||||
|
implements InviteCodeMappingService {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
package com.mcwl.communityCenter.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.mcwl.communityCenter.domain.Invite;
|
|
||||||
import com.mcwl.communityCenter.domain.InviteMapping;
|
|
||||||
import com.mcwl.communityCenter.mapper.InviteMapper;
|
|
||||||
import com.mcwl.communityCenter.mapper.InviteMappingMapper;
|
|
||||||
import com.mcwl.communityCenter.service.InviteMappingService;
|
|
||||||
import com.mcwl.communityCenter.service.InviteService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class InviteMappingServiceImpl extends ServiceImpl<InviteMappingMapper, InviteMapping> implements InviteMappingService {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInviteCode() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return "https://aaa.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -9,13 +9,20 @@ import com.mcwl.common.constant.HttpStatus;
|
||||||
import com.mcwl.common.core.page.PageDomain;
|
import com.mcwl.common.core.page.PageDomain;
|
||||||
import com.mcwl.common.core.page.TableDataInfo;
|
import com.mcwl.common.core.page.TableDataInfo;
|
||||||
import com.mcwl.common.utils.SecurityUtils;
|
import com.mcwl.common.utils.SecurityUtils;
|
||||||
|
import com.mcwl.common.utils.ShareCodeUtils;
|
||||||
|
import com.mcwl.communityCenter.constant.InviteConstant;
|
||||||
import com.mcwl.communityCenter.domain.Invite;
|
import com.mcwl.communityCenter.domain.Invite;
|
||||||
|
import com.mcwl.communityCenter.domain.InviteCodeMapping;
|
||||||
import com.mcwl.communityCenter.domain.Publish;
|
import com.mcwl.communityCenter.domain.Publish;
|
||||||
|
import com.mcwl.communityCenter.domain.UserCommunity;
|
||||||
import com.mcwl.communityCenter.domain.vo.PublishVo;
|
import com.mcwl.communityCenter.domain.vo.PublishVo;
|
||||||
import com.mcwl.communityCenter.mapper.InviteMapper;
|
import com.mcwl.communityCenter.mapper.InviteMapper;
|
||||||
import com.mcwl.communityCenter.mapper.PublishMapper;
|
import com.mcwl.communityCenter.mapper.PublishMapper;
|
||||||
|
import com.mcwl.communityCenter.service.InviteCodeMappingService;
|
||||||
import com.mcwl.communityCenter.service.InviteService;
|
import com.mcwl.communityCenter.service.InviteService;
|
||||||
import com.mcwl.communityCenter.service.PublishService;
|
import com.mcwl.communityCenter.service.PublishService;
|
||||||
|
import com.mcwl.communityCenter.service.UserCommunityService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -23,10 +30,68 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> implements InviteService {
|
public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> implements InviteService {
|
||||||
|
|
||||||
|
private final UserCommunityService userCommunityService;
|
||||||
|
|
||||||
|
private final InviteCodeMappingService inviteCodeMappingService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInviteCode() {
|
public String getInviteCode(Long communityId) {
|
||||||
String url = "https://www.yaoqing.com?name=lisi";
|
|
||||||
return url;
|
|
||||||
|
// 查询用户的社区
|
||||||
|
UserCommunity userCommunity = userCommunityService.lambdaQuery()
|
||||||
|
.eq(UserCommunity::getCommunityId, communityId)
|
||||||
|
.one();
|
||||||
|
|
||||||
|
if (Objects.isNull(userCommunity)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String idCode = ShareCodeUtils.idToCode(SecurityUtils.getUserId());
|
||||||
|
|
||||||
|
String inviteCode = "https://www.yaoqing.com?communityId=" + communityId + "&inviteCode=" + idCode;
|
||||||
|
|
||||||
|
// 插入数据库
|
||||||
|
InviteCodeMapping inviteCodeMapping = new InviteCodeMapping();
|
||||||
|
inviteCodeMapping.setUserId(SecurityUtils.getUserId());
|
||||||
|
inviteCodeMapping.setInviteCode(idCode);
|
||||||
|
inviteCodeMapping.setStatus(1);
|
||||||
|
inviteCodeMappingService.save(inviteCodeMapping);
|
||||||
|
|
||||||
|
return inviteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptInvite(Long communityId, String inviteCode) {
|
||||||
|
|
||||||
|
// 解析邀请码
|
||||||
|
Long userId = ShareCodeUtils.codeToId(inviteCode);
|
||||||
|
if (Objects.isNull(userId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询邀请码
|
||||||
|
InviteCodeMapping inviteCodeMapping = inviteCodeMappingService.lambdaQuery()
|
||||||
|
.eq(InviteCodeMapping::getUserId, userId)
|
||||||
|
.eq(InviteCodeMapping::getInviteCode, inviteCode)
|
||||||
|
.eq(InviteCodeMapping::getStatus, 1)
|
||||||
|
.one();
|
||||||
|
|
||||||
|
if (Objects.isNull(inviteCodeMapping)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Invite invite = new Invite();
|
||||||
|
invite.setTenantId(userId);
|
||||||
|
invite.setInviteeUserId(SecurityUtils.getUserId());
|
||||||
|
invite.setType(InviteConstant.INVITE_ADMIN);
|
||||||
|
invite.setFeeType(InviteConstant.INVITE_FEE);
|
||||||
|
baseMapper.insert(invite);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue