<commit_before>package br.com.fourdev.orderfood.service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.stomp.StompSession;
import org.springframework.stereotype.Service;

import br.com.fourdev.orderfood.config.ClientWebSocketConfig;
import br.com.fourdev.orderfood.model.Mesa;
import br.com.fourdev.orderfood.model.StatusMesa;
import br.com.fourdev.orderfood.repository.mesa.MesaRepository;

@Service
public class MesaService {

	final static Logger logger = LoggerFactory.getLogger(MesaService.class);

	@Autowired
	private MesaRepository mesaRepository;

	private StompSession stompSession;

	public List<Mesa> selectMesaList() {
		return mesaRepository.selectMesaList();
	}

	public Mesa selectMesaById(int id) {
		return mesaRepository.selectMesaPorId(id);
	}

	public void insertMesa(Mesa mesa) {
		mesaRepository.insertMesa(mesa);
	}

	public void updateMesa(String id, Mesa mesa) {
		mesaRepository.updateMesa(id, mesa);
	}

	public void deleteMesa(String id) {
		mesaRepository.deleteMesa(id);
	}

	public int contaMesas() {
		return mesaRepository.contaMesas();
	}

	public boolean verificarStatusMesa(int idmesa) throws InterruptedException, ExecutionException {
		boolean vbliberouMesa = false;
		
		Mesa mesa = mesaRepository.selectMesaPorId(idmesa);
		
		if ("LIBERADA".equalsIgnoreCase(mesa.getStatus().toString())) {
			ClientWebSocketConfig cws = null;
			cws.conectaOuRetornaWebSocket();

			logger.info("Inscrever-se no tópico usando a sessão " + cws.stompSession.getSessionId());
			cws.helloClient.subscribeGreetings(cws.stompSession);

			logger.info("Enviando mensagem" + cws.stompSession);
			cws.helloClient.sendHello(cws.stompSession, String.valueOf(mesa.getIdmesa()));
			Thread.sleep(1000);
			vbliberouMesa = true;			

			
		}
		return vbliberouMesa;
	}

	public StatusMesa reservarMesa(int idmesa) {
		Mesa mesa = new Mesa();
		StatusMesa statusMesa = null;
		mesa.setStatus(statusMesa.OCUPADA.getDescricao());
		mesa.setIdmesa(idmesa);
		mesa.setHoraAberta(LocalDate.now());
		mesa.setHoraFechada(LocalDate.now());
		mesa.setTotal(BigDecimal.ONE);
		mesa.setIdmesa(idmesa);
		return mesaRepository.reservarMesa(mesa);
	}


}<commit_msg>Adicionado "mesaRepository.updateMesa(idmesa, mesa);"<commit_after>package br.com.fourdev.orderfood.service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.stomp.StompSession;
import org.springframework.stereotype.Service;

import br.com.fourdev.orderfood.config.ClientWebSocketConfig;
import br.com.fourdev.orderfood.model.Mesa;
import br.com.fourdev.orderfood.model.StatusMesa;
import br.com.fourdev.orderfood.repository.mesa.MesaRepository;

@Service
public class MesaService {

	final static Logger logger = LoggerFactory.getLogger(MesaService.class);

	@Autowired
	private MesaRepository mesaRepository;

	private StompSession stompSession;

	public List<Mesa> selectMesaList() {
		return mesaRepository.selectMesaList();
	}

	public Mesa selectMesaById(int id) {
		return mesaRepository.selectMesaPorId(id);
	}

	public void insertMesa(Mesa mesa) {
		mesaRepository.insertMesa(mesa);
	}

	public void updateMesa(int id, Mesa mesa) {
		mesaRepository.updateMesa(id, mesa);
	}

	public void deleteMesa(int id) {
		mesaRepository.deleteMesa(id);
	}

	public int contaMesas() {
		return mesaRepository.contaMesas();
	}

	public boolean verificarStatusMesa(int idmesa) throws InterruptedException, ExecutionException {
		boolean vbliberouMesa = false;
		
		Mesa mesa = mesaRepository.selectMesaPorId(idmesa);
		
		if ("LIBERADA".equalsIgnoreCase(mesa.getStatus().toString())) {
			ClientWebSocketConfig cws = null;
			cws.conectaOuRetornaWebSocket();

			logger.info("Inscrever-se no tópico usando a sessão " + cws.stompSession.getSessionId());
			cws.helloClient.subscribeGreetings(cws.stompSession);

			logger.info("Enviando mensagem" + cws.stompSession);
			cws.helloClient.sendHello(cws.stompSession, String.valueOf(mesa.getIdmesa()));
			Thread.sleep(1000);
		
			mesa.setStatus(StatusMesa.OCUPADA.getDescricao());
			mesaRepository.updateMesa(idmesa, mesa);
			vbliberouMesa = true;			

		}
		return vbliberouMesa;
	}

	public StatusMesa reservarMesa(int idmesa) {
		Mesa mesa = new Mesa();
		StatusMesa statusMesa = null;
		mesa.setStatus(statusMesa.OCUPADA.getDescricao());
		mesa.setIdmesa(idmesa);
		mesa.setHoraAberta(LocalDate.now());
		mesa.setHoraFechada(LocalDate.now());
		mesa.setTotal(BigDecimal.ONE);
		mesa.setIdmesa(idmesa);
		return mesaRepository.reservarMesa(mesa);
	}


}
{'fraction_non_alphanumeric': 0.10898082744702321, 'fraction_numerical': 0.0024217961654894047, 'mean_word_length': 5.538258575197889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3955461', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1746, 'n_words': 273}