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