영업사원 동기화 배치 작업
This commit is contained in:
parent
299bc998e3
commit
5da5124047
@ -178,4 +178,34 @@ public class JobLauncherController {
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/**
|
||||
* 영업사원 동기화 배치
|
||||
*
|
||||
* @return
|
||||
* @throws JobInstanceAlreadyCompleteException
|
||||
* @throws JobExecutionAlreadyRunningException
|
||||
* @throws JobParametersInvalidException
|
||||
* @throws JobRestartException
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * *")
|
||||
public String businessChargerJob()
|
||||
throws JobInstanceAlreadyCompleteException,
|
||||
JobExecutionAlreadyRunningException,
|
||||
JobParametersInvalidException,
|
||||
JobRestartException {
|
||||
|
||||
String jobName = "businessChargerJob";
|
||||
Job job = jobs.get(jobName);
|
||||
if (job == null) {
|
||||
return "Job " + jobName + " not found";
|
||||
}
|
||||
|
||||
JobParameters jobParameters =
|
||||
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
||||
|
||||
jobLauncher.run(job, jobParameters);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
/** chunk 방식의 Job을 생성하는 Configuration */
|
||||
/** Bom Item 마스터 동기화 배치 */
|
||||
@Configuration
|
||||
public class BomConfiguration implements JobExecutionListener {
|
||||
private final DisplayItemService displayItemService;
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
package com.interplug.qcast.batch.master;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.interplug.qcast.biz.user.UserService;
|
||||
import com.interplug.qcast.biz.user.dto.BusinessChargerSyncResponse;
|
||||
import com.interplug.qcast.util.InterfaceQsp;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecutionListener;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.configuration.annotation.StepScope;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
/** 영업사원 동기화 배치 */
|
||||
@Configuration
|
||||
public class BusinessChargerConfiguration implements JobExecutionListener {
|
||||
private final UserService userService;
|
||||
|
||||
private final InterfaceQsp interfaceQsp;
|
||||
|
||||
List<BusinessChargerSyncResponse> businessChargerSyncList;
|
||||
|
||||
@Value("${qsp.master-business-charger-batch-url}")
|
||||
private String qspInterfaceUrl;
|
||||
|
||||
public BusinessChargerConfiguration(UserService userService, InterfaceQsp interfaceQsp) {
|
||||
this.userService = userService;
|
||||
this.interfaceQsp = interfaceQsp;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job businessChargerJob(JobRepository jobRepository, Step businessChargerStep) {
|
||||
return new JobBuilder("businessChargerJob", jobRepository).start(businessChargerStep).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step businessChargerStep(
|
||||
JobRepository jobRepository, PlatformTransactionManager transactionManager) throws Exception {
|
||||
return new StepBuilder("businessChargerStep", jobRepository)
|
||||
.<BusinessChargerSyncResponse, BusinessChargerSyncResponse>chunk(100, transactionManager)
|
||||
.reader(businessChargerReader())
|
||||
.processor(businessChargerProcessor())
|
||||
.writer(businessChargerWriter())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@StepScope
|
||||
public ItemReader<BusinessChargerSyncResponse> businessChargerReader() throws Exception {
|
||||
this.businessChargerSyncList =
|
||||
interfaceQsp.callApiData(
|
||||
HttpMethod.GET,
|
||||
qspInterfaceUrl,
|
||||
null,
|
||||
new TypeReference<List<BusinessChargerSyncResponse>>() {});
|
||||
return (businessChargerSyncList != null)
|
||||
? new ListItemReader<>(businessChargerSyncList)
|
||||
: new ListItemReader<>(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemProcessor<BusinessChargerSyncResponse, BusinessChargerSyncResponse>
|
||||
businessChargerProcessor() {
|
||||
return item -> item;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemWriter<BusinessChargerSyncResponse> businessChargerWriter() {
|
||||
return items -> {
|
||||
userService.setBusinessChargerSyncSave((List<BusinessChargerSyncResponse>) items.getItems());
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
/** chunk 방식의 Job을 생성하는 Configuration */
|
||||
/** Item 마스터 동기화 배치 */
|
||||
@Configuration
|
||||
public class MaterialConfiguration implements JobExecutionListener {
|
||||
private final DisplayItemService displayItemService;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.interplug.qcast.biz.user;
|
||||
|
||||
import com.interplug.qcast.biz.user.dto.BusinessChargerSyncResponse;
|
||||
import com.interplug.qcast.biz.user.dto.StoreRequest;
|
||||
import com.interplug.qcast.biz.user.dto.UserRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -42,4 +43,23 @@ public interface UserMapper {
|
||||
* @throws Exception
|
||||
*/
|
||||
int setUserSave(UserRequest userReqList) throws Exception;
|
||||
|
||||
/**
|
||||
* 영업사원 삭제
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
int deleteBusinessChargerSync() throws Exception;
|
||||
|
||||
/**
|
||||
* 영업사원 정보 동기화 저장
|
||||
*
|
||||
* @param businessChargerSyncData
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
int setBusinessChargerSyncSave(BusinessChargerSyncResponse businessChargerSyncData)
|
||||
throws Exception;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.interplug.qcast.biz.user;
|
||||
|
||||
import com.interplug.qcast.biz.user.dto.BusinessChargerSyncResponse;
|
||||
import com.interplug.qcast.biz.user.dto.StoreRequest;
|
||||
import com.interplug.qcast.biz.user.dto.UserRequest;
|
||||
import java.util.List;
|
||||
@ -82,4 +83,21 @@ public class UserService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 영업사원 정보 동기화
|
||||
*
|
||||
* @param businessChargerSyncList 영업사원 목록
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int setBusinessChargerSyncSave(List<BusinessChargerSyncResponse> businessChargerSyncList)
|
||||
throws Exception {
|
||||
int cnt = 0;
|
||||
userMapper.deleteBusinessChargerSync();
|
||||
for (BusinessChargerSyncResponse businessChargerSyncData : businessChargerSyncList) {
|
||||
cnt += userMapper.setBusinessChargerSyncSave(businessChargerSyncData);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package com.interplug.qcast.biz.user.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/** 아이템 동기화 Request */
|
||||
@Data
|
||||
public class BusinessChargerSyncResponse {
|
||||
|
||||
@Schema(description = "Business Charger Code")
|
||||
String businessChargerCd;
|
||||
|
||||
@Schema(description = "Business Charger Name")
|
||||
String businessCharger;
|
||||
|
||||
@Schema(description = "Business Charger Team Code")
|
||||
String businessTeamCd;
|
||||
|
||||
@Schema(description = "Business Charger Telephone")
|
||||
String businessChargerTel;
|
||||
|
||||
@Schema(description = "Business Charger Email")
|
||||
String businessChargerMail;
|
||||
|
||||
@Schema(description = "Delete Flg")
|
||||
String delFlg;
|
||||
}
|
||||
@ -249,4 +249,41 @@
|
||||
);
|
||||
</insert>
|
||||
|
||||
<delete id="deleteBusinessChargerSync" parameterType="com.interplug.qcast.biz.user.dto.BusinessChargerSyncResponse" >
|
||||
UPDATE M_BUSINESS_CHARGER SET DEL_FLG = '1'
|
||||
</delete>
|
||||
|
||||
<insert id="setBusinessChargerSyncSave" parameterType="com.interplug.qcast.biz.user.dto.BusinessChargerSyncResponse" >
|
||||
/* sqlid : com.interplug.qcast.user.setBusinessChargerSyncSave */
|
||||
MERGE INTO M_BUSINESS_CHARGER AS A
|
||||
USING ( SELECT #{businessChargerCd} AS BUSINESS_CHARGER_CD ) AS D
|
||||
ON A.BUSINESS_CHARGER_CD = D.BUSINESS_CHARGER_CD
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET
|
||||
BUSINESS_CHARGER = #{businessCharger}
|
||||
, BUSINESS_TEAM_CD = #{businessTeamCd}
|
||||
, BUSINESS_CHARGER_TEL = #{businessChargerTel}
|
||||
, BUSINESS_CHARGER_MAIL = #{businessChargerMail}
|
||||
, DEL_FLG = #{delFlg}
|
||||
, LAST_EDIT_DATETIME = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (
|
||||
BUSINESS_CHARGER_CD
|
||||
, BUSINESS_CHARGER
|
||||
, BUSINESS_TEAM_CD
|
||||
, BUSINESS_CHARGER_TEL
|
||||
, BUSINESS_CHARGER_MAIL
|
||||
, DEL_FLG
|
||||
, LAST_EDIT_DATETIME
|
||||
) VALUES (
|
||||
#{businessChargerCd}
|
||||
, #{businessCharger}
|
||||
, #{businessTeamCd}
|
||||
, #{businessChargerTel}
|
||||
, #{businessChargerMail}
|
||||
, #{delFlg}
|
||||
, GETDATE()
|
||||
);
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Loading…
x
Reference in New Issue
Block a user