var mapper  = mapperFactory.createMapper("ProcessarCupomNFCe");

if(message.get("obj")){
    var obj = message.get("obj");
}else{
    var obj = message;
}

var rs = mapper.selectOne("cdControleExiste", obj);

var result = 0;
if(null === rs){// se nao existe inclui
    mapper.insert("incluirPdvVdArq", obj);
    result = obj.get("cdControle");
}else{// se existe retorna codigo
    result = rs.get("controle");
}
mapper.insert("incluirPdvVdArqHistorico", {"cdControle" : result});  
mapper.commit();
result;