package com.mortals.xhx.common.utils;

import cn.hutool.core.util.StrUtil;
import com.mortals.xhx.common.code.AreaLevelEnum;

public class AreaMatchCodeUtil {


    /**
     * 遂宁市  510900000000
     * 蓬溪县  510921000000
     * 普安街  510921174000
     *
     * @param matchCode
     * @param areaLevel
     * @return
     */
    public static String getMatchCode(String matchCode, Integer areaLevel) {

        if (AreaLevelEnum.地市州.getValue() == areaLevel) {

            matchCode=StrUtil.sub(matchCode, 0, 4);
            return StrUtil.padAfter(matchCode, 4, "0");
        } else if (AreaLevelEnum.区县.getValue() == areaLevel) {
            //510921174000
            matchCode=StrUtil.sub(matchCode, 0, 6);
            return StrUtil.padAfter(matchCode, 6, "0");
        } else if (AreaLevelEnum.街道.getValue() == areaLevel) {
            //510921174000
            //510921100249
            matchCode=StrUtil.sub(matchCode, 0, 9);
            return StrUtil.padAfter(matchCode, 9, "0");
        } else if (AreaLevelEnum.社区.getValue() == areaLevel) {
            return StrUtil.padAfter(matchCode, 12, "0");
        } else {
            return matchCode;
        }
    }

    public static void main(String[] args) {
        System.out.println(getMatchCode("510921000000", 3));
        System.out.println(getMatchCode("510921174000", 4));
       // System.out.println(getMatchCode("510921100249", 5));
    }

}
