package com.bonus.material.record.service.impl;

import com.bonus.material.record.mapper.SltRecordQueryMapper;
import com.bonus.material.record.service.ISltReocrdQueryService;
import com.bonus.material.settlement.domain.SltAgreementInfo;
import com.bonus.material.settlement.domain.vo.SltInfoVo;
import com.bonus.material.settlement.service.ISltAgreementInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
* @description 结算记录查询
* @author hay
* @date   2025/2/19 10:47
*/
@Service
public class SltRecordQueryServiceImpl implements ISltReocrdQueryService {
    @Resource
    private SltRecordQueryMapper mapper;

    @Autowired
    private ISltAgreementInfoService sltAgreementInfoService;

    @Override
    public List<SltAgreementInfo> getList(SltAgreementInfo bean) {
        return mapper.getList(bean);
    }

    @Override
    public List<SltAgreementInfo> getAppList(SltAgreementInfo bean) {
        List<SltAgreementInfo> list = mapper.getList(bean);
        if (list.size()>0){
            for (SltAgreementInfo sltAgreementInfo : list) {
                if (sltAgreementInfo.getAgreementId()!=null){
                    //todo 后面优化
                    SltInfoVo beans = sltAgreementInfoService.getSltRecordDetailsList(sltAgreementInfo);
                    if (beans!=null){
                        sltAgreementInfo.setLeaseCost(beans.getLeaseCost());
                        sltAgreementInfo.setRepairCost(beans.getRepairCost());
                        sltAgreementInfo.setScrapCost(beans.getScrapCost());
                        sltAgreementInfo.setLoseCost(beans.getLoseCost());
                        sltAgreementInfo.setReductionCost(beans.getReductionCost());
                        BigDecimal totalCostAll = beans.getLeaseCost().add(beans.getLoseCost()).add(beans.getRepairCost()).add(beans.getScrapCost()).subtract(beans.getReductionCost());
                        sltAgreementInfo.setTotalCostAll(totalCostAll);
                    }
                }
            }
        }
        return list;
    }
}
