Rev 507 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 507 | blopes | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.Collections; |
||
| 6 | import java.util.Comparator; |
||
| 7 | import java.util.Date; |
||
| 8 | import java.util.List; |
||
| 9 | |||
| 10 | import javax.persistence.CascadeType; |
||
| 11 | import javax.persistence.Column; |
||
| 12 | import javax.persistence.Entity; |
||
| 13 | import javax.persistence.GeneratedValue; |
||
| 14 | import javax.persistence.GenerationType; |
||
| 15 | import javax.persistence.Id; |
||
| 16 | import javax.persistence.JoinColumn; |
||
| 17 | import javax.persistence.ManyToOne; |
||
| 18 | import javax.persistence.OneToMany; |
||
| 19 | import javax.persistence.SequenceGenerator; |
||
| 20 | import javax.persistence.Table; |
||
| 21 | import javax.persistence.Transient; |
||
| 22 | import javax.validation.constraints.NotNull; |
||
| 23 | |||
| 24 | import org.hibernate.annotations.ForeignKey; |
||
| 25 | |||
| 26 | import br.com.ec.core.generic.identidade.Identidade; |
||
| 27 | import br.com.ec.core.interfaces.Alterar; |
||
| 28 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 29 | import br.com.ec.core.util.DataUtils; |
||
| 30 | import br.com.ec.core.util.VerificadorUtil; |
||
| 520 | blopes | 31 | import br.com.ec.domain.dto.LojaDTO; |
| 32 | import br.com.ec.domain.dto.TransferenciaDTO; |
||
| 507 | blopes | 33 | import br.com.ec.domain.dto.TransferenciaProdutoDTO; |
| 34 | import br.com.ec.domain.model.tipos.TipoProduto; |
||
| 520 | blopes | 35 | import br.com.ec.domain.shared.ConstantesSEC; |
| 507 | blopes | 36 | |
| 37 | @Entity |
||
| 38 | @Table(name="sec_transferencia", schema="sc_sec") |
||
| 39 | public class Transferencia implements Serializable, Identidade { |
||
| 40 | |||
| 41 | private static final long serialVersionUID = 1L; |
||
| 42 | |||
| 43 | private Long sequencial; |
||
| 44 | private Loja lojaSaida; |
||
| 45 | private Loja lojaEntrada; |
||
| 46 | private Date dataSolicitacao; |
||
| 47 | private Boolean conferido; |
||
| 48 | private Date dataFinalizacao; |
||
| 49 | private NotaFiscal notaFiscalRemessa; |
||
| 50 | private Date dataHoraInicioTransporte; |
||
| 51 | private Usuario usuarioTransportador; |
||
| 52 | private Usuario usuarioReceptor; |
||
| 53 | |||
| 54 | private List<TransferenciaProduto> listaProdutos; |
||
| 55 | private List<TransferenciaProdutoDTO> produtosDTO; |
||
| 56 | |||
| 520 | blopes | 57 | public Transferencia() {} |
| 58 | |||
| 59 | public Transferencia(TransferenciaDTO transferenciaDTO) { |
||
| 60 | this.sequencial = transferenciaDTO.getSequencial(); |
||
| 61 | this.lojaSaida = new Loja(transferenciaDTO.sequencialDaLojaSaida()); |
||
| 62 | this.lojaEntrada = new Loja(transferenciaDTO.sequencialDaLojaEntrada()); |
||
| 63 | this.dataSolicitacao = transferenciaDTO.getDataSolicitacao(); |
||
| 64 | this.conferido = transferenciaDTO.getConferido(); |
||
| 65 | this.dataFinalizacao = transferenciaDTO.getDataFinalizacao(); |
||
| 66 | } |
||
| 67 | |||
| 507 | blopes | 68 | @Override |
| 69 | @Transient |
||
| 70 | public Object getId() { |
||
| 71 | return this.getSequencial(); |
||
| 72 | } |
||
| 73 | @Override |
||
| 74 | public void setId(Object id) { |
||
| 75 | this.sequencial = (Long) id; |
||
| 76 | } |
||
| 77 | |||
| 78 | @Id |
||
| 79 | @SequenceGenerator(name = "sq_transferencia") |
||
| 80 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 81 | @Column(name="seq_transferencia", nullable=false) |
||
| 82 | public Long getSequencial() { |
||
| 83 | return sequencial; |
||
| 84 | } |
||
| 85 | public void setSequencial(Long sequencial) { |
||
| 86 | this.sequencial = sequencial; |
||
| 87 | } |
||
| 88 | |||
| 89 | @ManyToOne |
||
| 90 | @ForeignKey(name="fk_transferencia_loja_saida") |
||
| 91 | @JoinColumn(name = "seq_loja_saida", nullable = false) |
||
| 92 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de saída", groups = {Cadastrar.class, Alterar.class}) |
||
| 93 | public Loja getLojaSaida() { |
||
| 94 | return lojaSaida; |
||
| 95 | } |
||
| 96 | public void setLojaSaida(Loja lojaSaida) { |
||
| 97 | this.lojaSaida = lojaSaida; |
||
| 98 | } |
||
| 99 | |||
| 100 | @ManyToOne |
||
| 101 | @ForeignKey(name="fk_transferencia_loja_entrada") |
||
| 102 | @JoinColumn(name = "seq_loja_entrada", nullable = false) |
||
| 103 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de destino", groups = {Cadastrar.class, Alterar.class}) |
||
| 104 | public Loja getLojaEntrada() { |
||
| 105 | return lojaEntrada; |
||
| 106 | } |
||
| 107 | public void setLojaEntrada(Loja lojaEntrada) { |
||
| 108 | this.lojaEntrada = lojaEntrada; |
||
| 109 | } |
||
| 110 | |||
| 111 | @NotNull(message = "Parâmetro obrigatório não preenchido: Data da Solicitação", groups = {Cadastrar.class, Alterar.class}) |
||
| 112 | @Column(name="dat_solicitacao") |
||
| 113 | public Date getDataSolicitacao() { |
||
| 114 | return dataSolicitacao; |
||
| 115 | } |
||
| 116 | public void setDataSolicitacao(Date dataSolicitacao) { |
||
| 117 | this.dataSolicitacao = dataSolicitacao; |
||
| 118 | } |
||
| 119 | |||
| 120 | @Column(name="ind_conferido") |
||
| 121 | @NotNull(message = "Parâmetro obrigatório não preenchido: Transferência conferida", groups = {Cadastrar.class, Alterar.class}) |
||
| 122 | public Boolean getConferido() { |
||
| 123 | return conferido; |
||
| 124 | } |
||
| 125 | public void setConferido(Boolean conferido) { |
||
| 126 | this.conferido = conferido; |
||
| 127 | } |
||
| 128 | |||
| 129 | @Column(name="dat_finalizacao") |
||
| 130 | public Date getDataFinalizacao() { |
||
| 131 | return dataFinalizacao; |
||
| 132 | } |
||
| 133 | public void setDataFinalizacao(Date dataFinalizacao) { |
||
| 134 | this.dataFinalizacao = dataFinalizacao; |
||
| 135 | } |
||
| 136 | |||
| 137 | @ManyToOne |
||
| 138 | @ForeignKey(name="fk_transferencia_notafiscalremessa") |
||
| 139 | @JoinColumn(name = "seq_nota_fiscal") |
||
| 140 | public NotaFiscal getNotaFiscalRemessa() { |
||
| 141 | return notaFiscalRemessa; |
||
| 142 | } |
||
| 143 | public void setNotaFiscalRemessa(NotaFiscal notaFiscalRemessa) { |
||
| 144 | this.notaFiscalRemessa = notaFiscalRemessa; |
||
| 145 | } |
||
| 146 | |||
| 147 | @Column(name="dth_inicio_transporte") |
||
| 148 | public Date getDataHoraInicioTransporte() { |
||
| 149 | return dataHoraInicioTransporte; |
||
| 150 | } |
||
| 151 | public void setDataHoraInicioTransporte(Date dataHoraInicioTransporte) { |
||
| 152 | this.dataHoraInicioTransporte = dataHoraInicioTransporte; |
||
| 153 | } |
||
| 154 | public String dataHoraInicioTransporteFormatado() { |
||
| 155 | return DataUtils.converterDataComHorarioParaString(getDataHoraInicioTransporte()); |
||
| 156 | } |
||
| 157 | |||
| 158 | @ManyToOne |
||
| 159 | @ForeignKey(name="fk_transferencia_usuairo_transportador") |
||
| 160 | @JoinColumn(name = "seq_usuario_transportador", nullable = true) |
||
| 161 | public Usuario getUsuarioTransportador() { |
||
| 162 | return usuarioTransportador; |
||
| 163 | } |
||
| 164 | public void setUsuarioTransportador(Usuario usuarioTransportador) { |
||
| 165 | this.usuarioTransportador = usuarioTransportador; |
||
| 166 | } |
||
| 167 | |||
| 168 | @ManyToOne |
||
| 169 | @ForeignKey(name="fk_transferencia_usuairo_receptor") |
||
| 170 | @JoinColumn(name = "seq_usuario_receptor", nullable = true) |
||
| 171 | public Usuario getUsuarioReceptor() { |
||
| 172 | return usuarioReceptor; |
||
| 173 | } |
||
| 174 | public void setUsuarioReceptor(Usuario usuarioReceptor) { |
||
| 175 | this.usuarioReceptor = usuarioReceptor; |
||
| 176 | } |
||
| 177 | |||
| 178 | @OneToMany(mappedBy="transferencia", cascade=CascadeType.ALL, orphanRemoval=true) |
||
| 179 | public List<TransferenciaProduto> getListaProdutos() { |
||
| 180 | return listaProdutos; |
||
| 181 | } |
||
| 182 | public void setListaProdutos(List<TransferenciaProduto> listaProdutos) { |
||
| 183 | this.listaProdutos = listaProdutos; |
||
| 184 | } |
||
| 185 | |||
| 186 | @Transient |
||
| 187 | public List<TransferenciaProdutoDTO> getProdutosDTO() { |
||
| 188 | return produtosDTO; |
||
| 189 | } |
||
| 190 | public void setProdutosDTO(List<TransferenciaProdutoDTO> produtosDTO) { |
||
| 191 | this.produtosDTO = produtosDTO; |
||
| 192 | } |
||
| 193 | |||
| 194 | @Override |
||
| 195 | public int hashCode() { |
||
| 196 | final int prime = 31; |
||
| 197 | int result = 1; |
||
| 198 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 199 | return result; |
||
| 200 | } |
||
| 201 | @Override |
||
| 202 | public boolean equals(Object obj) { |
||
| 203 | if (this == obj) |
||
| 204 | return true; |
||
| 205 | if (obj == null) |
||
| 206 | return false; |
||
| 207 | if (getClass() != obj.getClass()) |
||
| 208 | return false; |
||
| 209 | Transferencia other = (Transferencia) obj; |
||
| 210 | if (sequencial == null) { |
||
| 211 | if (other.sequencial != null) |
||
| 212 | return false; |
||
| 213 | } else if (!sequencial.equals(other.sequencial)) |
||
| 214 | return false; |
||
| 215 | return true; |
||
| 216 | } |
||
| 217 | |||
| 218 | @Transient |
||
| 219 | public Object getSequencialDaLojaEntrada() { |
||
| 220 | return VerificadorUtil.naoEstaNulo(getLojaEntrada())? getLojaEntrada().getSequencial() : null; |
||
| 221 | } |
||
| 222 | |||
| 223 | @Transient |
||
| 224 | public Object getSequencialDaLojaSaida() { |
||
| 225 | return VerificadorUtil.naoEstaNulo(getLojaSaida())? getLojaSaida().getSequencial() : null; |
||
| 226 | } |
||
| 227 | |||
| 228 | @Transient |
||
| 229 | public List<TransferenciaProduto> getProdutosOrdenados() { |
||
| 230 | List<TransferenciaProduto> produtosOrdenados = null; |
||
| 231 | if (VerificadorUtil.naoEstaNulo(getListaProdutos())) { |
||
| 232 | produtosOrdenados = new ArrayList<TransferenciaProduto>(getListaProdutos()); |
||
| 233 | Collections.sort(produtosOrdenados, new Comparator<TransferenciaProduto>() { |
||
| 234 | public int compare(TransferenciaProduto p1, TransferenciaProduto p2) { |
||
| 235 | return p1.getProduto().getDescricaoDoModelo().compareTo(p2.getProduto().getDescricaoDoModelo()); |
||
| 236 | }; |
||
| 237 | }); |
||
| 238 | } |
||
| 239 | return produtosOrdenados; |
||
| 240 | } |
||
| 241 | |||
| 242 | public void adicionarProduto(TransferenciaProduto produto) { |
||
| 243 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 244 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 245 | } |
||
| 246 | getListaProdutos().add(produto); |
||
| 247 | } |
||
| 248 | |||
| 249 | public void removerProduto(TransferenciaProduto transferenciaProduto) { |
||
| 250 | if (!VerificadorUtil.isListaNulaOuVazia(getListaProdutos())) { |
||
| 251 | getListaProdutos().remove(transferenciaProduto); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | public void removerProduto(TransferenciaProdutoDTO transferenciaProdutoDTO) { |
||
| 256 | if (!VerificadorUtil.isListaNulaOuVazia(getProdutosDTO())) { |
||
| 257 | getProdutosDTO().remove(transferenciaProdutoDTO); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | public boolean verificarSeProdutoJaConstaNaLista(TransferenciaProduto transferenciaProduto) { |
||
| 262 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 263 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 264 | } |
||
| 265 | for (TransferenciaProduto item : getListaProdutos()) { |
||
| 266 | if (item.equals(transferenciaProduto)) { |
||
| 267 | return true; |
||
| 268 | } |
||
| 269 | } |
||
| 270 | return false; |
||
| 271 | } |
||
| 272 | |||
| 273 | /* |
||
| 274 | public boolean verificarSeProdutoJaConstaNaLista(Long sequencialProduto) { |
||
| 275 | if (VerificadorUtil.estaNulo(getProdutosDTO())) { |
||
| 276 | setProdutosDTO(new ArrayList<TransferenciaProdutoDTO>()); |
||
| 277 | } |
||
| 278 | for (TransferenciaProdutoDTO item : getProdutosDTO()) { |
||
| 279 | if (item.getSequencialProduto().equals(sequencialProduto)) { |
||
| 280 | return true; |
||
| 281 | } |
||
| 282 | } |
||
| 283 | return false; |
||
| 284 | } |
||
| 285 | |||
| 286 | @Transient |
||
| 287 | private Integer quantidadeProdutos(String tipoProduto) { |
||
| 288 | Integer quantidadeTotal = 0; |
||
| 289 | if (VerificadorUtil.naoEstaNuloOuVazio(getProdutosDTO())) { |
||
| 290 | for (TransferenciaProdutoDTO transferenciaProduto : getProdutosDTO()) { |
||
| 291 | if (transferenciaProduto.ehTipoProduto(tipoProduto)) { |
||
| 292 | quantidadeTotal = quantidadeTotal + transferenciaProduto.getQuantidade(); |
||
| 293 | } |
||
| 294 | } |
||
| 295 | } |
||
| 296 | return quantidadeTotal; |
||
| 297 | } |
||
| 298 | |||
| 299 | @Transient |
||
| 300 | public Integer quantidadeProdutosTipoCapa() { |
||
| 301 | return quantidadeProdutos(TipoProduto.CAPA.getValor()); |
||
| 302 | } |
||
| 303 | |||
| 304 | @Transient |
||
| 305 | public Integer quantidadeProdutosTipoPelicula() { |
||
| 306 | return quantidadeProdutos(TipoProduto.PELICULA.getValor()); |
||
| 307 | } |
||
| 308 | |||
| 309 | @Transient |
||
| 310 | public Integer quantidadeProdutosTipoOutrosExcetoCapaEePelicula() { |
||
| 311 | Integer quantidadeTotal = 0; |
||
| 312 | if (VerificadorUtil.naoEstaNuloOuVazio(getProdutosDTO())) { |
||
| 313 | for (TransferenciaProdutoDTO transferenciaProduto : getProdutosDTO()) { |
||
| 314 | if (!transferenciaProduto.ehTipoProduto(TipoProduto.CAPA.getValor()) && |
||
| 315 | !transferenciaProduto.ehTipoProduto(TipoProduto.PELICULA.getValor())) { |
||
| 316 | quantidadeTotal = quantidadeTotal + transferenciaProduto.getQuantidade(); |
||
| 317 | } |
||
| 318 | } |
||
| 319 | } |
||
| 320 | return quantidadeTotal; |
||
| 321 | } |
||
| 322 | */ |
||
| 323 | } |