Rev 629 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 625 | blopes | 1 | package br.com.ec.controller; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.List; |
||
| 6 | |||
| 7 | import javax.inject.Inject; |
||
| 8 | import javax.inject.Named; |
||
| 9 | |||
| 10 | import org.springframework.context.annotation.Scope; |
||
| 11 | |||
| 12 | import br.com.ec.core.generic.GenericService; |
||
| 13 | import br.com.ec.core.util.VerificadorUtil; |
||
| 14 | import br.com.ec.domain.dto.ComercialPosVendaDTO; |
||
| 631 | blopes | 15 | import br.com.ec.domain.dto.NpsPosVendaDTO; |
| 625 | blopes | 16 | import br.com.ec.domain.model.NpsPosVenda; |
| 17 | import br.com.ec.domain.model.PosVenda; |
||
| 18 | import br.com.ec.domain.model.tipos.TipoNpsPosVenda; |
||
| 19 | import br.com.ec.domain.model.tipos.TipoPeriodoConsulta; |
||
| 628 | blopes | 20 | import br.com.ec.domain.service.NpsPosVendaService; |
| 625 | blopes | 21 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 22 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 23 | import br.com.ec.web.generic.AbstractBean; |
||
| 24 | |||
| 25 | @Named |
||
| 26 | @Scope("view") |
||
| 27 | public class NpsPosVendaBean extends AbstractBean<ComercialPosVendaDTO> implements Serializable { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 628 | blopes | 31 | private NpsPosVendaService npsPosVendaService; |
| 625 | blopes | 32 | |
| 33 | private NpsPosVenda npsPosVendaSelecionado; |
||
| 34 | |||
| 35 | public static class NpsItem { |
||
| 36 | private final Integer nota; |
||
| 37 | private final String icone; |
||
| 38 | private final String estrelas; |
||
| 39 | |||
| 40 | public NpsItem(Integer nota, String icone, String estrelas) { |
||
| 41 | this.nota = nota; |
||
| 42 | this.icone = icone; |
||
| 43 | this.estrelas = estrelas; |
||
| 44 | } |
||
| 45 | |||
| 46 | public Integer getNota() { return nota; } |
||
| 47 | public String getIcone() { return icone; } |
||
| 48 | public String getEstrelas() { return estrelas; } |
||
| 49 | } |
||
| 50 | |||
| 51 | @Inject |
||
| 628 | blopes | 52 | public NpsPosVendaBean(NpsPosVendaService npsPosVendaService) { |
| 53 | this.npsPosVendaService = npsPosVendaService; |
||
| 625 | blopes | 54 | } |
| 55 | |||
| 56 | @Override |
||
| 57 | public GenericService<ComercialPosVendaDTO> getService() { |
||
| 58 | return null; |
||
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | public ComercialPosVendaDTO getId() { |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | @Override |
||
| 67 | public void preCarregamento() { |
||
| 68 | limparEntidade(); |
||
| 69 | } |
||
| 70 | |||
| 71 | @Override |
||
| 72 | public void limparEntidade() { |
||
| 73 | } |
||
| 74 | |||
| 75 | public List<NpsItem> getRostosNps() { |
||
| 76 | List<NpsItem> lista = new ArrayList<>(); |
||
| 77 | for (int i = 1; i <= 5; i++) { |
||
| 627 | blopes | 78 | String icone = "rosto-" + i + ".png"; // Ex: emoji0.png até emoji10.png |
| 625 | blopes | 79 | String estrelas = new String(new char[5]).replace("\0", "⭐");//"⭐".repeat(Math.max(0, i / 2)); // Converte nota para estrelas visuais |
| 80 | lista.add(new NpsItem(new Integer(i), icone, estrelas)); |
||
| 81 | } |
||
| 82 | return lista; |
||
| 83 | } |
||
| 84 | |||
| 85 | /**************************************************/ |
||
| 86 | |||
| 87 | public TipoPeriodoConsulta[] getTiposPeriodoConsulta() { |
||
| 88 | return TipoPeriodoConsulta.values(); |
||
| 89 | } |
||
| 90 | |||
| 91 | /**************************************************/ |
||
| 92 | |||
| 93 | public NpsPosVenda getNpsPosVendaSelecionado() { |
||
| 94 | if (VerificadorUtil.estaNulo(npsPosVendaSelecionado)) { |
||
| 95 | if (VerificadorUtil.naoEstaNulo(getParametro("sq"))) { |
||
| 631 | blopes | 96 | PosVenda posVenda = new PosVenda(new Long(getParametro("sq").toString())); |
| 97 | NpsPosVendaDTO npsPosVendaDTO = npsPosVendaService.consultarPorPosVendaEeTipo(posVenda.getSequencial(), TipoNpsPosVenda.ATENDIMENTO_A.getValor()); |
||
| 625 | blopes | 98 | npsPosVendaSelecionado = new NpsPosVenda(); |
| 631 | blopes | 99 | if (VerificadorUtil.naoEstaNulo(npsPosVendaDTO)) { |
| 100 | npsPosVendaSelecionado.setPosVenda(posVenda); |
||
| 101 | npsPosVendaSelecionado.preencherDados(npsPosVendaDTO); |
||
| 102 | } else { |
||
| 103 | npsPosVendaSelecionado.setPosVenda(posVenda); |
||
| 104 | npsPosVendaSelecionado.setObservacao(""); |
||
| 105 | npsPosVendaSelecionado.setTipoNps(TipoNpsPosVenda.ATENDIMENTO_A.getValor()); |
||
| 106 | } |
||
| 625 | blopes | 107 | } |
| 108 | } |
||
| 109 | return npsPosVendaSelecionado; |
||
| 110 | } |
||
| 111 | public void setNpsPosVendaSelecionado(NpsPosVenda npsPosVendaSelecionado) { |
||
| 112 | this.npsPosVendaSelecionado = npsPosVendaSelecionado; |
||
| 113 | } |
||
| 114 | |||
| 628 | blopes | 115 | public void selecionarNota() { |
| 116 | if (VerificadorUtil.naoEstaNulo(getNpsPosVendaSelecionado())) { |
||
| 117 | System.out.println(getNpsPosVendaSelecionado().getNota()); |
||
| 118 | } else { |
||
| 119 | System.out.println("SEM NOTA!"); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 625 | blopes | 123 | public void efetivarNps() { |
| 124 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 125 | public void execute() { |
||
| 629 | blopes | 126 | npsPosVendaService.efetivarNpsAtendimento(getNpsPosVendaSelecionado()); |
| 625 | blopes | 127 | } |
| 128 | }); |
||
| 129 | } |
||
| 130 | |||
| 131 | } |