Subversion Repositories Integrator Subversion

Rev

Rev 761 | Go to most recent revision | Details | 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
 
46
    private LocalDateTime dataHoraTime;
47
    private Timeframe periodoTimeFramde;
48
 
49
    public Candle() {}
50
 
51
    public Candle(Ativo ativo, LocalDateTime fimCandle, CandleState situacaoCandle, String periodoCandle) {
52
        this.ativo = ativo;
53
        this.dataHora = Date.from(situacaoCandle.getLastTickTime().atZone(ZoneId.systemDefault()).toInstant());
54
        this.abertura = situacaoCandle.getAbertura();
55
        this.maxima = situacaoCandle.getMaxima();
56
        this.minima = situacaoCandle.getMinima();
57
        this.fechamento = situacaoCandle.getFechamento();
58
        this.periodo = periodoCandle;
59
    }
60
 
61
        @Id
62
        @SequenceGenerator(name = "sq_candle")
63
        @GeneratedValue(strategy = GenerationType.IDENTITY)
64
        @Column(name="seq_candle", 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_candleativo_candle")
74
        @JoinColumn(name="seq_ativo", referencedColumnName="seq_ativo")
75
        public Ativo getAtivo() {
76
                return ativo;
77
        }
78
        public void setAtivo(Ativo ativo) {
79
                this.ativo = ativo;
80
        }
81
 
82
        @NotNull(message = "Parâmetro obrigatório não preenchido: Data e hora", groups = {Cadastrar.class, Alterar.class})
83
        @Column(name="dat_datahora", nullable=false)
84
        public Date getDataHora() {
85
                return dataHora;
86
        }
87
        public void setDataHora(Date dataHora) {
88
                this.dataHora = dataHora;
89
        }
90
 
91
        @NotNull(message = "Parâmetro obrigatório não preenchido: Preço de abertura", groups = {Cadastrar.class, Alterar.class})
92
        @Column(name="val_abertura", nullable=false)
93
        public BigDecimal getAbertura() {
94
                return abertura;
95
        }
96
        public void setAbertura(BigDecimal abertura) {
97
                this.abertura = abertura;
98
        }
99
 
100
        @NotNull(message = "Parâmetro obrigatório não preenchido: Preço da máxima", groups = {Cadastrar.class, Alterar.class})
101
        @Column(name="val_maxima", nullable=false)
102
        public BigDecimal getMaxima() {
103
                return maxima;
104
        }
105
        public void setMaxima(BigDecimal maxima) {
106
                this.maxima = maxima;
107
        }
108
 
109
        @NotNull(message = "Parâmetro obrigatório não preenchido: Preço da mínima", groups = {Cadastrar.class, Alterar.class})
110
        @Column(name="val_minima", nullable=false)
111
        public BigDecimal getMinima() {
112
                return minima;
113
        }
114
        public void setMinima(BigDecimal minima) {
115
                this.minima = minima;
116
        }
117
 
118
        @NotNull(message = "Parâmetro obrigatório não preenchido: Preço de fechamento", groups = {Cadastrar.class, Alterar.class})
119
        @Column(name="val_fechamento", nullable=false)
120
        public BigDecimal getFechamento() {
121
                return fechamento;
122
        }
123
        public void setFechamento(BigDecimal fechamento) {
124
                this.fechamento = fechamento;
125
        }
126
 
127
        @Column(name="val_volume", nullable=true)
128
        public BigDecimal getVolume() {
129
                return volume;
130
        }
131
        public void setVolume(BigDecimal volume) {
132
                this.volume = volume;
133
        }
134
 
135
        @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo do período do candle", groups = {Cadastrar.class, Alterar.class})
136
        @Column(name="tip_periodo", nullable=false)
137
        public String getPeriodo() {
138
                return periodo;
139
        }
140
        public void setPeriodo(String periodo) {
141
                this.periodo = periodo;
142
        }
143
        @Transient
144
        public String getTipoPeriodoCandle() {
145
                return VerificadorUtil.naoEstaNulo(getPeriodo())? TipoPeriodoCandle.parse(getPeriodo()).getValor() : "";
146
        }
147
 
148
        @Transient
149
        public LocalDateTime getDataHoraTime() {
150
                return dataHoraTime;
151
        }
152
        public void setDataHoraTime(LocalDateTime dataHoraTime) {
153
                this.dataHoraTime = dataHoraTime;
154
        }
155
 
156
        @Transient
157
        public Timeframe getPeriodoTimeFramde() {
158
                return periodoTimeFramde;
159
        }
160
        public void setPeriodoTimeFramde(Timeframe periodoTimeFramde) {
161
                this.periodoTimeFramde = periodoTimeFramde;
162
        }
163
 
164
        @Override
165
        public int hashCode() {
166
                final int prime = 31;
167
                int result = 1;
168
                result = prime * result
169
                                + ((sequencial == null) ? 0 : sequencial.hashCode());
170
                return result;
171
        }
172
 
173
        @Override
174
        public boolean equals(Object obj) {
175
                if (this == obj)
176
                        return true;
177
                if (obj == null)
178
                        return false;
179
                if (getClass() != obj.getClass())
180
                        return false;
181
                Candle other = (Candle) obj;
182
                if (sequencial == null) {
183
                        if (other.sequencial != null)
184
                                return false;
185
                } else if (!sequencial.equals(other.sequencial))
186
                        return false;
187
                return true;
188
        }
189
 
190
}