feat: 社区、邀请、发布调整
parent
8fda8397f2
commit
84f3caf7af
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
@RestController
|
||||
@RequestMapping("invite")
|
||||
@RequiredArgsConstructor
|
||||
@Valid
|
||||
public class InviteController {
|
||||
|
||||
private final InviteService inviteService;
|
||||
|
@ -38,7 +39,6 @@ public class InviteController {
|
|||
@GetMapping("inviteCode")
|
||||
public AjaxResult inviteCode(@NotNull(message = "社区不能为空")
|
||||
@ApiParam(value = "社区", required = true)
|
||||
@Valid
|
||||
Long communityId) {
|
||||
// 获取邀请码链接
|
||||
String inviteCode = inviteService.getInviteCode(communityId);
|
||||
|
@ -60,12 +60,8 @@ public class InviteController {
|
|||
@NotBlank(message = "邀请码不能为空")
|
||||
@ApiParam(value = "邀请码", required = true)
|
||||
String inviteCode) {
|
||||
// 接受邀请
|
||||
boolean result = inviteService.acceptInvite(communityId, inviteCode);
|
||||
if (result) {
|
||||
return AjaxResult.success("接受邀请成功");
|
||||
}
|
||||
return AjaxResult.warn("接受邀请失败");
|
||||
|
||||
return inviteService.acceptInvite(communityId, inviteCode);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.mcwl.communityCenter.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
|
@ -24,8 +26,9 @@ public class Community extends BaseEntity {
|
|||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
@ApiModelProperty(value = "租户id")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 社区名称
|
||||
|
|
|
@ -21,8 +21,12 @@ public class CustomTenantHandler implements TenantLineHandler {
|
|||
* 需要根据业务需要进行调整.需要多租户的表名
|
||||
*/
|
||||
static {
|
||||
// 社区表
|
||||
tables.add("cc_community");
|
||||
// 邀请表
|
||||
tables.add("cc_invite");
|
||||
// 发布表
|
||||
// tables.add("cc_publish");
|
||||
tables.add("cc_publish");
|
||||
// 提问表
|
||||
tables.add("cc_question");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.mcwl.communityCenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.communityCenter.domain.Community;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
@ -9,9 +10,10 @@ import javax.validation.constraints.NotNull;
|
|||
|
||||
@Mapper
|
||||
public interface CommunityMapper extends BaseMapper<Community> {
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Community getByUserIdAndCommunityId(@NotNull(message = "租户id不能为空")
|
||||
@Param("userId")
|
||||
Long userId,
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@NotNull(message = "社区id不能为空")
|
||||
@Param("communityId")
|
||||
Long communityId);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.mcwl.communityCenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.communityCenter.domain.Invite;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
@ -11,10 +12,21 @@ import java.util.Set;
|
|||
|
||||
@Mapper
|
||||
public interface InviteMapper extends BaseMapper<Invite> {
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Set<Long> selectInviteIds(@NotNull(message = "租户id不能为空")
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@NotNull(message = "社区id不能为空")
|
||||
@Param("communityId")
|
||||
Long communityId);
|
||||
|
||||
/**
|
||||
* 查询是否已邀请
|
||||
* @param tenantId 租户id
|
||||
* @param communityId 社区id
|
||||
* @param userId 用户id
|
||||
* @return 邀请记录
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Invite isInvite(@Param("tenantId") Long tenantId,@Param("communityId") Long communityId,@Param("userId") Long userId);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
package com.mcwl.communityCenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mcwl.communityCenter.domain.Publish;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
|
||||
@Mapper
|
||||
public interface PublishMapper extends BaseMapper<Publish> {
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Page<Publish> selectByTenantIdAndCommunityIdPage(Page<Publish> page, @Param("tenantId") Long tenantId, @Param("communityId") Long communityId);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Publish selectByIdAndTenantIdAndCommunityId(@Param("id")
|
||||
Long id,
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@Param("communityId")
|
||||
Long communityId);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.communityCenter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.communityCenter.domain.Invite;
|
||||
|
@ -23,7 +24,7 @@ public interface InviteService extends IService<Invite> {
|
|||
* 接受邀请
|
||||
* @param communityId 社区id
|
||||
* @param inviteCode 邀请码
|
||||
* @return 是否成功
|
||||
* @return 结果
|
||||
*/
|
||||
boolean acceptInvite(@NotNull(message = "communityId不能为空") Long communityId, @NotBlank(message = "inviteCode不能为空") String inviteCode);
|
||||
AjaxResult acceptInvite(@NotNull(message = "communityId不能为空") Long communityId, @NotBlank(message = "inviteCode不能为空") String inviteCode);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.communityCenter.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
|
@ -42,7 +43,7 @@ public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community
|
|||
OrderItem orderItem = new OrderItem(pageDomain.getOrderByColumn(), isAsc);
|
||||
page.addOrder(orderItem);
|
||||
|
||||
baseMapper.selectPage(page, new LambdaQueryWrapper<Community>().eq(Community::getUserId, SecurityUtils.getUserId()));
|
||||
baseMapper.selectPage(page, null);
|
||||
|
||||
List<Community> communityList = page.getRecords();
|
||||
List<CommunityVo> communityVoList = new ArrayList<>();
|
||||
|
@ -65,7 +66,6 @@ public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community
|
|||
public void addCommunity(CommunityRes communityRes) {
|
||||
Community community = new Community();
|
||||
BeanUtil.copyProperties(communityRes, community);
|
||||
community.setUserId(SecurityUtils.getUserId());
|
||||
baseMapper.insert(community);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.mcwl.communityCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.ShareCodeUtils;
|
||||
import com.mcwl.communityCenter.constant.InviteConstant;
|
||||
|
@ -26,6 +28,8 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
|
||||
private final CommunityService communityService;
|
||||
|
||||
private final InviteMapper inviteMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public String getInviteCode(Long communityId) {
|
||||
|
@ -34,7 +38,6 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
// 查询用户的社区
|
||||
Community userCommunity = communityService.lambdaQuery()
|
||||
.eq(Community::getId, communityId)
|
||||
.eq(Community::getUserId, SecurityUtils.getUserId())
|
||||
.one();
|
||||
|
||||
if (Objects.isNull(userCommunity)) {
|
||||
|
@ -58,39 +61,48 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean acceptInvite(Long communityId, String inviteCode) {
|
||||
public AjaxResult acceptInvite(Long communityId, String inviteCode) {
|
||||
|
||||
// 解析邀请码
|
||||
Long userId = ShareCodeUtils.codeToId(inviteCode);
|
||||
if (Objects.isNull(userId)) {
|
||||
return false;
|
||||
return AjaxResult.error("邀请码有误");
|
||||
}
|
||||
|
||||
// 判断是否是同一个人
|
||||
if (Objects.equals(userId, SecurityUtils.getUserId())) {
|
||||
return false;
|
||||
return AjaxResult.error("不能邀请自己");
|
||||
}
|
||||
|
||||
// 查询邀请码
|
||||
InviteCodeMapping inviteCodeMapping = inviteCodeMappingService.lambdaQuery()
|
||||
.eq(InviteCodeMapping::getUserId, userId)
|
||||
.eq(InviteCodeMapping::getCommunityId, communityId)
|
||||
.eq(InviteCodeMapping::getInviteCode, inviteCode)
|
||||
.eq(InviteCodeMapping::getStatus, StatusConstant.STATUS_AVAILABLE)
|
||||
.one();
|
||||
|
||||
if (Objects.isNull(inviteCodeMapping)) {
|
||||
return false;
|
||||
return AjaxResult.error("没查询到该邀请码");
|
||||
}
|
||||
|
||||
// 判断是否已经邀请过
|
||||
Invite inv = inviteMapper.isInvite(userId, communityId, SecurityUtils.getUserId());
|
||||
if (Objects.nonNull(inv)) {
|
||||
return AjaxResult.error("不能重复邀请");
|
||||
}
|
||||
|
||||
|
||||
inviteCodeMapping.setStatus(StatusConstant.STATUS_UNAVAILABLE);
|
||||
inviteCodeMappingService.updateById(inviteCodeMapping);
|
||||
|
||||
Invite invite = new Invite();
|
||||
invite.setTenantId(userId);
|
||||
invite.setCommunityId(communityId);
|
||||
invite.setInviteeUserId(SecurityUtils.getUserId());
|
||||
invite.setType(InviteConstant.INVITE_ADMIN);
|
||||
invite.setFeeType(InviteConstant.INVITE_FEE);
|
||||
baseMapper.insert(invite);
|
||||
return true;
|
||||
return AjaxResult.success("邀请成功");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.communityCenter.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -35,15 +36,11 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
@RequiredArgsConstructor
|
||||
public class PublishServiceImpl extends ServiceImpl<PublishMapper, Publish> implements PublishService {
|
||||
|
||||
private final QuestionMapper questionMapper;
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
private final InviteMapper inviteMapper;
|
||||
|
||||
private CommunityMapper userCommunityMapper;
|
||||
|
||||
private final ThreadPoolExecutor threadPoll = new AutoCloseableExecutorService(10);
|
||||
private final CommunityMapper communityMapper;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -51,10 +48,10 @@ public class PublishServiceImpl extends ServiceImpl<PublishMapper, Publish> impl
|
|||
Long id = publishDetailRes.getId();
|
||||
Long tenantId = publishDetailRes.getTenantId();
|
||||
Long communityId = publishDetailRes.getCommunityId();
|
||||
Publish publish = baseMapper.selectOne(new LambdaQueryWrapper<Publish>()
|
||||
.eq(Publish::getId, id)
|
||||
.eq(Publish::getTenantId, tenantId)
|
||||
.eq(Publish::getCommunityId, communityId));
|
||||
|
||||
// 根据id和租户id和社区id查询发布信息
|
||||
Publish publish = baseMapper.selectByIdAndTenantIdAndCommunityId(id, tenantId, communityId);
|
||||
|
||||
if (Objects.isNull(publish)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -72,7 +69,7 @@ public class PublishServiceImpl extends ServiceImpl<PublishMapper, Publish> impl
|
|||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
Community community = userCommunityMapper.getByUserIdAndCommunityId(publishRes.getTenantId(), publishRes.getCommunityId());
|
||||
Community community = communityMapper.getByUserIdAndCommunityId(publishRes.getTenantId(), publishRes.getCommunityId());
|
||||
|
||||
if (Objects.isNull(community)) {
|
||||
return AjaxResult.error(HttpStatus.ERROR, "用户社区未创建");
|
||||
|
@ -111,12 +108,8 @@ public class PublishServiceImpl extends ServiceImpl<PublishMapper, Publish> impl
|
|||
|
||||
page.addOrder(orderItem);
|
||||
|
||||
// 查询条件
|
||||
LambdaQueryWrapper<Publish> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(Publish::getCommunityId, publishPageRes.getCommunityId())
|
||||
.eq(Publish::getTenantId, publishPageRes.getTenantId());
|
||||
|
||||
baseMapper.selectPage(page, lqw);
|
||||
// 根据租户id和社区id查询分页数据
|
||||
baseMapper.selectByTenantIdAndCommunityIdPage(page, publishPageRes.getTenantId(), publishPageRes.getCommunityId());
|
||||
|
||||
|
||||
List<Publish> publishList = page.getRecords();
|
||||
|
|
|
@ -61,7 +61,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|||
|
||||
Community community = communityService.lambdaQuery()
|
||||
.eq(Community::getId, communityId)
|
||||
.eq(Community::getUserId, tenantId).one();
|
||||
.eq(Community::getTenantId, tenantId).one();
|
||||
|
||||
if (Objects.isNull(community)) {
|
||||
return AjaxResult.error("租户或社区不存在");
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
<mapper namespace="com.mcwl.communityCenter.mapper.CommunityMapper">
|
||||
|
||||
<select id="getByUserIdAndCommunityId" resultType="com.mcwl.communityCenter.domain.Community">
|
||||
select id, user_id
|
||||
select id,
|
||||
tenant_id,
|
||||
community_name,
|
||||
type,
|
||||
price,
|
||||
validity_type
|
||||
from cc_community
|
||||
where user_id = #{userId}
|
||||
where tenant_id = #{tenantId}
|
||||
and id = #{communityId}
|
||||
and del_flag = '0';
|
||||
</select>
|
||||
|
|
|
@ -11,4 +11,12 @@
|
|||
and community_id = #{communityId}
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
<select id="isInvite" resultType="com.mcwl.communityCenter.domain.Invite">
|
||||
select id, tenant_id, community_id, invitee_user_id, type, fee_type, create_by, create_time, update_by, update_time, del_flag, remark
|
||||
from cc_invite
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and invitee_user_id = #{userId}
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.mcwl.communityCenter.mapper.PublishMapper">
|
||||
<select id="selectByTenantIdAndCommunityIdPage" resultType="com.mcwl.communityCenter.domain.Publish">
|
||||
select id, tenant_id, community_id, user_id, content, publish_time, like_num, comment_num, status, create_by, create_time
|
||||
from cc_publish
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
<select id="selectByIdAndTenantIdAndCommunityId" resultType="com.mcwl.communityCenter.domain.Publish">
|
||||
select id, tenant_id, community_id, user_id, content, publish_time, like_num, comment_num, status, create_by, create_time
|
||||
from cc_publish
|
||||
where id = #{id}
|
||||
and tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue