package com.cf.imes.module.executor.service.funds.balancedetails;


import cn.hutool.core.collection.CollUtil;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.executor.controller.admin.funds.balancedetails.vo.BalanceDetailsPageReqVO;
import com.cf.imes.module.executor.controller.admin.funds.balancedetails.vo.BalanceDetailsRespVO;
import com.cf.imes.module.executor.dal.dataobject.funds.balancedetails.IncomeExpenseDetailsDO;
import com.cf.imes.module.executor.dal.mysql.funds.balancedetails.IncomeExpenseDetailsMapper;
import com.cf.imes.module.executor.enums.amount.IncomeExpenseTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * @author 组织余额明细接口 实现类
 */
@Slf4j
@Service
public class BalanceDetailsServiceImpl implements BalanceDetailsService{


    @Resource
    private IncomeExpenseDetailsMapper incomeExpenseDetailsMapper;



    @Override
    public PageResult<BalanceDetailsRespVO> getBalanceDetailsPage(BalanceDetailsPageReqVO pageReqVO) {

        PageResult<IncomeExpenseDetailsDO> pageResult = incomeExpenseDetailsMapper.selectDetailsPage(pageReqVO,null);

        if(CollUtil.isNotEmpty(pageResult.getList())){
            return new PageResult<>();
        }

        PageResult<BalanceDetailsRespVO> result = BeanUtils.toBean(pageResult, BalanceDetailsRespVO.class);


        result.getList().forEach(f->{
            if(f.getIncomeExpenseType().equals(IncomeExpenseTypeEnum.INCOME.getType())){
                f.setEntryAmount(f.getCashAmountChange());
                f.setEntryGiftAmount(f.getBonusAmountChange());
            }else {
                f.setExpensesAmount(f.getCashAmountChange());
                f.setExpensesGiftAmount(f.getBonusAmountChange());
            }

        });

        return result;
    }


}
