Rev 764 | Rev 767 | 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; |
| 765 | blopes | 34 | private Integer contadorUltimoCandle; |
| 764 | blopes | 35 | |
| 36 | private List<PadraoGatilho> padroes; |
||
| 37 | private List<PadraoGatilho> padroesComG3; // completos (G3 != null) |
||
| 38 | private List<PadraoGatilho> padroesAteG2; // parciais (G2 != null && G3 == null) |
||
| 39 | |||
| 761 | blopes | 40 | @Inject |
| 41 | public RoboBean(RoboOperadorService roboOperadorService) { |
||
| 42 | this.roboOperadorService = roboOperadorService; |
||
| 43 | } |
||
| 44 | |||
| 45 | @Override |
||
| 46 | public void preCarregamento() { |
||
| 47 | limparEntidade(); |
||
| 48 | getEntidade().setRodando(roboOperadorService.isRodando()); |
||
| 49 | } |
||
| 50 | |||
| 51 | @Override |
||
| 52 | public void limparEntidade() { |
||
| 53 | setEntidade(new RoboDTO()); |
||
| 764 | blopes | 54 | setPadroes(new ArrayList<PadraoGatilho>()); |
| 55 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
||
| 56 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
||
| 761 | blopes | 57 | } |
| 58 | |||
| 59 | @Override |
||
| 60 | public GenericService<RoboDTO> getService() { |
||
| 61 | return roboOperadorService; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public RoboDTO getEntidade() { |
||
| 66 | return entidade; |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | public RoboDTO getId() { |
||
| 71 | return getEntidade(); |
||
| 72 | } |
||
| 73 | |||
| 764 | blopes | 74 | public List<PadraoGatilho> getPadroes() { |
| 75 | return padroes; |
||
| 76 | } |
||
| 77 | public void setPadroes(List<PadraoGatilho> padroes) { |
||
| 78 | this.padroes = padroes; |
||
| 79 | } |
||
| 80 | |||
| 81 | public List<PadraoGatilho> getPadroesComG3() { |
||
| 82 | return padroesComG3; |
||
| 83 | } |
||
| 84 | public void setPadroesComG3(List<PadraoGatilho> padroesComG3) { |
||
| 85 | this.padroesComG3 = padroesComG3; |
||
| 86 | } |
||
| 87 | |||
| 88 | public List<PadraoGatilho> getPadroesAteG2() { |
||
| 89 | return padroesAteG2; |
||
| 90 | } |
||
| 91 | public void setPadroesAteG2(List<PadraoGatilho> padroesAteG2) { |
||
| 92 | this.padroesAteG2 = padroesAteG2; |
||
| 93 | } |
||
| 94 | |||
| 761 | blopes | 95 | public void iniciar() { |
| 96 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 97 | public void execute() { |
||
| 98 | // ANALISAR POR HISTÓRICO |
||
| 99 | getEntidade().setAnalisarPorHistoricoArquivo(true); |
||
| 100 | |||
| 101 | roboOperadorService.iniciarOperacao(getEntidade().getAnalisarPorHistoricoArquivo()); |
||
| 102 | setEntidade(roboOperadorService.statusRobo()); |
||
| 103 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
||
| 104 | } |
||
| 105 | }); |
||
| 106 | } |
||
| 107 | |||
| 108 | public void parar() { |
||
| 109 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 110 | public void execute() { |
||
| 111 | roboOperadorService.pararOperacao(); |
||
| 112 | setEntidade(roboOperadorService.statusRobo()); |
||
| 113 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
||
| 114 | } |
||
| 115 | }); |
||
| 116 | } |
||
| 764 | blopes | 117 | |
| 118 | public void preencherOutrosPadroes() { |
||
| 119 | padroesComG3 = padroes.stream() |
||
| 120 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() != null) |
||
| 121 | .collect(Collectors.toList()); |
||
| 122 | inverterLista(padroesComG3); |
||
| 761 | blopes | 123 | |
| 764 | blopes | 124 | padroesAteG2 = padroes.stream() |
| 125 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() == null) |
||
| 126 | .collect(Collectors.toList()); |
||
| 127 | inverterLista(padroesAteG2); |
||
| 128 | } |
||
| 129 | |||
| 130 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
||
| 131 | List<PadraoGatilho> invertida = new ArrayList<>(candles); |
||
| 132 | Collections.reverse(invertida); |
||
| 133 | return invertida; |
||
| 134 | } |
||
| 135 | |||
| 761 | blopes | 136 | public void atualizarStatus() { |
| 137 | setEntidade(roboOperadorService.statusRobo()); |
||
| 764 | blopes | 138 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getPadroes())) { |
| 139 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
||
| 140 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
||
| 141 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
||
| 142 | } |
||
| 143 | setPadroes(getEntidade().getPadroes()); |
||
| 144 | preencherOutrosPadroes(); |
||
| 145 | } |
||
| 146 | verificarNovosPadroes(); |
||
| 761 | blopes | 147 | } |
| 764 | blopes | 148 | |
| 149 | public void verificarNovosPadroes() { |
||
| 150 | List<String> alertas = AlertaPadraoService.consumirAlertas(); |
||
| 761 | blopes | 151 | |
| 764 | blopes | 152 | if (!alertas.isEmpty()) { |
| 153 | for (String msg : alertas) { |
||
| 154 | FacesMessage facesMessage = new FacesMessage( |
||
| 155 | FacesMessage.SEVERITY_INFO, |
||
| 156 | "Novo padrão identificado", |
||
| 157 | msg |
||
| 158 | ); |
||
| 159 | javax.faces.context.FacesContext.getCurrentInstance() |
||
| 160 | .addMessage(null, facesMessage); |
||
| 161 | } |
||
| 162 | |||
| 163 | // Toca o som no cliente |
||
| 164 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
||
| 165 | // Se estiver em PF antigo: |
||
| 166 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();"); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 761 | blopes | 170 | } |