Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 779 | blopes | 1 | package br.com.sl.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.math.BigDecimal; |
||
| 5 | import java.util.Date; |
||
| 6 | import java.util.Objects; |
||
| 7 | |||
| 8 | import javax.persistence.Column; |
||
| 9 | import javax.persistence.Entity; |
||
| 10 | import javax.persistence.GeneratedValue; |
||
| 11 | import javax.persistence.GenerationType; |
||
| 12 | import javax.persistence.Id; |
||
| 13 | import javax.persistence.JoinColumn; |
||
| 14 | import javax.persistence.ManyToOne; |
||
| 15 | import javax.persistence.Table; |
||
| 16 | import javax.persistence.Transient; |
||
| 17 | import javax.validation.constraints.NotNull; |
||
| 18 | |||
| 19 | import org.hibernate.annotations.ForeignKey; |
||
| 20 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 21 | |||
| 22 | import br.com.ec.core.interfaces.Alterar; |
||
| 23 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 24 | import br.com.ec.core.util.DataUtils; |
||
| 25 | import br.com.ec.core.util.VerificadorUtil; |
||
| 26 | import br.com.sl.domain.model.tipos.TipoSinal; |
||
| 27 | import br.com.sl.domain.model.tipos.TipoSituacaoSinal; |
||
| 28 | |||
| 29 | @Entity |
||
| 30 | @Table(name="slp_sinal", schema="sc_slp") |
||
| 31 | public class Sinal implements Serializable { |
||
| 32 | |||
| 33 | private static final long serialVersionUID = 1L; |
||
| 34 | |||
| 35 | private String codigo; // SEQ_ATIVO#DATA#CONTADOR_CANDLE_REF#TIPO_PERIODO EXEMPLO: 1#27112025#32#M1 |
||
| 36 | private Date dataHoraSinal; |
||
| 37 | private String tipoSinal; // C - COMPRAR / V - VENDER |
||
| 38 | private String tipoSituacaoSinal; // A - ABERTO / F - FECHADO / |
||
| 39 | private Candle candleReferencia; |
||
| 40 | private Candle candleGatilho1; |
||
| 41 | private Candle candleGatilho2; |
||
| 42 | private Candle candleGatilho3; |
||
| 43 | private Candle candleGatilho4; |
||
| 44 | private BigDecimal valorEntrada1; |
||
| 45 | private BigDecimal valorEntrada2; |
||
| 46 | private BigDecimal alvo1; |
||
| 47 | private BigDecimal alvo2; |
||
| 48 | private BigDecimal stop1; |
||
| 49 | private BigDecimal stop2; |
||
| 50 | |||
| 51 | public Sinal() {} |
||
| 52 | |||
| 53 | @Id |
||
| 54 | @GeneratedValue(strategy=GenerationType.IDENTITY) |
||
| 55 | @Column(name="cod_sinal", nullable=false) |
||
| 56 | public String getCodigo() { |
||
| 57 | return codigo; |
||
| 58 | } |
||
| 59 | public void setCodigo(String codigo) { |
||
| 60 | this.codigo = codigo; |
||
| 61 | } |
||
| 62 | |||
| 63 | @Transient |
||
| 64 | public String montarCodigo() { |
||
| 65 | String codigo = null; |
||
| 66 | if (VerificadorUtil.naoEstaNulo(getCandleReferencia())) { |
||
| 67 | if (VerificadorUtil.naoEstaNulo(getCandleReferencia().getAtivo())) { |
||
| 68 | codigo = codigo + getCandleReferencia().getAtivo().getSequencial() + "#"; |
||
| 69 | codigo = codigo + DataUtils.converterDataParaStringNoFormato(getDataHoraSinal(), "ddMMyyyy") + "#"; |
||
| 70 | codigo = codigo + getCandleReferencia().getContadorCandle() + "#"; |
||
| 71 | codigo = codigo + getCandleReferencia().getTipoPeriodoCandle(); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | return codigo; |
||
| 75 | } |
||
| 76 | |||
| 77 | @Column(name="dth_sinal") |
||
| 78 | @NotNull(message="Obrigatório informar a data e hora do sinal", groups={Cadastrar.class, Alterar.class}) |
||
| 79 | public Date getDataHoraSinal() { |
||
| 80 | return dataHoraSinal; |
||
| 81 | } |
||
| 82 | public void setDataHoraSinal(Date dataHoraSinal) { |
||
| 83 | this.dataHoraSinal = dataHoraSinal; |
||
| 84 | } |
||
| 85 | |||
| 86 | @Column(name="tip_sinal") |
||
| 87 | @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo do sinal", groups = {Cadastrar.class, Alterar.class}) |
||
| 88 | public String getTipoSinal() { |
||
| 89 | return tipoSinal; |
||
| 90 | } |
||
| 91 | public void setTipoSinal(String tipoSinal) { |
||
| 92 | this.tipoSinal = tipoSinal; |
||
| 93 | } |
||
| 94 | |||
| 95 | @Transient |
||
| 96 | public String getDescricaoDoSinal() { |
||
| 97 | return VerificadorUtil.naoEstaNulo(getTipoSinal())? TipoSinal.parse(getTipoSinal()).getDescricao() : ""; |
||
| 98 | } |
||
| 99 | |||
| 100 | @Column(name="tip_situacao_sinal") |
||
| 101 | @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo da situação do sinal", groups = {Cadastrar.class, Alterar.class}) |
||
| 102 | public String getTipoSituacaoSinal() { |
||
| 103 | return tipoSituacaoSinal; |
||
| 104 | } |
||
| 105 | public void setTipoSituacaoSinal(String tipoSituacaoSinal) { |
||
| 106 | this.tipoSituacaoSinal = tipoSituacaoSinal; |
||
| 107 | } |
||
| 108 | |||
| 109 | @Transient |
||
| 110 | public String getDescricaoDaSituacaoSinal() { |
||
| 111 | return VerificadorUtil.naoEstaNulo(getTipoSituacaoSinal())? TipoSituacaoSinal.parse(getTipoSituacaoSinal()).getDescricao() : ""; |
||
| 112 | } |
||
| 113 | |||
| 114 | @ManyToOne |
||
| 115 | @ForeignKey(name = "fk_sinal_candleref") |
||
| 116 | @JoinColumn(name="seq_candleref", referencedColumnName="seq_candle") |
||
| 117 | public Candle getCandleReferencia() { |
||
| 118 | return candleReferencia; |
||
| 119 | } |
||
| 120 | public void setCandleReferencia(Candle candleReferencia) { |
||
| 121 | this.candleReferencia = candleReferencia; |
||
| 122 | } |
||
| 123 | |||
| 124 | @ManyToOne |
||
| 125 | @ForeignKey(name = "fk_sinal_candleg1") |
||
| 126 | @JoinColumn(name="seq_candleg1", referencedColumnName="seq_candle") |
||
| 127 | public Candle getCandleGatilho1() { |
||
| 128 | return candleGatilho1; |
||
| 129 | } |
||
| 130 | public void setCandleGatilho1(Candle candleGatilho1) { |
||
| 131 | this.candleGatilho1 = candleGatilho1; |
||
| 132 | } |
||
| 133 | |||
| 134 | @ManyToOne |
||
| 135 | @ForeignKey(name = "fk_sinal_candleg2") |
||
| 136 | @JoinColumn(name="seq_candleg2", referencedColumnName="seq_candle") |
||
| 137 | public Candle getCandleGatilho2() { |
||
| 138 | return candleGatilho2; |
||
| 139 | } |
||
| 140 | public void setCandleGatilho2(Candle candleGatilho2) { |
||
| 141 | this.candleGatilho2 = candleGatilho2; |
||
| 142 | } |
||
| 143 | |||
| 144 | @ManyToOne |
||
| 145 | @ForeignKey(name = "fk_sinal_candleg3") |
||
| 146 | @JoinColumn(name="seq_candleg3", referencedColumnName="seq_candle") |
||
| 147 | public Candle getCandleGatilho3() { |
||
| 148 | return candleGatilho3; |
||
| 149 | } |
||
| 150 | public void setCandleGatilho3(Candle candleGatilho3) { |
||
| 151 | this.candleGatilho3 = candleGatilho3; |
||
| 152 | } |
||
| 153 | |||
| 154 | @ManyToOne |
||
| 155 | @ForeignKey(name = "fk_sinal_candleg4") |
||
| 156 | @JoinColumn(name="seq_candleg4", referencedColumnName="seq_candle") |
||
| 157 | public Candle getCandleGatilho4() { |
||
| 158 | return candleGatilho4; |
||
| 159 | } |
||
| 160 | public void setCandleGatilho4(Candle candleGatilho4) { |
||
| 161 | this.candleGatilho4 = candleGatilho4; |
||
| 162 | } |
||
| 163 | |||
| 164 | @Column(name="val_entrada1") |
||
| 165 | public BigDecimal getValorEntrada1() { |
||
| 166 | return valorEntrada1; |
||
| 167 | } |
||
| 168 | public void setValorEntrada1(BigDecimal valorEntrada1) { |
||
| 169 | this.valorEntrada1 = valorEntrada1; |
||
| 170 | } |
||
| 171 | |||
| 172 | @Column(name="val_entrada2") |
||
| 173 | public BigDecimal getValorEntrada2() { |
||
| 174 | return valorEntrada2; |
||
| 175 | } |
||
| 176 | public void setValorEntrada2(BigDecimal valorEntrada2) { |
||
| 177 | this.valorEntrada2 = valorEntrada2; |
||
| 178 | } |
||
| 179 | |||
| 180 | @Column(name="val_alvo1") |
||
| 181 | public BigDecimal getAlvo1() { |
||
| 182 | return alvo1; |
||
| 183 | } |
||
| 184 | public void setAlvo1(BigDecimal alvo1) { |
||
| 185 | this.alvo1 = alvo1; |
||
| 186 | } |
||
| 187 | |||
| 188 | @Column(name="val_alvo2") |
||
| 189 | public BigDecimal getAlvo2() { |
||
| 190 | return alvo2; |
||
| 191 | } |
||
| 192 | public void setAlvo2(BigDecimal alvo2) { |
||
| 193 | this.alvo2 = alvo2; |
||
| 194 | } |
||
| 195 | |||
| 196 | @Column(name="val_stop1") |
||
| 197 | public BigDecimal getStop1() { |
||
| 198 | return stop1; |
||
| 199 | } |
||
| 200 | public void setStop1(BigDecimal stop1) { |
||
| 201 | this.stop1 = stop1; |
||
| 202 | } |
||
| 203 | |||
| 204 | @Column(name="val_stop2") |
||
| 205 | public BigDecimal getStop2() { |
||
| 206 | return stop2; |
||
| 207 | } |
||
| 208 | public void setStop2(BigDecimal stop2) { |
||
| 209 | this.stop2 = stop2; |
||
| 210 | } |
||
| 211 | |||
| 212 | @Override |
||
| 213 | public int hashCode() { |
||
| 214 | return Objects.hash(codigo); |
||
| 215 | } |
||
| 216 | |||
| 217 | @Override |
||
| 218 | public boolean equals(Object obj) { |
||
| 219 | if (this == obj) |
||
| 220 | return true; |
||
| 221 | if (obj == null) |
||
| 222 | return false; |
||
| 223 | if (getClass() != obj.getClass()) |
||
| 224 | return false; |
||
| 225 | Sinal other = (Sinal) obj; |
||
| 226 | return Objects.equals(codigo, other.codigo); |
||
| 227 | } |
||
| 228 | |||
| 229 | } |