manailin
2021-06-27 76ed3735c23da4b7ef97b8a0f365facbc14f6903
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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));
    }
 
}