Go to most recent revision | Details | 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.Date; |
||
| 5 | |||
| 6 | import javax.persistence.Column; |
||
| 7 | import javax.persistence.EmbeddedId; |
||
| 8 | import javax.persistence.Entity; |
||
| 9 | import javax.persistence.JoinColumn; |
||
| 10 | import javax.persistence.ManyToOne; |
||
| 11 | import javax.persistence.Table; |
||
| 12 | import javax.persistence.Transient; |
||
| 13 | import javax.validation.constraints.Size; |
||
| 14 | |||
| 15 | import org.hibernate.annotations.ForeignKey; |
||
| 16 | |||
| 17 | import br.com.ec.core.generic.identidade.Identidade; |
||
| 18 | import br.com.ec.core.util.StringUtil; |
||
| 19 | import br.com.ec.core.util.VerificadorUtil; |
||
| 20 | |||
| 21 | @Entity |
||
| 22 | @Table(name="sec_produto_loja", schema="sc_sec") |
||
| 23 | public class ProdutoLoja implements Serializable, Identidade { |
||
| 24 | |||
| 25 | private static final long serialVersionUID = 1L; |
||
| 26 | |||
| 27 | private ProdutoLojaId produtoLojaId; |
||
| 28 | private Produto produto; |
||
| 29 | private Loja loja; |
||
| 30 | private Integer quantidadeEstoque; |
||
| 31 | private Integer quantidadeEstoqueContagem; |
||
| 32 | // private Integer quantidadeEstoqueUltimaContagem; |
||
| 33 | private Date dataContagem; |
||
| 34 | private Date dataContagemPreparacao; |
||
| 35 | private Usuario usuarioUltimaContagem; |
||
| 36 | private Usuario usuarioUltimaContagemPreparacao; |
||
| 37 | private String localizacao; |
||
| 38 | private Boolean indicadorContagemSolicitada = false; |
||
| 39 | |||
| 40 | public ProdutoLoja() { |
||
| 41 | this.produtoLojaId = new ProdutoLojaId(); |
||
| 42 | } |
||
| 43 | |||
| 44 | public ProdutoLoja(ProdutoLojaId produtoLojaId) { |
||
| 45 | this.produtoLojaId = produtoLojaId; |
||
| 46 | } |
||
| 47 | |||
| 48 | public ProdutoLoja(Produto produto, Loja loja) { |
||
| 49 | produtoLojaId = new ProdutoLojaId(); |
||
| 50 | setProduto(produto); |
||
| 51 | setLoja(loja); |
||
| 52 | } |
||
| 53 | |||
| 54 | @Override |
||
| 55 | @Transient |
||
| 56 | public Object getId() { |
||
| 57 | return getProdutoLojaId(); |
||
| 58 | } |
||
| 59 | @Override |
||
| 60 | public void setId(Object id) { |
||
| 61 | this.produtoLojaId = (ProdutoLojaId) id; |
||
| 62 | } |
||
| 63 | |||
| 64 | @EmbeddedId |
||
| 65 | public ProdutoLojaId getProdutoLojaId() { |
||
| 66 | return produtoLojaId; |
||
| 67 | } |
||
| 68 | public void setProdutoLojaId(ProdutoLojaId produtoLojaId) { |
||
| 69 | this.produtoLojaId = produtoLojaId; |
||
| 70 | } |
||
| 71 | |||
| 72 | @ManyToOne |
||
| 73 | @ForeignKey(name="fk_produtoloja_produto") |
||
| 74 | @JoinColumn(name = "seq_produto", insertable=false, updatable=false, nullable = false) |
||
| 75 | public Produto getProduto() { |
||
| 76 | return produto; |
||
| 77 | } |
||
| 78 | public void setProduto(Produto produto) { |
||
| 79 | if (VerificadorUtil.naoEstaNulo(produto)) { |
||
| 80 | produtoLojaId.setSequencialProduto(produto.getSequencial()); |
||
| 81 | } |
||
| 82 | this.produto = produto; |
||
| 83 | } |
||
| 84 | |||
| 85 | @ManyToOne |
||
| 86 | @ForeignKey(name="fk_produtoloja_loja") |
||
| 87 | @JoinColumn(name = "seq_loja", insertable=false, updatable=false, nullable = false) |
||
| 88 | public Loja getLoja() { |
||
| 89 | return loja; |
||
| 90 | } |
||
| 91 | public void setLoja(Loja loja) { |
||
| 92 | if (VerificadorUtil.naoEstaNulo(loja)) { |
||
| 93 | produtoLojaId.setSequencialLoja(loja.getSequencial()); |
||
| 94 | } |
||
| 95 | this.loja = loja; |
||
| 96 | } |
||
| 97 | |||
| 98 | @Column(name="qtd_estoque") |
||
| 99 | public Integer getQuantidadeEstoque() { |
||
| 100 | return quantidadeEstoque; |
||
| 101 | } |
||
| 102 | public void setQuantidadeEstoque(Integer quantidadeEstoque) { |
||
| 103 | this.quantidadeEstoque = quantidadeEstoque; |
||
| 104 | } |
||
| 105 | |||
| 106 | @Column(name="qtd_estoque_contagem") |
||
| 107 | public Integer getQuantidadeEstoqueContagem() { |
||
| 108 | return quantidadeEstoqueContagem; |
||
| 109 | } |
||
| 110 | public void setQuantidadeEstoqueContagem(Integer quantidadeEstoqueContagem) { |
||
| 111 | this.quantidadeEstoqueContagem = quantidadeEstoqueContagem; |
||
| 112 | } |
||
| 113 | |||
| 114 | @Column(name="dat_contagem") |
||
| 115 | public Date getDataContagem() { |
||
| 116 | return dataContagem; |
||
| 117 | } |
||
| 118 | public void setDataContagem(Date dataContagem) { |
||
| 119 | this.dataContagem = dataContagem; |
||
| 120 | } |
||
| 121 | |||
| 122 | @Column(name="dth_contagem_preparacao") |
||
| 123 | public Date getDataContagemPreparacao() { |
||
| 124 | return dataContagemPreparacao; |
||
| 125 | } |
||
| 126 | public void setDataContagemPreparacao(Date dataContagemPreparacao) { |
||
| 127 | this.dataContagemPreparacao = dataContagemPreparacao; |
||
| 128 | } |
||
| 129 | |||
| 130 | @ManyToOne |
||
| 131 | @ForeignKey(name="fk_produtoloja_usuario") |
||
| 132 | @JoinColumn(name = "seq_usuario_contagem", nullable = false) |
||
| 133 | public Usuario getUsuarioUltimaContagem() { |
||
| 134 | return usuarioUltimaContagem; |
||
| 135 | } |
||
| 136 | public void setUsuarioUltimaContagem(Usuario usuarioUltimaContagem) { |
||
| 137 | this.usuarioUltimaContagem = usuarioUltimaContagem; |
||
| 138 | } |
||
| 139 | |||
| 140 | @ManyToOne |
||
| 141 | @ForeignKey(name="fk_produtoloja_usuariopreparacao") |
||
| 142 | @JoinColumn(name = "seq_usuario_contagem_preparacao", nullable = false) |
||
| 143 | public Usuario getUsuarioUltimaContagemPreparacao() { |
||
| 144 | return usuarioUltimaContagemPreparacao; |
||
| 145 | } |
||
| 146 | public void setUsuarioUltimaContagemPreparacao(Usuario usuarioUltimaContagemPreparacao) { |
||
| 147 | this.usuarioUltimaContagemPreparacao = usuarioUltimaContagemPreparacao; |
||
| 148 | } |
||
| 149 | |||
| 150 | @Column(name="dsc_localizacao") |
||
| 151 | @Size(max = 20, message = "Limite de caracteres ultrapassado: Localização") |
||
| 152 | public String getLocalizacao() { |
||
| 153 | return localizacao; |
||
| 154 | } |
||
| 155 | public void setLocalizacao(String localizacao) { |
||
| 156 | this.localizacao = StringUtil.setarUpperCaseComTrim(localizacao); |
||
| 157 | } |
||
| 158 | |||
| 159 | @Column(name="ind_contagem_solicitada") |
||
| 160 | public Boolean getIndicadorContagemSolicitada() { |
||
| 161 | return indicadorContagemSolicitada; |
||
| 162 | } |
||
| 163 | public void setIndicadorContagemSolicitada(Boolean indicadorContagemSolicitada) { |
||
| 164 | this.indicadorContagemSolicitada = indicadorContagemSolicitada; |
||
| 165 | } |
||
| 166 | |||
| 167 | @Transient |
||
| 168 | public Long getSequencialDoProduto() { |
||
| 169 | return VerificadorUtil.naoEstaNulo(produto)? produto.getSequencial() : null; |
||
| 170 | } |
||
| 171 | |||
| 172 | @Transient |
||
| 173 | public Long getSequencialDaLoja() { |
||
| 174 | return VerificadorUtil.naoEstaNulo(loja)? loja.getSequencial() : null; |
||
| 175 | } |
||
| 176 | |||
| 177 | @Transient |
||
| 178 | public Modelo getModeloDoProduto() { |
||
| 179 | return VerificadorUtil.naoEstaNulo(produto)? VerificadorUtil.naoEstaNulo(produto.getModelo())? produto.getModelo() : null : null; |
||
| 180 | } |
||
| 181 | |||
| 182 | @Transient |
||
| 183 | public String getNomeDoUsuarioUltimaContagem() { |
||
| 184 | return VerificadorUtil.naoEstaNulo(getUsuarioUltimaContagem())? getUsuarioUltimaContagem().getNomeDaPessoa() : null; |
||
| 185 | } |
||
| 186 | |||
| 187 | @Transient |
||
| 188 | public String getNomeDoUsuarioUltimaContagemPreparacao() { |
||
| 189 | return VerificadorUtil.naoEstaNulo(getUsuarioUltimaContagemPreparacao())? getUsuarioUltimaContagemPreparacao().getNomeDaPessoa() : null; |
||
| 190 | } |
||
| 191 | |||
| 192 | @Transient |
||
| 193 | public Boolean contagemFoiIniciada() { |
||
| 194 | return getDataContagemPreparacao().after(getDataContagem()); |
||
| 195 | } |
||
| 196 | |||
| 197 | @Override |
||
| 198 | public int hashCode() { |
||
| 199 | final int prime = 31; |
||
| 200 | int result = 1; |
||
| 201 | result = prime * result + ((produtoLojaId == null) ? 0 : produtoLojaId.hashCode()); |
||
| 202 | return result; |
||
| 203 | } |
||
| 204 | |||
| 205 | @Override |
||
| 206 | public boolean equals(Object obj) { |
||
| 207 | if (this == obj) |
||
| 208 | return true; |
||
| 209 | if (obj == null) |
||
| 210 | return false; |
||
| 211 | if (getClass() != obj.getClass()) |
||
| 212 | return false; |
||
| 213 | ProdutoLoja other = (ProdutoLoja) obj; |
||
| 214 | if (produtoLojaId == null) { |
||
| 215 | if (other.produtoLojaId != null) |
||
| 216 | return false; |
||
| 217 | } else if (!produtoLojaId.equals(other.produtoLojaId)) |
||
| 218 | return false; |
||
| 219 | return true; |
||
| 220 | } |
||
| 221 | |||
| 222 | } |