Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 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.Table; |
||
| 22 | import javax.persistence.Transient; |
||
| 23 | import javax.validation.constraints.NotNull; |
||
| 24 | |||
| 25 | import org.hibernate.annotations.ForeignKey; |
||
| 26 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 27 | |||
| 28 | import br.edu.cesmac.core.interfaces.Alterar; |
||
| 29 | import br.edu.cesmac.core.interfaces.Cadastrar; |
||
| 30 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 31 | |||
| 32 | @Entity |
||
| 33 | @Table(name="sec_linha_vivo", schema="sc_sec") |
||
| 34 | public class LinhaVivo implements Serializable { |
||
| 35 | |||
| 36 | private static final long serialVersionUID = 1L; |
||
| 37 | |||
| 38 | private Long sequencial; |
||
| 39 | private String numero; |
||
| 40 | private Cliente cliente; |
||
| 41 | private ProdutoVivo planoAtual; |
||
| 42 | private Date dataAtualizacao; |
||
| 43 | |||
| 44 | private Set<VendaVivo> listaVendasVivo; |
||
| 45 | |||
| 46 | public LinhaVivo() { |
||
| 47 | listaVendasVivo = new HashSet<VendaVivo>(); |
||
| 48 | } |
||
| 49 | |||
| 50 | @Id |
||
| 51 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 52 | @Column(name="seq_linha_vivo", nullable=false) |
||
| 53 | public Long getSequencial() { |
||
| 54 | return sequencial; |
||
| 55 | } |
||
| 56 | public void setSequencial(Long sequencial) { |
||
| 57 | this.sequencial = sequencial; |
||
| 58 | } |
||
| 59 | |||
| 60 | @Column(name="dsc_numero") |
||
| 61 | @NotNull(message = "Informe o número", groups = {Cadastrar.class, Alterar.class}) |
||
| 62 | @NotEmpty(message = "Informe o número", groups = {Cadastrar.class, Alterar.class}) |
||
| 63 | public String getNumero() { |
||
| 64 | return numero; |
||
| 65 | } |
||
| 66 | public void setNumero(String numero) { |
||
| 67 | this.numero = numero; |
||
| 68 | } |
||
| 69 | |||
| 70 | @ManyToOne |
||
| 71 | @ForeignKey(name="fk_linhavivo_cliente") |
||
| 72 | @JoinColumn(name = "seq_cliente") |
||
| 73 | @NotNull(message = "Informe o cliente da linha", groups = {Cadastrar.class/*, Alterar.class*/}) |
||
| 74 | public Cliente getCliente() { |
||
| 75 | return cliente; |
||
| 76 | } |
||
| 77 | public void setCliente(Cliente cliente) { |
||
| 78 | this.cliente = cliente; |
||
| 79 | } |
||
| 80 | |||
| 81 | @ManyToOne |
||
| 82 | @ForeignKey(name="fk_linhavivo_produtovivo") |
||
| 83 | @JoinColumn(name = "seq_produto_vivo", nullable = true) |
||
| 84 | public ProdutoVivo getPlanoAtual() { |
||
| 85 | return planoAtual; |
||
| 86 | } |
||
| 87 | public void setPlanoAtual(ProdutoVivo planoAtual) { |
||
| 88 | this.planoAtual = planoAtual; |
||
| 89 | } |
||
| 90 | |||
| 91 | @Column(name="dth_atualizacao") |
||
| 92 | @NotNull(message = "Informe a data da atualização", groups = {Cadastrar.class, Alterar.class}) |
||
| 93 | public Date getDataAtualizacao() { |
||
| 94 | return dataAtualizacao; |
||
| 95 | } |
||
| 96 | public void setDataAtualizacao(Date dataAtualizacao) { |
||
| 97 | this.dataAtualizacao = dataAtualizacao; |
||
| 98 | } |
||
| 99 | |||
| 100 | @OneToMany(mappedBy="linhaVivo", fetch=FetchType.LAZY, orphanRemoval=false) |
||
| 101 | public Set<VendaVivo> getListaVendasVivo() { |
||
| 102 | return listaVendasVivo; |
||
| 103 | } |
||
| 104 | public void setListaVendasVivo(Set<VendaVivo> listaVendasVivo) { |
||
| 105 | this.listaVendasVivo = listaVendasVivo; |
||
| 106 | } |
||
| 107 | |||
| 108 | @Override |
||
| 109 | public int hashCode() { |
||
| 110 | final int prime = 31; |
||
| 111 | int result = 1; |
||
| 112 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 113 | return result; |
||
| 114 | } |
||
| 115 | |||
| 116 | @Override |
||
| 117 | public boolean equals(Object obj) { |
||
| 118 | if (this == obj) |
||
| 119 | return true; |
||
| 120 | if (obj == null) |
||
| 121 | return false; |
||
| 122 | if (getClass() != obj.getClass()) |
||
| 123 | return false; |
||
| 124 | LinhaVivo other = (LinhaVivo) obj; |
||
| 125 | if (sequencial == null) { |
||
| 126 | if (other.sequencial != null) |
||
| 127 | return false; |
||
| 128 | } else if (!sequencial.equals(other.sequencial)) |
||
| 129 | return false; |
||
| 130 | return true; |
||
| 131 | } |
||
| 132 | |||
| 133 | @Transient |
||
| 134 | public List<VendaVivo> getVendasVivoOrdenadas() { |
||
| 135 | List<VendaVivo> vendasVivoOrdenadas = null; |
||
| 136 | if (VerificadorUtil.naoEstaNuloOuVazio(getListaVendasVivo())) { |
||
| 137 | vendasVivoOrdenadas = new ArrayList<VendaVivo>(getListaVendasVivo()); |
||
| 138 | Collections.sort(vendasVivoOrdenadas, new Comparator<VendaVivo>() { |
||
| 139 | public int compare(VendaVivo p1, VendaVivo p2) { |
||
| 140 | return p2.getDataVenda().compareTo(p1.getDataVenda()); |
||
| 141 | }; |
||
| 142 | }); |
||
| 143 | } |
||
| 144 | return vendasVivoOrdenadas; |
||
| 145 | } |
||
| 146 | |||
| 147 | @Transient |
||
| 148 | public String getNomeDoCliente() { |
||
| 149 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getNome() : ""; |
||
| 150 | } |
||
| 151 | |||
| 152 | @Transient |
||
| 153 | public String getCpfDoCliente() { |
||
| 154 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getCpfCnpj() : ""; |
||
| 155 | } |
||
| 156 | |||
| 157 | @Transient |
||
| 158 | public String getCpfCnpjFormatadoDoCliente() { |
||
| 159 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getCpfCnpjFormatado() : ""; |
||
| 160 | } |
||
| 161 | |||
| 162 | } |