org.shoulder.batch.repository.JdbcBatchRecordDetailPersistentService Maven / Gradle / Ivy
package org.shoulder.batch.repository;
import org.apache.commons.collections4.CollectionUtils;
import org.shoulder.batch.enums.ProcessStatusEnum;
import org.shoulder.batch.model.BatchRecordDetail;
import org.shoulder.batch.repository.po.BatchRecordDetailPO;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import javax.annotation.Nonnull;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
/**
* 批处理记录持久化接口
*
* @author lym
*/
public class JdbcBatchRecordDetailPersistentService implements BatchRecordDetailPersistentService {
private static String ALL_COLUMNS = "id, record_id, index, operation, status, fail_reason, source";
private static String BATCH_INSERT = "INSERT INTO batch_record_detail (" + ALL_COLUMNS + ") " +
"VALUES (?,?,?,?,?,?,?)";
private static String QUERY_ALL_WITH_CONDITION = "SELECT " + ALL_COLUMNS +
" FROM batch_record_detail WHERE record_id=?, AND status in (?)";
private static String QUERY_ALL = "SELECT " + ALL_COLUMNS +
" FROM batch_record_detail WHERE record_id=?";
private final JdbcTemplate jdbc;
private RowMapper mapper = new BatchRecordDetailRowMapper();
public JdbcBatchRecordDetailPersistentService(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}
public JdbcBatchRecordDetailPersistentService(DataSource dataSource) {
this.jdbc = new JdbcTemplate(dataSource);
}
/**
* 批量新增处理详情
*
* @param batchRecordDetailList 要插入的记录
*/
@Override
public void batchSave(String recordId, List batchRecordDetailList) {
jdbc.batchUpdate(BATCH_INSERT, flatFieldsToArray(batchRecordDetailList));
}
private List