package com.yem.wm.es.storagetrans.validator;

import com.yem.wm.es.Util.TotalUtil;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.servicehelper.BusinessDataServiceHelper;

/**
 * @author zhouc
 * @date 2024/1/17 21:15
 * @className StorageTransAuditValid
 * @description
 */
public class StorageTransAuditValid extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            dataEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), dataEntity.getDynamicObjectType().getName());
            DynamicObject customer = dataEntity.getDynamicObject("yem_customer");
            DynamicObject method = TotalUtil.getSettlementMethod(dataEntity);
            DynamicObject company = dataEntity.getDynamicObject("yem_company.yem_erporg");
            String swiftCode = TotalUtil.getSwiftCode(dataEntity);
            DynamicObject csrCreditLine = TotalUtil.getCsrCreditLine(customer, method, company, swiftCode);
            if (csrCreditLine != null) {
                boolean yem_changing = csrCreditLine.getBoolean("yem_changing");
                boolean yem_effective = csrCreditLine.getBoolean("yem_effective");
                String billno = csrCreditLine.getString("billno");
                if (yem_changing) {
                    this.addErrorMessage(dataEntitie, "获取到客户信保额度申请【" + billno + "】正在变更中，请稍后重试！");
                }
            }
        }
    }
}
