Merge branch 'feature/community-center' into preview
commit
d0238c2320
|
@ -1,13 +1,11 @@
|
||||||
package com.mcwl.web.controller.communityCenter;
|
package com.mcwl.web.controller.communityCenter;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
|
||||||
import com.mcwl.common.core.domain.R;
|
import com.mcwl.common.core.domain.R;
|
||||||
import com.mcwl.common.core.page.PageDomain;
|
|
||||||
import com.mcwl.common.core.page.TableDataInfo;
|
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.CommunityRes;
|
||||||
|
import com.mcwl.communityCenter.domain.dto.JoinCommunityRes;
|
||||||
import com.mcwl.communityCenter.service.CommunityService;
|
import com.mcwl.communityCenter.service.CommunityService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
@ -37,8 +35,8 @@ public class CommunityController {
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = "社区列表")
|
@ApiOperation(value = "社区列表")
|
||||||
@PostMapping("list")
|
@PostMapping("list")
|
||||||
public TableDataInfo getCommunityList(@RequestBody @Valid PageDomain pageDomain) {
|
public TableDataInfo getCommunityList(@RequestBody @Valid CommunityListPageRes communityListPageRes) {
|
||||||
return communityService.listByPage(pageDomain);
|
return communityService.listByPage(communityListPageRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,6 +53,16 @@ public class CommunityController {
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入社区
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "加入社区")
|
||||||
|
@PostMapping("join")
|
||||||
|
public R<Object> joinCommunity(@Valid JoinCommunityRes joinCommunityRes) {
|
||||||
|
|
||||||
|
return communityService.joinCommunity(joinCommunityRes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除社区
|
* 删除社区
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,12 +30,30 @@ public class Community extends BaseEntity {
|
||||||
@TableField(fill = FieldFill.INSERT)
|
@TableField(fill = FieldFill.INSERT)
|
||||||
private Long tenantId;
|
private Long tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社区图片
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "社区图片")
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社区名称
|
* 社区名称
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "社区名称")
|
@ApiModelProperty(value = "社区名称")
|
||||||
private String communityName;
|
private String communityName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社区标签id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "社区标签id")
|
||||||
|
private Long communityTagId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社区类型
|
* 社区类型
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
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;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社区
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("cc_community_user")
|
||||||
|
@ApiModel(value = "社区用户")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
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,0 +1,23 @@
|
||||||
|
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 CommunityListPageRes extends PageDomain {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社区标签id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "社区标签id")
|
||||||
|
private Long communityTagId;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.mcwl.communityCenter.domain.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入社区请求参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ApiModel(value = "加入社区请求参数")
|
||||||
|
public class JoinCommunityRes {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "租户id", required = true)
|
||||||
|
@NotNull(message = "租户id不能为空")
|
||||||
|
private Long tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社区id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "社区id", required = true)
|
||||||
|
@NotNull(message = "社区id不能为空")
|
||||||
|
private Long communityId;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -22,12 +22,47 @@ public class CommunityVo {
|
||||||
@ApiModelProperty(value = "社区id")
|
@ApiModelProperty(value = "社区id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社区图片
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "社区图片")
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社区名称
|
* 社区名称
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "社区名称")
|
@ApiModelProperty(value = "社区名称")
|
||||||
private String communityName;
|
private String communityName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 价格
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "价格")
|
||||||
|
private Double price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "创建人")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建天数
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "创建天数")
|
||||||
|
private Long createDay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入人数
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "加入人数")
|
||||||
|
private Integer joinNum;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CommunityMapper extends BaseMapper<Community> {
|
public interface CommunityMapper extends BaseMapper<Community> {
|
||||||
|
@ -17,4 +18,11 @@ public interface CommunityMapper extends BaseMapper<Community> {
|
||||||
@NotNull(message = "社区id不能为空")
|
@NotNull(message = "社区id不能为空")
|
||||||
@Param("communityId")
|
@Param("communityId")
|
||||||
Long communityId);
|
Long communityId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有社区加入人数, 以map形式返回,key为社区id,value为加入人数
|
||||||
|
* @return map
|
||||||
|
*/
|
||||||
|
@InterceptorIgnore(tenantLine = "true")
|
||||||
|
Map<Long, Integer> selectCommunityJoinNum();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
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 com.mcwl.communityCenter.domain.CommunityUser;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CommunityUserMapper extends BaseMapper<CommunityUser> {
|
||||||
|
|
||||||
|
@InterceptorIgnore(tenantLine = "true")
|
||||||
|
CommunityUser selectByTenantIdAndCommunityIdAndUserId(@Param("tenantId") Long tenantId,
|
||||||
|
@Param("communityId") Long communityId,
|
||||||
|
@Param("userId") Long userId);
|
||||||
|
}
|
|
@ -1,17 +1,28 @@
|
||||||
package com.mcwl.communityCenter.service;
|
package com.mcwl.communityCenter.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.mcwl.common.core.page.PageDomain;
|
import com.mcwl.common.core.domain.R;
|
||||||
import com.mcwl.common.core.page.TableDataInfo;
|
import com.mcwl.common.core.page.TableDataInfo;
|
||||||
import com.mcwl.communityCenter.domain.Community;
|
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.CommunityRes;
|
||||||
|
import com.mcwl.communityCenter.domain.dto.JoinCommunityRes;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public interface CommunityService extends IService<Community> {
|
public interface CommunityService extends IService<Community> {
|
||||||
TableDataInfo listByPage(PageDomain pageDomain);
|
TableDataInfo listByPage(CommunityListPageRes communityListPageRes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加社区
|
* 添加社区
|
||||||
* @param communityRes 社区信息
|
* @param communityRes 社区信息
|
||||||
*/
|
*/
|
||||||
void addCommunity(CommunityRes communityRes);
|
void addCommunity(CommunityRes communityRes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入社区
|
||||||
|
* @param joinCommunityRes 加入社区信息
|
||||||
|
*/
|
||||||
|
R<Object> joinCommunity(JoinCommunityRes joinCommunityRes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,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.TableDataInfo;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public interface CommunityUserService extends IService<CommunityUser> {
|
||||||
|
}
|
|
@ -1,55 +1,79 @@
|
||||||
package com.mcwl.communityCenter.service.impl;
|
package com.mcwl.communityCenter.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
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.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.mcwl.common.constant.HttpStatus;
|
import com.mcwl.common.constant.HttpStatus;
|
||||||
import com.mcwl.common.core.page.PageDomain;
|
import com.mcwl.common.core.domain.R;
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
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.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.communityCenter.domain.Community;
|
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.CommunityRes;
|
||||||
|
import com.mcwl.communityCenter.domain.dto.JoinCommunityRes;
|
||||||
import com.mcwl.communityCenter.domain.vo.CommunityVo;
|
import com.mcwl.communityCenter.domain.vo.CommunityVo;
|
||||||
import com.mcwl.communityCenter.mapper.CommunityMapper;
|
import com.mcwl.communityCenter.mapper.CommunityMapper;
|
||||||
|
import com.mcwl.communityCenter.mapper.CommunityUserMapper;
|
||||||
import com.mcwl.communityCenter.service.CommunityService;
|
import com.mcwl.communityCenter.service.CommunityService;
|
||||||
|
import com.mcwl.system.service.ISysUserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.time.LocalDate;
|
||||||
import java.util.Objects;
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community> implements CommunityService {
|
public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community> implements CommunityService {
|
||||||
|
|
||||||
|
private final CommunityUserMapper communityUserMapper;
|
||||||
|
|
||||||
|
private final ISysUserService sysUserService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo listByPage(PageDomain pageDomain) {
|
public TableDataInfo listByPage(CommunityListPageRes communityListPageRes) {
|
||||||
|
|
||||||
Page<Community> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
|
// 查询社区加入人数,以map形式返回,key为社区id,value为加入人数
|
||||||
|
Map<Long, Integer> communityJoinNumMap = baseMapper.selectCommunityJoinNum();
|
||||||
|
|
||||||
|
Page<Community> page = new Page<>(communityListPageRes.getPageNum(), communityListPageRes.getPageSize());
|
||||||
|
|
||||||
|
|
||||||
boolean isAsc = Objects.equals(pageDomain.getIsAsc(), "asc");
|
boolean isAsc = Objects.equals(communityListPageRes.getIsAsc(), "asc");
|
||||||
|
|
||||||
if (StringUtils.isBlank(pageDomain.getOrderByColumn())) {
|
if (StringUtils.isBlank(communityListPageRes.getOrderByColumn())) {
|
||||||
pageDomain.setOrderByColumn("create_time");
|
communityListPageRes.setOrderByColumn("create_time");
|
||||||
}
|
}
|
||||||
OrderItem orderItem = new OrderItem(pageDomain.getOrderByColumn(), isAsc);
|
OrderItem orderItem = new OrderItem(communityListPageRes.getOrderByColumn(), isAsc);
|
||||||
page.addOrder(orderItem);
|
page.addOrder(orderItem);
|
||||||
|
|
||||||
baseMapper.selectPage(page, null);
|
baseMapper.selectPage(page, new LambdaQueryWrapper<Community>()
|
||||||
|
.eq(communityListPageRes.getCommunityTagId() != null, Community::getCommunityTagId, communityListPageRes.getCommunityTagId()));
|
||||||
|
|
||||||
List<Community> communityList = page.getRecords();
|
List<Community> communityList = page.getRecords();
|
||||||
List<CommunityVo> communityVoList = new ArrayList<>();
|
List<CommunityVo> communityVoList = new ArrayList<>();
|
||||||
|
|
||||||
|
LocalDate currentLocalDate = LocalDate.now(ZoneId.systemDefault());
|
||||||
for (Community community : communityList) {
|
for (Community community : communityList) {
|
||||||
CommunityVo communityVo = new CommunityVo();
|
CommunityVo communityVo = new CommunityVo();
|
||||||
BeanUtil.copyProperties(community, 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.setCreateDay(daysBetween);
|
||||||
|
communityVo.setJoinNum(communityJoinNumMap.getOrDefault(community.getId(), 0));
|
||||||
communityVoList.add(communityVo);
|
communityVoList.add(communityVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,5 +94,47 @@ public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入社区
|
||||||
|
*
|
||||||
|
* @param joinCommunityRes 加入社区请求参数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public R<Object> joinCommunity(JoinCommunityRes joinCommunityRes) {
|
||||||
|
Long tenantId = joinCommunityRes.getTenantId();
|
||||||
|
Long communityId = joinCommunityRes.getCommunityId();
|
||||||
|
Community community = baseMapper.getByTenantIdAndCommunityId(tenantId, communityId);
|
||||||
|
if (Objects.isNull(community)) {
|
||||||
|
return R.fail("社区不存在,请重新加入");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommunityUser communityUser = communityUserMapper.selectByTenantIdAndCommunityIdAndUserId(tenantId,
|
||||||
|
communityId,
|
||||||
|
SecurityUtils.getUserId());
|
||||||
|
|
||||||
|
if (Objects.nonNull(communityUser)) {
|
||||||
|
return R.fail("您已加入该社区,不能重复加入");
|
||||||
|
}
|
||||||
|
|
||||||
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
||||||
|
Double wallet = user.getWallet();
|
||||||
|
Double price = community.getPrice();
|
||||||
|
if (wallet < price) {
|
||||||
|
return R.fail("钱包余额不足,请充值");
|
||||||
|
}
|
||||||
|
// 扣费
|
||||||
|
BigDecimal priceBigDecimal = new BigDecimal(price.toString());
|
||||||
|
BigDecimal walletBigDecimal = new BigDecimal(wallet.toString());
|
||||||
|
user.setWallet(walletBigDecimal.subtract(priceBigDecimal).doubleValue());
|
||||||
|
|
||||||
|
sysUserService.updateUser(user);
|
||||||
|
|
||||||
|
communityUserMapper.insert(new CommunityUser(null, tenantId, communityId, SecurityUtils.getUserId()));
|
||||||
|
|
||||||
|
|
||||||
|
return R.ok("加入成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.mcwl.communityCenter.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
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.TableDataInfo;
|
||||||
|
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.vo.CommunityVo;
|
||||||
|
import com.mcwl.communityCenter.mapper.CommunityMapper;
|
||||||
|
import com.mcwl.communityCenter.mapper.CommunityUserMapper;
|
||||||
|
import com.mcwl.communityCenter.service.CommunityService;
|
||||||
|
import com.mcwl.communityCenter.service.CommunityUserService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CommunityUserServiceImpl extends ServiceImpl<CommunityUserMapper, CommunityUser> implements CommunityUserService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -16,4 +16,13 @@
|
||||||
and id = #{communityId}
|
and id = #{communityId}
|
||||||
and del_flag = '0';
|
and del_flag = '0';
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCommunityJoinNum" resultType="java.util.Map">
|
||||||
|
select c.id, COALESCE(count(*), 0)
|
||||||
|
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>
|
||||||
</mapper>
|
</mapper>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?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.CommunityUserMapper">
|
||||||
|
|
||||||
|
<select id="selectByTenantIdAndCommunityIdAndUserId"
|
||||||
|
resultType="com.mcwl.communityCenter.domain.CommunityUser">
|
||||||
|
select id,
|
||||||
|
tenant_id,
|
||||||
|
community_id,
|
||||||
|
user_id
|
||||||
|
from cc_community_user
|
||||||
|
where tenant_id = #{tenantId}
|
||||||
|
and community_id = #{communityId}
|
||||||
|
and user_id = #{userId}
|
||||||
|
and del_flag = '0';
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue