首页 > 解决方案 > 如何使用弹簧批处理在不同的文件中写入 csv,具体取决于时间

问题描述

我有一个非常大的 csv 文件,这使我的作业运行到 30 分钟。我的数据来自纯云。我需要根据时间字段 (2021-03-10T11:44:01.781Z) 的值在三个不同的时间段内编写它:00-10、10-14、14-23 小时。

这是文件中的一行:

b1df888d-bebe-4a0b-a44a-0b891c660586;tAlert;205;2021-03-10T11:44:01.781Z

我使用这样的 tasklet 块运行:

 <step id="step1">
        <tasklet>
            <chunk reader="itemReader" writer="testCompositeWriter"
                   commit-interval="1">
            </chunk>
        </tasklet>
    </step>

在阅读器中,我正在做这样的事情:

fecha = obtenerFechaFin(i).split("T");           //2021-03-07T07:19:18.051Z string DATE
    horas = fecha[1];                            //07:19:18.051Z   string HOURS
    horaIntervalo = horas.split(":");
    hora = horaIntervalo[0];                     //07 string
    horaInt = Integer.parseInt(hora);           //07 int  HOUR

    if (horaInt >= 00 && horaInt < 10){
        
        lisConversationOutBackup.addAll(generarSalida(conversationsOut.getConversations()));

    }
    if (horaInt >= 10 && horaInt < 14){

    }
    if (horaInt >= 14 && horaInt < 23){

    }

“commit-interval”或任何其他句子可以做到这一点吗?

标签: springcsvspring-batchfilewriter

解决方案


推荐阅读