package com.engine.organization.wrapper;

import com.engine.organization.entity.company.po.CompPO;
import com.engine.organization.entity.department.po.DepartmentPO;
import com.engine.organization.trigger.cusfielddata.CusFieldDataTrigger;
import com.engine.organization.util.OrganizationWrapper;
import com.engine.organization.util.relation.EcHrmRelationUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * @author:dxfeng
 * @createTime: 2022/08/02
 * @version: 1.0
 */
public class JclOrgWrapper extends OrganizationWrapper {


    public String getEcOrgId(String jclId, String type) {
        if (StringUtils.isAnyBlank(jclId, type)) {
            return null;
        }
        switch (type) {
            case "1":
                return EcHrmRelationUtil.getEcCompanyId(jclId);
            case "2":
                return EcHrmRelationUtil.getEcDepartmentId(jclId);
            case "3":
            default:
                return "";
        }
    }

    public String getJclOrgId(String ecId, String type) {
        if (StringUtils.isAnyBlank(ecId, type)) {
            return null;
        }
        String jclOrgId = "";
        switch (type) {
            case "1":
                CompPO jclCompanyId = EcHrmRelationUtil.getJclCompanyId(ecId);
                if (null != jclCompanyId) {
                    jclOrgId = jclCompanyId.getId().toString();
                }
                break;
            case "2":
                DepartmentPO jclDepartmentId = EcHrmRelationUtil.getJclDepartmentId(ecId);
                if (null != jclDepartmentId) {
                    jclOrgId = jclDepartmentId.getId().toString();
                }
            case "3":
            default:
                break;
        }
        return jclOrgId;
    }

    public void syncCusFieldData(String id) {
        CusFieldDataTrigger.run(StringUtils.isNotBlank(id) ? Long.parseLong(id) : null);
    }
}
