package com.kingdee.eas.custom.expandassess.service;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.*;
import com.kingdee.eas.custom.expandassess.*;
import com.kingdee.eas.custom.expandassess.app.ExpandStatusEunm;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseImportService;
import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseRowInfo;
import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.util.StringUtils;

/**
 * @author qingwu
 * @date 2024/5/17
 * @apiNote 拓展人员考核专员导入
 */
public class ExpandAssessEntryImportService extends BaseImportService {
    private Context ctx = SHRContext.getInstance().getContext();

    @Override
    protected void verifyRow(BaseRowInfo row) throws ImportException {
        super.verifyRow(row);
        String parentId = getCustomParam("parentId");
        FilterInfo filterInfo = new FilterInfo();
        FilterItemCollection filterItems = filterInfo.getFilterItems();
        filterItems.add(new FilterItemInfo("id", parentId));
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add("periodStatus");
        sic.add("entrys.*");
        try {
            IExpandAssess iExpandAssess = ExpandAssessFactory.getLocalInstance(ctx);
            EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);

        } catch (BOSException e) {
            throw new RuntimeException(e);
        }
        row.getValueOfString("meritA");
    }

    @Override
    protected String getPKSelectString(BaseRowInfo row) {
        String pkSelectString = super.getPKSelectString(row);
        String parentId = getCustomParam("parentId");
        if (StringUtils.isEmpty(parentId)) {
            throw new RuntimeException("拓展人员考核周期ID不可为空！！");
        }
        return pkSelectString + " and parent.id ='" + parentId + "'";
    }

    @Override
    protected void beforeSubmitData(CoreBaseInfo coreBaseInfo) throws ImportException {
        String parentId = getCustomParam("parentId");
        ExpandAssessEntryInfo expandAssessEntryInfo = (ExpandAssessEntryInfo) coreBaseInfo;
        expandAssessEntryInfo.put("parent", parentId);
        expandAssessEntryInfo.setAsseStatus(ExpandStatusEunm.UNSTART);
    }
}
