package com.orgimport.service;

import com.engine.organization.exception.OrganizationRunTimeException;
import com.orgimport.service.action.StaffInfoImportUtil;
import weaver.hrm.User;

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

/**
 * @author:dxfeng
 * @createTime: 2022/09/15
 * @version: 1.0
 */
public enum OrgImportEnum implements OrgImportAdapter {
    STAFF("staff_info") {
        @Override
        public Map<String, Object> orgImport(Map<String, Object> params, User user) {
            Map<String, Object> resultMap = new HashMap<>();
            String excelFile = (String) params.get("excelfile");
            resultMap.put("pId", StaffInfoImportUtil.saveImport("add", excelFile, user));
            return resultMap;
        }

        @Override
        public List<Map<String, Object>> orgForm(User user) {
            return StaffInfoImportUtil.importForm(user);
        }
    };


    private String tableName;

    OrgImportEnum(String tableName) {
        this.tableName = tableName;
    }

    public static OrgImportEnum getOrgImportUtil(String tableName) {
        for (OrgImportEnum item : OrgImportEnum.values()) {
            if (item.tableName.equalsIgnoreCase(tableName)) {
                return item;
            }
        }
        throw new OrganizationRunTimeException("不支持的导入类型");
    }
}
