FILE(FIXED) TO FILE(DELIMITED)
-
배치 작업 Xml Sample
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch-int="http://www.springframework.org/schema/batch-integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/batch-integration http://www.springframework.org/schema/batch-integration/spring-batch-integration.xsd">
<!--
* 배치작업 : FIXED FILE TO DELIMITED FILE 샘플
* 배치스텝
- sample-fixed-to-delimited-001 : FIXED FILE TO DELIMITED FILE 처리
-->
<job id="sample-fixed-to-delimited" xmlns="http://www.springframework.org/schema/batch">
<step id="sample-fixed-to-delimited-001">
<tasklet>
<chunk reader="r-sample-fixed-to-delimited-001" processor="SmpFixedToDelimitedChunk" writer="w-sample-fixed-to-delimited-001" />
</tasklet>
</step>
</job>
<!--
* 샘플용직원정보 Fixed File을 Read 하기위한 bean 설정
-->
<bean id="r-sample-fixed-to-delimited-001" parent="RFix" scope="step">
<property name="name" value="r-sample-fixed-to-delimited-001" />
<property name="resource" value="file:///${prefixFilePath}/test-fixed-file-#{jobParameters['deptNo']}.txt" />
<property name="targetType" value="sample.batch.service.dto.SmpFixedToDelimitedChunkDto" />
</bean>
<!--
* 샘플용직원정보 Delimited File을 Write 하기위한 bean 설정
-->
<bean id="w-sample-fixed-to-delimited-001" parent="WDelimit" scope="step">
<property name="name" value="w-sample-fixed-to-delimited-001" />
<property name="resource" value="file:///${prefixFilePath}/test-delimited-file-#{jobParameters['deptNo']}.txt" />
<property name="targetType" value="sample.batch.service.dto.SmpFixedToDelimitedChunkDto" />
<property name="delimiter" value=";" />
</bean>
</beans>
-
배치 소스코드 Sample
package sample.batch.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import bxm.common.annotaion.BxmCategory;
import sample.batch.service.dto.SmpFixedToDelimitedChunkDto;
/**
* 샘플 FILE(Fixed) To File(Delimite) 배치
*
* @author sysadmin
*/
@Scope("step")
@Service("SmpFixedToDelimitedChunk")
@BxmCategory(logicalName="샘플 FILE(Fixed) To File(Delimite) 배치", description="샘플 FILE(Fixed) To File(Delimite) 배치")
public class SmpFixedToDelimitedChunk implements ItemProcessor<SmpFixedToDelimitedChunkDto, SmpFixedToDelimitedChunkDto>{
private Logger logger= LoggerFactory.getLogger(getClass());
/**
* process
* - 처리 대상 데이터를 건 별로 업무요건에 따라 처리하는 역할을 수행한다.
*/
@Override
@BxmCategory(logicalName = "process : 샘플용 직원정보 처리", description = "process : 샘플용 직원정보를 1건씩 처리한다.")
public SmpFixedToDelimitedChunkDto process(SmpFixedToDelimitedChunkDto in) throws Exception {
SmpFixedToDelimitedChunkDto out;
/**
* 관리자임직원번호가 없는 경우에는 null 를 return 하여 해당 Item에 대하여 Skip 처리한다.
* - 참고 : process에서 null을 return 하면 write로 item이 넘어가지 않는다.
*/
if(in.getFeduMngrEmpNo() == 0)
{
logger.warn("임직원번호[{}]에 대한 관리자 번호가 0 입니다. Skip 처리합니다.", in.getFeduEmpNo());
return null;
}
/**
* 개별 업무로직 수행
* ...
* ...
*/
out = in;
return out;
}
}