package com.yem.tws.op;

import com.yem.tws.common1.StringUtils;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

public class BilllogonSaveValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.dataEntities;
        for (int i = 0; i < dataEntities.length; i++) {
            ExtendedDataEntity exde = dataEntities[i];
            DynamicObject dataEntity = exde.getDataEntity();
            DynamicObjectCollection entitycontainerObjCons = dataEntity.getDynamicObjectCollection("yem_entitycontainer");
            if (entitycontainerObjCons != null && entitycontainerObjCons.getRowCount() > 0) {
                for (int j = 0; j < entitycontainerObjCons.size(); j++) {
                    DynamicObject entitycontainerObjCon = entitycontainerObjCons.get(j);
                    //默认跟动态默认只允许存在一个
                    DynamicObjectCollection entityfieldcols = entitycontainerObjCon.getDynamicObjectCollection("yem_entityfieldcol");
                    if (entityfieldcols != null && entityfieldcols.getRowCount() > 0) {
                        for (int k = 0; k < entityfieldcols.getRowCount(); k++) {
                            DynamicObject entityfieldcol = entityfieldcols.get(k);
                            String defaultvalue = entityfieldcol.getString("yem_defaultvalue");
                            String modledefaultvalue = entityfieldcol.getString("yem_modledefaultvalue");
                            if (StringUtils.isNotEmpty(defaultvalue) && StringUtils.isNotEmpty(modledefaultvalue)) {
                                this.addMessage(exde, "关务单据注册：容器标识分录第【"+j+1+"】行，实体字段集合第【"+k+1+"】行默认值与动态默认不能同时存在，请检查！");
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
}
