package nckd.jimin.jyyy.hr.tsrsc.plugin.operate;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.MainEntityType;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.servicehelper.MetadataServiceHelper;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * description: 年度招聘申请提交校验插件
 * nckd_yearapply
 * @author Tyx
 * @date  2025/5/8
 */

public class YearCrApplySubmitValidator extends AbstractOperationServicePlugIn {

    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        super.onPreparePropertys(e);
        // 提前加载表单里的字段
        List<String> fieldKeys = e.getFieldKeys();
        fieldKeys.addAll(this.billEntityType.getAllFields().keySet());
    }




    @Override
    public void onAddValidators(AddValidatorsEventArgs e) {
        super.onAddValidators(e);
        e.addValidator(new AbstractValidator() {
            @Override
            public void validate() {
                ExtendedDataEntity[] dataEntities = this.getDataEntities();
                for (ExtendedDataEntity dataEntity : dataEntities) {
                    DynamicObject dynamicObject = dataEntity.getDataEntity();
                    String nckdSummarstatus = dynamicObject.getString("nckd_summarstatus");
                    if(StringUtils.isNotEmpty(nckdSummarstatus) && !"A".equals(nckdSummarstatus)){
                        this.addErrorMessage(dataEntity, "汇总状态为已汇总和汇总中的数据,不能进行操作！");
                        break;
                    }
                }
            }
        });
    }

}
