package com.trade.client.advocacypage.cmp;

import com.trade.client.advocacypage.constant.QuotaDimensionEnum;
import com.trade.client.advocacypage.constant.StandardSettingEnum;
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.NodeBooleanComponent;

import javax.annotation.Resource;

/**
 * @description: 买方合作时间
 * @Author: wanglang
 * @Date: 2024/6/7 11:33
 * @Version: 1.0
 */
@LiteflowComponent("buyerCooperationTimeCmp")
public class BuyerCooperationTimeCmp extends NodeBooleanComponent {

    @Resource
    private CreditQuotaLogicService creditQuotaLogicService;

    @Override
    public boolean processBoolean() throws Exception {
        CreditQuotaContext creditQuotaContext = this.getContextBean(CreditQuotaContext.class);
        EstimatedCreditQuotaDto req = this.getRequestData();
        if (StandardSettingEnum.CT_SIX_MONTH_BELOW.getCode().equals(req.getBuyerCooperationTime())) {
            creditQuotaContext.setScore(0.00);
            return false;
        }
        CreditQuotaLogic creditQuotaLogic = creditQuotaLogicService.lambdaQuery()
                .eq(CreditQuotaLogic::getDimension, QuotaDimensionEnum.COOPERATION_TIME.getCode())
                .eq(CreditQuotaLogic::getStandardSetting, req.getBuyerCooperationTime()).one();
        // 计算分数
        double score = creditQuotaLogic.getEstimateScore() + creditQuotaContext.getScore();
        creditQuotaContext.setScore(score);
        return true;
    }
}
