package com.lantone.qc.kernel.catalogue.firstpagerecord;

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
import com.lantone.qc.pub.Content;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : FIRP02972
 * @Description : 现住址要具体到门牌号
 * @Author : Mark
 * @Date: 2020-06-19 10:23
 */
@Component
public class FIRP02972 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureMap() != null) {
            Map<String, String> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
            String address = firstpageStructureMap.get(Content.current_address);
            if (!CatalogueUtil.isEmpty(address)) {
                String suffix = (address.length()<=5)?address:(address.substring(address.length()-5));
                Pattern p = Pattern.compile("[0-9一二三四五六七八九０１２３４５６７８９]");
                Matcher m = p.matcher(suffix);
                if (!m.find()) {
                    status.set("-1");
                }
            }
        }
    }
}