123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package cn.fastfun.util;
- import cn.fastfun.service.entity.Product;
- import java.util.Map;
- import java.util.regex.Pattern;
- public class VerifyUtil {
- // 校验输入的sn切片编号,用于典表的校验
- public static String checkSnTypeCode(Product product) {
- String sntypecode = product.getSnTypeCode();
- switch (product.getSnType()) {
- case "产品类型":
- if(sntypecode.length() != 1) {
- return "产品类型的编号长度必须为1";
- }
- if(!(Pattern.matches("[MCPS]+",sntypecode))){
- return "产品类型的编号不符合规则,必须是M,C,P的一种";
- }
- break;
- case "PACK制造商":
- if(sntypecode.length() != 2) {
- return "PACK制造商的编号长度必须为2";
- }
- if(!(Pattern.matches("[A-Z]{2}",sntypecode))) {
- return "PACK制造商的编号不符合规则,必须为两位大写字母";
- }
- if(!(Pattern.matches("[^IO]{2}",sntypecode))) {
- return "PACK制造商的编号不符合规则,不能包含I或者O";
- }
- break;
- case "电芯厂家":
- if(sntypecode.length() != 2) {
- return "电芯厂家的编号长度必须为2";
- }
- if(!(Pattern.matches("[A-Z]{2}",sntypecode))) {
- return "电芯厂家的编号不符合规则,必须为两位大写字母";
- }
- if(!(Pattern.matches("[^IO]{2}",sntypecode))) {
- return "电芯厂家的编号不符合规则,不能包含I或者O";
- }
- break;
- // case "产品规格":
- // if(sntypecode.length() != 4) {
- // return "产品规格的编号长度必须为4";
- // }
- // break;
- case "化学体系":
- if(sntypecode.length() != 1) {
- return "化学体系的编号长度必须为1";
- }
- if(!(Pattern.matches("[L|N]",sntypecode))) {
- return "化学体系的编号不符合规则,必须是L,N的一种";
- }
- break;
- case "电池平台":
- if(sntypecode.length() != 1) {
- return "电池平台的编号长度必须为1";
- }
- if(!(Pattern.matches("[0-9]+",sntypecode))) {
- return "电池平台的编号不符合规则,必须是数字";
- }
- break;
- case "容量":
- if(sntypecode.length() != 2) {
- return "容量的编号长度必须为2";
- }
- if(!(Pattern.matches("[0-9]{2}",sntypecode))) {
- return "容量的编号不符合规则,必须是数字";
- }
- break;
- case "产品扩展":
- if(sntypecode.length() != 1) {
- return "产品扩展的编号长度必须为1";
- }
- if(!(Pattern.matches("[NMS]+",sntypecode))) {
- return "产品扩展的编号不符合规则,必须是N,M,S的一种";
- }
- break;
- // case "生产日期":
- // //
- // if(sntypecode.length() != 4) {
- // return "生产日期的编号长度必须为4";
- // }
- // if(!(Pattern.matches("[0-9]{2}[0-9|A-Z]{2}",sntypecode))) {
- // return "生产日期的编号不符合规则,年为两位数字,月和日为一位数字或者大写字母";
- // }
- // if(!(Pattern.matches("[0-9]{2}[^IO]{2}",sntypecode))) {
- // return "生产日期的编号不符合规则,月和日不能包含I或者O";
- // }
- // break;
- // case "序列号":
- // if(sntypecode.length() != 3) {
- // return "序列号的编号长度必须为3";
- // }
- // if(!(Pattern.matches("[0-9|A-Z][0-9]{2}",sntypecode))) {
- // return "序列号的编号不符合规则,第1位用0-9或者A-Z表示,第2、3位可表示为0-9";
- // }
- // if(!(Pattern.matches("[^IO][0-9]{2}",sntypecode))) {
- // return "序列号的编号不符合规则,第一位不能包含I或者O";
- // }
- // break;
- default:
- return "sn的切片类型指明不正确,必须为" +
- "产品类型,PACK制造商,电芯厂家,化学体系,电池平台,容量,产品扩展,生产日期(未开放),序列号(未开放)" +
- "中的一种";
- }
- return "passed";
- }
- // 校验输入的sn
- public static String checkImei(String imei) {
- if(imei.length() != 17) {
- return "sn的编号长度必须为17";
- }
- Map<String,String> splitSnResult = ResolveUtil.splitImei(imei);
- if(!(Pattern.matches("[MCPS]",splitSnResult.get("产品类型代码")))){
- return "产品类型的编号不符合规则,必须是M,C,P的一种";
- }
- if(!(Pattern.matches("[A-Z]{2}",splitSnResult.get("pack制造商代码")))) {
- return "PACK制造商的编号不符合规则,必须为两位大写字母";
- }
- if(!(Pattern.matches("[^IO]{2}",splitSnResult.get("pack制造商代码")))) {
- return "PACK制造商的编号不符合规则,不能包含I或者O";
- }
- if(!(Pattern.matches("[A-Z]{2}",splitSnResult.get("电芯厂家代码")))) {
- return "电芯厂家的编号不符合规则,必须为两位大写字母";
- }
- if(!(Pattern.matches("[^IO]{2}",splitSnResult.get("电芯厂家代码")))) {
- return "电芯厂家的编号不符合规则,不能包含I或者O";
- }
- if(!(Pattern.matches("[L|N]",splitSnResult.get("化学体系代码")))) {
- return "化学体系的编号不符合规则,必须是L,N的一种";
- }
- if(!(Pattern.matches("[0-9]",splitSnResult.get("电池平台代码")))) {
- return "电池平台的编号不符合规则,必须是数字";
- }
- if(!(Pattern.matches("[0-9]{2}",splitSnResult.get("容量代码")))) {
- return "容量的编号不符合规则,必须是数字";
- }
- if(!(Pattern.matches("[NMS]",splitSnResult.get("产品扩展代码")))) {
- return "产品扩展的编号不符合规则,必须是N,M,S的一种";
- }
- if(!(Pattern.matches("[0-9]{2}[0-9|A-Z]{2}",splitSnResult.get("生产日期代码")))) {
- return "生产日期的编号不符合规则,年为两位数字,月和日为一位数字或者大写字母";
- }
- if(!(Pattern.matches("[0-9]{2}[^IO]{2}",splitSnResult.get("生产日期代码")))) {
- return "生产日期的编号不符合规则,月和日不能包含I或者O";
- }
- if(!(Pattern.matches("[0-9|A-Z][0-9]{2}",splitSnResult.get("序列号代码")))) {
- return "序列号的编号不符合规则,第1位用0-9或者A-Z表示,第2、3位可表示为0-9";
- }
- if(!(Pattern.matches("[^IO][0-9]{2}",splitSnResult.get("序列号代码")))) {
- return "序列号的编号不符合规则,第一位不能包含I或者O";
- }
- return "passed";
- }
- }
|