CustomInfoUtil.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package com.crm.rely.backend.util;
  2. import com.crm.rely.backend.core.entity.custom.info.CustomInfoEntity;
  3. import com.crm.rely.backend.core.pojo.table.CustomInfoTable;
  4. import com.crm.rely.backend.core.pojo.view.CustomAccountExportView;
  5. import com.crm.rely.backend.core.pojo.view.CustomInfoGetCidView;
  6. import com.crm.rely.backend.core.pojo.view.CustomInfoGetEmailView;
  7. import com.crm.rely.backend.core.pojo.view.CustomView;
  8. import com.google.common.base.Strings;
  9. public class CustomInfoUtil {
  10. /**
  11. * ase 正序( firstName middle lastName) desc 倒序 正序(lastName middle firstName)
  12. */
  13. public static final String ORDER_ASE = "ASE";
  14. public static final String ORDER_DESC = "DESC";
  15. /**
  16. * 获取客户姓名
  17. *
  18. * @param table
  19. * @return
  20. */
  21. public static String getName(CustomInfoTable table) {
  22. if (CountryUtil.isCTHM(table.getCountry())) {
  23. if ((!Strings.isNullOrEmpty(table.getFirstName()) && table.getFirstName().contains(".")) || (!Strings.isNullOrEmpty(table.getLastName()) && table.getLastName().contains(".")) || ("" + table.getFirstName() + table.getLastName()).length() >= 5) {
  24. return getName(table, ORDER_DESC);
  25. } else {
  26. return getName(table, ORDER_DESC);
  27. }
  28. } else {
  29. return getName(table, ORDER_ASE);
  30. }
  31. }
  32. /**
  33. * @param table
  34. * @param order 顺序 ace 正序( firstName middle lastName) desc 倒序 正序(lastName middle firstName)
  35. * @return
  36. */
  37. public static String getName(CustomInfoTable table, String order) {
  38. if (table == null) {
  39. return null;
  40. }
  41. return getName(table.getFirstName(), table.getMiddle(), table.getLastName(), null, order);
  42. }
  43. public static String getName(CustomAccountExportView view) {
  44. if (CountryUtil.isCTHM(view.getCountry())) {
  45. return getName(view, ORDER_DESC);
  46. } else {
  47. return getName(view, ORDER_ASE);
  48. }
  49. }
  50. public static String getName(CustomAccountExportView view, String order) {
  51. if (view == null) {
  52. return null;
  53. }
  54. return getName(view.getFirstName(), view.getMiddle(), view.getLastName(), null, order);
  55. }
  56. public static String getName(CustomInfoEntity entity) {
  57. if (CountryUtil.isCTHM(entity.getCountry())) {
  58. return getName(entity, ORDER_DESC);
  59. } else {
  60. return getName(entity, ORDER_ASE);
  61. }
  62. }
  63. public static String getName(CustomInfoEntity entity, String order) {
  64. if (entity == null) {
  65. return null;
  66. }
  67. return getName(entity.getFirstName(), entity.getMiddle(), entity.getLastName(), null, order);
  68. }
  69. public static String getName(CustomView view) {
  70. if (CountryUtil.isCTHM(view.getCountry())) {
  71. return getName(view, ORDER_DESC);
  72. } else {
  73. return getName(view, ORDER_ASE);
  74. }
  75. }
  76. public static String getName(CustomView view, String order) {
  77. if (view == null) {
  78. return null;
  79. }
  80. return getName(view.getFirstName(), view.getMiddle(), view.getLastName(), null, order);
  81. }
  82. public static String getName(CustomInfoGetEmailView view) {
  83. if (CountryUtil.isCTHM(view.getCountry())) {
  84. return getName(view, ORDER_DESC);
  85. } else {
  86. return getName(view, ORDER_ASE);
  87. }
  88. }
  89. public static String getName(CustomInfoGetEmailView view, String order) {
  90. if (view == null) {
  91. return null;
  92. }
  93. return getName(view.getFirstName(), view.getMiddle(), view.getLastName(), null, order);
  94. }
  95. public static String getName(CustomInfoGetCidView view) {
  96. if (CountryUtil.isCTHM(view.getCountry())) {
  97. return getName(view, ORDER_DESC);
  98. } else {
  99. return getName(view, ORDER_ASE);
  100. }
  101. }
  102. public static String getName(CustomInfoGetCidView view, String order) {
  103. if (view == null) {
  104. return null;
  105. }
  106. return getName(view.getFirstName(), view.getMiddle(), view.getLastName(), null, order);
  107. }
  108. public static String getName(String firstName, String middle, String lastName) {
  109. return getName(firstName, middle, lastName, " ");
  110. }
  111. public static String getNameByCountry(String firstName, String middle, String lastName, String country) {
  112. if (CountryUtil.isCTHM(country)) {
  113. return getName(firstName, middle, lastName, null, ORDER_DESC);
  114. } else {
  115. return getName(firstName, middle, lastName, null, ORDER_ASE);
  116. }
  117. }
  118. public static String getName(String firstName, String middle, String lastName, String fill) {
  119. return getName(firstName, middle, lastName, fill, null);
  120. }
  121. public static String getName(String firstName, String middle, String lastName, String fill, String order) {
  122. if (Strings.isNullOrEmpty(order)) {
  123. order = ORDER_ASE;
  124. }
  125. if (fill == null) {
  126. if (ORDER_ASE.equals(order)) {
  127. fill = " ";
  128. } else {
  129. fill = "";
  130. }
  131. }
  132. StringBuffer nameSbuff = new StringBuffer();
  133. if (ORDER_ASE.equals(order)) {
  134. append(nameSbuff, fill, firstName);
  135. } else {
  136. append(nameSbuff, fill, lastName);
  137. }
  138. if (!Strings.isNullOrEmpty(middle)) {
  139. append(nameSbuff, fill, middle);
  140. }
  141. if (ORDER_ASE.equals(order)) {
  142. append(nameSbuff, fill, lastName);
  143. } else {
  144. append(nameSbuff, fill, firstName);
  145. }
  146. return nameSbuff.toString();
  147. }
  148. private static void append(StringBuffer nameSbuff, String fill, String str) {
  149. if (nameSbuff == null) {
  150. nameSbuff = new StringBuffer(20);
  151. }
  152. if (!Strings.isNullOrEmpty(str)) {
  153. if (nameSbuff.length() > 0) {
  154. if (!Strings.isNullOrEmpty(fill)) {
  155. nameSbuff.append(fill);
  156. }
  157. }
  158. nameSbuff.append(str);
  159. }
  160. }
  161. public static Integer isXJ(CustomInfoTable table) {
  162. String name = getName(table);
  163. return isXJ(table.getCountry(), name);
  164. }
  165. public static Integer isXJ(CustomInfoEntity entity) {
  166. String name = getName(entity);
  167. return isXJ(entity.getCountry(), name);
  168. }
  169. private static Integer isXJ(String country, String name) {
  170. Integer xj = 0;
  171. if ("CN".equals(country)) {
  172. if (!Strings.isNullOrEmpty(name) && name.trim().length() > 4 && (name.indexOf(".") > 0 || name.indexOf(
  173. "·") > 0)) {
  174. xj = 1;
  175. }
  176. }
  177. return xj;
  178. }
  179. public static void main(String[] args) throws Exception {
  180. System.out.println("苏·托乎提".length());
  181. }
  182. }