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:30
 * @Version: 1.0
 */
@LiteflowComponent("buyerEnterpriseTypeCmp")
public class BuyerEnterpriseTypeCmp 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.ENTERPRISE_TYPE.getCode())
                .eq(CreditQuotaLogic::getStandardSetting, req.getBuyerEnterpriseType()).one();
        // 计算分数
        double score = creditQuotaLogic.getEstimateScore() + creditQuotaContext.getScore();
        creditQuotaContext.setScore(score);
    }
}
