WalletServiceImpl.java 6.22 KB
Newer Older
licc's avatar
licc committed
1 2
package cn.wisenergy.service.app.impl;

3 4
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
licc's avatar
licc committed
5
import cn.wisenergy.mapper.AccountMapper;
6
import cn.wisenergy.mapper.LastAccountMapper;
7 8
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.model.app.AccountInfo;
9
import cn.wisenergy.model.app.LastMonthAccount;
10 11 12
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.vo.*;
licc's avatar
licc committed
13
import cn.wisenergy.service.app.WalletService;
14
import io.swagger.models.auth.In;
licc's avatar
licc committed
15
import lombok.extern.slf4j.Slf4j;
16
import org.apache.commons.lang3.StringUtils;
licc's avatar
licc committed
17 18
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
19 20 21 22
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
23
import java.util.Calendar;
24 25
import java.util.Date;
import java.util.List;
licc's avatar
licc committed
26 27 28 29 30 31 32

/**
 * @author 86187
 */
@Service
@Slf4j
public class WalletServiceImpl implements WalletService {
33 34
    private static final String PATTERN = "yyyy-MM";

licc's avatar
licc committed
35 36 37
    @Autowired
    private AccountMapper accountMapper;

38 39 40
    @Autowired
    private TradeRecordMapper tradeRecordMapper;

41 42 43
    @Autowired
    private LastAccountMapper lastAccountMapper;

licc's avatar
licc committed
44 45

    @Override
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 73 74 75 76 77 78
    public R<MoneyPackageVo> getMoneyPackage(String userId) {
        log.info("shop-mall[]WalletServiceImpl[]getMoneyPackage[]input.param.userId:" + userId);
        if (StringUtils.isBlank(userId)) {
            return R.error("入参为空!");
        }

        Date date = new Date();
        String yearMonth = DateUtil.convertDateToStr(date, PATTERN);

        //1、获取用户账户信息
        AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
        if (null == accountInfo) {
            return R.error("用户账户信息不存在!");
        }
        MoneyPackageVo moneyPackageVo = new MoneyPackageVo();
        moneyPackageVo.setUserId(accountInfo.getUserId());
        moneyPackageVo.setMoneyIncome(accountInfo.getEarningsMonth());
        moneyPackageVo.setTotalIncome(accountInfo.getEarningsTotal());
        moneyPackageVo.setCurrentMoneyCan(accountInfo.getExtractMoney());

        return R.ok(moneyPackageVo);
    }

    @Override
    public R<WithdrawalAmountVo> getWithdrawalAmount(String userId) {
        log.info("shop-mall[]WalletServiceImpl[]getWithdrawalAmount[]input.param.userId:" + userId);
        if (StringUtils.isBlank(userId)) {
            return R.error("入参为空!");
        }

        Date date = new Date();
        String yearMonth = DateUtil.convertDateToStr(date, PATTERN);

79 80
        WithdrawalAmountVo withdrawalAmountVo = new WithdrawalAmountVo();
        withdrawalAmountVo.setUserId(userId);
81
        withdrawalAmountVo.setWithdrawRule("这是一条规则!");
82

83 84 85
        //1、获取用户账户信息
        AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
        if (null == accountInfo) {
86 87 88
            withdrawalAmountVo.setCurrentMoneyCan(new BigDecimal(0));
        } else {
            withdrawalAmountVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
89 90
        }

91 92 93 94 95 96 97 98 99 100 101 102
        //2、 获取上月未提现
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.MONTH, -1);
        Date lastDate = cal.getTime();
        String lastMonthTime = DateUtil.convertDateToStr(lastDate, PATTERN);
        LastMonthAccount lastMonthAccount = lastAccountMapper.getByUserIdAndTime(userId, lastMonthTime);
        if (null == lastMonthAccount) {
            withdrawalAmountVo.setLastMoneyNot(new BigDecimal(0));
        } else {
            withdrawalAmountVo.setLastMoneyNot(lastMonthAccount.getExtractMoney());
        }
103 104 105 106 107 108 109 110 111 112
        return R.ok(withdrawalAmountVo);
    }

    @Override
    public R<List<AccumulatedIncomeVo>> showIncomeRecord(String userId) {
        log.info("shop-mall[]WalletServiceImpl[]showIncomeRecord[]input.param.userId:" + userId);
        if (StringUtils.isBlank(userId)) {
            return R.error("入参为空!");
        }

113 114 115
        //获取不包括本月在内的六个月的收益
        List<AccumulatedIncomeVo> list = tradeRecordMapper.getSixMonthIncome(userId);
        return R.ok(list);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    }

    @Override
    public R<MoneyPackageDetailVo> queryIncomeDetail(String userId) {
        log.info("shop-mall[]WalletServiceImpl[]queryIncomeDetail[]input.param.userId:" + userId);
        if (StringUtils.isBlank(userId)) {
            return R.error("入参为空!");
        }

        Date date = new Date();
        String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
        //获取当月账户信息
        AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
        if (null == accountInfo) {
            return R.error("账户信息为空!");
        }

        //获取本月交易记录
134
        List<TradeRecord> list = tradeRecordMapper.getByUserIdAndTime(userId, date);
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
        if (CollectionUtils.isEmpty(list)) {
            return R.ok(new MoneyPackageDetailVo());
        }

        MoneyPackageDetailVo detailVo = new MoneyPackageDetailVo();
        detailVo.setUserId(userId);
        detailVo.setTotalIncome(accountInfo.getEarningsTotal());

        List<IncomeDetailVo> incomeDetailVos = new ArrayList<>();
        for (TradeRecord tradeRecord : list) {
            IncomeDetailVo incomeDetailVo = new IncomeDetailVo();
            String typeName = TradeRecordEnum.getByCode(tradeRecord.getTradeType());

            incomeDetailVo.setTypeName(typeName);
            incomeDetailVo.setMoney(tradeRecord.getMoney());
            incomeDetailVo.setIncomeTime(tradeRecord.getCreateTime());
            incomeDetailVos.add(incomeDetailVo);
        }

        detailVo.setList(incomeDetailVos);

        return R.ok(detailVo);
licc's avatar
licc committed
157
    }
158 159 160 161 162 163 164 165 166 167 168 169

    @Override
    public R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth) {
        log.info("shop-mall[]WalletServiceImpl[]queryIncomeDetail[]input.param.yearMonth:" + yearMonth);
        if (StringUtils.isBlank(yearMonth)) {
            return R.error("入参为空!");
        }

        Date date = DateUtil.convertStrToDate(yearMonth, PATTERN);
        List<WithdrawalRecordVo> list = tradeRecordMapper.getWithdrawalRecord(userId, date);
        return R.ok(list);
    }
licc's avatar
licc committed
170
}