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

import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.custom.esign.*;
import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK;
//import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean;
//import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import com.kingdee.eas.framework.app.CoreBillBaseControllerBean;
import com.kingdee.eas.framework.SystemEnum;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.eas.framework.ObjectBaseCollection;
import java.lang.String;
import com.kingdee.eas.framework.CoreBillBaseCollection;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;

public class FieldMappingControllerBean extends AbstractFieldMappingControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.custom.esign.app.FieldMappingControllerBean");

    @Override
    protected IObjectPK _save(Context ctx, IObjectValue model) throws BOSException, EASBizException {
        FieldMappingInfo fieldMappingInfo = (FieldMappingInfo) model;
        FieldMappingEntryCollection entrys = fieldMappingInfo.getEntrys();
        for (int i = 0; i < entrys.size(); i++) {
            FieldMappingEntryInfo fieldMappingEntryInfo = entrys.get(i);
            ESignTemplateFileEntryFieldInfo eField = fieldMappingEntryInfo.getEField();
            if (eField!=null){
                BOSUuid id = eField.getId();
                ESignTemplateFileEntryFieldInfo fieldInfo = ESignTemplateFileEntryFieldFactory.getLocalInstance(ctx)
                        .getESignTemplateFileEntryFieldInfo(new ObjectUuidPK(id));
                ESignTemplateFileEntryInfo parent1 = fieldInfo.getParent1();
                fieldMappingEntryInfo.setTemplate(parent1);

                String eFieldMark = fieldMappingEntryInfo.getEFieldMark();
                if (eFieldMark==null||eFieldMark.equals("")){
                    fieldMappingEntryInfo.setEFieldMark(fieldInfo.getTemplateFieldId());
                }
                String eFieldName = fieldMappingEntryInfo.getEFieldName();
                if (eFieldName==null||eFieldName.equals("")){
                    fieldMappingEntryInfo.setEFieldName(fieldInfo.getTemplateFieldName());
                }
            }
        }
        return super._save(ctx, model);
    }
}