package com.bonus.canteen.core.report.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.account.domain.param.AccountInfoQueryParam;
import com.bonus.canteen.core.account.domain.vo.AccInfoDetailsVO;
import com.bonus.canteen.core.account.service.IAccInfoService;
import com.bonus.canteen.core.report.domain.*;
import com.bonus.canteen.core.report.mapper.AccReportMapper;
import com.bonus.canteen.core.report.mapper.TradeReportMapper;
import com.bonus.canteen.core.report.service.AccReportService;
import com.bonus.canteen.core.report.service.TradeReportService;
import com.bonus.common.houqin.utils.SM4EncryptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AccReportServiceImpl implements AccReportService {
    @Resource
    AccReportMapper accReportMapper;
    @Autowired
    IAccInfoService accInfoService;

    @Override
    public List<AccInfoDetailsVO> balanceList(AccountInfoQueryParam accountInfoQueryParam) {
        return accInfoService.selectAccInfoList(accountInfoQueryParam);
    }

    @Override
    public AccInfoDetailsVO balanceListSum(AccountInfoQueryParam accountInfoQueryParam) {
        return accInfoService.queryAccInfoBalanceSum(accountInfoQueryParam);
    }

    @Override
    public List<RechargeRecordVO> rechargeCount(RechargeRecordParam param) {
        return accReportMapper.selectRechargeRecord(param);
    }
    @Override
    public List<WithdrawRecordVO> selectWithdrawRecord(WithdrawRecordParam param) {
        return accReportMapper.selectWithdrawRecord(param);
    }

    @Override
    public List<DeptIncomeOutcomeVO> selectDeptIncomeOutcome(DeptIncomeOutcomeParam param) {
        return accReportMapper.selectDeptIncomeOutcome(param);
    }

    @Override
    public List<UserIncomeOutcomeVO> selectUserIncomeOutcome(UserIncomeOutcomeParam param) {
        String encryptedSearchValue = SM4EncryptUtils.sm4Encrypt(param.getSearchValue());
        List<UserIncomeOutcomeVO> list = accReportMapper.selectUserIncomeOutcome(param, encryptedSearchValue);
        if(CollUtil.isNotEmpty(list)) {
            for (UserIncomeOutcomeVO userIncomeOutcomeVO : list) {
                userIncomeOutcomeVO.setPhonenumber(SM4EncryptUtils.sm4Decrypt(userIncomeOutcomeVO.getPhonenumber()));
            }
        }
        return list;
    }
}
