package com.hdkj.lt.utils.sys;

import cn.hutool.core.collection.CollectionUtil;
import com.hdkj.lt.base.constants.SystemGlobalConstant;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class MappingValueUtils {

    /**
     * 将struType类型和专业映射成对应orderBy节点
     */
    public static Integer struTypeToOrderBy(String struType, List<String> majorCodeList) {
        Integer orderBy = 999999;
        if (StringUtils.isNotEmpty(struType)) {
            switch (struType) {
                case SystemGlobalConstant.ORGAN_TYPE_PROVINCE:
                    orderBy = 0;
                    break;
                case SystemGlobalConstant.ORGAN_TYPE_CITY:
                    orderBy = 2;
                    break;
                case SystemGlobalConstant.ORGAN_TYPE_COUNTY:
                    orderBy = 3;
                    break;
                case SystemGlobalConstant.ORGAN_TYPE_TEAM:
                    orderBy = 4;
                    break;
                case SystemGlobalConstant.ORGAN_TYPE_USER:
                    orderBy = 5;
                    break;
                default:
                    orderBy = 999999;
            }
            if (SystemGlobalConstant.ORGAN_TYPE_PROVINCE.equals(struType) && CollectionUtil.isNotEmpty(majorCodeList)) {
                orderBy = 1;
            }
        }
        return orderBy;
    }

    public static List<Integer> struTypeBeOrderBys(String struType, List<String> majorCodeList) {
        List<Integer> collect = new ArrayList<>();
        if (StringUtils.isNotEmpty(struType)) {
            if (SystemGlobalConstant.ORGAN_TYPE_PROVINCE.equals(struType) && CollectionUtil.isNotEmpty(majorCodeList)) {
                collect.add(2);
                collect.add(3);
                collect.add(4);
                return collect;
            }
            switch (struType) {
                case SystemGlobalConstant.ORGAN_TYPE_PROVINCE:
                    collect.add(1);
                    collect.add(2);
                    collect.add(3);
                    collect.add(4);
                    return collect;
                case SystemGlobalConstant.ORGAN_TYPE_CITY:
                    collect.add(3);
                    collect.add(4);
                    return collect;
                case SystemGlobalConstant.ORGAN_TYPE_COUNTY:
                    collect.add(4);
                    return collect;
                default:
                    return new ArrayList<>();
            }
        }
        return new ArrayList<>();
    }

    public static String orderbyToStruType(Integer orderBy) {
        switch (orderBy) {
            case 0:
                return SystemGlobalConstant.ORGAN_TYPE_PROVINCE;
            case 1:
                return SystemGlobalConstant.ORGAN_TYPE_PROVINCE;
            case 2:
                return SystemGlobalConstant.ORGAN_TYPE_CITY;
            case 3:
                return SystemGlobalConstant.ORGAN_TYPE_COUNTY;
            case 4:
                return SystemGlobalConstant.ORGAN_TYPE_TEAM;
            default:
                return "";
        }
    }

}
