package co.dc.aptiv.mina;

import co.dc.aptiv.service.BillService;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.mina.core.session.IoSession;

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


/**
 * 一道采集逻辑处理类
 *
 * @author mx
 */
public class TestMachineCollectorMinaHandler extends MinaAbstractHandler {

    private static final Log log = LogFactory.getLog(TestMachineCollectorMinaHandler.class);

    public TestMachineCollectorMinaHandler(TestMachineCollectorMina collectorMina, QueryRunner queryRunner) {
        super(collectorMina, queryRunner);
    }

    private BillService billService;


    public TestMachineCollectorMinaHandler(MinaAbstract mina, QueryRunner queryRunner, BillService billService) {
        super(mina, queryRunner);
        this.billService = billService;
    }


    /**
     * 处理收到的信息
     */
    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        String data = (String) message;
        log.info("Sendcollector received [" + data + "]");
        if (data != null) {
//			//说明是网址
//			data = AptivApp.httpStr(data);
            /*billService.receivedscandata(replaceBlank(data));*/
        }


    }

    public static String replaceBlank(String str) {
        String dest = "";
        if (str != null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
}
