Rev 776 | Rev 782 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 776 | Rev 779 | ||
|---|---|---|---|
| Line 27... | Line 27... | ||
| 27 | 27 | ||
| 28 | import br.com.kronus.core.Timeframe; |
28 | import br.com.kronus.core.Timeframe; |
| 29 | import br.com.sl.domain.dto.robo.ProfitTick; |
29 | import br.com.sl.domain.dto.robo.ProfitTick; |
| 30 | import br.com.sl.domain.model.Candle; |
30 | import br.com.sl.domain.model.Candle; |
| 31 | import br.com.sl.domain.model.tipos.TipoPeriodoCandle; |
31 | import br.com.sl.domain.model.tipos.TipoPeriodoCandle; |
| - | 32 | import br.com.sl.domain.util.BigDecimalUtils; |
|
| 32 | import br.com.sl.shared.ExcelDataUtils; |
33 | import br.com.sl.shared.ExcelDataUtils; |
| 33 | 34 | ||
| 34 | public class ExcelProfitHistoricoDataProvider implements ProfitDataProvider { |
35 | public class ExcelProfitHistoricoDataProvider implements ProfitDataProvider { |
| 35 | 36 | ||
| 36 | private final Path excelFile; // agora pode ser arquivo OU pasta |
37 | private final Path excelFile; // agora pode ser arquivo OU pasta |
| Line 63... | Line 64... | ||
| 63 | try (Stream<Path> stream = Files.list(excelFile)) { |
64 | try (Stream<Path> stream = Files.list(excelFile)) { |
| 64 | stream |
65 | stream |
| 65 | .filter(Files::isRegularFile) |
66 | .filter(Files::isRegularFile) |
| 66 | .filter(p -> { |
67 | .filter(p -> { |
| 67 | String name = p.getFileName().toString().toLowerCase(Locale.ROOT); |
68 | String name = p.getFileName().toString().toLowerCase(Locale.ROOT); |
| 68 | return name.endsWith(".xlsx") || name.endsWith(".xls") || name.endsWith(".csv"); |
- | |
| - | 69 | return name.endsWith(".xlsm") || name.endsWith(".xlsx") || name.endsWith(".xls") || name.endsWith(".csv"); |
|
| 69 | }) |
70 | }) |
| 70 | .forEach(path -> { |
71 | .forEach(path -> { |
| 71 | try { |
72 | try { |
| 72 | lerCandlesDeArquivo(path, candles); |
73 | lerCandlesDeArquivo(path, candles); |
| 73 | } catch (IOException e) { |
74 | } catch (IOException e) { |
| Line 88... | Line 89... | ||
| 88 | * Decide se o arquivo é Excel ou CSV e delega para o método correto.
|
89 | * Decide se o arquivo é Excel ou CSV e delega para o método correto.
|
| 89 | */
|
90 | */
|
| 90 | private void lerCandlesDeArquivo(Path arquivo, List<Candle> candles) throws IOException { |
91 | private void lerCandlesDeArquivo(Path arquivo, List<Candle> candles) throws IOException { |
| 91 | String name = arquivo.getFileName().toString().toLowerCase(Locale.ROOT); |
92 | String name = arquivo.getFileName().toString().toLowerCase(Locale.ROOT); |
| 92 | 93 | ||
| 93 | if (name.endsWith(".xlsx") || name.endsWith(".xls")) { |
- | |
| - | 94 | if (name.endsWith(".xlsm") || name.endsWith(".xlsx") || name.endsWith(".xls")) { |
|
| 94 | lerCandlesDeArquivoExcel(arquivo, candles); |
95 | lerCandlesDeArquivoExcel(arquivo, candles); |
| 95 | } else if (name.endsWith(".csv")) { |
96 | } else if (name.endsWith(".csv")) { |
| 96 | lerCandlesDeArquivoCsv(arquivo, candles); |
97 | lerCandlesDeArquivoCsv(arquivo, candles); |
| 97 | } else { |
98 | } else { |
| 98 | // Tipo não suportado, ignora ou loga
|
99 | // Tipo não suportado, ignora ou loga
|
| Line 232... | Line 233... | ||
| 232 | 233 | ||
| 233 | LocalDate data = LocalDate.parse(dataStr, DATE_FORMAT); |
234 | LocalDate data = LocalDate.parse(dataStr, DATE_FORMAT); |
| 234 | LocalTime hora = LocalTime.parse(horaStr, TIME_FORMAT); |
235 | LocalTime hora = LocalTime.parse(horaStr, TIME_FORMAT); |
| 235 | LocalDateTime dataHora = LocalDateTime.of(data, hora); |
236 | LocalDateTime dataHora = LocalDateTime.of(data, hora); |
| 236 | 237 | ||
| 237 | BigDecimal abertura = parseBigDecimal(aberturaStr); |
- | |
| 238 | BigDecimal topo = parseBigDecimal(maximaStr); |
- | |
| 239 | BigDecimal fundo = parseBigDecimal(minimaStr); |
- | |
| 240 | BigDecimal fechamento = parseBigDecimal(fechamentoStr); |
- | |
| - | 238 | BigDecimal abertura = BigDecimalUtils.converterStringEmBigDecimal(aberturaStr); |
|
| - | 239 | BigDecimal topo = BigDecimalUtils.converterStringEmBigDecimal(maximaStr); |
|
| - | 240 | BigDecimal fundo = BigDecimalUtils.converterStringEmBigDecimal(minimaStr); |
|
| - | 241 | BigDecimal fechamento = BigDecimalUtils.converterStringEmBigDecimal(fechamentoStr); |
|
| 241 | 242 | ||
| 242 | Candle candle = new Candle( |
243 | Candle candle = new Candle( |
| 243 | null,
|
244 | null,
|
| 244 | ativoDescricao, |
245 | ativoDescricao, |
| 245 | dataHora, |
246 | dataHora, |
| Line 250... | Line 251... | ||
| 250 | TipoPeriodoCandle.M1.getValor() |
251 | TipoPeriodoCandle.M1.getValor() |
| 251 | ); |
252 | ); |
| 252 | candles.add(candle); |
253 | candles.add(candle); |
| 253 | }
|
254 | }
|
| 254 | }
|
255 | }
|
| 255 | }
|
- | |
| 256 | - | ||
| 257 | - | ||
| 258 | private BigDecimal parseBigDecimal(String value) { |
- | |
| 259 | if (value == null) return null; |
- | |
| 260 | String normalized = value.trim().replace(".", "").replace(",", "."); |
- | |
| 261 | // Se o Profit já exportar com ponto como separador decimal, remova o replace(".","")
|
- | |
| 262 | // e deixe apenas: value.trim().replace(",", ".")
|
- | |
| 263 | if (normalized.isEmpty()) return null; |
- | |
| 264 | return new BigDecimal(normalized); |
- | |
| 265 | }
|
256 | }
|
| 266 | 257 | ||
| 267 | private boolean isNumericString(String value) { |
258 | private boolean isNumericString(String value) { |
| 268 | if (value == null) return false; |
259 | if (value == null) return false; |
| 269 | String normalized = value.trim().replace(".", "").replace(",", "."); |
260 | String normalized = value.trim().replace(".", "").replace(",", "."); |