Rev 761 | Rev 765 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 761 | blopes | 1 | package br.com.sl.controller; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 764 | blopes | 4 | import java.util.ArrayList; |
| 5 | import java.util.Collections; |
||
| 6 | import java.util.List; |
||
| 7 | import java.util.stream.Collectors; |
||
| 761 | blopes | 8 | |
| 764 | blopes | 9 | import javax.faces.application.FacesMessage; |
| 761 | blopes | 10 | import javax.inject.Inject; |
| 11 | import javax.inject.Named; |
||
| 12 | |||
| 764 | blopes | 13 | import org.primefaces.PrimeFaces; |
| 761 | blopes | 14 | import org.springframework.context.annotation.Scope; |
| 15 | |||
| 16 | import br.com.ec.core.generic.GenericService; |
||
| 764 | blopes | 17 | import br.com.ec.core.util.VerificadorUtil; |
| 761 | blopes | 18 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 19 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 20 | import br.com.ec.web.generic.AbstractBean; |
||
| 21 | import br.com.ec.web.message.LancadorMensagem; |
||
| 764 | blopes | 22 | import br.com.kronus.core.PadraoGatilho; |
| 761 | blopes | 23 | import br.com.sl.domain.dto.RoboDTO; |
| 764 | blopes | 24 | import br.com.sl.domain.dto.robo.AlertaPadraoService; |
| 761 | blopes | 25 | import br.com.sl.domain.service.RoboOperadorService; |
| 26 | |||
| 27 | @Named |
||
| 28 | @Scope("view") |
||
| 29 | public class RoboBean extends AbstractBean<RoboDTO> implements Serializable { |
||
| 30 | |||
| 31 | private RoboOperadorService roboOperadorService; |
||
| 32 | |||
| 764 | blopes | 33 | private List<PadraoGatilho> padroesEmAberto; |
| 34 | |||
| 35 | private List<PadraoGatilho> padroes; |
||
| 36 | private List<PadraoGatilho> padroesComG3; // completos (G3 != null) |
||
| 37 | private List<PadraoGatilho> padroesAteG2; // parciais (G2 != null && G3 == null) |
||
| 38 | |||
| 761 | blopes | 39 | @Inject |
| 40 | public RoboBean(RoboOperadorService roboOperadorService) { |
||
| 41 | this.roboOperadorService = roboOperadorService; |
||
| 42 | } |
||
| 43 | |||
| 44 | @Override |
||
| 45 | public void preCarregamento() { |
||
| 46 | limparEntidade(); |
||
| 47 | getEntidade().setRodando(roboOperadorService.isRodando()); |
||
| 48 | } |
||
| 49 | |||
| 50 | @Override |
||
| 51 | public void limparEntidade() { |
||
| 52 | setEntidade(new RoboDTO()); |
||
| 764 | blopes | 53 | setPadroes(new ArrayList<PadraoGatilho>()); |
| 54 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
||
| 55 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
||
| 761 | blopes | 56 | } |
| 57 | |||
| 58 | @Override |
||
| 59 | public GenericService<RoboDTO> getService() { |
||
| 60 | return roboOperadorService; |
||
| 61 | } |
||
| 62 | |||
| 63 | @Override |
||
| 64 | public RoboDTO getEntidade() { |
||
| 65 | return entidade; |
||
| 66 | } |
||
| 67 | |||
| 68 | @Override |
||
| 69 | public RoboDTO getId() { |
||
| 70 | return getEntidade(); |
||
| 71 | } |
||
| 72 | |||
| 764 | blopes | 73 | public List<PadraoGatilho> getPadroes() { |
| 74 | return padroes; |
||
| 75 | } |
||
| 76 | public void setPadroes(List<PadraoGatilho> padroes) { |
||
| 77 | this.padroes = padroes; |
||
| 78 | } |
||
| 79 | |||
| 80 | public List<PadraoGatilho> getPadroesComG3() { |
||
| 81 | return padroesComG3; |
||
| 82 | } |
||
| 83 | public void setPadroesComG3(List<PadraoGatilho> padroesComG3) { |
||
| 84 | this.padroesComG3 = padroesComG3; |
||
| 85 | } |
||
| 86 | |||
| 87 | public List<PadraoGatilho> getPadroesAteG2() { |
||
| 88 | return padroesAteG2; |
||
| 89 | } |
||
| 90 | public void setPadroesAteG2(List<PadraoGatilho> padroesAteG2) { |
||
| 91 | this.padroesAteG2 = padroesAteG2; |
||
| 92 | } |
||
| 93 | |||
| 761 | blopes | 94 | public void iniciar() { |
| 95 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 96 | public void execute() { |
||
| 97 | // ANALISAR POR HISTÓRICO |
||
| 98 | getEntidade().setAnalisarPorHistoricoArquivo(true); |
||
| 99 | |||
| 100 | roboOperadorService.iniciarOperacao(getEntidade().getAnalisarPorHistoricoArquivo()); |
||
| 101 | setEntidade(roboOperadorService.statusRobo()); |
||
| 102 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
||
| 103 | } |
||
| 104 | }); |
||
| 105 | } |
||
| 106 | |||
| 107 | public void parar() { |
||
| 108 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 109 | public void execute() { |
||
| 110 | roboOperadorService.pararOperacao(); |
||
| 111 | setEntidade(roboOperadorService.statusRobo()); |
||
| 112 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
||
| 113 | } |
||
| 114 | }); |
||
| 115 | } |
||
| 764 | blopes | 116 | |
| 117 | public void preencherOutrosPadroes() { |
||
| 118 | padroesComG3 = padroes.stream() |
||
| 119 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() != null) |
||
| 120 | .collect(Collectors.toList()); |
||
| 121 | inverterLista(padroesComG3); |
||
| 761 | blopes | 122 | |
| 764 | blopes | 123 | padroesAteG2 = padroes.stream() |
| 124 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() == null) |
||
| 125 | .collect(Collectors.toList()); |
||
| 126 | inverterLista(padroesAteG2); |
||
| 127 | } |
||
| 128 | |||
| 129 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
||
| 130 | List<PadraoGatilho> invertida = new ArrayList<>(candles); |
||
| 131 | Collections.reverse(invertida); |
||
| 132 | return invertida; |
||
| 133 | } |
||
| 134 | |||
| 761 | blopes | 135 | public void atualizarStatus() { |
| 136 | setEntidade(roboOperadorService.statusRobo()); |
||
| 764 | blopes | 137 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getPadroes())) { |
| 138 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
||
| 139 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
||
| 140 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
||
| 141 | } |
||
| 142 | setPadroes(getEntidade().getPadroes()); |
||
| 143 | preencherOutrosPadroes(); |
||
| 144 | } |
||
| 145 | verificarNovosPadroes(); |
||
| 761 | blopes | 146 | } |
| 764 | blopes | 147 | |
| 148 | public void verificarNovosPadroes() { |
||
| 149 | List<String> alertas = AlertaPadraoService.consumirAlertas(); |
||
| 761 | blopes | 150 | |
| 764 | blopes | 151 | if (!alertas.isEmpty()) { |
| 152 | for (String msg : alertas) { |
||
| 153 | FacesMessage facesMessage = new FacesMessage( |
||
| 154 | FacesMessage.SEVERITY_INFO, |
||
| 155 | "Novo padrão identificado", |
||
| 156 | msg |
||
| 157 | ); |
||
| 158 | javax.faces.context.FacesContext.getCurrentInstance() |
||
| 159 | .addMessage(null, facesMessage); |
||
| 160 | } |
||
| 161 | |||
| 162 | // Toca o som no cliente |
||
| 163 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
||
| 164 | // Se estiver em PF antigo: |
||
| 165 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();"); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 761 | blopes | 169 | } |