package com.yem.wm.im.merchantapply.validator;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.QueryServiceHelper;

/**
 * @author zhouc
 * @date 2024/3/25 10:18
 * @className MerChantApplySubmitValidator
 * @description
 */
public class MerChantApplySubmitValidator extends AbstractValidator {
    @Override
    public void validate() {
        //校验跟组织下有无同名称客户
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntity : dataEntities) {
            DynamicObject Obj = dataEntity.getDataEntity();
            boolean exists = QueryServiceHelper.exists("bd_customer", new QFilter[]{new QFilter("name", QCP.equals,
                    Obj.get("yem_merchantstnames")), new QFilter("createorg.id", QCP.equals, 100000l)});
            if (exists){
                this.addErrorMessage(dataEntity,"此名称在跟组织下存在客户，无法保存！");
            }
            DynamicObjectCollection yem_merchantapply_a = Obj.getDynamicObjectCollection("yem_merchantapply_a");
            if(yem_merchantapply_a.size()==0){
                this.addErrorMessage(dataEntity,"请维护至少一条分配信息！");
            }
        }
    }
}
