package com.ym.mec.collectfee.service.impl;

import com.ym.mec.collectfee.common.dao.BaseDAO;
import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
import com.ym.mec.collectfee.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import com.ym.mec.collectfee.entity.Account;
import com.ym.mec.collectfee.service.AccountService;
import com.ym.mec.collectfee.dao.AccountDao;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AccountServiceImpl extends BaseServiceImpl<Integer, Account> implements AccountService {

    @Autowired
    AccountDao accountDao;

    @Autowired
    OrderService orderService;

    @Override
    public BaseDAO<Integer, Account> getDAO() {
        return accountDao;
    }

    @Override
    public Account getAccountByBranchId(Integer branchId, BigDecimal money) {
        return accountDao.getAccountByBranchId(branchId, money);
    }

    @Override
    public int upByIdAndVersion(Account account) {
        return accountDao.upByIdAndVersion(account);
    }

    /**
     * 获取分佣账户
     *
     * @param branchId 默认收款账户
     * @return
     */
    @Override
    public Account getRoutingAccount(int branchId, BigDecimal money) {
        int payOrderNums = orderService.getPayOrderNums(); //获取支付中和成功的订单数
        //分佣账户（1、每10笔，前四笔收入私户 2、私户每个商户最多收款400万），进武汉商户
        int rem = (payOrderNums + 1) % 10;
        if (rem > 0 && rem <= 4) { //私人账户
            branchId = 0;
        }
        return this.getAccountByBranchId(branchId, money);
    }


}