Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 412 | espaco | 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.Entity; |
||
| 8 | import javax.persistence.GeneratedValue; |
||
| 9 | import javax.persistence.GenerationType; |
||
| 10 | import javax.persistence.Id; |
||
| 11 | import javax.persistence.JoinColumn; |
||
| 12 | import javax.persistence.ManyToOne; |
||
| 13 | import javax.persistence.SequenceGenerator; |
||
| 14 | import javax.persistence.Table; |
||
| 15 | import javax.persistence.Transient; |
||
| 16 | import javax.validation.constraints.NotNull; |
||
| 17 | import javax.validation.constraints.Size; |
||
| 18 | |||
| 19 | import org.hibernate.annotations.ForeignKey; |
||
| 20 | |||
| 21 | import br.com.ec.core.generic.identidade.Identidade; |
||
| 22 | import br.com.ec.core.interfaces.Alterar; |
||
| 23 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 24 | import br.com.ec.core.util.StringUtil; |
||
| 25 | import br.com.ec.core.util.VerificadorUtil; |
||
| 26 | import br.com.ec.domain.dto.BancoHorasDTO; |
||
| 27 | import br.com.ec.domain.dto.FuncionarioEventoDTO; |
||
| 28 | |||
| 29 | @Entity |
||
| 30 | @Table(name="sec_banco_horas", schema="sc_sec") |
||
| 31 | public class BancoHoras implements Serializable, Identidade { |
||
| 32 | |||
| 33 | private static final long serialVersionUID = 1L; |
||
| 34 | |||
| 35 | private Long sequencial; |
||
| 36 | private Funcionario funcionario; |
||
| 37 | private Date data; |
||
| 38 | private Double valor; |
||
| 39 | private String observacao; |
||
| 40 | |||
| 41 | public BancoHoras() {} |
||
| 42 | |||
| 43 | public BancoHoras(BancoHorasDTO bancoHorasDTO) { |
||
| 44 | this.sequencial = bancoHorasDTO.getSequencial(); |
||
| 45 | this.funcionario = new Funcionario(bancoHorasDTO.getFuncionarioDTO()); |
||
| 46 | this.data = bancoHorasDTO.getData(); |
||
| 47 | this.valor = bancoHorasDTO.getValor(); |
||
| 48 | this.observacao = bancoHorasDTO.getObservacao(); |
||
| 49 | } |
||
| 50 | |||
| 51 | @Override |
||
| 52 | @Transient |
||
| 53 | public Object getId() { |
||
| 54 | return this.getSequencial(); |
||
| 55 | } |
||
| 56 | @Override |
||
| 57 | public void setId(Object id) { |
||
| 58 | this.sequencial = (Long) id; |
||
| 59 | } |
||
| 60 | |||
| 61 | @Id |
||
| 62 | @SequenceGenerator(name = "sq_bancohoras") |
||
| 63 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 64 | @Column(name="seq_banco_horas", nullable=false) |
||
| 65 | public Long getSequencial() { |
||
| 66 | return sequencial; |
||
| 67 | } |
||
| 68 | public void setSequencial(Long sequencial) { |
||
| 69 | this.sequencial = sequencial; |
||
| 70 | } |
||
| 71 | |||
| 72 | @ManyToOne |
||
| 73 | @ForeignKey(name="fk_bancohoras_funcionario") |
||
| 74 | @JoinColumn(name = "seq_funcionario", nullable=false) |
||
| 75 | @NotNull(message="Obrigatório informar o funcionário", groups={Cadastrar.class, Alterar.class}) |
||
| 76 | public Funcionario getFuncionario() { |
||
| 77 | return funcionario; |
||
| 78 | } |
||
| 79 | public void setFuncionario(Funcionario funcionario) { |
||
| 80 | this.funcionario = funcionario; |
||
| 81 | } |
||
| 82 | |||
| 83 | @NotNull(message="Obrigatório informar a data", groups={Cadastrar.class, Alterar.class}) |
||
| 84 | @Column(name="dat_banco_horas") |
||
| 85 | public Date getData() { |
||
| 86 | return data; |
||
| 87 | } |
||
| 88 | public void setData(Date data) { |
||
| 89 | this.data = data; |
||
| 90 | } |
||
| 91 | |||
| 92 | @Column(name="val_banco_horas") |
||
| 93 | public Double getValor() { |
||
| 94 | return valor; |
||
| 95 | } |
||
| 96 | public void setValor(Double valor) { |
||
| 97 | this.valor = valor; |
||
| 98 | } |
||
| 99 | |||
| 100 | @Column(name="dsc_observacao") |
||
| 101 | @Size(max = 250, message = "Limite de caracteres ultrapassado: Observação") |
||
| 102 | public String getObservacao() { |
||
| 103 | return observacao; |
||
| 104 | } |
||
| 105 | public void setObservacao(String observacao) { |
||
| 106 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 107 | } |
||
| 108 | |||
| 109 | @Transient |
||
| 110 | public String nomeDoFuncionario() { |
||
| 111 | return VerificadorUtil.naoEstaNulo(getFuncionario())? getFuncionario().getNomeDaPessoa() : null; |
||
| 112 | } |
||
| 113 | |||
| 114 | @Override |
||
| 115 | public int hashCode() { |
||
| 116 | final int prime = 31; |
||
| 117 | int result = 1; |
||
| 118 | result = prime * result |
||
| 119 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 120 | return result; |
||
| 121 | } |
||
| 122 | |||
| 123 | @Override |
||
| 124 | public boolean equals(Object obj) { |
||
| 125 | if (this == obj) |
||
| 126 | return true; |
||
| 127 | if (obj == null) |
||
| 128 | return false; |
||
| 129 | if (getClass() != obj.getClass()) |
||
| 130 | return false; |
||
| 131 | BancoHoras other = (BancoHoras) obj; |
||
| 132 | if (sequencial == null) { |
||
| 133 | if (other.sequencial != null) |
||
| 134 | return false; |
||
| 135 | } else if (!sequencial.equals(other.sequencial)) |
||
| 136 | return false; |
||
| 137 | return true; |
||
| 138 | } |
||
| 139 | |||
| 140 | public void atualizarDados(BancoHorasDTO bancoHorasDTO) { |
||
| 141 | this.data = bancoHorasDTO.getData(); |
||
| 142 | this.valor = bancoHorasDTO.getValor(); |
||
| 143 | this.observacao = bancoHorasDTO.getObservacao(); |
||
| 144 | } |
||
| 145 | |||
| 146 | } |