Rev 572 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.inject.Inject; |
||
| 6 | import javax.inject.Named; |
||
| 571 | blopes | 7 | import javax.servlet.http.HttpServletRequest; |
| 106 | espaco | 8 | |
| 571 | blopes | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 106 | espaco | 10 | import org.springframework.context.annotation.Scope; |
| 11 | |||
| 571 | blopes | 12 | import br.com.ec.controller.util.IpUtil; |
| 195 | espaco | 13 | import br.com.ec.core.generic.GenericService; |
| 14 | import br.com.ec.core.util.DataUtils; |
||
| 572 | blopes | 15 | import br.com.ec.core.util.VerificadorUtil; |
| 106 | espaco | 16 | import br.com.ec.domain.model.Ponto; |
| 572 | blopes | 17 | import br.com.ec.domain.model.TransferenciaProduto; |
| 18 | import br.com.ec.domain.service.email.impl.GerenciadorEmailImpl; |
||
| 106 | espaco | 19 | import br.com.ec.domain.service.ponto.PontoService; |
| 572 | blopes | 20 | import br.com.ec.domain.shared.ConstantesSEC; |
| 195 | espaco | 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 | import br.com.ec.web.message.LancadorMensagem; |
||
| 106 | espaco | 25 | |
| 26 | @Named |
||
| 27 | @Scope("view") |
||
| 28 | public class PontoBean extends AbstractBean<Ponto> implements Serializable { |
||
| 29 | |||
| 30 | private static final long serialVersionUID = 1L; |
||
| 31 | |||
| 32 | private String senhaUsuario; |
||
| 33 | |||
| 34 | private PontoService pontoService; |
||
| 35 | |||
| 571 | blopes | 36 | // @Autowired |
| 37 | // private HttpServletRequest request; |
||
| 38 | |||
| 106 | espaco | 39 | @Inject |
| 40 | public PontoBean(PontoService pontoService) { |
||
| 41 | this.pontoService = pontoService; |
||
| 42 | } |
||
| 43 | |||
| 44 | @Override |
||
| 45 | public void preCarregamento() { |
||
| 46 | limparEntidade(); |
||
| 47 | } |
||
| 48 | |||
| 49 | @Override |
||
| 50 | public void limparEntidade() { |
||
| 51 | entidade = new Ponto(); |
||
| 52 | setSenhaUsuario(""); |
||
| 53 | } |
||
| 54 | |||
| 55 | @Override |
||
| 56 | public GenericService<Ponto> getService() { |
||
| 57 | return pontoService; |
||
| 58 | } |
||
| 59 | |||
| 60 | @Override |
||
| 61 | public Ponto getEntidade() { |
||
| 62 | return entidade; |
||
| 63 | } |
||
| 64 | |||
| 65 | @Override |
||
| 66 | public Ponto getId() { |
||
| 67 | return getEntidade(); |
||
| 68 | } |
||
| 69 | |||
| 70 | public String getSenhaUsuario() { |
||
| 71 | return senhaUsuario; |
||
| 72 | } |
||
| 73 | public void setSenhaUsuario(String senhaUsuario) { |
||
| 74 | this.senhaUsuario = senhaUsuario; |
||
| 75 | } |
||
| 76 | |||
| 77 | /***************************************************************/ |
||
| 78 | |||
| 79 | public void iniciarPonto(final Long lojaSequencial) { |
||
| 80 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 81 | public void execute() { |
||
| 82 | setEntidade(pontoService.consultarPonto(DataUtils.getDataAtual(), senhaUsuario, lojaSequencial)); |
||
| 83 | } |
||
| 84 | }); |
||
| 85 | } |
||
| 86 | |||
| 87 | public void baterPontoInicio() { |
||
| 88 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 89 | public void execute() { |
||
| 90 | getEntidade().setDataHoraPontoInicio(DataUtils.getDataAtual()); |
||
| 571 | blopes | 91 | getEntidade().setIpPontoInicio(recuperarIpUsuario()); |
| 580 | blopes | 92 | // verificarSeIpIgualLoja(recuperarIpUsuario()); |
| 106 | espaco | 93 | baterPonto(); |
| 94 | } |
||
| 95 | }); |
||
| 96 | } |
||
| 97 | |||
| 98 | public void excluirPontoInicio() { |
||
| 99 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 100 | public void execute() { |
||
| 101 | getEntidade().setDataHoraPontoInicio(null); |
||
| 102 | baterPonto(); |
||
| 103 | } |
||
| 104 | }); |
||
| 105 | } |
||
| 106 | |||
| 107 | public void baterPontoFim() { |
||
| 108 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 109 | public void execute() { |
||
| 110 | getEntidade().setDataHoraPontoFim(DataUtils.getDataAtual()); |
||
| 571 | blopes | 111 | getEntidade().setIpPontoFim(recuperarIpUsuario()); |
| 580 | blopes | 112 | // verificarSeIpIgualLoja(recuperarIpUsuario()); |
| 106 | espaco | 113 | baterPonto(); |
| 114 | } |
||
| 115 | }); |
||
| 116 | } |
||
| 117 | |||
| 118 | public void excluirPontoFim() { |
||
| 119 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 120 | public void execute() { |
||
| 121 | getEntidade().setDataHoraPontoFim(null); |
||
| 122 | baterPonto(); |
||
| 123 | } |
||
| 124 | }); |
||
| 125 | } |
||
| 126 | |||
| 127 | public void baterIntervaloInicio() { |
||
| 128 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 129 | public void execute() { |
||
| 130 | getEntidade().setDataHoraIntervaloInicio(DataUtils.getDataAtual()); |
||
| 571 | blopes | 131 | getEntidade().setIpPontoIntervaloInicio(recuperarIpUsuario()); |
| 580 | blopes | 132 | // verificarSeIpIgualLoja(recuperarIpUsuario()); |
| 106 | espaco | 133 | baterPonto(); |
| 134 | } |
||
| 135 | }); |
||
| 136 | } |
||
| 137 | |||
| 138 | public void excluirIntervaloInicio() { |
||
| 139 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 140 | public void execute() { |
||
| 141 | getEntidade().setDataHoraIntervaloInicio(null); |
||
| 142 | baterPonto(); |
||
| 143 | } |
||
| 144 | }); |
||
| 145 | } |
||
| 146 | |||
| 147 | public void baterIntervaloFim() { |
||
| 148 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 149 | public void execute() { |
||
| 150 | getEntidade().setDataHoraIntervaloFim(DataUtils.getDataAtual()); |
||
| 571 | blopes | 151 | getEntidade().setIpPontoIntervaloFim(recuperarIpUsuario()); |
| 580 | blopes | 152 | // verificarSeIpIgualLoja(recuperarIpUsuario()); |
| 106 | espaco | 153 | baterPonto(); |
| 154 | } |
||
| 155 | }); |
||
| 156 | } |
||
| 157 | |||
| 158 | public void excluirIntervaloFim() { |
||
| 159 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 160 | public void execute() { |
||
| 161 | getEntidade().setDataHoraIntervaloFim(null); |
||
| 162 | baterPonto(); |
||
| 163 | } |
||
| 164 | }); |
||
| 165 | } |
||
| 166 | |||
| 571 | blopes | 167 | private String recuperarIpUsuario() { |
| 168 | HttpServletRequest request = (HttpServletRequest) getContext().getExternalContext().getRequest(); |
||
| 169 | return IpUtil.getClientIp(request); |
||
| 170 | } |
||
| 171 | |||
| 106 | espaco | 172 | private void baterPonto() { |
| 173 | pontoService.alterar(getEntidade()); |
||
| 174 | limparEntidade(); |
||
| 572 | blopes | 175 | LancadorMensagem.lancarSucesso("PONTO REALIZADO COM SUCESSO!"); |
| 106 | espaco | 176 | } |
| 572 | blopes | 177 | |
| 178 | private void verificarSeIpIgualLoja(String ipUsuario) { |
||
| 179 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getLoja().getIpInternet())) { |
||
| 180 | if (!ipUsuario.contains(getEntidade().getLoja().getIpInternet())) { |
||
| 181 | StringBuilder conteudo = new StringBuilder(); |
||
| 182 | conteudo.append(getEntidade().getNomeDaPessoa() + "\n"); |
||
| 183 | conteudo.append("LOJA: " + getEntidade().getLoja().getDescricao() + "\n"); |
||
| 184 | conteudo.append("DATA: " + DataUtils.converterDataComHorarioParaString(DataUtils.getDataAtual()) + "\n"); |
||
| 185 | conteudo.append("\n\n"); |
||
| 186 | conteudo.toString(); |
||
| 187 | |||
| 188 | new GerenciadorEmailImpl() |
||
| 189 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_GESTAO) |
||
| 190 | .comAssunto("ESPAÇO CASE - PONTO SUSPEITO DE " + getEntidade().getNomeDaPessoa()) |
||
| 191 | .comConteudo(conteudo.toString()) |
||
| 192 | .enviar(); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | } |
||
| 106 | espaco | 196 | |
| 197 | } |