Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 739 | 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.HashSet; |
||
| 9 | import java.util.List; |
||
| 10 | import java.util.Set; |
||
| 11 | |||
| 12 | import javax.persistence.Column; |
||
| 13 | import javax.persistence.Entity; |
||
| 14 | import javax.persistence.FetchType; |
||
| 15 | import javax.persistence.GeneratedValue; |
||
| 16 | import javax.persistence.GenerationType; |
||
| 17 | import javax.persistence.Id; |
||
| 18 | import javax.persistence.JoinColumn; |
||
| 19 | import javax.persistence.ManyToOne; |
||
| 20 | import javax.persistence.OneToMany; |
||
| 21 | import javax.persistence.SequenceGenerator; |
||
| 22 | import javax.persistence.Table; |
||
| 23 | import javax.persistence.Transient; |
||
| 24 | import javax.validation.constraints.Size; |
||
| 25 | |||
| 26 | import org.hibernate.annotations.ForeignKey; |
||
| 27 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 28 | |||
| 29 | import br.com.ec.core.interfaces.Alterar; |
||
| 30 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 31 | import br.com.ec.core.util.StringUtil; |
||
| 32 | import br.com.ec.core.util.VerificadorUtil; |
||
| 33 | import br.com.ec.domain.model.tipos.TipoSexo; |
||
| 34 | import br.com.ec.domain.util.ValidadorCpfCnpjUtil; |
||
| 35 | import br.com.ec.web.converters.FormatarUtil; |
||
| 36 | |||
| 37 | //@Entity |
||
| 38 | //@Table(name="sec_cliente", schema="sc_sec") |
||
| 39 | public class Marketplace implements Serializable { |
||
| 40 | |||
| 41 | private static final long serialVersionUID = 1L; |
||
| 42 | |||
| 43 | private String nome; |
||
| 44 | private Long sequencial; |
||
| 45 | private String cpfCnpj; |
||
| 46 | private String sexo; |
||
| 47 | private String email; |
||
| 48 | private String contato; |
||
| 49 | private String telefone; |
||
| 50 | private String endereco; |
||
| 51 | private String observacao; |
||
| 52 | private Date dataNascimento; |
||
| 53 | private Date dataCadastro; |
||
| 54 | private Boolean indicadorNovidades; |
||
| 55 | private Boolean ativo; |
||
| 56 | |||
| 57 | private Modelo modelo; |
||
| 58 | private Set<Venda> listaVendas; |
||
| 59 | private Set<EstoqueAuditoria> listaTrocas; |
||
| 60 | private Set<Cupom> listaCupons; |
||
| 61 | private List<Pedido> pedidos = new ArrayList<Pedido>(); |
||
| 62 | |||
| 63 | public Marketplace() { |
||
| 64 | listaVendas = new HashSet<Venda>(); |
||
| 65 | listaTrocas = new HashSet<EstoqueAuditoria>(); |
||
| 66 | listaCupons= new HashSet<Cupom>(); |
||
| 67 | } |
||
| 68 | |||
| 69 | // @Id |
||
| 70 | // @SequenceGenerator(name = "sq_cliente") |
||
| 71 | // @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 72 | // @Column(name="seq_cliente", nullable=false) |
||
| 73 | public Long getSequencial() { |
||
| 74 | return sequencial; |
||
| 75 | } |
||
| 76 | public void setSequencial(Long sequencial) { |
||
| 77 | this.sequencial = sequencial; |
||
| 78 | } |
||
| 79 | |||
| 80 | @Column(name="dsc_nome") |
||
| 81 | @NotEmpty(message = "Parâmetro obrigatório não preenchido: Nome", groups = {Cadastrar.class, Alterar.class}) |
||
| 82 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Nome") |
||
| 83 | public String getNome() { |
||
| 84 | return nome; |
||
| 85 | } |
||
| 86 | public void setNome(String nome) { |
||
| 87 | this.nome = StringUtil.setarUpperCaseComTrim(nome.trim()); |
||
| 88 | } |
||
| 89 | |||
| 90 | @Column(name="dsc_cpf_cnpj") |
||
| 91 | @Size(max = 14, message = "Limite de caracteres ultrapassado: CPF/CNPJ") |
||
| 92 | @NotEmpty(message = "Parâmetro obrigatório não preenchido: CPF/CNPJ", groups = {Cadastrar.class, Alterar.class}) |
||
| 93 | public String getCpfCnpj() { |
||
| 94 | return cpfCnpj; |
||
| 95 | } |
||
| 96 | public void setCpfCnpj(String cpfCnpj) { |
||
| 97 | this.cpfCnpj = cpfCnpj; |
||
| 98 | } |
||
| 99 | |||
| 100 | @Column(name="tip_sexo") |
||
| 101 | public String getSexo() { |
||
| 102 | return sexo; |
||
| 103 | } |
||
| 104 | public void setSexo(String sexo) { |
||
| 105 | this.sexo = sexo; |
||
| 106 | } |
||
| 107 | |||
| 108 | @Column(name="dsc_email") |
||
| 109 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Email") |
||
| 110 | public String getEmail() { |
||
| 111 | return email; |
||
| 112 | } |
||
| 113 | public void setEmail(String email) { |
||
| 114 | this.email = email; |
||
| 115 | } |
||
| 116 | |||
| 117 | @Column(name="dsc_contato") |
||
| 118 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Contato") |
||
| 119 | public String getContato() { |
||
| 120 | return contato; |
||
| 121 | } |
||
| 122 | public void setContato(String contato) { |
||
| 123 | this.contato = contato; |
||
| 124 | } |
||
| 125 | |||
| 126 | @Column(name="dsc_telefone") |
||
| 127 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Telefone") |
||
| 128 | public String getTelefone() { |
||
| 129 | return telefone; |
||
| 130 | } |
||
| 131 | public void setTelefone(String telefone) { |
||
| 132 | this.telefone = telefone; |
||
| 133 | } |
||
| 134 | |||
| 135 | @Column(name="dsc_endereco") |
||
| 136 | @Size(max = 250, message = "Limite de caracteres ultrapassado: Endereço") |
||
| 137 | public String getEndereco() { |
||
| 138 | return endereco; |
||
| 139 | } |
||
| 140 | public void setEndereco(String endereco) { |
||
| 141 | this.endereco = StringUtil.setarUpperCaseComTrim(endereco); |
||
| 142 | } |
||
| 143 | |||
| 144 | @Column(name="dsc_observacao") |
||
| 145 | @Size(max = 240, message = "Limite de caracteres ultrapassado: Observação") |
||
| 146 | public String getObservacao() { |
||
| 147 | return observacao; |
||
| 148 | } |
||
| 149 | public void setObservacao(String observacao) { |
||
| 150 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 151 | } |
||
| 152 | |||
| 153 | @Column(name="dat_nascimento") |
||
| 154 | public Date getDataNascimento() { |
||
| 155 | return dataNascimento; |
||
| 156 | } |
||
| 157 | public void setDataNascimento(Date dataNascimento) { |
||
| 158 | this.dataNascimento = dataNascimento; |
||
| 159 | } |
||
| 160 | |||
| 161 | @Column(name="dat_cadastro") |
||
| 162 | public Date getDataCadastro() { |
||
| 163 | return dataCadastro; |
||
| 164 | } |
||
| 165 | public void setDataCadastro(Date dataCadastro) { |
||
| 166 | this.dataCadastro = dataCadastro; |
||
| 167 | } |
||
| 168 | |||
| 169 | @Column(name="ind_novidades") |
||
| 170 | public Boolean getIndicadorNovidades() { |
||
| 171 | return indicadorNovidades; |
||
| 172 | } |
||
| 173 | public void setIndicadorNovidades(Boolean indicadorNovidades) { |
||
| 174 | this.indicadorNovidades = indicadorNovidades; |
||
| 175 | } |
||
| 176 | |||
| 177 | @Column(name="ind_ativo", nullable=false) |
||
| 178 | public Boolean getAtivo() { |
||
| 179 | return ativo; |
||
| 180 | } |
||
| 181 | public void setAtivo(Boolean ativo) { |
||
| 182 | this.ativo = ativo; |
||
| 183 | } |
||
| 184 | |||
| 185 | @ManyToOne |
||
| 186 | @ForeignKey(name="fk_cliente_modelo") |
||
| 187 | @JoinColumn(name = "seq_modelo", nullable=true) |
||
| 188 | public Modelo getModelo() { |
||
| 189 | return modelo; |
||
| 190 | } |
||
| 191 | public void setModelo(Modelo modelo) { |
||
| 192 | this.modelo = modelo; |
||
| 193 | } |
||
| 194 | |||
| 195 | @OneToMany(mappedBy="cliente", fetch=FetchType.LAZY, orphanRemoval=false) |
||
| 196 | public Set<Venda> getListaVendas() { |
||
| 197 | return listaVendas; |
||
| 198 | } |
||
| 199 | public void setListaVendas(Set<Venda> listaVendas) { |
||
| 200 | this.listaVendas = listaVendas; |
||
| 201 | } |
||
| 202 | |||
| 203 | @OneToMany(mappedBy="cliente", fetch=FetchType.LAZY, orphanRemoval=false) |
||
| 204 | public Set<EstoqueAuditoria> getListaTrocas() { |
||
| 205 | return listaTrocas; |
||
| 206 | } |
||
| 207 | public void setListaTrocas(Set<EstoqueAuditoria> listaTrocas) { |
||
| 208 | this.listaTrocas = listaTrocas; |
||
| 209 | } |
||
| 210 | |||
| 211 | @OneToMany(mappedBy="cliente", fetch=FetchType.LAZY, orphanRemoval=false) |
||
| 212 | public Set<Cupom> getListaCupons() { |
||
| 213 | return listaCupons; |
||
| 214 | } |
||
| 215 | public void setListaCupons(Set<Cupom> listaCupons) { |
||
| 216 | this.listaCupons = listaCupons; |
||
| 217 | } |
||
| 218 | |||
| 219 | @Transient |
||
| 220 | public List<Pedido> getPedidos() { |
||
| 221 | return pedidos; |
||
| 222 | } |
||
| 223 | public void setPedidos(List<Pedido> pedidos) { |
||
| 224 | this.pedidos = pedidos; |
||
| 225 | } |
||
| 226 | |||
| 227 | @Override |
||
| 228 | public int hashCode() { |
||
| 229 | final int prime = 31; |
||
| 230 | int result = 1; |
||
| 231 | result = prime * result |
||
| 232 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 233 | return result; |
||
| 234 | } |
||
| 235 | |||
| 236 | @Override |
||
| 237 | public boolean equals(Object obj) { |
||
| 238 | if (this == obj) |
||
| 239 | return true; |
||
| 240 | if (obj == null) |
||
| 241 | return false; |
||
| 242 | if (getClass() != obj.getClass()) |
||
| 243 | return false; |
||
| 244 | Marketplace other = (Marketplace) obj; |
||
| 245 | if (sequencial == null) { |
||
| 246 | if (other.sequencial != null) |
||
| 247 | return false; |
||
| 248 | } else if (!sequencial.equals(other.sequencial)) |
||
| 249 | return false; |
||
| 250 | return true; |
||
| 251 | } |
||
| 252 | |||
| 253 | @Transient |
||
| 254 | public String getDescricaoDoModelo() { |
||
| 255 | return VerificadorUtil.naoEstaNulo(getModelo())? getModelo().getDescricao() : ""; |
||
| 256 | } |
||
| 257 | |||
| 258 | @Transient |
||
| 259 | public String getDescricaoDoSexo() { |
||
| 260 | return VerificadorUtil.naoEstaNulo(getSexo())? TipoSexo.parse(getSexo()).getDescricao(): ""; |
||
| 261 | } |
||
| 262 | |||
| 263 | @Transient |
||
| 264 | public String getCpfCnpjFormatado() { |
||
| 265 | return VerificadorUtil.naoEstaNulo(getCpfCnpj())? FormatarUtil.retornarCpfCnpjFormatado(getCpfCnpj()) : ""; |
||
| 266 | } |
||
| 267 | |||
| 268 | @Transient |
||
| 269 | public Boolean ehCpf() { |
||
| 270 | if (VerificadorUtil.naoEstaNulo(getCpfCnpj()) && getCpfCnpj().length() == 11) { |
||
| 271 | return ValidadorCpfCnpjUtil.isCPF(getCpfCnpj()); |
||
| 272 | } |
||
| 273 | return false; |
||
| 274 | } |
||
| 275 | |||
| 276 | @Transient |
||
| 277 | public Boolean ehCnpj() { |
||
| 278 | if (VerificadorUtil.naoEstaNulo(getCpfCnpj()) && getCpfCnpj().length() == 14) { |
||
| 279 | return ValidadorCpfCnpjUtil.isCNPJ(getCpfCnpj()); |
||
| 280 | } |
||
| 281 | return false; |
||
| 282 | } |
||
| 283 | |||
| 284 | @Transient |
||
| 285 | public Boolean cpfCnpjEhValido() { |
||
| 286 | return ehCpf() || ehCnpj()? true : false; |
||
| 287 | } |
||
| 288 | |||
| 289 | @Transient |
||
| 290 | public List<Venda> getVendasOrdenadas() { |
||
| 291 | List<Venda> vendasOrdenadas = null; |
||
| 292 | if (VerificadorUtil.naoEstaNulo(getListaVendas())) { |
||
| 293 | vendasOrdenadas = new ArrayList<Venda>(getListaVendas()); |
||
| 294 | Collections.sort(vendasOrdenadas, new Comparator<Venda>() { |
||
| 295 | public int compare(Venda p1, Venda p2) { |
||
| 296 | return p2.getDataVenda().compareTo(p1.getDataVenda()); |
||
| 297 | }; |
||
| 298 | }); |
||
| 299 | } |
||
| 300 | return vendasOrdenadas; |
||
| 301 | } |
||
| 302 | |||
| 303 | @Transient |
||
| 304 | public List<EstoqueAuditoria> getTrocasOrdenadas() { |
||
| 305 | List<EstoqueAuditoria> trocasOrdenadas = null; |
||
| 306 | if (VerificadorUtil.naoEstaNulo(getListaTrocas())) { |
||
| 307 | trocasOrdenadas = new ArrayList<EstoqueAuditoria>(getListaTrocas()); |
||
| 308 | Collections.sort(trocasOrdenadas, new Comparator<EstoqueAuditoria>() { |
||
| 309 | public int compare(EstoqueAuditoria p1, EstoqueAuditoria p2) { |
||
| 310 | return p2.getDataAtualizacao().compareTo(p1.getDataAtualizacao()); |
||
| 311 | }; |
||
| 312 | }); |
||
| 313 | } |
||
| 314 | return trocasOrdenadas; |
||
| 315 | } |
||
| 316 | |||
| 317 | @Transient |
||
| 318 | public List<Cupom> getCuponsOrdenados() { |
||
| 319 | List<Cupom> cuponsOrdenados = null; |
||
| 320 | if (VerificadorUtil.naoEstaNulo(getListaCupons())) { |
||
| 321 | cuponsOrdenados = new ArrayList<Cupom>(getListaCupons()); |
||
| 322 | Collections.sort(cuponsOrdenados, new Comparator<Cupom>() { |
||
| 323 | public int compare(Cupom p1, Cupom p2) { |
||
| 324 | return p2.getDataHoraEmissao().compareTo(p1.getDataHoraEmissao()); |
||
| 325 | }; |
||
| 326 | }); |
||
| 327 | } |
||
| 328 | return cuponsOrdenados; |
||
| 329 | } |
||
| 330 | |||
| 331 | } |