package com.panzhihua.service_community.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.panzhihua.common.constants.Constants;
|
import com.panzhihua.common.model.dtos.community.integral.ComActIntegralCommunityRankDTO;
|
import com.panzhihua.common.model.dtos.community.integral.ComActIntegralCountDTO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.community.integral.ComActIntegralUserListVO;
|
import com.panzhihua.common.model.vos.community.integral.ComActIntegralUserRuleVO;
|
import com.panzhihua.common.model.vos.community.integral.ComActIntegralUserVO;
|
import com.panzhihua.common.model.vos.community.integral.IntegralUserRankVO;
|
import com.panzhihua.common.utlis.DateUtils;
|
import com.panzhihua.common.utlis.StringUtils;
|
import com.panzhihua.service_community.dao.ComActDAO;
|
import com.panzhihua.service_community.dao.ComActIntegralRuleMapper;
|
import com.panzhihua.service_community.dao.ComActIntegralUserMapper;
|
import com.panzhihua.service_community.dao.ComActUserWalletMapper;
|
import com.panzhihua.service_community.model.dos.ComActDO;
|
import com.panzhihua.service_community.model.dos.ComActIntegralRuleDO;
|
import com.panzhihua.service_community.model.dos.ComActIntegralUserDO;
|
import com.panzhihua.service_community.model.dos.ComActIntegralUserTradeDO;
|
import com.panzhihua.service_community.service.ComActIntegralRuleService;
|
import com.panzhihua.service_community.service.ComActIntegralUserService;
|
import com.panzhihua.service_community.service.ComActIntegralUserTradeService;
|
import com.panzhihua.service_community.service.ComActService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @auther lyq
|
* @create 2021-07-28 16:02:57
|
* @describe 用户积分账户表服务实现类
|
*/
|
@Slf4j
|
@Service
|
public class ComActIntegralUserServiceImpl extends ServiceImpl<ComActIntegralUserMapper, ComActIntegralUserDO> implements ComActIntegralUserService {
|
|
@Resource
|
private ComActUserWalletMapper comActUserWalletMapper;
|
@Resource
|
private ComActIntegralRuleService comActIntegralRuleService;
|
@Resource
|
private ComActIntegralUserTradeService comActIntegralUserTradeService;
|
@Resource
|
private ComActDAO comActDAO;
|
|
/**
|
* 小程序-查询积分说明
|
* @return 积分说明
|
*/
|
@Override
|
public R getIntegralExplainApplets(){
|
String result = "";
|
Map<String,String> resultMap = comActUserWalletMapper.getAgreementContent(0L,6);
|
if(resultMap != null){
|
if(StringUtils.isEmpty(resultMap.get("content"))){
|
comActUserWalletMapper.insertSysAgreement(Constants.INTEGRAL_EXPLAIN,"积分规则说明",0L,6);
|
result = Constants.INTEGRAL_EXPLAIN;
|
}else{
|
result = resultMap.get("content");
|
}
|
}else{
|
comActUserWalletMapper.insertSysAgreement(Constants.INTEGRAL_EXPLAIN,"积分规则说明",0L,6);
|
result = Constants.INTEGRAL_EXPLAIN;
|
}
|
return R.ok(result);
|
}
|
|
/**
|
* 用户查询当前社区可领取积分规则列表
|
* @param userId 用户id
|
* @param communityId 社区id
|
* @return 可领取积分规则列表
|
*/
|
@Override
|
public R getIntegralReceiveApplets(Long userId,Long communityId){
|
|
List<ComActIntegralUserRuleVO> integralUserRuleList = comActIntegralRuleService.getIntegralReceiveApplets(communityId);
|
if(integralUserRuleList.isEmpty()){
|
//如果没有查询到列表数据,增给社区增加默认规则列表再查询
|
List<ComActIntegralRuleDO> integralRuleList = comActIntegralRuleService.getIntegralRuleList(communityId);
|
comActIntegralRuleService.saveBatch(integralRuleList);
|
integralUserRuleList = comActIntegralRuleService.getIntegralReceiveApplets(communityId);
|
}
|
if(!integralUserRuleList.isEmpty()){
|
integralUserRuleList.forEach(integralUserRule -> {
|
if(integralUserRule.getIsRestrict().equals(ComActIntegralRuleDO.isRestrict.no)){
|
integralUserRule.setIsComplete(ComActIntegralUserRuleVO.isComplete.no);
|
}else{
|
ComActIntegralCountDTO integralCountDTO = new ComActIntegralCountDTO();
|
integralCountDTO.setUserId(userId);
|
integralCountDTO.setCommunityId(communityId);
|
integralCountDTO.setType(ComActIntegralUserTradeDO.changeType.add);
|
integralCountDTO.setServiceType(integralUserRule.getIntegralType());
|
if(integralUserRule.getType().equals(ComActIntegralRuleDO.type.month)){
|
integralCountDTO.setStartTime(DateUtils.getFirstDayOfMonthString());
|
integralCountDTO.setEndTime(DateUtils.getLastDayOfMonthString());
|
}else if(integralUserRule.getType().equals(ComActIntegralRuleDO.type.day)){
|
integralCountDTO.setStartTime(DateUtils.getDayOfMonthString() + " 00:00:00");
|
integralCountDTO.setEndTime(DateUtils.getDayOfMonthString() + " 23:59:59");
|
}
|
Integer count = comActIntegralUserTradeService.getIntegralCount(integralCountDTO);
|
if(count >= integralUserRule.getCount()){
|
integralUserRule.setIsComplete(ComActIntegralUserRuleVO.isComplete.yes);
|
}else{
|
integralUserRule.setIsComplete(ComActIntegralUserRuleVO.isComplete.no);
|
}
|
}
|
});
|
}
|
return R.ok(integralUserRuleList);
|
}
|
|
/**
|
* 小程序-查询用户积分列表
|
* @param userId 用户id
|
* @return 用户积分列表
|
*/
|
@Override
|
public R getIntegralUserListApplets(Long userId,Long communityId){
|
ComActIntegralUserVO integralUserVO = new ComActIntegralUserVO();
|
Integer amount = 0;
|
//查询该用户在本社区下的积分账户是否存在,不存在则需要给用户创建
|
ComActIntegralUserDO integralUserDO = this.baseMapper.selectOne(new QueryWrapper<ComActIntegralUserDO>().lambda()
|
.eq(ComActIntegralUserDO::getCommunityId,communityId).eq(ComActIntegralUserDO::getUserId,userId));
|
if(integralUserDO == null){
|
integralUserDO = new ComActIntegralUserDO();
|
integralUserDO.setCommunityId(communityId);
|
integralUserDO.setUserId(userId);
|
integralUserDO.setCreateAt(new Date());
|
this.baseMapper.insert(integralUserDO);
|
}
|
|
//查询用户积分账户列表
|
List<ComActIntegralUserListVO> integralUserList = this.baseMapper.getIntegralUserListApplets(userId);
|
if(!integralUserList.isEmpty()){
|
for (ComActIntegralUserListVO integralUser:integralUserList) {
|
//查询用户在本社区积分排行
|
IntegralUserRankVO userRank = this.baseMapper.getIntegralUserRank(integralUser.getCommunityId(),userId);
|
if(userRank != null){
|
integralUser.setRank(userRank.getRank());
|
amount += integralUser.getAmount();
|
}
|
}
|
}
|
//查询用户绑定社区名字
|
ComActDO actDO = comActDAO.selectById(communityId);
|
if(actDO != null){
|
integralUserVO.setCommunityName(actDO.getName());
|
}
|
|
integralUserVO.setAmount(amount);
|
integralUserVO.setIntegralUserList(integralUserList);
|
return R.ok(integralUserVO);
|
}
|
|
/**
|
* 查询社区积分账户排行榜
|
* @param communityRankDTO 请求参数
|
* @return 社区积分账户排行榜
|
*/
|
@Override
|
public R getIntegralCommunityRankApplets(ComActIntegralCommunityRankDTO communityRankDTO){
|
return R.ok(this.baseMapper.getIntegralCommunityRankApplets(new Page(communityRankDTO.getPageNum(),communityRankDTO.getPageSize()),communityRankDTO));
|
}
|
|
/**
|
* 根据社区活动id查询社区活动报名人员列表
|
* @param activityId 活动id
|
* @return 社区活动报名人员列表
|
*/
|
@Override
|
public R getTaskActivityPeopleList(Long activityId){
|
return R.ok(this.baseMapper.getTaskActivityPeopleList(activityId));
|
}
|
}
|