Rev 761 | Rev 765 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 761 | Rev 764 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | 2 | ||
| 3 | import java.io.Serializable; |
3 | import java.io.Serializable; |
| - | 4 | import java.util.ArrayList; |
|
| - | 5 | import java.util.Collections; |
|
| - | 6 | import java.util.List; |
|
| - | 7 | import java.util.stream.Collectors; |
|
| 4 | 8 | ||
| - | 9 | import javax.faces.application.FacesMessage; |
|
| 5 | import javax.inject.Inject; |
10 | import javax.inject.Inject; |
| 6 | import javax.inject.Named; |
11 | import javax.inject.Named; |
| 7 | 12 | ||
| - | 13 | import org.primefaces.PrimeFaces; |
|
| 8 | import org.springframework.context.annotation.Scope; |
14 | import org.springframework.context.annotation.Scope; |
| 9 | 15 | ||
| 10 | import br.com.ec.core.generic.GenericService; |
16 | import br.com.ec.core.generic.GenericService; |
| - | 17 | import br.com.ec.core.util.VerificadorUtil; |
|
| 11 | import br.com.ec.web.exception.VerificadorLancamentoException; |
18 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 12 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
19 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
| 13 | import br.com.ec.web.generic.AbstractBean; |
20 | import br.com.ec.web.generic.AbstractBean; |
| 14 | import br.com.ec.web.message.LancadorMensagem; |
21 | import br.com.ec.web.message.LancadorMensagem; |
| - | 22 | import br.com.kronus.core.PadraoGatilho; |
|
| 15 | import br.com.sl.domain.dto.RoboDTO; |
23 | import br.com.sl.domain.dto.RoboDTO; |
| 16 | import br.com.sl.domain.service.RoboColetorService; |
- | |
| - | 24 | import br.com.sl.domain.dto.robo.AlertaPadraoService; |
|
| 17 | import br.com.sl.domain.service.RoboOperadorService; |
25 | import br.com.sl.domain.service.RoboOperadorService; |
| 18 | 26 | ||
| 19 | @Named |
27 | @Named |
| 20 | @Scope("view") |
28 | @Scope("view") |
| 21 | public class RoboBean extends AbstractBean<RoboDTO> implements Serializable { |
29 | public class RoboBean extends AbstractBean<RoboDTO> implements Serializable { |
| 22 | 30 | ||
| 23 | private RoboOperadorService roboOperadorService; |
31 | private RoboOperadorService roboOperadorService; |
| - | 32 | ||
| - | 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) |
|
| 24 | 38 | ||
| 25 | @Inject |
39 | @Inject |
| 26 | public RoboBean(RoboOperadorService roboOperadorService) { |
40 | public RoboBean(RoboOperadorService roboOperadorService) { |
| 27 | this.roboOperadorService = roboOperadorService; |
41 | this.roboOperadorService = roboOperadorService; |
| 28 | }
|
42 | }
|
| Line 34... | Line 48... | ||
| 34 | }
|
48 | }
|
| 35 | 49 | ||
| 36 | @Override |
50 | @Override |
| 37 | public void limparEntidade() { |
51 | public void limparEntidade() { |
| 38 | setEntidade(new RoboDTO()); |
52 | setEntidade(new RoboDTO()); |
| - | 53 | setPadroes(new ArrayList<PadraoGatilho>()); |
|
| - | 54 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
|
| - | 55 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
|
| 39 | }
|
56 | }
|
| 40 | 57 | ||
| 41 | @Override |
58 | @Override |
| 42 | public GenericService<RoboDTO> getService() { |
59 | public GenericService<RoboDTO> getService() { |
| 43 | return roboOperadorService; |
60 | return roboOperadorService; |
| Line 49... | Line 66... | ||
| 49 | }
|
66 | }
|
| 50 | 67 | ||
| 51 | @Override |
68 | @Override |
| 52 | public RoboDTO getId() { |
69 | public RoboDTO getId() { |
| 53 | return getEntidade(); |
70 | return getEntidade(); |
| - | 71 | }
|
|
| - | 72 | ||
| - | 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; |
|
| 54 | }
|
92 | }
|
| 55 | 93 | ||
| 56 | public void iniciar() { |
94 | public void iniciar() { |
| 57 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
95 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
| 58 | public void execute() { |
96 | public void execute() { |
| Line 72... | Line 110... | ||
| 72 | roboOperadorService.pararOperacao(); |
110 | roboOperadorService.pararOperacao(); |
| 73 | setEntidade(roboOperadorService.statusRobo()); |
111 | setEntidade(roboOperadorService.statusRobo()); |
| 74 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
112 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
| 75 | }
|
113 | }
|
| 76 | }); |
114 | }); |
| - | 115 | }
|
|
| - | 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); |
|
| - | 122 | ||
| - | 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; |
|
| 77 | }
|
133 | }
|
| 78 | 134 | ||
| 79 | public void atualizarStatus() { |
135 | public void atualizarStatus() { |
| 80 | setEntidade(roboOperadorService.statusRobo()); |
136 | setEntidade(roboOperadorService.statusRobo()); |
| - | 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(); |
|
| - | 146 | }
|
|
| - | 147 | ||
| - | 148 | public void verificarNovosPadroes() { |
|
| - | 149 | List<String> alertas = AlertaPadraoService.consumirAlertas(); |
|
| - | 150 | ||
| - | 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 | }
|
|
| 81 | }
|
167 | }
|
| 82 | 168 | ||
| 83 | }
|
169 | }
|