Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 623 | 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; |
||
| 31 | import br.com.ec.domain.dto.TransferenciaDTO; |
||
| 32 | import br.com.ec.domain.dto.TransferenciaProdutoDTO; |
||
| 33 | import br.com.ec.domain.model.tipos.TipoPosVendaAtivacao; |
||
| 34 | |||
| 35 | //@Entity |
||
| 36 | //@Table(name="sec_posvenda_ativacao", schema="sc_sec") |
||
| 37 | public class PosVendaAtivacao implements Serializable, Identidade { |
||
| 38 | |||
| 39 | private static final long serialVersionUID = 1L; |
||
| 40 | |||
| 41 | private Long sequencial; |
||
| 42 | private PosVenda posVenda; |
||
| 43 | |||
| 44 | private Date dataAtivacao; |
||
| 45 | private Date dataFinalização; |
||
| 46 | private String observacoes; |
||
| 47 | private TipoPosVendaAtivacao tipoAtivacao; // 1: AGRADECIMENTO+DICAS DE USO, 2: CHECK-UP DO PRODUTO + NPS (7 DIAS DEPOIS), 3: |
||
| 48 | |||
| 49 | // private List<PosVendaAtivacaoDTO> listaAtivacoes; |
||
| 50 | |||
| 51 | public PosVendaAtivacao() {} |
||
| 52 | |||
| 53 | public PosVendaAtivacao(TransferenciaDTO transferenciaDTO) { |
||
| 54 | this.sequencial = transferenciaDTO.getSequencial(); |
||
| 55 | } |
||
| 56 | |||
| 57 | @Override |
||
| 58 | @Transient |
||
| 59 | public Object getId() { |
||
| 60 | return this.getSequencial(); |
||
| 61 | } |
||
| 62 | @Override |
||
| 63 | public void setId(Object id) { |
||
| 64 | this.sequencial = (Long) id; |
||
| 65 | } |
||
| 66 | |||
| 67 | public Long getSequencial() { |
||
| 68 | return sequencial; |
||
| 69 | } |
||
| 70 | public void setSequencial(Long sequencial) { |
||
| 71 | this.sequencial = sequencial; |
||
| 72 | } |
||
| 73 | /* |
||
| 74 | @Id |
||
| 75 | @SequenceGenerator(name = "sq_posvendaativ") |
||
| 76 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 77 | @Column(name="seq_transferencia", nullable=false) |
||
| 78 | public Long getSequencial() { |
||
| 79 | return sequencial; |
||
| 80 | } |
||
| 81 | public void setSequencial(Long sequencial) { |
||
| 82 | this.sequencial = sequencial; |
||
| 83 | } |
||
| 84 | |||
| 85 | @ManyToOne |
||
| 86 | @ForeignKey(name="fk_transferencia_loja_saida") |
||
| 87 | @JoinColumn(name = "seq_loja_saida", nullable = false) |
||
| 88 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de saída", groups = {Cadastrar.class, Alterar.class}) |
||
| 89 | public Loja getLojaSaida() { |
||
| 90 | return lojaSaida; |
||
| 91 | } |
||
| 92 | public void setLojaSaida(Loja lojaSaida) { |
||
| 93 | this.lojaSaida = lojaSaida; |
||
| 94 | } |
||
| 95 | |||
| 96 | @ManyToOne |
||
| 97 | @ForeignKey(name="fk_transferencia_loja_entrada") |
||
| 98 | @JoinColumn(name = "seq_loja_entrada", nullable = false) |
||
| 99 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de destino", groups = {Cadastrar.class, Alterar.class}) |
||
| 100 | public Loja getLojaEntrada() { |
||
| 101 | return lojaEntrada; |
||
| 102 | } |
||
| 103 | public void setLojaEntrada(Loja lojaEntrada) { |
||
| 104 | this.lojaEntrada = lojaEntrada; |
||
| 105 | } |
||
| 106 | |||
| 107 | @NotNull(message = "Parâmetro obrigatório não preenchido: Data da Solicitação", groups = {Cadastrar.class, Alterar.class}) |
||
| 108 | @Column(name="dat_solicitacao") |
||
| 109 | public Date getDataSolicitacao() { |
||
| 110 | return dataSolicitacao; |
||
| 111 | } |
||
| 112 | public void setDataSolicitacao(Date dataSolicitacao) { |
||
| 113 | this.dataSolicitacao = dataSolicitacao; |
||
| 114 | } |
||
| 115 | |||
| 116 | @Column(name="ind_conferido") |
||
| 117 | @NotNull(message = "Parâmetro obrigatório não preenchido: Transferência conferida", groups = {Cadastrar.class, Alterar.class}) |
||
| 118 | public Boolean getConferido() { |
||
| 119 | return conferido; |
||
| 120 | } |
||
| 121 | public void setConferido(Boolean conferido) { |
||
| 122 | this.conferido = conferido; |
||
| 123 | } |
||
| 124 | |||
| 125 | @Column(name="dat_finalizacao") |
||
| 126 | public Date getDataFinalizacao() { |
||
| 127 | return dataFinalizacao; |
||
| 128 | } |
||
| 129 | public void setDataFinalizacao(Date dataFinalizacao) { |
||
| 130 | this.dataFinalizacao = dataFinalizacao; |
||
| 131 | } |
||
| 132 | |||
| 133 | @ManyToOne |
||
| 134 | @ForeignKey(name="fk_transferencia_notafiscalremessa") |
||
| 135 | @JoinColumn(name = "seq_nota_fiscal") |
||
| 136 | public NotaFiscal getNotaFiscalRemessa() { |
||
| 137 | return notaFiscalRemessa; |
||
| 138 | } |
||
| 139 | public void setNotaFiscalRemessa(NotaFiscal notaFiscalRemessa) { |
||
| 140 | this.notaFiscalRemessa = notaFiscalRemessa; |
||
| 141 | } |
||
| 142 | |||
| 143 | @Column(name="dth_inicio_transporte") |
||
| 144 | public Date getDataHoraInicioTransporte() { |
||
| 145 | return dataHoraInicioTransporte; |
||
| 146 | } |
||
| 147 | public void setDataHoraInicioTransporte(Date dataHoraInicioTransporte) { |
||
| 148 | this.dataHoraInicioTransporte = dataHoraInicioTransporte; |
||
| 149 | } |
||
| 150 | public String dataHoraInicioTransporteFormatado() { |
||
| 151 | return DataUtils.converterDataComHorarioParaString(getDataHoraInicioTransporte()); |
||
| 152 | } |
||
| 153 | |||
| 154 | @ManyToOne |
||
| 155 | @ForeignKey(name="fk_transferencia_usuairo_transportador") |
||
| 156 | @JoinColumn(name = "seq_usuario_transportador", nullable = true) |
||
| 157 | public Usuario getUsuarioTransportador() { |
||
| 158 | return usuarioTransportador; |
||
| 159 | } |
||
| 160 | public void setUsuarioTransportador(Usuario usuarioTransportador) { |
||
| 161 | this.usuarioTransportador = usuarioTransportador; |
||
| 162 | } |
||
| 163 | |||
| 164 | @ManyToOne |
||
| 165 | @ForeignKey(name="fk_transferencia_usuairo_receptor") |
||
| 166 | @JoinColumn(name = "seq_usuario_receptor", nullable = true) |
||
| 167 | public Usuario getUsuarioReceptor() { |
||
| 168 | return usuarioReceptor; |
||
| 169 | } |
||
| 170 | public void setUsuarioReceptor(Usuario usuarioReceptor) { |
||
| 171 | this.usuarioReceptor = usuarioReceptor; |
||
| 172 | } |
||
| 173 | |||
| 174 | @OneToMany(mappedBy="transferencia", cascade=CascadeType.ALL, orphanRemoval=true) |
||
| 175 | public List<TransferenciaProduto> getListaProdutos() { |
||
| 176 | return listaProdutos; |
||
| 177 | } |
||
| 178 | public void setListaProdutos(List<TransferenciaProduto> listaProdutos) { |
||
| 179 | this.listaProdutos = listaProdutos; |
||
| 180 | } |
||
| 181 | |||
| 182 | @Transient |
||
| 183 | public List<TransferenciaProdutoDTO> getProdutosDTO() { |
||
| 184 | return produtosDTO; |
||
| 185 | } |
||
| 186 | public void setProdutosDTO(List<TransferenciaProdutoDTO> produtosDTO) { |
||
| 187 | this.produtosDTO = produtosDTO; |
||
| 188 | } |
||
| 189 | |||
| 190 | @Override |
||
| 191 | public int hashCode() { |
||
| 192 | final int prime = 31; |
||
| 193 | int result = 1; |
||
| 194 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 195 | return result; |
||
| 196 | } |
||
| 197 | @Override |
||
| 198 | public boolean equals(Object obj) { |
||
| 199 | if (this == obj) |
||
| 200 | return true; |
||
| 201 | if (obj == null) |
||
| 202 | return false; |
||
| 203 | if (getClass() != obj.getClass()) |
||
| 204 | return false; |
||
| 205 | PosVendaAtivacao other = (PosVendaAtivacao) obj; |
||
| 206 | if (sequencial == null) { |
||
| 207 | if (other.sequencial != null) |
||
| 208 | return false; |
||
| 209 | } else if (!sequencial.equals(other.sequencial)) |
||
| 210 | return false; |
||
| 211 | return true; |
||
| 212 | } |
||
| 213 | |||
| 214 | @Transient |
||
| 215 | public Object getSequencialDaLojaEntrada() { |
||
| 216 | return VerificadorUtil.naoEstaNulo(getLojaEntrada())? getLojaEntrada().getSequencial() : null; |
||
| 217 | } |
||
| 218 | |||
| 219 | @Transient |
||
| 220 | public Object getSequencialDaLojaSaida() { |
||
| 221 | return VerificadorUtil.naoEstaNulo(getLojaSaida())? getLojaSaida().getSequencial() : null; |
||
| 222 | } |
||
| 223 | |||
| 224 | @Transient |
||
| 225 | public List<TransferenciaProduto> getProdutosOrdenados() { |
||
| 226 | List<TransferenciaProduto> produtosOrdenados = null; |
||
| 227 | if (VerificadorUtil.naoEstaNulo(getListaProdutos())) { |
||
| 228 | produtosOrdenados = new ArrayList<TransferenciaProduto>(getListaProdutos()); |
||
| 229 | Collections.sort(produtosOrdenados, new Comparator<TransferenciaProduto>() { |
||
| 230 | public int compare(TransferenciaProduto p1, TransferenciaProduto p2) { |
||
| 231 | return p1.getProduto().getDescricaoDoModelo().compareTo(p2.getProduto().getDescricaoDoModelo()); |
||
| 232 | }; |
||
| 233 | }); |
||
| 234 | } |
||
| 235 | return produtosOrdenados; |
||
| 236 | } |
||
| 237 | |||
| 238 | public void adicionarProduto(TransferenciaProduto produto) { |
||
| 239 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 240 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 241 | } |
||
| 242 | getListaProdutos().add(produto); |
||
| 243 | } |
||
| 244 | |||
| 245 | public void removerProduto(TransferenciaProduto transferenciaProduto) { |
||
| 246 | if (!VerificadorUtil.isListaNulaOuVazia(getListaProdutos())) { |
||
| 247 | getListaProdutos().remove(transferenciaProduto); |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 251 | public void removerProduto(TransferenciaProdutoDTO transferenciaProdutoDTO) { |
||
| 252 | if (!VerificadorUtil.isListaNulaOuVazia(getProdutosDTO())) { |
||
| 253 | getProdutosDTO().remove(transferenciaProdutoDTO); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | public boolean verificarSeProdutoJaConstaNaLista(TransferenciaProduto transferenciaProduto) { |
||
| 258 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 259 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 260 | } |
||
| 261 | for (TransferenciaProduto item : getListaProdutos()) { |
||
| 262 | if (item.equals(transferenciaProduto)) { |
||
| 263 | return true; |
||
| 264 | } |
||
| 265 | } |
||
| 266 | return false; |
||
| 267 | } |
||
| 268 | */ |
||
| 269 | } |