Merge remote-tracking branch 'origin/preview' into preview
commit
d5ff1265d7
|
@ -1,14 +1,18 @@
|
|||
package com.mcwl.web.controller.communityCenter;
|
||||
|
||||
|
||||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.communityCenter.domain.Community;
|
||||
import com.mcwl.communityCenter.domain.dto.CommunityListPageRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommunityRes;
|
||||
import com.mcwl.communityCenter.domain.dto.JoinCommunityListPageRes;
|
||||
import com.mcwl.communityCenter.domain.dto.JoinCommunityRes;
|
||||
import com.mcwl.communityCenter.service.CommunityService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -16,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 社区
|
||||
|
@ -40,23 +45,15 @@ public class CommunityController {
|
|||
return communityService.listByPage(communityListPageRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 我创建的社区
|
||||
*/
|
||||
@ApiOperation(value = "我创建的社区")
|
||||
@PostMapping("myCreate")
|
||||
public R<Object> getMyCreateCommunity(@RequestBody @Valid PageDomain pageDomain) {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 我加入的社区
|
||||
*/
|
||||
@ApiOperation(value = "我加入的社区")
|
||||
@GetMapping("myJoin")
|
||||
public R<Object> getMyJoinCommunity() {
|
||||
return R.ok();
|
||||
@PostMapping("myJoin")
|
||||
public TableDataInfo getMyJoinCommunity(@RequestBody JoinCommunityListPageRes joinCommunityListPageRes) {
|
||||
|
||||
return communityService.getMyJoinCommunity(joinCommunityListPageRes);
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,11 +75,28 @@ public class CommunityController {
|
|||
*/
|
||||
@ApiOperation(value = "加入社区")
|
||||
@PostMapping("join")
|
||||
public R<Object> joinCommunity(@Valid JoinCommunityRes joinCommunityRes) {
|
||||
public R<Object> joinCommunity(@RequestBody @Valid JoinCommunityRes joinCommunityRes) {
|
||||
|
||||
return communityService.joinCommunity(joinCommunityRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出社区
|
||||
*/
|
||||
@ApiOperation(value = "退出社区")
|
||||
@PostMapping("quit")
|
||||
public R<Object> quitCommunity(@ApiParam(value = "租户id", required = true)
|
||||
@NotNull(message = "租户id不能为空")
|
||||
@Valid
|
||||
Long tenantId,
|
||||
@ApiParam(value = "社区id", required = true)
|
||||
@NotNull(message = "社区id不能为空")
|
||||
@Valid
|
||||
Long communityId) {
|
||||
|
||||
return communityService.quitCommunity(tenantId, communityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除社区
|
||||
*
|
||||
|
@ -95,6 +109,10 @@ public class CommunityController {
|
|||
@ApiParam(value = "id", required = true)
|
||||
@Valid
|
||||
Long id) {
|
||||
Community community = communityService.getById(id);
|
||||
if (Objects.isNull(community)) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG, "该社区不存在");
|
||||
}
|
||||
communityService.removeById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class Community extends BaseEntity {
|
|||
private Integer communityTag;
|
||||
|
||||
/**
|
||||
* 社区类型
|
||||
* 社区类型 0免费 1付费
|
||||
*/
|
||||
@ApiModelProperty(value = "社区类型")
|
||||
private Integer type;
|
||||
|
@ -67,10 +67,10 @@ public class Community extends BaseEntity {
|
|||
private Double price;
|
||||
|
||||
/**
|
||||
* 有效期类型
|
||||
* 有效期天数
|
||||
*/
|
||||
@ApiModelProperty(value = "有效期类型")
|
||||
private Integer validityType;
|
||||
@ApiModelProperty(value = "有效期天数")
|
||||
private Integer validityDay;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,13 +7,12 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 社区
|
||||
* 社区用户
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -21,31 +20,53 @@ import lombok.NoArgsConstructor;
|
|||
@ApiModel(value = "社区用户")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CommunityUser extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
@ApiModelProperty(value = "社区用户id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty(value = "租户id")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 社区id
|
||||
*/
|
||||
@ApiModelProperty(value = "社区id")
|
||||
private Long communityId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户类型 0普通用户 1群主
|
||||
*/
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 邀请类型id
|
||||
*/
|
||||
private Long inviteId;
|
||||
|
||||
/**
|
||||
* 加入社区时的价格
|
||||
*/
|
||||
private Double communityPrice;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private Date startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,19 +19,6 @@ public class Invite extends BaseEntity {
|
|||
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 用户id - 租户id
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long tenantId;
|
||||
/**
|
||||
* 社区id
|
||||
*/
|
||||
private Long communityId;
|
||||
/**
|
||||
* 被邀请人
|
||||
*/
|
||||
private Long inviteeUserId;
|
||||
/**
|
||||
* 受邀类型 0普通 1管理员
|
||||
*/
|
||||
|
|
|
@ -26,5 +26,11 @@ public class CommunityListPageRes extends PageDomain {
|
|||
@ApiModelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 搜索内容
|
||||
*/
|
||||
@ApiModelProperty(value = "搜索内容")
|
||||
private String searchContent;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,13 @@ import javax.validation.constraints.NotNull;
|
|||
@ApiModel(value = "社区请求参数")
|
||||
public class CommunityRes {
|
||||
|
||||
|
||||
/**
|
||||
* 社区图片
|
||||
*/
|
||||
@ApiModelProperty(value = "社区图片")
|
||||
private String imageUrl;
|
||||
|
||||
/**
|
||||
* 社区名称
|
||||
*/
|
||||
|
@ -22,10 +29,17 @@ public class CommunityRes {
|
|||
@NotBlank(message = "社区名称不能为空")
|
||||
private String communityName;
|
||||
|
||||
/**
|
||||
* 社区标签id
|
||||
*/
|
||||
@ApiModelProperty(value = "社区标签", required = true)
|
||||
@NotNull(message = "社区标签不能为空")
|
||||
private Integer communityTag;
|
||||
|
||||
/**
|
||||
* 社区类型
|
||||
*/
|
||||
@ApiModelProperty(value = "社区类型", required = true)
|
||||
@ApiModelProperty(value = "社区类型 0免费 1付费", required = true)
|
||||
@NotNull(message = "社区类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
|
@ -37,11 +51,11 @@ public class CommunityRes {
|
|||
private Double price;
|
||||
|
||||
/**
|
||||
* 有效期类型
|
||||
* 有效期天数
|
||||
*/
|
||||
@ApiModelProperty(value = "有效期类型", required = true)
|
||||
@NotNull(message = "有效期类型不能为空")
|
||||
private Integer validityType;
|
||||
@ApiModelProperty(value = "有效期天数", required = true)
|
||||
@NotNull(message = "有效期天数")
|
||||
private Integer validityDay;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.mcwl.communityCenter.domain.dto;
|
||||
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 社区列表分页请求参数
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "社区列表分页请求参数")
|
||||
public class JoinCommunityListPageRes extends PageDomain {
|
||||
|
||||
/**
|
||||
* 搜索内容
|
||||
*/
|
||||
@ApiModelProperty(value = "搜索内容")
|
||||
private String searchContent;
|
||||
|
||||
|
||||
}
|
|
@ -52,10 +52,16 @@ public class CommunityVo {
|
|||
private Long userId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
* 用户头像
|
||||
*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createBy;
|
||||
@ApiModelProperty(value = "用户头像")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ApiModelProperty(value = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 创建天数
|
||||
|
|
|
@ -16,14 +16,15 @@ import java.util.Map;
|
|||
public interface CommunityMapper extends BaseMapper<Community> {
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Community getByTenantIdAndCommunityId(@NotNull(message = "租户id不能为空")
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@NotNull(message = "社区id不能为空")
|
||||
@Param("communityId")
|
||||
Long communityId);
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@NotNull(message = "社区id不能为空")
|
||||
@Param("communityId")
|
||||
Long communityId);
|
||||
|
||||
/**
|
||||
* 查询所有社区加入人数, 以map形式返回,key为社区id,value为加入人数
|
||||
*
|
||||
* @return map
|
||||
*/
|
||||
@MapKey("id")
|
||||
|
@ -32,6 +33,7 @@ public interface CommunityMapper extends BaseMapper<Community> {
|
|||
|
||||
/**
|
||||
* 查询所有社区发布数量,以map形式返回,key为社区id,value为发布数量
|
||||
*
|
||||
* @return map
|
||||
*/
|
||||
@MapKey("id")
|
||||
|
@ -39,5 +41,21 @@ public interface CommunityMapper extends BaseMapper<Community> {
|
|||
Map<Long, Map<String, Object>> selectCommunityPublishNum();
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<Community> selectPageByCommunityTag(@Param("page") Page<Community> page, @Param("communityTag") Long communityTag);
|
||||
List<Community> selectPageByCommunityTag(@Param("page")
|
||||
Page<Community> page,
|
||||
@Param("communityTag")
|
||||
Long communityTag,
|
||||
@Param("searchContent")
|
||||
String searchContent);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<Community> getMyJoinCommunity(@Param("page")
|
||||
Page<Community> page,
|
||||
@Param("userId")
|
||||
Long userId,
|
||||
@Param("searchContent")
|
||||
String searchContent);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
void quitCommunity(Long tenantId, Long communityId, Long userId);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package com.mcwl.communityCenter.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.communityCenter.domain.Community;
|
||||
import com.mcwl.communityCenter.domain.dto.CommunityListPageRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommunityRes;
|
||||
import com.mcwl.communityCenter.domain.dto.JoinCommunityListPageRes;
|
||||
import com.mcwl.communityCenter.domain.dto.JoinCommunityRes;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
@ -25,4 +27,16 @@ public interface CommunityService extends IService<Community> {
|
|||
* @param joinCommunityRes 加入社区信息
|
||||
*/
|
||||
R<Object> joinCommunity(JoinCommunityRes joinCommunityRes);
|
||||
|
||||
/**
|
||||
* 我加入的社区
|
||||
*/
|
||||
TableDataInfo getMyJoinCommunity(JoinCommunityListPageRes joinCommunityListPageRes);
|
||||
|
||||
Community getByTenantIdAndCommunityId(Long userId, Long communityId);
|
||||
|
||||
/**
|
||||
* 退出社区
|
||||
*/
|
||||
R<Object> quitCommunity(Long tenantId, Long communityId);
|
||||
}
|
||||
|
|
|
@ -8,13 +8,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.domain.R;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.common.core.redis.RedisCache;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.communityCenter.domain.Community;
|
||||
import com.mcwl.communityCenter.domain.CommunityUser;
|
||||
import com.mcwl.communityCenter.domain.dto.CommunityListPageRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommunityRes;
|
||||
import com.mcwl.communityCenter.domain.dto.JoinCommunityListPageRes;
|
||||
import com.mcwl.communityCenter.domain.dto.JoinCommunityRes;
|
||||
import com.mcwl.communityCenter.domain.vo.CommunityVo;
|
||||
import com.mcwl.communityCenter.mapper.CommunityMapper;
|
||||
|
@ -30,6 +34,7 @@ import java.time.LocalDate;
|
|||
import java.time.ZoneId;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
|
@ -39,79 +44,50 @@ public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community
|
|||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
private final RedisCache redisCache;
|
||||
|
||||
@Override
|
||||
public TableDataInfo listByPage(CommunityListPageRes communityListPageRes) {
|
||||
|
||||
// 查询社区加入人数,以map形式返回,key为社区id,value为加入人数
|
||||
Map<Long, Integer> communityJoinNumMap = new HashMap<>();
|
||||
Map<Long, Map<String, Object>> joinMap = baseMapper.selectCommunityJoinNum();
|
||||
if (joinMap != null && !joinMap.isEmpty()) {
|
||||
joinMap.forEach((key, value) -> {
|
||||
communityJoinNumMap.put(key, Integer.valueOf(value.get("joinNum").toString()));
|
||||
});
|
||||
}
|
||||
|
||||
// 查询社区发布数,以map形式返回,key为社区id,value为发布数
|
||||
Map<Long, Integer> communityPublishNumMap = new HashMap<>();
|
||||
Map<Long, Map<String, Object>> publishMap = baseMapper.selectCommunityPublishNum();
|
||||
if (publishMap != null && !publishMap.isEmpty()) {
|
||||
publishMap.forEach((key, value) -> {
|
||||
communityPublishNumMap.put(key, Integer.valueOf(value.get("publishNum").toString()));
|
||||
});
|
||||
}
|
||||
|
||||
Page<Community> page = new Page<>(communityListPageRes.getPageNum(), communityListPageRes.getPageSize());
|
||||
|
||||
|
||||
boolean isAsc = Objects.equals(communityListPageRes.getIsAsc(), "asc");
|
||||
|
||||
if (StringUtils.isBlank(communityListPageRes.getOrderByColumn())) {
|
||||
communityListPageRes.setOrderByColumn("create_time");
|
||||
}
|
||||
OrderItem orderItem = new OrderItem(communityListPageRes.getOrderByColumn(), isAsc);
|
||||
OrderItem orderItem = new OrderItem("create_time", false);
|
||||
page.addOrder(orderItem);
|
||||
|
||||
List<Community> communityList;
|
||||
if (Objects.isNull(communityListPageRes.getUserId())) {
|
||||
communityList = baseMapper.selectPageByCommunityTag(page, communityListPageRes.getCommunityTag());
|
||||
communityList = baseMapper.selectPageByCommunityTag(page, communityListPageRes.getCommunityTag(), communityListPageRes.getSearchContent());
|
||||
} else {
|
||||
baseMapper.selectPage(page, null);
|
||||
baseMapper.selectPage(page, new LambdaQueryWrapper<Community>()
|
||||
.like(StringUtils.isNotBlank(communityListPageRes.getSearchContent()), Community::getCommunityName, communityListPageRes.getSearchContent())
|
||||
.like(StringUtils.isNotBlank(communityListPageRes.getSearchContent()), Community::getDescription, communityListPageRes.getSearchContent()));
|
||||
communityList = page.getRecords();
|
||||
}
|
||||
|
||||
List<CommunityVo> communityVoList = new ArrayList<>();
|
||||
|
||||
LocalDate currentLocalDate = LocalDate.now(ZoneId.systemDefault());
|
||||
for (Community community : communityList) {
|
||||
CommunityVo communityVo = new CommunityVo();
|
||||
BeanUtil.copyProperties(community, communityVo);
|
||||
// 当前时间和创建时间差
|
||||
Date createTime = community.getCreateTime();
|
||||
LocalDate createLocalDate = createTime.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
long daysBetween = ChronoUnit.DAYS.between(createLocalDate, currentLocalDate);
|
||||
communityVo.setUserId(community.getTenantId());
|
||||
communityVo.setCreateDay(daysBetween);
|
||||
communityVo.setJoinNum(communityJoinNumMap.getOrDefault(community.getId(), 0));
|
||||
communityVo.setPublishNum(communityPublishNumMap.getOrDefault(community.getId(), 0));
|
||||
communityVoList.add(communityVo);
|
||||
}
|
||||
|
||||
TableDataInfo tableDataInfo = new TableDataInfo();
|
||||
tableDataInfo.setRows(communityVoList);
|
||||
tableDataInfo.setTotal(page.getTotal());
|
||||
tableDataInfo.setCode(HttpStatus.SUCCESS);
|
||||
tableDataInfo.setMsg("查询成功");
|
||||
|
||||
return tableDataInfo;
|
||||
return this.getCommunityVoTableDataInfo(communityList, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addCommunity(CommunityRes communityRes) {
|
||||
Community community = new Community();
|
||||
BeanUtil.copyProperties(communityRes, community);
|
||||
baseMapper.insert(community);
|
||||
try {
|
||||
Community community = new Community();
|
||||
BeanUtil.copyProperties(communityRes, community);
|
||||
if (Objects.equals(communityRes.getType(), 0)) {
|
||||
community.setPrice(0.0);
|
||||
}
|
||||
baseMapper.insert(community);
|
||||
|
||||
communityUserMapper.insert(CommunityUser
|
||||
.builder()
|
||||
.tenantId(SecurityUtils.getUserId())
|
||||
.communityId(community.getId())
|
||||
.userId(SecurityUtils.getUserId())
|
||||
.userType(1)
|
||||
.build());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage(), HttpStatus.SHOW_ERROR_MSG);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -151,11 +127,116 @@ public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community
|
|||
|
||||
sysUserService.updateUser(user);
|
||||
|
||||
communityUserMapper.insert(new CommunityUser(null, tenantId, communityId, SecurityUtils.getUserId()));
|
||||
Calendar now = Calendar.getInstance();
|
||||
Date startTime = now.getTime();
|
||||
now.add(Calendar.DAY_OF_YEAR, community.getValidityDay());
|
||||
Date endTime = now.getTime();
|
||||
|
||||
CommunityUser cu = CommunityUser.builder()
|
||||
.tenantId(tenantId)
|
||||
.communityId(communityId)
|
||||
.userId(SecurityUtils.getUserId())
|
||||
.userType(0)
|
||||
.communityPrice(price)
|
||||
.startTime(startTime)
|
||||
.endTime(endTime)
|
||||
.build();
|
||||
|
||||
communityUserMapper.insert(cu);
|
||||
|
||||
|
||||
return R.ok("加入成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo getMyJoinCommunity(JoinCommunityListPageRes joinCommunityListPageRes) {
|
||||
Page<Community> page = new Page<>(joinCommunityListPageRes.getPageNum(), joinCommunityListPageRes.getPageSize());
|
||||
OrderItem orderItem = new OrderItem("create_time", false);
|
||||
page.addOrder(orderItem);
|
||||
|
||||
String searchContent = joinCommunityListPageRes.getSearchContent();
|
||||
List<Community> communityList = baseMapper.getMyJoinCommunity(page, SecurityUtils.getUserId(), searchContent);
|
||||
|
||||
|
||||
return this.getCommunityVoTableDataInfo(communityList, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Community getByTenantIdAndCommunityId(Long userId, Long communityId) {
|
||||
return baseMapper.getByTenantIdAndCommunityId(userId, communityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Object> quitCommunity(Long tenantId, Long communityId) {
|
||||
baseMapper.quitCommunity(tenantId, communityId, SecurityUtils.getUserId());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
private TableDataInfo getCommunityVoTableDataInfo(List<Community> communityList, Long total) {
|
||||
|
||||
|
||||
// 查询社区加入人数,以map形式返回,key为社区id,value为加入人数
|
||||
Map<String, Object> communityJoinNumMap = redisCache.getCacheMap("communityJoinNumMap");
|
||||
if (communityJoinNumMap.isEmpty()) {
|
||||
Map<Long, Map<String, Object>> joinMap = baseMapper.selectCommunityJoinNum();
|
||||
if (joinMap != null && !joinMap.isEmpty()) {
|
||||
joinMap.forEach((key, value) -> {
|
||||
communityJoinNumMap.put(key.toString(), Integer.valueOf(value.get("joinNum").toString()));
|
||||
});
|
||||
redisCache.setCacheMap("communityJoinNumMap", communityJoinNumMap);
|
||||
} else {
|
||||
redisCache.setCacheMap("communityJoinNumMap", new HashMap<>());
|
||||
}
|
||||
redisCache.expire("communityJoinNumMap", 1, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
// 查询社区发布数,以map形式返回,key为社区id,value为发布数
|
||||
Map<String, Object> communityPublishNumMap = redisCache.getCacheMap("communityPublishNumMap");
|
||||
if (communityPublishNumMap.isEmpty()) {
|
||||
Map<Long, Map<String, Object>> publishMap = baseMapper.selectCommunityPublishNum();
|
||||
if (publishMap != null && !publishMap.isEmpty()) {
|
||||
publishMap.forEach((key, value) -> {
|
||||
communityPublishNumMap.put(key.toString(), Integer.valueOf(value.get("publishNum").toString()));
|
||||
});
|
||||
redisCache.setCacheMap("communityPublishNumMap", communityPublishNumMap);
|
||||
} else {
|
||||
redisCache.setCacheMap("communityPublishNumMap", new HashMap<>());
|
||||
}
|
||||
redisCache.expire("communityPublishNumMap", 1, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
|
||||
List<CommunityVo> communityVoList = new ArrayList<>();
|
||||
|
||||
LocalDate currentLocalDate = LocalDate.now(ZoneId.systemDefault());
|
||||
for (Community community : communityList) {
|
||||
CommunityVo communityVo = new CommunityVo();
|
||||
BeanUtil.copyProperties(community, communityVo);
|
||||
// 当前时间和创建时间差
|
||||
Date createTime = community.getCreateTime();
|
||||
LocalDate createLocalDate = createTime.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
long daysBetween = ChronoUnit.DAYS.between(createLocalDate, currentLocalDate);
|
||||
SysUser sysUser = sysUserService.selectUserById(community.getTenantId());
|
||||
communityVo.setUserId(community.getTenantId());
|
||||
communityVo.setAvatar(sysUser.getAvatar());
|
||||
communityVo.setNickName(sysUser.getNickName());
|
||||
communityVo.setCreateDay(daysBetween);
|
||||
communityVo.setJoinNum((Integer) communityJoinNumMap.getOrDefault(community.getId().toString(), 0));
|
||||
communityVo.setPublishNum((Integer) communityPublishNumMap.getOrDefault(community.getId().toString(), 0));
|
||||
communityVoList.add(communityVo);
|
||||
}
|
||||
|
||||
TableDataInfo tableDataInfo = new TableDataInfo();
|
||||
tableDataInfo.setRows(communityVoList);
|
||||
tableDataInfo.setTotal(total);
|
||||
tableDataInfo.setCode(HttpStatus.SUCCESS);
|
||||
tableDataInfo.setMsg("查询成功");
|
||||
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,16 +10,21 @@ import com.mcwl.common.utils.ShareCodeUtils;
|
|||
import com.mcwl.communityCenter.constant.InviteConstant;
|
||||
import com.mcwl.communityCenter.constant.StatusConstant;
|
||||
import com.mcwl.communityCenter.domain.Community;
|
||||
import com.mcwl.communityCenter.domain.CommunityUser;
|
||||
import com.mcwl.communityCenter.domain.Invite;
|
||||
import com.mcwl.communityCenter.domain.InviteCodeMapping;
|
||||
import com.mcwl.communityCenter.mapper.CommunityUserMapper;
|
||||
import com.mcwl.communityCenter.mapper.InviteMapper;
|
||||
import com.mcwl.communityCenter.service.CommunityService;
|
||||
import com.mcwl.communityCenter.service.CommunityUserService;
|
||||
import com.mcwl.communityCenter.service.InviteCodeMappingService;
|
||||
import com.mcwl.communityCenter.service.InviteService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
|
@ -32,6 +37,8 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
|
||||
private final InviteMapper inviteMapper;
|
||||
|
||||
private final CommunityUserMapper communityUserMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public String getInviteCode(Long communityId) {
|
||||
|
@ -66,16 +73,24 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
public R<Object> acceptInvite(Long communityId, String inviteCode) {
|
||||
|
||||
// 解析邀请码
|
||||
Long userId = ShareCodeUtils.codeToId(inviteCode);
|
||||
Long userId;
|
||||
try {
|
||||
userId = ShareCodeUtils.codeToId(inviteCode);
|
||||
} catch (Exception e) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG, "邀请码有误");
|
||||
}
|
||||
|
||||
if (Objects.isNull(userId)) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"邀请码有误");
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG, "邀请码有误");
|
||||
}
|
||||
|
||||
// 判断是否是同一个人
|
||||
if (Objects.equals(userId, SecurityUtils.getUserId())) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"不能邀请自己");
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG, "不能邀请自己");
|
||||
}
|
||||
|
||||
Community community = communityService.getByTenantIdAndCommunityId(userId, communityId);
|
||||
|
||||
// 查询邀请码
|
||||
InviteCodeMapping inviteCodeMapping = inviteCodeMappingService.lambdaQuery()
|
||||
.eq(InviteCodeMapping::getUserId, userId)
|
||||
|
@ -85,13 +100,13 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
.one();
|
||||
|
||||
if (Objects.isNull(inviteCodeMapping)) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"没查询到该邀请码");
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG, "没查询到该邀请码");
|
||||
}
|
||||
|
||||
// 判断是否已经邀请过
|
||||
Invite inv = inviteMapper.isInvite(userId, communityId, SecurityUtils.getUserId());
|
||||
if (Objects.nonNull(inv)) {
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG,"不能重复邀请");
|
||||
return R.fail(HttpStatus.SHOW_ERROR_MSG, "不能重复邀请");
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,12 +114,26 @@ public class InviteServiceImpl extends ServiceImpl<InviteMapper, Invite> impleme
|
|||
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);
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
Date startTime = now.getTime();
|
||||
now.add(Calendar.DAY_OF_YEAR, community.getValidityDay());
|
||||
Date endTime = now.getTime();
|
||||
|
||||
communityUserMapper.insert(CommunityUser
|
||||
.builder()
|
||||
.tenantId(userId)
|
||||
.communityId(communityId)
|
||||
.userId(SecurityUtils.getUserId())
|
||||
.userType(0)
|
||||
.inviteId(invite.getId())
|
||||
.startTime(startTime)
|
||||
.endTime(endTime)
|
||||
.build());
|
||||
|
||||
return R.ok(null, "邀请成功");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,14 @@
|
|||
<id property="id" column="id" javaType="java.lang.Long" /> <!-- 键字段 -->
|
||||
<result property="publishNum" column="publish_num" javaType="java.lang.Integer" /> <!-- 值字段 -->
|
||||
</resultMap>
|
||||
<update id="quitCommunity">
|
||||
update cc_community_user
|
||||
set del_flag = '1'
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and user_id = #{userId}
|
||||
and del_flag = '0';
|
||||
</update>
|
||||
|
||||
<select id="getByTenantIdAndCommunityId" resultType="com.mcwl.communityCenter.domain.Community">
|
||||
select id,
|
||||
|
@ -20,7 +28,7 @@
|
|||
community_name,
|
||||
type,
|
||||
price,
|
||||
validity_type
|
||||
validity_day
|
||||
from cc_community
|
||||
where tenant_id = #{tenantId}
|
||||
and id = #{communityId}
|
||||
|
@ -28,18 +36,16 @@
|
|||
</select>
|
||||
|
||||
<select id="selectCommunityJoinNum" resultMap="CommunityJoinNumMap">
|
||||
select c.id as id, COALESCE(count(*), 0) as join_num
|
||||
from cc_community c
|
||||
join cc_invite i on c.id = i.community_id
|
||||
where c.del_flag = '0'
|
||||
and i.del_flag = '0'
|
||||
group by i.community_id
|
||||
select cu.community_id as id, COALESCE(count(*), 0) as join_num
|
||||
from cc_community_user cu
|
||||
where cu.del_flag = '0'
|
||||
group by cu.community_id
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<select id="selectCommunityPublishNum" resultMap="CommunityPublishNumMap">
|
||||
select c.id as id, COALESCE(count(*), 0) as publish_num
|
||||
select p.community_id as id, COALESCE(count(*), 0) as publish_num
|
||||
from cc_community c
|
||||
join cc_publish p on c.id = p.community_id
|
||||
join cc_question q on c.id = q.community_id
|
||||
|
@ -58,7 +64,7 @@
|
|||
community_tag,
|
||||
type,
|
||||
price,
|
||||
validity_type,
|
||||
validity_day,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
|
@ -66,8 +72,36 @@
|
|||
from cc_community
|
||||
<where>
|
||||
<if test="communityTag != null">
|
||||
and c.community_tag = #{communityTag}
|
||||
and community_tag = #{communityTag}
|
||||
</if>
|
||||
<if test="searchContent != null and searchContent != ''">
|
||||
and (community_name like concat('%', #{searchContent}, '%')
|
||||
or `description` like concat('%', #{searchContent}, '%'))
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="getMyJoinCommunity" resultType="com.mcwl.communityCenter.domain.Community">
|
||||
select c.id,
|
||||
c.tenant_id,
|
||||
c.image_url,
|
||||
c.community_name,
|
||||
c.description,
|
||||
c.community_tag,
|
||||
c.type,
|
||||
c.price,
|
||||
c.validity_day,
|
||||
c.create_by,
|
||||
c.create_time,
|
||||
c.update_by,
|
||||
c.update_time
|
||||
from cc_community c
|
||||
join cc_community_user cu on c.id = cu.community_id
|
||||
where cu.user_id = #{userId}
|
||||
and c.del_flag = '0'
|
||||
and cu.del_flag = '0'
|
||||
<if test="searchContent != null and searchContent != ''">
|
||||
and (c.community_name like concat('%', #{searchContent}, '%')
|
||||
or c.description like concat('%', #{searchContent}, '%'))
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
|
@ -5,27 +5,40 @@
|
|||
<mapper namespace="com.mcwl.communityCenter.mapper.InviteMapper">
|
||||
|
||||
<select id="selectInviteIds" resultType="java.lang.Long">
|
||||
select invitee_user_id
|
||||
from cc_invite
|
||||
select user_id
|
||||
from cc_community_user
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and invite_id is not null
|
||||
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 i.id,
|
||||
invite_type,
|
||||
fee_type
|
||||
from cc_community_user cu
|
||||
left join cc_invite i on cu.invite_id = i.id
|
||||
where cu.tenant_id = #{tenantId}
|
||||
and cu.community_id = #{communityId}
|
||||
and cu.user_id = #{userId}
|
||||
and cu.invite_id is not null
|
||||
and cu.del_flag = '0'
|
||||
and i.del_flag = '0'
|
||||
</select>
|
||||
<select id="selectByTenantIdAndCommunityIdAndInviteeUserId"
|
||||
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
|
||||
select i.id,
|
||||
tenant_id,
|
||||
community_id,
|
||||
fee_type,
|
||||
remark
|
||||
from cc_community_user cu
|
||||
left join cc_invite i on cu.invite_id = i.id
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and invitee_user_id = #{inviteeUserId}
|
||||
and del_flag = '0'
|
||||
and user_id = #{inviteeUserId}
|
||||
and cu.invite_id is not null
|
||||
and cu.del_flag = '0'
|
||||
and i.del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue