Rev 356 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 356 | Rev 557 | ||
|---|---|---|---|
| Line 9... | Line 9... | ||
| 9 | import javax.inject.Named; |
9 | import javax.inject.Named; |
| 10 | 10 | ||
| 11 | import org.springframework.context.annotation.Scope; |
11 | import org.springframework.context.annotation.Scope; |
| 12 | 12 | ||
| 13 | import br.com.ec.controller.util.UtilBean; |
13 | import br.com.ec.controller.util.UtilBean; |
| - | 14 | import br.com.ec.core.exception.NegocioException; |
|
| 14 | import br.com.ec.core.generic.GenericService; |
15 | import br.com.ec.core.generic.GenericService; |
| 15 | import br.com.ec.core.util.DataUtils; |
16 | import br.com.ec.core.util.DataUtils; |
| 16 | import br.com.ec.core.util.StringUtil; |
17 | import br.com.ec.core.util.StringUtil; |
| 17 | import br.com.ec.core.util.VerificadorUtil; |
18 | import br.com.ec.core.util.VerificadorUtil; |
| 18 | import br.com.ec.domain.dto.CockpitDTO; |
19 | import br.com.ec.domain.dto.CockpitDTO; |
| 19 | import br.com.ec.domain.dto.RankingLojaDTO; |
20 | import br.com.ec.domain.dto.RankingLojaDTO; |
| 20 | import br.com.ec.domain.dto.RankingVendedorDTO; |
21 | import br.com.ec.domain.dto.RankingVendedorDTO; |
| 21 | import br.com.ec.domain.model.Loja; |
22 | import br.com.ec.domain.model.Loja; |
| - | 23 | import br.com.ec.domain.model.Usuario; |
|
| 22 | import br.com.ec.domain.model.Vendedor; |
24 | import br.com.ec.domain.model.Vendedor; |
| 23 | import br.com.ec.domain.service.loja.LojaService; |
25 | import br.com.ec.domain.service.loja.LojaService; |
| - | 26 | import br.com.ec.domain.service.perfil.PerfilService; |
|
| - | 27 | import br.com.ec.domain.service.seguranca.ContextoSeguranca; |
|
| 24 | import br.com.ec.domain.service.venda.VendaService; |
28 | import br.com.ec.domain.service.venda.VendaService; |
| 25 | import br.com.ec.domain.service.vendedor.VendedorService; |
29 | import br.com.ec.domain.service.vendedor.VendedorService; |
| 26 | import br.com.ec.domain.shared.ConstantesSEC; |
- | |
| - | 30 | import br.com.ec.web.exception.VerificadorLancamentoException; |
|
| - | 31 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
|
| 27 | import br.com.ec.web.generic.AbstractBean; |
32 | import br.com.ec.web.generic.AbstractBean; |
| - | 33 | import br.com.ec.web.message.LancadorMensagem; |
|
| 28 | import br.com.ec.web.util.DataUtil; |
34 | import br.com.ec.web.util.DataUtil; |
| 29 | 35 | ||
| 30 | @Named |
36 | @Named |
| 31 | @Scope("view") |
37 | @Scope("view") |
| 32 | public class CockpitBean extends AbstractBean<CockpitDTO> implements Serializable { |
38 | public class CockpitBean extends AbstractBean<CockpitDTO> implements Serializable { |
| Line 34... | Line 40... | ||
| 34 | private static final long serialVersionUID = 1L; |
40 | private static final long serialVersionUID = 1L; |
| 35 | 41 | ||
| 36 | private VendaService vendaService; |
42 | private VendaService vendaService; |
| 37 | private VendedorService vendedorService; |
43 | private VendedorService vendedorService; |
| 38 | private LojaService lojaService; |
44 | private LojaService lojaService; |
| - | 45 | private PerfilService perfilService; |
|
| - | 46 | private ContextoSeguranca contextoSeguranca; |
|
| 39 | private Date dataInicial; |
47 | private Date dataInicial; |
| 40 | private Date dataFinal; |
48 | private Date dataFinal; |
| 41 | 49 | ||
| 42 | private Double percentualVendidoMesAtual; |
50 | private Double percentualVendidoMesAtual; |
| 43 | private Double percentualPercorridoMesAtual; |
51 | private Double percentualPercorridoMesAtual; |
| Line 45... | Line 53... | ||
| 45 | private Loja lojaParcial; |
53 | private Loja lojaParcial; |
| 46 | private Loja lojaVendedores; |
54 | private Loja lojaVendedores; |
| 47 | private String parcialEmTexto; |
55 | private String parcialEmTexto; |
| 48 | 56 | ||
| 49 | @Inject |
57 | @Inject |
| 50 | public CockpitBean(VendaService vendaService, VendedorService vendedorService, LojaService lojaService) { |
- | |
| - | 58 | public CockpitBean(VendaService vendaService, VendedorService vendedorService, LojaService lojaService, PerfilService perfilService, |
|
| - | 59 | ContextoSeguranca contextoSeguranca) { |
|
| 51 | this.vendaService = vendaService; |
60 | this.vendaService = vendaService; |
| 52 | this.vendedorService = vendedorService; |
61 | this.vendedorService = vendedorService; |
| 53 | this.lojaService = lojaService; |
62 | this.lojaService = lojaService; |
| - | 63 | this.perfilService = perfilService; |
|
| - | 64 | this.contextoSeguranca = contextoSeguranca; |
|
| 54 | }
|
65 | }
|
| 55 | 66 | ||
| 56 | @Override |
67 | @Override |
| 57 | public void preCarregamento() { |
68 | public void preCarregamento() { |
| 58 | setDataInicial(DataUtils.getPrimeiroDiaDoMesAtual()); |
69 | setDataInicial(DataUtils.getPrimeiroDiaDoMesAtual()); |
| Line 132... | Line 143... | ||
| 132 | public void setParcialEmTexto(String parcialEmTexto) { |
143 | public void setParcialEmTexto(String parcialEmTexto) { |
| 133 | this.parcialEmTexto = parcialEmTexto; |
144 | this.parcialEmTexto = parcialEmTexto; |
| 134 | }
|
145 | }
|
| 135 | 146 | ||
| 136 | public void consultarRankingVendedores() { |
147 | public void consultarRankingVendedores() { |
| - | 148 | verificarPermissaoDataInicial(); |
|
| - | 149 | ||
| 137 | if (VerificadorUtil.estaNulo(getEntidade())) { |
150 | if (VerificadorUtil.estaNulo(getEntidade())) { |
| 138 | entidade = new CockpitDTO(); |
151 | entidade = new CockpitDTO(); |
| 139 | }
|
152 | }
|
| 140 | List<RankingVendedorDTO> rankingVendedor = new ArrayList<RankingVendedorDTO>(); |
153 | List<RankingVendedorDTO> rankingVendedor = new ArrayList<RankingVendedorDTO>(); |
| 141 | List<RankingVendedorDTO> rankingVendedorVivo = new ArrayList<RankingVendedorDTO>(); |
154 | List<RankingVendedorDTO> rankingVendedorVivo = new ArrayList<RankingVendedorDTO>(); |
| Line 151... | Line 164... | ||
| 151 | entidade.setRankingVendedores(rankingVendedor); |
164 | entidade.setRankingVendedores(rankingVendedor); |
| 152 | entidade.setRankingVendedoresVivo(rankingVendedorVivo); |
165 | entidade.setRankingVendedoresVivo(rankingVendedorVivo); |
| 153 | }
|
166 | }
|
| 154 | 167 | ||
| 155 | public void consultarRankingLojas() { |
168 | public void consultarRankingLojas() { |
| - | 169 | verificarPermissaoDataInicial(); |
|
| - | 170 | ||
| 156 | if (VerificadorUtil.estaNulo(getEntidade())) { |
171 | if (VerificadorUtil.estaNulo(getEntidade())) { |
| 157 | entidade = new CockpitDTO(); |
172 | entidade = new CockpitDTO(); |
| 158 | }
|
173 | }
|
| 159 | entidade.setRankingLojas(vendaService.consultarRankingLojas(getDataInicial(), getDataFinal())); |
174 | entidade.setRankingLojas(vendaService.consultarRankingLojas(getDataInicial(), getDataFinal())); |
| 160 | entidade.setRankingLojasExtras(vendaService.consultarRankingLojasExtras(getDataInicial(), getDataFinal())); |
175 | entidade.setRankingLojasExtras(vendaService.consultarRankingLojasExtras(getDataInicial(), getDataFinal())); |
| Line 177... | Line 192... | ||
| 177 | Integer diaAtual = DataUtils.getDataAtual().getDate(); |
192 | Integer diaAtual = DataUtils.getDataAtual().getDate(); |
| 178 | setPercentualPercorridoMesAtual(new Double(100*diaAtual/ultimoDiaDoMes)); |
193 | setPercentualPercorridoMesAtual(new Double(100*diaAtual/ultimoDiaDoMes)); |
| 179 | }
|
194 | }
|
| 180 | 195 | ||
| 181 | public void consultarRankings() { |
196 | public void consultarRankings() { |
| 182 | consultarRankingVendedores(); |
- | |
| 183 | consultarRankingLojas(); |
- | |
| 184 | consultarRankingPromocaoInterna(); |
- | |
| - | 197 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
|
| - | 198 | public void execute() { |
|
| - | 199 | consultarRankingVendedores(); |
|
| - | 200 | consultarRankingLojas(); |
|
| - | 201 | consultarRankingPromocaoInterna(); |
|
| - | 202 | }
|
|
| - | 203 | }); |
|
| 185 | }
|
204 | }
|
| 186 | 205 | ||
| - | 206 | private void verificarPermissaoDataInicial() { |
|
| - | 207 | Usuario usuario = contextoSeguranca.obterUsuario(); |
|
| - | 208 | if (!perfilService.temPerfilAdministrador(usuario)) { |
|
| - | 209 | Date dataUmAnoAnterior = DataUtils.acrescentarAnos(DataUtils.getDataAtual(), -1); |
|
| - | 210 | if (getDataInicial().before(dataUmAnoAnterior)) { |
|
| - | 211 | throw new NegocioException("Sem permissão para esta operação. Limite de 1 ano"); |
|
| - | 212 | }
|
|
| - | 213 | }
|
|
| - | 214 | }
|
|
| - | 215 | ||
| 187 | public void consultarParciais() { |
216 | public void consultarParciais() { |
| 188 | StringBuilder parcial = new StringBuilder(); |
217 | StringBuilder parcial = new StringBuilder(); |
| 189 | List<Loja> lojas = new ArrayList<Loja>(); |
218 | List<Loja> lojas = new ArrayList<Loja>(); |
| 190 | if (VerificadorUtil.estaNulo(getLojaParcial())) { |
219 | if (VerificadorUtil.estaNulo(getLojaParcial())) { |
| 191 | lojas.addAll(lojaService.listarLojasAtivas()); |
220 | lojas.addAll(lojaService.listarLojasAtivas()); |