Rev 760 | Rev 762 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 760 | blopes | 1 | package br.com.sl.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.math.BigDecimal; |
||
| 5 | import java.time.LocalDateTime; |
||
| 6 | import java.time.ZoneId; |
||
| 7 | import java.util.Date; |
||
| 8 | |||
| 9 | import javax.persistence.Column; |
||
| 10 | import javax.persistence.Entity; |
||
| 11 | import javax.persistence.GeneratedValue; |
||
| 12 | import javax.persistence.GenerationType; |
||
| 13 | import javax.persistence.Id; |
||
| 14 | import javax.persistence.JoinColumn; |
||
| 15 | import javax.persistence.ManyToOne; |
||
| 16 | import javax.persistence.SequenceGenerator; |
||
| 17 | import javax.persistence.Table; |
||
| 18 | import javax.persistence.Transient; |
||
| 19 | import javax.validation.constraints.NotNull; |
||
| 20 | |||
| 21 | import org.hibernate.annotations.ForeignKey; |
||
| 22 | |||
| 23 | import br.com.ec.core.interfaces.Alterar; |
||
| 24 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 25 | import br.com.ec.core.util.VerificadorUtil; |
||
| 26 | import br.com.kronus.core.Timeframe; |
||
| 27 | import br.com.sl.domain.dto.robo.CandleState; |
||
| 28 | import br.com.sl.domain.model.tipos.TipoPeriodoCandle; |
||
| 29 | |||
| 30 | @Entity |
||
| 31 | @Table(name="slp_candle", schema="sc_slp") |
||
| 32 | public class Candle implements Serializable { |
||
| 33 | |||
| 34 | private static final long serialVersionUID = 1L; |
||
| 35 | |||
| 36 | private Long sequencial; |
||
| 37 | private Ativo ativo; |
||
| 38 | private Date dataHora; |
||
| 39 | private BigDecimal abertura; |
||
| 40 | private BigDecimal maxima; |
||
| 41 | private BigDecimal minima; |
||
| 42 | private BigDecimal fechamento; |
||
| 43 | private BigDecimal volume; |
||
| 44 | private String periodo; |
||
| 45 | |||
| 761 | blopes | 46 | private String nomeAtivo; |
| 47 | private Integer contadorCandle; |
||
| 760 | blopes | 48 | private LocalDateTime dataHoraTime; |
| 49 | private Timeframe periodoTimeFramde; |
||
| 50 | |||
| 51 | public Candle() {} |
||
| 52 | |||
| 53 | public Candle(Ativo ativo, LocalDateTime fimCandle, CandleState situacaoCandle, String periodoCandle) { |
||
| 54 | this.ativo = ativo; |
||
| 55 | this.dataHora = Date.from(situacaoCandle.getLastTickTime().atZone(ZoneId.systemDefault()).toInstant()); |
||
| 56 | this.abertura = situacaoCandle.getAbertura(); |
||
| 57 | this.maxima = situacaoCandle.getMaxima(); |
||
| 58 | this.minima = situacaoCandle.getMinima(); |
||
| 59 | this.fechamento = situacaoCandle.getFechamento(); |
||
| 60 | this.periodo = periodoCandle; |
||
| 61 | } |
||
| 761 | blopes | 62 | |
| 63 | public Candle(String ativoDescricao, LocalDateTime time, BigDecimal abertura, BigDecimal topo, BigDecimal fundo, |
||
| 64 | BigDecimal fechamento, String periodoCandle) { |
||
| 65 | this.nomeAtivo = ativoDescricao; |
||
| 66 | this.dataHora = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); |
||
| 67 | this.abertura = abertura; |
||
| 68 | this.maxima = topo; |
||
| 69 | this.minima = fundo; |
||
| 70 | this.fechamento = fechamento; |
||
| 71 | this.periodo = periodoCandle; |
||
| 72 | } |
||
| 73 | |||
| 760 | blopes | 74 | @Id |
| 75 | @SequenceGenerator(name = "sq_candle") |
||
| 76 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 77 | @Column(name="seq_candle", 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_candleativo_candle") |
||
| 87 | @JoinColumn(name="seq_ativo", referencedColumnName="seq_ativo") |
||
| 88 | public Ativo getAtivo() { |
||
| 89 | return ativo; |
||
| 90 | } |
||
| 91 | public void setAtivo(Ativo ativo) { |
||
| 92 | this.ativo = ativo; |
||
| 93 | } |
||
| 94 | |||
| 95 | @NotNull(message = "Parâmetro obrigatório não preenchido: Data e hora", groups = {Cadastrar.class, Alterar.class}) |
||
| 96 | @Column(name="dat_datahora", nullable=false) |
||
| 97 | public Date getDataHora() { |
||
| 98 | return dataHora; |
||
| 99 | } |
||
| 100 | public void setDataHora(Date dataHora) { |
||
| 101 | this.dataHora = dataHora; |
||
| 102 | } |
||
| 103 | |||
| 104 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço de abertura", groups = {Cadastrar.class, Alterar.class}) |
||
| 105 | @Column(name="val_abertura", nullable=false) |
||
| 106 | public BigDecimal getAbertura() { |
||
| 107 | return abertura; |
||
| 108 | } |
||
| 109 | public void setAbertura(BigDecimal abertura) { |
||
| 110 | this.abertura = abertura; |
||
| 111 | } |
||
| 112 | |||
| 113 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço da máxima", groups = {Cadastrar.class, Alterar.class}) |
||
| 114 | @Column(name="val_maxima", nullable=false) |
||
| 115 | public BigDecimal getMaxima() { |
||
| 116 | return maxima; |
||
| 117 | } |
||
| 118 | public void setMaxima(BigDecimal maxima) { |
||
| 119 | this.maxima = maxima; |
||
| 120 | } |
||
| 121 | |||
| 122 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço da mínima", groups = {Cadastrar.class, Alterar.class}) |
||
| 123 | @Column(name="val_minima", nullable=false) |
||
| 124 | public BigDecimal getMinima() { |
||
| 125 | return minima; |
||
| 126 | } |
||
| 127 | public void setMinima(BigDecimal minima) { |
||
| 128 | this.minima = minima; |
||
| 129 | } |
||
| 130 | |||
| 131 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço de fechamento", groups = {Cadastrar.class, Alterar.class}) |
||
| 132 | @Column(name="val_fechamento", nullable=false) |
||
| 133 | public BigDecimal getFechamento() { |
||
| 134 | return fechamento; |
||
| 135 | } |
||
| 136 | public void setFechamento(BigDecimal fechamento) { |
||
| 137 | this.fechamento = fechamento; |
||
| 138 | } |
||
| 139 | |||
| 140 | @Column(name="val_volume", nullable=true) |
||
| 141 | public BigDecimal getVolume() { |
||
| 142 | return volume; |
||
| 143 | } |
||
| 144 | public void setVolume(BigDecimal volume) { |
||
| 145 | this.volume = volume; |
||
| 146 | } |
||
| 147 | |||
| 148 | @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo do período do candle", groups = {Cadastrar.class, Alterar.class}) |
||
| 149 | @Column(name="tip_periodo", nullable=false) |
||
| 150 | public String getPeriodo() { |
||
| 151 | return periodo; |
||
| 152 | } |
||
| 153 | public void setPeriodo(String periodo) { |
||
| 154 | this.periodo = periodo; |
||
| 155 | } |
||
| 156 | @Transient |
||
| 157 | public String getTipoPeriodoCandle() { |
||
| 158 | return VerificadorUtil.naoEstaNulo(getPeriodo())? TipoPeriodoCandle.parse(getPeriodo()).getValor() : ""; |
||
| 159 | } |
||
| 160 | |||
| 161 | @Transient |
||
| 162 | public LocalDateTime getDataHoraTime() { |
||
| 163 | return dataHoraTime; |
||
| 164 | } |
||
| 165 | public void setDataHoraTime(LocalDateTime dataHoraTime) { |
||
| 166 | this.dataHoraTime = dataHoraTime; |
||
| 167 | } |
||
| 168 | |||
| 169 | @Transient |
||
| 170 | public Timeframe getPeriodoTimeFramde() { |
||
| 171 | return periodoTimeFramde; |
||
| 172 | } |
||
| 173 | public void setPeriodoTimeFramde(Timeframe periodoTimeFramde) { |
||
| 174 | this.periodoTimeFramde = periodoTimeFramde; |
||
| 175 | } |
||
| 176 | |||
| 761 | blopes | 177 | @Transient |
| 178 | public String getNomeAtivo() { |
||
| 179 | return nomeAtivo; |
||
| 180 | } |
||
| 181 | public void setNomeAtivo(String nomeAtivo) { |
||
| 182 | this.nomeAtivo = nomeAtivo; |
||
| 183 | } |
||
| 184 | |||
| 185 | @Transient |
||
| 186 | public Integer getContadorCandle() { |
||
| 187 | return contadorCandle; |
||
| 188 | } |
||
| 189 | public void setContadorCandle(Integer contadorCandle) { |
||
| 190 | this.contadorCandle = contadorCandle; |
||
| 191 | } |
||
| 192 | |||
| 760 | blopes | 193 | @Override |
| 194 | public int hashCode() { |
||
| 195 | final int prime = 31; |
||
| 196 | int result = 1; |
||
| 197 | result = prime * result |
||
| 198 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 199 | return result; |
||
| 200 | } |
||
| 201 | |||
| 202 | @Override |
||
| 203 | public boolean equals(Object obj) { |
||
| 204 | if (this == obj) |
||
| 205 | return true; |
||
| 206 | if (obj == null) |
||
| 207 | return false; |
||
| 208 | if (getClass() != obj.getClass()) |
||
| 209 | return false; |
||
| 210 | Candle other = (Candle) obj; |
||
| 211 | if (sequencial == null) { |
||
| 212 | if (other.sequencial != null) |
||
| 213 | return false; |
||
| 214 | } else if (!sequencial.equals(other.sequencial)) |
||
| 215 | return false; |
||
| 216 | return true; |
||
| 217 | } |
||
| 218 | |||
| 219 | } |