package com.yem.ia.intebilllogon.Utils;

import kd.bos.dataentity.metadata.dynamicobject.DynamicPropertyCollection;
import kd.bos.entity.MainEntityType;
import kd.bos.metadata.dao.MetaCategory;
import kd.bos.metadata.dao.MetadataDao;
import kd.bos.metadata.form.BillFormAp;
import kd.bos.metadata.form.ControlAp;
import kd.bos.metadata.form.FormMetadata;
import kd.bos.metadata.form.control.EntryAp;

import java.util.List;

/**
 * @author zhouc
 * @date 2023/8/24 10:34
 * @className GetDocumentTypeUtils
 * @description 根据标识判断是否单据头或者单据体
 * H：单据头   D：单据体    S：子单据体
 */
public class GetDocumentTypeUtils {

    public static String GetDocumentType(MainEntityType sourceMainType, String fieldId) {
        String result = "";
        FormMetadata taskMeta = (FormMetadata) MetadataDao.readRuntimeMeta(MetadataDao.getIdByNumber(sourceMainType.getName(), MetaCategory.Form), MetaCategory.Form);
        //获取所有控件集合
        List<ControlAp<?>> items = taskMeta.getItems();
        DynamicPropertyCollection dynPropColl = (DynamicPropertyCollection) sourceMainType.getProperties();
        for (ControlAp<?> item : items) {
            String key = item.getKey();
            if (key.equals("yem_retrofitting")) {//yem_retrofitting
                if (item instanceof BillFormAp) {
                    result = "H";
                    break;
                }
                if (item instanceof EntryAp) {
                    result = "D";
                    break;
                }
            }
        }
        return result;
    }
}
