spring-batch - 如何在 Spring Batch 中实现这个简单的逻辑?

标签 spring-batch spring-batch-admin

我试图让这尽可能简单。我是 Spring Batch 的新手,我有一个小问题,了解如何将 Spring 项目关联在一起,特别是在涉及多步骤作业时,但是这是我的逻辑而不是代码(简化),我不知道知道在 Spring Batch 中实现它,所以我认为这可能是正确的结构

  • reader_money
  • 读者详细信息
  • 小任务
  • 读者利润
  • tasklet_calculation
  • 作家

但是,如果我错了,请纠正我,并在可能的情况下提供一些代码。 非常感谢

逻辑:

sql = "select * from MONEY where id= user input"; //the user will input the condition

while (records are available) { 

    int currency= resultset(currency column);
    sql= "select * from DETAILS where D_currency = currency";


    while (records are available) {

        int amount= resultset(amount column);
        string money_flag= resultset(money_type column);
        sql= "select * from PROFIT where Mtypes = money_type";

        while (records are available) {

            int revenue= resultset(revenue);

            if (money_type== 1) {
                int net_profit= revenue * 3.75;
                sql = "update PROFIT set Nprofit = net_profit";
            }

            else (money_type== 2) {
                int net_profit = (revenue - 5 ) * 3.7 ;
                sql = "update PROFIT set Nprofit = net_profit";
            }
        }
    sql="update DETAILS set detail_falg = 001 ";
    }
sql = "update MONEY set currency_flag = 009";

}

最佳答案

为了将其适应“传统” Spring 批处理配置,如果可能的话,您需要将三个循环压平为一个循环。

也许是一条 sql 语句,它会在一个循环中返回它,类似于;

select p.revenue, d.amount from PROFIT p, DETAILS d, MONEY m where p.MTypes = d.money_type and d.D_currency = m.currency and m.id = :?

一旦你“扁平化”它,你就会陷入更“传统”的 block 模式读取/处理/写入,其中读取器从结果集中检索记录,处理器执行 Money_type 逻辑,写入器执行然后执行“更新”语句。

关于spring-batch - 如何在 Spring Batch 中实现这个简单的逻辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16190410/

相关文章:

java - block 中的 Spring 批处理异常

java - 如何在服务器停机后恢复 Spring Batch 作业

spring - 如何将 Spring Batch Admin 与 Spring 3.2 和 @Schedule 注释一起使用?

java - RepositoryItemReader : java. util.ArrayList 无法转换为 org.springframework.data.domain.Page

spring-batch - Spring Batch 应用程序与 Spring Batch Admin 集成

Spring Batch 管理员 (2.0.0.M1) : error creating bean batchMBeanExporter

java - 在面向读写 block 的过程中,Spring Batch 在哪里提交?

spring-batch - 为什么我不应该在 tasklet 中使用 block ?

Spring 批 : Assemble a job rather than configuring it (Extensible job configuration)

java - 带有 sortKeys 和参数值的 Spring Batch Paging