ValuationDataUtils.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.simuwang.base.common.util;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.simuwang.base.common.conts.ValuationConst;
  4. import com.simuwang.base.pojo.valuation.PreAssetsValuationBase;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.apache.commons.lang3.StringUtils;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. import java.util.regex.Matcher;
  10. import java.util.regex.Pattern;
  11. @Slf4j
  12. public class ValuationDataUtils {
  13. /**
  14. * 支持正负整型或浮点型
  15. */
  16. public static boolean isNumber(String str) {
  17. return (StringUtils.isNotEmpty(str) && str.matches("^-?\\d+(\\.\\d+)?$"));
  18. }
  19. public static Double string2Double(String str) {
  20. if (StrUtil.isBlank(str) || StrUtil.isBlank(str.trim())) {
  21. return null;
  22. }
  23. str = str.trim().replace(",", "");
  24. try {
  25. if (str.endsWith("%")) {
  26. return Double.parseDouble(str.substring(0, str.length() - 1)) / 100D;
  27. }
  28. return Double.parseDouble(str);
  29. } catch (NumberFormatException e) {
  30. log.error("parse Double error");
  31. }
  32. return 0D;
  33. }
  34. public static int string2Int(String str) {
  35. if (str == null || "".equals(str.trim())) {
  36. return 0;
  37. }
  38. try {
  39. return Integer.parseInt(str.trim());
  40. } catch (NumberFormatException e) {
  41. log.error("parse Integer error");
  42. }
  43. return 0;
  44. }
  45. /**
  46. * 判断字符串是否为空或者null
  47. *
  48. * @param str 要验证的参数
  49. * @return boolean
  50. */
  51. public static boolean isValid(String str) {
  52. return null != str && str.length() != 0 && !"null".equals(str.toLowerCase());
  53. }
  54. /**
  55. * 判断字符串是有汉字
  56. *
  57. * @param str 待判断的字符串
  58. * @param isAll true:判断该字符串是否是汉字,false:判断该字符串是否包含汉字
  59. */
  60. public static boolean hasChinese(String str, boolean isAll) {
  61. Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+");
  62. Matcher m = pattern.matcher(str);
  63. if (isAll) {
  64. return m.find() && m.group(0).equals(str);
  65. } else {
  66. return m.find();
  67. }
  68. }
  69. public static String getSubjectCode(String str) {
  70. char[] cArr = str.toCharArray();
  71. if (!Character.isDigit(cArr[0])) {
  72. return str;
  73. }
  74. int startIndex = 0;
  75. for (int i = 0; i < cArr.length; i++) {
  76. int index = cArr[i];
  77. if ((index >= 48 && index <= 57) || (index >= 65 && index <= 90) || (index >= 97 && index <= 122)) {
  78. continue;
  79. }
  80. startIndex = i;
  81. break;
  82. }
  83. if (startIndex == 0) {
  84. return str;
  85. }
  86. str = str.substring(0, startIndex);
  87. return str;
  88. }
  89. public static List<PreAssetsValuationBase> removeUnderLine(List<PreAssetsValuationBase> list) {
  90. for (int i = 0; i < list.size(); i++) {
  91. list.get(i).setOriginalSubjectCode(list.get(i).getSubjectCode());
  92. String subjectCode = list.get(i).getSubjectCode();
  93. if (subjectCode != null) {
  94. subjectCode = subjectCode.toUpperCase();
  95. //含有中文不处理
  96. if (subjectCode.matches(".*[\u4e00-\u9fa5]+.*")) {
  97. continue;
  98. }
  99. subjectCode = subjectCode.replaceAll("[\\.\\s_-]", "");
  100. }
  101. list.get(i).setSubjectCode(subjectCode);
  102. }
  103. return list;
  104. }
  105. /**
  106. * 校验该科目是否是资产总值
  107. *
  108. * @param str 待校验字符串
  109. * @return 检验结果
  110. */
  111. public static boolean checkMarketValue(String str) {
  112. if (StringUtils.isEmpty(str)) {
  113. return false;
  114. }
  115. long count = Arrays.stream(ValuationConst.TOTAL_MARKET_VALUE).filter(p -> p.trim().equals(str)).count();
  116. return count > 0;
  117. }
  118. /**
  119. * 校验该科目是否是资产份额
  120. *
  121. * @param str 待校验字符串
  122. * @return 检验结果
  123. */
  124. public static boolean checkAssetShare(String str) {
  125. if (StringUtils.isEmpty(str)) {
  126. return false;
  127. }
  128. long count = Arrays.stream(ValuationConst.ASSET_SHARE_VALUE).filter(p -> p.trim().equals(str)).count();
  129. return count > 0;
  130. }
  131. /**
  132. * 校验该科目是否是资产净值
  133. *
  134. * @param str 待校验字符串
  135. * @return 检验结果
  136. */
  137. public static boolean checkNetAssetsValue(String str) {
  138. if (StringUtils.isEmpty(str)) {
  139. return false;
  140. }
  141. long count = Arrays.stream(ValuationConst.NET_ASSET_VALUE).filter(p -> p.trim().equals(str)).count();
  142. return count > 0;
  143. }
  144. }