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.model.dtos.community.wallet.ComActWalletDetailDTO;
|
import com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeDTO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.community.wallet.ComActWalletVO;
|
import com.panzhihua.service_community.dao.ComActUserWalletMapper;
|
import com.panzhihua.service_community.model.dos.ComActUserWalletDO;
|
import com.panzhihua.service_community.service.ComActUserWalletService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.Map;
|
|
/**
|
* @auther lyq
|
* @create 2021-06-25 10:35:11
|
* @describe 用户钱包表服务实现类
|
*/
|
@Slf4j
|
@Service
|
public class ComActUserWalletServiceImpl extends ServiceImpl<ComActUserWalletMapper, ComActUserWalletDO> implements ComActUserWalletService {
|
|
/**
|
* 查询用户钱包信息
|
* @param walletDetailDTO 请求参数
|
* @return 用户钱包信息
|
*/
|
@Override
|
public R getWallet(ComActWalletDetailDTO walletDetailDTO){
|
ComActWalletVO comActWalletVO = new ComActWalletVO();
|
//查询用户钱包
|
ComActUserWalletDO userWalletDO = this.baseMapper.selectOne(new QueryWrapper<ComActUserWalletDO>()
|
.lambda().eq(ComActUserWalletDO::getUserId,walletDetailDTO.getUserId())
|
.eq(ComActUserWalletDO::getCommunityId,walletDetailDTO.getCommunityId()));
|
if(userWalletDO == null){//若钱包不存在则新建钱包
|
userWalletDO = new ComActUserWalletDO();
|
userWalletDO.setIncomeAmount(BigDecimal.ZERO);
|
userWalletDO.setAvailableAmount(BigDecimal.ZERO);
|
userWalletDO.setSettlementAmount(BigDecimal.ZERO);
|
userWalletDO.setUserId(walletDetailDTO.getUserId());
|
userWalletDO.setCommunityId(walletDetailDTO.getCommunityId());
|
userWalletDO.setEasyCount(0);
|
userWalletDO.setCreateAt(new Date());
|
this.baseMapper.insert(userWalletDO);
|
}
|
BeanUtils.copyProperties(userWalletDO,comActWalletVO);
|
Map<String,String> resultMap = this.baseMapper.getCommunityName(walletDetailDTO.getCommunityId());
|
if(!resultMap.isEmpty()){
|
comActWalletVO.setCommunityName(resultMap.get("name"));
|
comActWalletVO.setAgreement(resultMap.get("content"));
|
}
|
return R.ok(comActWalletVO);
|
}
|
|
/**
|
* 查询用户绑定的社区收益排行榜
|
* @param walletTradeDTO 请求参数
|
* @return 社区收益排行榜
|
*/
|
@Override
|
public R getWalletRanking(PageComActWalletTradeDTO walletTradeDTO){
|
return R.ok(this.baseMapper.getWalletRanking(new Page(walletTradeDTO.getPageNum(),walletTradeDTO.getPageSize()),walletTradeDTO));
|
}
|
|
}
|