405 lines
12 KiB
Java
405 lines
12 KiB
Java
package com.interplug.qcast.batch;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.batch.core.BatchStatus;
|
|
import org.springframework.batch.core.ExitStatus;
|
|
import org.springframework.batch.core.Job;
|
|
import org.springframework.batch.core.JobExecution;
|
|
import org.springframework.batch.core.JobParameters;
|
|
import org.springframework.batch.core.JobParametersBuilder;
|
|
import org.springframework.batch.core.JobParametersInvalidException;
|
|
import org.springframework.batch.core.launch.JobLauncher;
|
|
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
|
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
|
import org.springframework.batch.core.repository.JobRestartException;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
public class JobLauncherController {
|
|
private final Map<String, Job> jobs; // 여러 Job을 주입받도록 변경
|
|
|
|
private final JobLauncher jobLauncher;
|
|
|
|
@Value("${qsp.master-admin-user-batch-url}")
|
|
private String qspInterfaceUrl;
|
|
|
|
@Value("${batch.job.enabled}")
|
|
private boolean batchJobEnabled;
|
|
/**
|
|
* 특정 Job을 매핑으로 실행하는 메소드
|
|
*
|
|
* @param jobName
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@GetMapping("/batch/job/{jobName}") // Path Variable로 jobName을 받음
|
|
public Map<String, Object> launchJob(@PathVariable String jobName)
|
|
throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException, JobRestartException {
|
|
|
|
Job job = jobs.get(jobName);
|
|
Map<String, Object> resultMap = new HashMap<String, Object>();
|
|
if (job == null) {
|
|
// return "Job " + jobName + " not found";
|
|
resultMap.put("code", "FAILED");
|
|
resultMap.put("message", "Job" + jobName + " not found");
|
|
return resultMap;
|
|
}
|
|
// String[] arryJob = {
|
|
// "storeAdditionalJob"
|
|
// ,"BOMJob"
|
|
// ,"materialJob"
|
|
// ,"businessChargerJob"
|
|
// ,"adminUserJob"
|
|
// ,"priceJob"
|
|
//// ,"commonCodeJob"
|
|
// ,"specialNoteDispItemAdditionalJob"
|
|
// ,"planConfirmJob"
|
|
// ,"estimateSyncJob"
|
|
// };
|
|
//
|
|
//
|
|
// if(!batchJobEnabled ){
|
|
// for(String jobName2 :arryJob){
|
|
// if(jobName2.equals(jobName)){
|
|
// resultMap.put("code", "FAILED");
|
|
// resultMap.put("message", "application.yml :: batch.job.enabled true");
|
|
// return resultMap;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
JobParameters jobParameters = new JobParametersBuilder().addString("jobName", jobName)
|
|
.addDate("time", new Date()).toJobParameters();
|
|
|
|
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
|
|
|
|
|
|
|
|
BatchStatus status = jobExecution.getStatus();
|
|
ExitStatus exitStatus = jobExecution.getExitStatus();
|
|
|
|
resultMap.put("code", status.toString());
|
|
resultMap.put("message", exitStatus.getExitDescription());
|
|
|
|
|
|
// return "Job " + jobName + " started";
|
|
return resultMap;
|
|
}
|
|
|
|
/**
|
|
* Q.CAST 판매점 / 사용자 / 즐겨찾기 / 노출 아이템 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
// @Scheduled(cron = "*/5 * * * * *")
|
|
@Scheduled(cron = "0 55 23 * * *")
|
|
public String storeAdditionalJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "storeAdditionalJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 아이템 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 30 02 * * *")
|
|
public String materialJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "materialJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
//if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
//}
|
|
}
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* BOM 아이템 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 40 02 * * *")
|
|
public String bomJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "bomJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
//if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
//}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 영업사원 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 40 03 * * *")
|
|
public String businessChargerJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "businessChargerJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 관리자 유저 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 0 01 * * *")
|
|
public String adminUserJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "adminUserJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 가격 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 0 0 * * *")
|
|
public String priceJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "priceJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 공통코드 M_COMM_H, M_COMM_L 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 10 03 * * *")
|
|
public String commonCodeJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "commonCodeJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* Q.CAST 견적특이사항 / 아이템 표시, 미표시 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 30 23 * * *")
|
|
public String specialNoteDispItemAdditionalInfoJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
String jobName = "specialNoteDispItemAdditionalJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* Plan Confrim 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 05 04 * * *")
|
|
public String planConfirmJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "planConfirmJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 견적서 전송 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 20 04 * * *")
|
|
public String estimateSyncJob() throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
|
|
|
|
String jobName = "estimateSyncJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
if ("Y".equals(System.getProperty("spring.profiles.scheduler"))) {
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
if (batchJobEnabled) {
|
|
jobLauncher.run(job, jobParameters);
|
|
}
|
|
}
|
|
|
|
return "OK";
|
|
}
|
|
}
|