package com.trade.client.advocacypage.cmp;

import com.trade.client.advocacypage.constant.QuotaDimensionEnum;
import com.trade.client.advocacypage.domain.CreditQuotaLogic;
import com.trade.client.advocacypage.dto.CreditQuotaContext;
import com.trade.client.advocacypage.dto.EstimatedCreditQuotaDto;
import com.trade.client.advocacypage.service.CreditQuotaLogicService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;

import javax.annotation.Resource;

/**
 * @description: 买方最长回款账期
 * @Author: wanglang
 * @Date: 2024/6/7 11:35
 * @Version: 1.0
 */
@LiteflowComponent("buyerMaximumPaybackPeriodCmp")
public class BuyerMaximumPaybackPeriodCmp extends NodeComponent {

    @Resource
    private CreditQuotaLogicService creditQuotaLogicService;

    @Override
    public void process() throws Exception {
        EstimatedCreditQuotaDto req = this.getRequestData();
        CreditQuotaContext creditQuotaContext = this.getContextBean(CreditQuotaContext.class);
        CreditQuotaLogic creditQuotaLogic = creditQuotaLogicService.lambdaQuery()
                .eq(CreditQuotaLogic::getDimension, QuotaDimensionEnum.MAXIMUM_PAYBACK_PERIOD.getCode())
                .eq(CreditQuotaLogic::getStandardSetting, req.getBuyerMaximumPaybackPeriod()).one();
        // 计算分数
        double score = creditQuotaLogic.getEstimateScore() + creditQuotaContext.getScore();
        creditQuotaContext.setScore(score);
    }
}
