package com.kingdee.eas.custom.esign.osf;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.bsf.service.app.IHRMsfService;
import com.kingdee.bos.metadata.entity.*;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.esign.ESignTemplateCollection;
import com.kingdee.eas.custom.esign.ESignTemplateFactory;
import com.kingdee.eas.custom.esign.IESignTemplate;
import com.kingdee.shr.base.syssetting.BaseItemStateEnum;

import java.util.Map;

/**
 * @Description 同步e签宝模板字段
 * @Date 2025/12/25 18:07
 * @Created by HeYuan
 */
public class SyncTemplateFieldsService implements IHRMsfService {
    @Override
    public Object process(Context ctx, Map map) throws EASBizException, BOSException {
        IESignTemplate iESignTemplate = ESignTemplateFactory.getLocalInstance(ctx);
        FilterInfo filterInfo = new FilterInfo();
        filterInfo.getFilterItems().add(new FilterItemInfo("state", BaseItemStateEnum.ENABLE_VALUE));
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add("id");
        EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
        ESignTemplateCollection eSignTemplateCollection = iESignTemplate.getESignTemplateCollection(viewInfo);
        for (int i = 0; i < eSignTemplateCollection.size(); i++) {
            String billId = eSignTemplateCollection.get(i).getId().toString();
            iESignTemplate.syncTemplateFields(billId);
        }
        return "成功";
    }
}
