RemarkUtils.java 3.38 KB
package cn.com.glsx.entmicro.util;

import cn.com.glsx.entmicro.constants.RegexConstants;
import cn.com.glsx.entmicro.dto.CustomerKafkaDTO;
import cn.com.glsx.entmicro.model.request.CustomerInfoRequest;
import com.glsx.plat.common.utils.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName RemarkUtils
 * @Description
 * @Author lichongyuan
 * @Date 2022/4/18
 */
public class RemarkUtils {

    /**
     * 识别备注内容 (只读取第一次匹配到的内容)
     *
     * @param description 识别字段
     * @return
     */
    public static CustomerKafkaDTO distinguishMethod(String description) {
//        tring palte = "LBV3M210XFME93683,15778727124,车牌号:桂N0005警";
        CustomerKafkaDTO customerKafkaDTO = new CustomerKafkaDTO();
        //去特殊符号
        if (com.glsx.plat.common.utils.StringUtils.isNotBlank(description)) {
            String[] split = description.split(RegexConstants.REGEX_SPLIT);

            //手机正则
            Pattern phoneReg = Pattern.compile(RegexConstants.REGEX_PHONENUM);

            //车架号正则
            Pattern carVin = Pattern.compile(RegexConstants.REGEX_CARVIN);

            //车牌号正则
            Pattern newCar = Pattern.compile(RegexConstants.NEW_ENERGY_PLATE_REGEX);
            Pattern police = Pattern.compile(RegexConstants.POLICE_PLATE_REGEX);
            Pattern wj = Pattern.compile(RegexConstants.WJ_PLATE_REGEX);
            Pattern ORDINARY = Pattern.compile(RegexConstants.ORDINARY_LICENSE_PLATE_REGEX);
            Pattern pla = Pattern.compile(RegexConstants.PLA__PLATE_REGEX);
            //按行匹配
            for (String s : split) {
                Matcher carVin_m = carVin.matcher(s);
                Matcher phoneReg_m = phoneReg.matcher(s);
                Matcher newCar_n = newCar.matcher(s);
                Matcher police_m = police.matcher(s);
                Matcher wj_m = wj.matcher(s);
                Matcher ORDINARY_m = ORDINARY.matcher(s);
                Matcher pla_m = pla.matcher(s);
                //手机号
                if (phoneReg_m.find()) {
                    customerKafkaDTO.setCustomerPhone(phoneReg_m.group());
                    continue;
                }
                //车架号
                if (carVin_m.find()) {
                    customerKafkaDTO.setCarVin(carVin_m.group());
                    continue;
                }
                //车牌
                //新能源牌
                if (newCar_n.find()) {
                    customerKafkaDTO.setCarNumber(newCar_n.group());
                    continue;
                }
                //警车车牌
                if (police_m.find()) {
                    customerKafkaDTO.setCarNumber(police_m.group());
                    continue;
                }
                //武警车牌
                if (wj_m.find()) {
                    customerKafkaDTO.setCarNumber(wj_m.group());
                    continue;
                }
                //普通车牌
                if (ORDINARY_m.find()) {
                    customerKafkaDTO.setCarNumber(ORDINARY_m.group());
                    continue;
                }
                //军牌
                if (pla_m.find()) {
                    customerKafkaDTO.setCarNumber(pla_m.group());
                    continue;
                }
            }
        }

        return customerKafkaDTO;
    }

}