318809cb15e28541c67dba68615dd3e7a5410511.svn-base 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package cn.com.goldenwater.dcproj.utils;
  2. import cn.com.goldenwater.dcproj.constValue.SplitValue;
  3. import org.apache.commons.collections.map.HashedMap;
  4. import org.apache.commons.lang3.StringUtils;
  5. import java.util.Map;
  6. /**
  7. * Created by 61618 on 2018/12/9.
  8. */
  9. public class AdLevelUtil {
  10. public static Map<String, Object> SubAd(String AD_CODE) {
  11. int AD_GRAD = 0;
  12. Map<String, Object> map = new HashedMap();
  13. if(AD_CODE.length()==6){
  14. map.put("level", "4");
  15. map.put(SplitValue.SUBAD, AD_CODE);
  16. }
  17. if(AD_CODE.length()==4){
  18. map.put("level", "3");
  19. map.put(SplitValue.SUBAD, AD_CODE);
  20. }
  21. if(AD_CODE.length()==2){
  22. map.put("level", "2");
  23. map.put(SplitValue.SUBAD, AD_CODE);
  24. }
  25. if ("000000000000".equals(AD_CODE) || "ROOT".equals(AD_CODE) || "".equals(AD_CODE)) {
  26. AD_CODE = "__0000000000" + "%";
  27. AD_GRAD = 5;
  28. map.put(SplitValue.SUBAD, AD_CODE.substring(0, 2));
  29. map.put("level", AD_GRAD);
  30. } else {
  31. if (AD_CODE.length() == 12) {
  32. String sub = AD_CODE.substring(2, 12);
  33. if ("0000000000".equals(sub)) {
  34. AD_GRAD = 4;
  35. map.put(SplitValue.SUBAD, AD_CODE.substring(0, 2));
  36. map.put("level", AD_GRAD);
  37. } else {
  38. String sub1 = AD_CODE.substring(4, 12);
  39. if ("00000000".equals(sub1)) {
  40. AD_GRAD = 3;
  41. map.put(SplitValue.SUBAD, AD_CODE.substring(0, 4));
  42. map.put("level", AD_GRAD);
  43. } else {
  44. String sub2 = AD_CODE.substring(6, 12);
  45. if ("000000".equals(sub2)) {
  46. AD_GRAD = 2;
  47. map.put(SplitValue.SUBAD, AD_CODE.substring(0, 6));
  48. map.put("level", AD_GRAD);
  49. } else {
  50. String sub3 = AD_CODE.substring(9, 12);
  51. if ("000".equals(sub3)) {
  52. AD_GRAD = 2;
  53. map.put(SplitValue.SUBAD, AD_CODE.substring(0, 9));
  54. map.put("level", AD_GRAD);
  55. } else {
  56. AD_GRAD = 1;
  57. map.put(SplitValue.SUBAD,AD_CODE);
  58. map.put("level", AD_GRAD);
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. return map;
  66. }
  67. public static String Subordinate(String AD_CODE) {
  68. int AD_GRAD = 0;
  69. Map<String, Object> map = new HashedMap();
  70. if ("000000000000".equals(AD_CODE) || "ROOT".equals(AD_CODE) || "".equals(AD_CODE)) {
  71. AD_CODE = "__0000000000" + "%";
  72. AD_GRAD = 5;
  73. } else {
  74. if (AD_CODE.length() == 12) {
  75. String sub = AD_CODE.substring(2, 12);
  76. if ("0000000000".equals(sub)) {
  77. AD_GRAD = 4;
  78. AD_CODE = AD_CODE.substring(0, 2) + "__" + "00000000" + "%";
  79. } else {
  80. String sub1 = AD_CODE.substring(4, 12);
  81. if ("00000000".equals(sub1)) {
  82. AD_GRAD = 3;
  83. AD_CODE = AD_CODE.substring(0, 4) + "__" + "000000" + "%";
  84. } else {
  85. String sub2 = AD_CODE.substring(6, 12);
  86. if ("000000".equals(sub2)) {
  87. AD_GRAD = 2;
  88. AD_CODE = AD_CODE.substring(0, 6) + "___" + "000" + "%";
  89. } else {
  90. String sub3 = AD_CODE.substring(9, 12);
  91. if ("000".equals(sub3)) {
  92. AD_GRAD = 2;
  93. AD_CODE = AD_CODE.substring(0, 9) + "___" + "%";
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100. return AD_CODE;
  101. }
  102. /**
  103. * 根据行政区代码截取 后面的零,省,市 长度 除保留特殊市,其他删除掉
  104. *
  105. * @param adList 逗号隔开行政区 10位代码
  106. * @return 逗号隔开去零后行政区代码,保留特殊市
  107. * @Author lhc
  108. * @date 2019-12-07
  109. */
  110. public static String getListAddvcd(String adList) {
  111. String[] ad = adList.split(",");
  112. String temp = "";
  113. for (String adItem : ad) {
  114. String newAddvcd = getAddvcd(adItem);
  115. if (newAddvcd.length() == 6 || "4419".equals(newAddvcd) || "4420".equals(newAddvcd) || "4604".equals(newAddvcd)) {
  116. temp += newAddvcd + ",";
  117. }
  118. }
  119. if (temp.length() > 0) {
  120. temp = temp.substring(0, temp.length() - 1);
  121. }
  122. return temp;
  123. }
  124. public static String getAddvcd(String temp) {
  125. if (StringUtils.isNotBlank(temp) && temp.trim().length() == 12) {
  126. temp = temp.trim();
  127. String str = "000";
  128. while (temp.endsWith(str)) {
  129. if (temp.length() == 12 || temp.length() == 9) {
  130. temp = temp.substring(0, temp.length() - str.length());
  131. } else {
  132. break;
  133. }
  134. }
  135. str = "00";
  136. while (temp.endsWith(str)) {
  137. if (temp.length() == 6 || temp.length() == 4 || temp.length() == 2) {
  138. temp = temp.substring(0, temp.length() - str.length());
  139. } else {
  140. break;
  141. }
  142. }
  143. }
  144. return temp;
  145. }
  146. /**
  147. * 返回所有下级adcode参数
  148. *
  149. * @param oldAdCode
  150. * @return
  151. */
  152. public static String getAllLowerLevelAdCode(String oldAdCode) {
  153. String subAd = "";
  154. //处理adcode
  155. if (null != oldAdCode) {
  156. Map<String, Object> stringObjectMap = AdLevelUtil.SubAd(oldAdCode);
  157. subAd = (String) stringObjectMap.get(SplitValue.SUBAD);
  158. subAd += "%";
  159. }
  160. return subAd;
  161. }
  162. public static Map<String, Object> subAdByGrad(String adGrad) {
  163. Map<String, Object> map = new HashedMap();
  164. if ("2".equals(adGrad)) {
  165. map.put("sub", "2");
  166. map.put("con", "0000000000");
  167. }
  168. if ("3".equals(adGrad)) {
  169. map.put("sub", "4");
  170. map.put("con", "00000000");
  171. }
  172. if ("4".equals(adGrad)) {
  173. map.put("sub", "6");
  174. map.put("con", "000000");
  175. }
  176. return map;
  177. }
  178. }