VerifyUtil.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package cn.fastfun.util;
  2. import cn.fastfun.service.entity.Product;
  3. import java.util.Map;
  4. import java.util.regex.Pattern;
  5. public class VerifyUtil {
  6. // 校验输入的sn切片编号,用于典表的校验
  7. public static String checkSnTypeCode(Product product) {
  8. String sntypecode = product.getSnTypeCode();
  9. switch (product.getSnType()) {
  10. case "产品类型":
  11. if(sntypecode.length() != 1) {
  12. return "产品类型的编号长度必须为1";
  13. }
  14. if(!(Pattern.matches("[MCPS]+",sntypecode))){
  15. return "产品类型的编号不符合规则,必须是M,C,P的一种";
  16. }
  17. break;
  18. case "PACK制造商":
  19. if(sntypecode.length() != 2) {
  20. return "PACK制造商的编号长度必须为2";
  21. }
  22. if(!(Pattern.matches("[A-Z]{2}",sntypecode))) {
  23. return "PACK制造商的编号不符合规则,必须为两位大写字母";
  24. }
  25. if(!(Pattern.matches("[^IO]{2}",sntypecode))) {
  26. return "PACK制造商的编号不符合规则,不能包含I或者O";
  27. }
  28. break;
  29. case "电芯厂家":
  30. if(sntypecode.length() != 2) {
  31. return "电芯厂家的编号长度必须为2";
  32. }
  33. if(!(Pattern.matches("[A-Z]{2}",sntypecode))) {
  34. return "电芯厂家的编号不符合规则,必须为两位大写字母";
  35. }
  36. if(!(Pattern.matches("[^IO]{2}",sntypecode))) {
  37. return "电芯厂家的编号不符合规则,不能包含I或者O";
  38. }
  39. break;
  40. // case "产品规格":
  41. // if(sntypecode.length() != 4) {
  42. // return "产品规格的编号长度必须为4";
  43. // }
  44. // break;
  45. case "化学体系":
  46. if(sntypecode.length() != 1) {
  47. return "化学体系的编号长度必须为1";
  48. }
  49. if(!(Pattern.matches("[L|N]",sntypecode))) {
  50. return "化学体系的编号不符合规则,必须是L,N的一种";
  51. }
  52. break;
  53. case "电池平台":
  54. if(sntypecode.length() != 1) {
  55. return "电池平台的编号长度必须为1";
  56. }
  57. if(!(Pattern.matches("[0-9]+",sntypecode))) {
  58. return "电池平台的编号不符合规则,必须是数字";
  59. }
  60. break;
  61. case "容量":
  62. if(sntypecode.length() != 2) {
  63. return "容量的编号长度必须为2";
  64. }
  65. if(!(Pattern.matches("[0-9]{2}",sntypecode))) {
  66. return "容量的编号不符合规则,必须是数字";
  67. }
  68. break;
  69. case "产品扩展":
  70. if(sntypecode.length() != 1) {
  71. return "产品扩展的编号长度必须为1";
  72. }
  73. if(!(Pattern.matches("[NMS]+",sntypecode))) {
  74. return "产品扩展的编号不符合规则,必须是N,M,S的一种";
  75. }
  76. break;
  77. // case "生产日期":
  78. // //
  79. // if(sntypecode.length() != 4) {
  80. // return "生产日期的编号长度必须为4";
  81. // }
  82. // if(!(Pattern.matches("[0-9]{2}[0-9|A-Z]{2}",sntypecode))) {
  83. // return "生产日期的编号不符合规则,年为两位数字,月和日为一位数字或者大写字母";
  84. // }
  85. // if(!(Pattern.matches("[0-9]{2}[^IO]{2}",sntypecode))) {
  86. // return "生产日期的编号不符合规则,月和日不能包含I或者O";
  87. // }
  88. // break;
  89. // case "序列号":
  90. // if(sntypecode.length() != 3) {
  91. // return "序列号的编号长度必须为3";
  92. // }
  93. // if(!(Pattern.matches("[0-9|A-Z][0-9]{2}",sntypecode))) {
  94. // return "序列号的编号不符合规则,第1位用0-9或者A-Z表示,第2、3位可表示为0-9";
  95. // }
  96. // if(!(Pattern.matches("[^IO][0-9]{2}",sntypecode))) {
  97. // return "序列号的编号不符合规则,第一位不能包含I或者O";
  98. // }
  99. // break;
  100. default:
  101. return "sn的切片类型指明不正确,必须为" +
  102. "产品类型,PACK制造商,电芯厂家,化学体系,电池平台,容量,产品扩展,生产日期(未开放),序列号(未开放)" +
  103. "中的一种";
  104. }
  105. return "passed";
  106. }
  107. // 校验输入的sn
  108. public static String checkImei(String imei) {
  109. if(imei.length() != 17) {
  110. return "sn的编号长度必须为17";
  111. }
  112. Map<String,String> splitSnResult = ResolveUtil.splitImei(imei);
  113. if(!(Pattern.matches("[MCPS]",splitSnResult.get("产品类型代码")))){
  114. return "产品类型的编号不符合规则,必须是M,C,P的一种";
  115. }
  116. if(!(Pattern.matches("[A-Z]{2}",splitSnResult.get("pack制造商代码")))) {
  117. return "PACK制造商的编号不符合规则,必须为两位大写字母";
  118. }
  119. if(!(Pattern.matches("[^IO]{2}",splitSnResult.get("pack制造商代码")))) {
  120. return "PACK制造商的编号不符合规则,不能包含I或者O";
  121. }
  122. if(!(Pattern.matches("[A-Z]{2}",splitSnResult.get("电芯厂家代码")))) {
  123. return "电芯厂家的编号不符合规则,必须为两位大写字母";
  124. }
  125. if(!(Pattern.matches("[^IO]{2}",splitSnResult.get("电芯厂家代码")))) {
  126. return "电芯厂家的编号不符合规则,不能包含I或者O";
  127. }
  128. if(!(Pattern.matches("[L|N]",splitSnResult.get("化学体系代码")))) {
  129. return "化学体系的编号不符合规则,必须是L,N的一种";
  130. }
  131. if(!(Pattern.matches("[0-9]",splitSnResult.get("电池平台代码")))) {
  132. return "电池平台的编号不符合规则,必须是数字";
  133. }
  134. if(!(Pattern.matches("[0-9]{2}",splitSnResult.get("容量代码")))) {
  135. return "容量的编号不符合规则,必须是数字";
  136. }
  137. if(!(Pattern.matches("[NMS]",splitSnResult.get("产品扩展代码")))) {
  138. return "产品扩展的编号不符合规则,必须是N,M,S的一种";
  139. }
  140. if(!(Pattern.matches("[0-9]{2}[0-9|A-Z]{2}",splitSnResult.get("生产日期代码")))) {
  141. return "生产日期的编号不符合规则,年为两位数字,月和日为一位数字或者大写字母";
  142. }
  143. if(!(Pattern.matches("[0-9]{2}[^IO]{2}",splitSnResult.get("生产日期代码")))) {
  144. return "生产日期的编号不符合规则,月和日不能包含I或者O";
  145. }
  146. if(!(Pattern.matches("[0-9|A-Z][0-9]{2}",splitSnResult.get("序列号代码")))) {
  147. return "序列号的编号不符合规则,第1位用0-9或者A-Z表示,第2、3位可表示为0-9";
  148. }
  149. if(!(Pattern.matches("[^IO][0-9]{2}",splitSnResult.get("序列号代码")))) {
  150. return "序列号的编号不符合规则,第一位不能包含I或者O";
  151. }
  152. return "passed";
  153. }
  154. }