Rev 195 | Rev 697 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 195 | Rev 693 | ||
|---|---|---|---|
| Line 7... | Line 7... | ||
| 7 | import br.com.ec.core.generic.AbstractService; |
7 | import br.com.ec.core.generic.AbstractService; |
| 8 | import br.com.ec.core.generic.GenericRepository; |
8 | import br.com.ec.core.generic.GenericRepository; |
| 9 | import br.com.ec.core.util.DataUtils; |
9 | import br.com.ec.core.util.DataUtils; |
| 10 | import br.com.ec.core.util.VerificadorUtil; |
10 | import br.com.ec.core.util.VerificadorUtil; |
| 11 | import br.com.ec.core.validador.Validador; |
11 | import br.com.ec.core.validador.Validador; |
| - | 12 | import br.com.ec.domain.dto.ParametrosVendaDTO; |
|
| 12 | import br.com.ec.domain.model.Cupom; |
13 | import br.com.ec.domain.model.Cupom; |
| - | 14 | import br.com.ec.domain.model.Lancamento; |
|
| - | 15 | import br.com.ec.domain.model.SubtipoProduto; |
|
| 13 | import br.com.ec.domain.model.tipos.TipoCupom; |
16 | import br.com.ec.domain.model.tipos.TipoCupom; |
| - | 17 | import br.com.ec.domain.model.tipos.TipoEstiloProduto; |
|
| - | 18 | import br.com.ec.domain.model.tipos.TipoProduto; |
|
| - | 19 | import br.com.ec.domain.model.tipos.TipoRegraCupom; |
|
| 14 | import br.com.ec.domain.service.cupom.CupomService; |
20 | import br.com.ec.domain.service.cupom.CupomService; |
| 15 | import br.com.ec.domain.service.lancamento.LancamentoService; |
21 | import br.com.ec.domain.service.lancamento.LancamentoService; |
| - | 22 | import br.com.ec.domain.shared.ConstantesSEC; |
|
| 16 | import br.com.ec.infrastructure.repository.CupomRepository; |
23 | import br.com.ec.infrastructure.repository.CupomRepository; |
| 17 | 24 | ||
| 18 | @Service |
25 | @Service |
| 19 | public class CupomServiceImpl extends AbstractService<Cupom> implements CupomService { |
26 | public class CupomServiceImpl extends AbstractService<Cupom> implements CupomService { |
| 20 | 27 | ||
| Line 147... | Line 154... | ||
| 147 | }
|
154 | }
|
| 148 | if (!cupom.getTipoCupom().equals(TipoCupom.REEMBOLSO.getValor())) { |
155 | if (!cupom.getTipoCupom().equals(TipoCupom.REEMBOLSO.getValor())) { |
| 149 | throw new NegocioException("OPERAÇÃO NÃO PERMITIDA: CUPOM DEVE SER PARA REEMBOLSO"); |
156 | throw new NegocioException("OPERAÇÃO NÃO PERMITIDA: CUPOM DEVE SER PARA REEMBOLSO"); |
| 150 | }
|
157 | }
|
| 151 | }
|
158 | }
|
| - | 159 | }
|
|
| - | 160 | ||
| - | 161 | @Override |
|
| - | 162 | public void validarRegrasCupom(ParametrosVendaDTO parametrosVenda, Cupom cupomSelecionado) { |
|
| - | 163 | // APENAS_PELICULA_TPUSOFT_P1("P1", "REGRA: APENAS PARA PELÍCULA TPU SOFT"),
|
|
| - | 164 | // APENAS_PELICULA_TPUSOFTTPASEIRA_P2("P2", "REGRA: APENAS PARA PELÍCULA TPU SOFT TRASEIRA"),
|
|
| - | 165 | // APENAS_PELICULA_CAMERACOMFRONTAL_P3("P3", "REGRA: APENAS PARA PELÍCULA DE CÂMERA NA COMPRA DA FRONTAL"),
|
|
| - | 166 | // APENAS_CAPA_C1("C1", "REGRA: APENAS PARA CAPAS"),
|
|
| - | 167 | // APENAS_2CAPAS_C2("C2", "REGRA: APENAS PARA VENDAS COM 2 CAPAS"),
|
|
| - | 168 | // APENAS_3CAPAS_C3("C3", "REGRA: APENAS PARA VENDAS COM 3 CAPAS"),
|
|
| - | 169 | // APENAS_CAPA_SILICONE_C4("C4", "REGRA: APENAS PARA CAPAS DE SILICONE");
|
|
| - | 170 | ||
| - | 171 | Boolean verificarSeTemPeliculaFrontalParaP2P3 = false; |
|
| - | 172 | Integer quantidadeCapas = 0; |
|
| - | 173 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
|
| - | 174 | if (lancamento.getProduto().getTipo().equals(TipoProduto.CAPA.getValor())) { |
|
| - | 175 | quantidadeCapas++;
|
|
| - | 176 | }
|
|
| - | 177 | if (lancamento.getProduto().getTipo().equals(TipoProduto.PELICULA.getValor()) && |
|
| - | 178 | VerificadorUtil.naoEstaNuloOuVazio(lancamento.getProduto().getSubtipoProduto())) { |
|
| - | 179 | if (!lancamento.getProduto().getSubtipoProduto().getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_TPU_SOFT_CAMERA_47) || |
|
| - | 180 | !lancamento.getProduto().getSubtipoProduto().getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_VIDRO_CAMERA_48)) { |
|
| - | 181 | verificarSeTemPeliculaFrontalParaP2P3 = true; |
|
| - | 182 | }
|
|
| - | 183 | }
|
|
| - | 184 | }
|
|
| - | 185 | ||
| - | 186 | for (Lancamento lancamento : parametrosVenda.getLancamentos()) { |
|
| - | 187 | if (lancamento.equals(cupomSelecionado.getLancamento()) && VerificadorUtil.naoEstaNuloOuVazio(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 188 | String tipoProdutoLancamento = lancamento.getProduto().getTipo(); |
|
| - | 189 | SubtipoProduto subtipoProdutoLancamento = lancamento.getProduto().getSubtipoProduto(); |
|
| - | 190 | ||
| - | 191 | // REGRAS PARA PELÍCULAS
|
|
| - | 192 | if (TipoRegraCupom.APENAS_PELICULA_TPUSOFT_P1.getValor().equals(cupomSelecionado.getTipoRegraCupom()) || |
|
| - | 193 | TipoRegraCupom.APENAS_PELICULA_TPUSOFTTPASEIRA_P2.getValor().equals(cupomSelecionado.getTipoRegraCupom()) || |
|
| - | 194 | TipoRegraCupom.APENAS_PELICULA_CAMERACOMFRONTAL_P3.getValor().equals(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 195 | if (!tipoProdutoLancamento.equals(TipoProduto.PELICULA.getValor())) { |
|
| - | 196 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 197 | }
|
|
| - | 198 | if (TipoRegraCupom.APENAS_PELICULA_TPUSOFT_P1.getValor().equals(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 199 | if (VerificadorUtil.naoEstaNulo(subtipoProdutoLancamento)) { |
|
| - | 200 | if (!subtipoProdutoLancamento.getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_TPU_SOFT_NORMAL_42) || |
|
| - | 201 | !subtipoProdutoLancamento.getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_TPU_SOFT_PRIVACIDADE_43)) { |
|
| - | 202 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 203 | }
|
|
| - | 204 | }
|
|
| - | 205 | }
|
|
| - | 206 | ||
| - | 207 | if (TipoRegraCupom.APENAS_PELICULA_TPUSOFTTPASEIRA_P2.getValor().equals(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 208 | if (VerificadorUtil.naoEstaNulo(subtipoProdutoLancamento)) { |
|
| - | 209 | if (!subtipoProdutoLancamento.getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_TPU_SOFT_TRASEIRA_46)) { |
|
| - | 210 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 211 | }
|
|
| - | 212 | }
|
|
| - | 213 | }
|
|
| - | 214 | ||
| - | 215 | if (TipoRegraCupom.APENAS_PELICULA_CAMERACOMFRONTAL_P3.getValor().equals(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 216 | if (VerificadorUtil.naoEstaNulo(subtipoProdutoLancamento)) { |
|
| - | 217 | if (verificarSeTemPeliculaFrontalParaP2P3 && |
|
| - | 218 | (!subtipoProdutoLancamento.getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_TPU_SOFT_CAMERA_47) || |
|
| - | 219 | !subtipoProdutoLancamento.getSequencial().equals(ConstantesSEC.SubtipoProduto.SEQUENCIAL_SUBTIPO_VIDRO_CAMERA_48))) { |
|
| - | 220 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 221 | }
|
|
| - | 222 | }
|
|
| - | 223 | }
|
|
| - | 224 | }
|
|
| - | 225 | ||
| - | 226 | // REGRAS PARA CAPAS
|
|
| - | 227 | if (TipoRegraCupom.APENAS_CAPA_C1.getValor().equals(cupomSelecionado.getTipoRegraCupom()) || |
|
| - | 228 | TipoRegraCupom.APENAS_2CAPAS_C2.getValor().equals(cupomSelecionado.getTipoRegraCupom()) || |
|
| - | 229 | TipoRegraCupom.APENAS_3CAPAS_C3.getValor().equals(cupomSelecionado.getTipoRegraCupom()) || |
|
| - | 230 | TipoRegraCupom.APENAS_CAPA_SILICONE_C4.getValor().equals(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 231 | if (!tipoProdutoLancamento.equals(TipoProduto.CAPA.getValor())) { |
|
| - | 232 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 233 | }
|
|
| - | 234 | if (TipoRegraCupom.APENAS_2CAPAS_C2.getValor().equals(cupomSelecionado.getTipoRegraCupom()) && quantidadeCapas<2) { |
|
| - | 235 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 236 | }
|
|
| - | 237 | if (TipoRegraCupom.APENAS_3CAPAS_C3.getValor().equals(cupomSelecionado.getTipoRegraCupom()) && quantidadeCapas<3) { |
|
| - | 238 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 239 | }
|
|
| - | 240 | if (TipoRegraCupom.APENAS_CAPA_SILICONE_C4.getValor().equals(cupomSelecionado.getTipoRegraCupom())) { |
|
| - | 241 | if (VerificadorUtil.naoEstaNuloOuVazio(lancamento.getProduto().getEstilo())) { |
|
| - | 242 | if (!lancamento.getProduto().getEstilo().equals(TipoEstiloProduto.SILICONE_CASE.getValor())) { |
|
| - | 243 | throw new RuntimeException(cupomSelecionado.getDescricaoDoTipoRegraCupom()); |
|
| - | 244 | }
|
|
| - | 245 | }
|
|
| - | 246 | }
|
|
| - | 247 | }
|
|
| - | 248 | ||
| - | 249 | break; |
|
| - | 250 | }
|
|
| - | 251 | }
|
|
| - | 252 | ||
| 152 | }
|
253 | }
|
| 153 | 254 | ||
| 154 | }
|
255 | }
|