| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- package cn.com.goldenwater.dcproj.utils;
- import cn.com.goldenwater.dcproj.constValue.SplitValue;
- import org.apache.commons.collections.map.HashedMap;
- import org.apache.commons.lang3.StringUtils;
- import java.util.Map;
- /**
- * Created by 61618 on 2018/12/9.
- */
- public class AdLevelUtil {
- public static Map<String, Object> SubAd(String AD_CODE) {
- int AD_GRAD = 0;
- Map<String, Object> map = new HashedMap();
- if(AD_CODE.length()==6){
- map.put("level", "4");
- map.put(SplitValue.SUBAD, AD_CODE);
- }
- if(AD_CODE.length()==4){
- map.put("level", "3");
- map.put(SplitValue.SUBAD, AD_CODE);
- }
- if(AD_CODE.length()==2){
- map.put("level", "2");
- map.put(SplitValue.SUBAD, AD_CODE);
- }
- if ("000000000000".equals(AD_CODE) || "ROOT".equals(AD_CODE) || "".equals(AD_CODE)) {
- AD_CODE = "__0000000000" + "%";
- AD_GRAD = 5;
- map.put(SplitValue.SUBAD, AD_CODE.substring(0, 2));
- map.put("level", AD_GRAD);
- } else {
- if (AD_CODE.length() == 12) {
- String sub = AD_CODE.substring(2, 12);
- if ("0000000000".equals(sub)) {
- AD_GRAD = 4;
- map.put(SplitValue.SUBAD, AD_CODE.substring(0, 2));
- map.put("level", AD_GRAD);
- } else {
- String sub1 = AD_CODE.substring(4, 12);
- if ("00000000".equals(sub1)) {
- AD_GRAD = 3;
- map.put(SplitValue.SUBAD, AD_CODE.substring(0, 4));
- map.put("level", AD_GRAD);
- } else {
- String sub2 = AD_CODE.substring(6, 12);
- if ("000000".equals(sub2)) {
- AD_GRAD = 2;
- map.put(SplitValue.SUBAD, AD_CODE.substring(0, 6));
- map.put("level", AD_GRAD);
- } else {
- String sub3 = AD_CODE.substring(9, 12);
- if ("000".equals(sub3)) {
- AD_GRAD = 2;
- map.put(SplitValue.SUBAD, AD_CODE.substring(0, 9));
- map.put("level", AD_GRAD);
- } else {
- AD_GRAD = 1;
- map.put(SplitValue.SUBAD,AD_CODE);
- map.put("level", AD_GRAD);
- }
- }
- }
- }
- }
- }
- return map;
- }
- public static String Subordinate(String AD_CODE) {
- int AD_GRAD = 0;
- Map<String, Object> map = new HashedMap();
- if ("000000000000".equals(AD_CODE) || "ROOT".equals(AD_CODE) || "".equals(AD_CODE)) {
- AD_CODE = "__0000000000" + "%";
- AD_GRAD = 5;
- } else {
- if (AD_CODE.length() == 12) {
- String sub = AD_CODE.substring(2, 12);
- if ("0000000000".equals(sub)) {
- AD_GRAD = 4;
- AD_CODE = AD_CODE.substring(0, 2) + "__" + "00000000" + "%";
- } else {
- String sub1 = AD_CODE.substring(4, 12);
- if ("00000000".equals(sub1)) {
- AD_GRAD = 3;
- AD_CODE = AD_CODE.substring(0, 4) + "__" + "000000" + "%";
- } else {
- String sub2 = AD_CODE.substring(6, 12);
- if ("000000".equals(sub2)) {
- AD_GRAD = 2;
- AD_CODE = AD_CODE.substring(0, 6) + "___" + "000" + "%";
- } else {
- String sub3 = AD_CODE.substring(9, 12);
- if ("000".equals(sub3)) {
- AD_GRAD = 2;
- AD_CODE = AD_CODE.substring(0, 9) + "___" + "%";
- }
- }
- }
- }
- }
- }
- return AD_CODE;
- }
- /**
- * 根据行政区代码截取 后面的零,省,市 长度 除保留特殊市,其他删除掉
- *
- * @param adList 逗号隔开行政区 10位代码
- * @return 逗号隔开去零后行政区代码,保留特殊市
- * @Author lhc
- * @date 2019-12-07
- */
- public static String getListAddvcd(String adList) {
- String[] ad = adList.split(",");
- String temp = "";
- for (String adItem : ad) {
- String newAddvcd = getAddvcd(adItem);
- if (newAddvcd.length() == 6 || "4419".equals(newAddvcd) || "4420".equals(newAddvcd) || "4604".equals(newAddvcd)) {
- temp += newAddvcd + ",";
- }
- }
- if (temp.length() > 0) {
- temp = temp.substring(0, temp.length() - 1);
- }
- return temp;
- }
- public static String getAddvcd(String temp) {
- if (StringUtils.isNotBlank(temp) && temp.trim().length() == 12) {
- temp = temp.trim();
- String str = "000";
- while (temp.endsWith(str)) {
- if (temp.length() == 12 || temp.length() == 9) {
- temp = temp.substring(0, temp.length() - str.length());
- } else {
- break;
- }
- }
- str = "00";
- while (temp.endsWith(str)) {
- if (temp.length() == 6 || temp.length() == 4 || temp.length() == 2) {
- temp = temp.substring(0, temp.length() - str.length());
- } else {
- break;
- }
- }
- }
- return temp;
- }
- /**
- * 返回所有下级adcode参数
- *
- * @param oldAdCode
- * @return
- */
- public static String getAllLowerLevelAdCode(String oldAdCode) {
- String subAd = "";
- //处理adcode
- if (null != oldAdCode) {
- Map<String, Object> stringObjectMap = AdLevelUtil.SubAd(oldAdCode);
- subAd = (String) stringObjectMap.get(SplitValue.SUBAD);
- subAd += "%";
- }
- return subAd;
- }
- public static Map<String, Object> subAdByGrad(String adGrad) {
- Map<String, Object> map = new HashedMap();
- if ("2".equals(adGrad)) {
- map.put("sub", "2");
- map.put("con", "0000000000");
- }
- if ("3".equals(adGrad)) {
- map.put("sub", "4");
- map.put("con", "00000000");
- }
- if ("4".equals(adGrad)) {
- map.put("sub", "6");
- map.put("con", "000000");
- }
- return map;
- }
- }
|