#153 견적특이사항/노출아이템 배치 추가 및 작업 소스 주석 추가

This commit is contained in:
LEEYONGJAE 2024-11-15 10:14:24 +09:00
parent 9aa7d94947
commit a1f36be38c
14 changed files with 375 additions and 56 deletions

View File

@ -2,7 +2,6 @@ package com.interplug.qcast.batch;
import java.util.Date;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
@ -16,6 +15,7 @@ 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;
import lombok.RequiredArgsConstructor;
@RestController
@RequiredArgsConstructor
@ -38,22 +38,16 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@GetMapping("/batch/job/{jobName}") // Path Variable로 jobName을 받음
public String launchJob(@PathVariable String jobName)
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String launchJob(@PathVariable String jobName) throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
Job job = jobs.get(jobName);
if (job == null) {
return "Job " + jobName + " not found";
}
JobParameters jobParameters =
new JobParametersBuilder()
.addString("jobName", jobName)
.addDate("time", new Date())
.toJobParameters();
JobParameters jobParameters = new JobParametersBuilder().addString("jobName", jobName)
.addDate("time", new Date()).toJobParameters();
jobLauncher.run(job, jobParameters);
@ -71,11 +65,8 @@ public class JobLauncherController {
*/
// @Scheduled(cron = "*/5 * * * * *")
@Scheduled(cron = "0 55 23 * * *")
public String storeAdditionalInfoJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String storeAdditionalInfoJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "storeAdditionalJob";
Job job = jobs.get(jobName);
@ -101,11 +92,8 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@Scheduled(cron = "0 30 02 * * *")
public String materialJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String materialJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "materialJob";
Job job = jobs.get(jobName);
@ -132,11 +120,8 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@Scheduled(cron = "0 40 02 * * *")
public String bomJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String bomJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "bomJob";
Job job = jobs.get(jobName);
@ -164,11 +149,8 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@Scheduled(cron = "0 40 03 * * *")
public String businessChargerJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String businessChargerJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "businessChargerJob";
Job job = jobs.get(jobName);
@ -196,11 +178,8 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@Scheduled(cron = "0 0 01 * * *")
public String adminUserJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String adminUserJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "adminUserJob";
Job job = jobs.get(jobName);
@ -228,11 +207,8 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@Scheduled(cron = "0 0 0 * * *")
public String priceJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String priceJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "priceJob";
Job job = jobs.get(jobName);
@ -260,11 +236,8 @@ public class JobLauncherController {
* @throws JobRestartException
*/
@Scheduled(cron = "0 10 03 * * *")
public String commonCodeJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,
JobParametersInvalidException,
JobRestartException {
public String commonCodeJob() throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
String jobName = "commonCodeJob";
Job job = jobs.get(jobName);
@ -280,4 +253,33 @@ public class JobLauncherController {
}
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();
jobLauncher.run(job, jobParameters);
}
return "OK";
}
}

View File

@ -0,0 +1,167 @@
package com.interplug.qcast.batch.master;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
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.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;
import com.interplug.qcast.biz.displayItem.DisplayItemService;
import com.interplug.qcast.biz.displayItem.dto.DisplayItemRequest;
import com.interplug.qcast.biz.specialNote.SpecialNoteService;
import com.interplug.qcast.biz.specialNote.dto.SpecialNoteItemRequest;
import com.interplug.qcast.biz.specialNote.dto.SpecialNoteRequest;
import com.interplug.qcast.biz.specialNote.dto.SpecialNoteSyncResponse;
import com.interplug.qcast.util.InterfaceQsp;
import lombok.extern.slf4j.Slf4j;
@Configuration
@Slf4j
public class SpecialNoteDispItemJobConfiguration implements JobExecutionListener {
private final InterfaceQsp interfaceQsp;
private final SpecialNoteService specialNoteService;
private final DisplayItemService displayItemService;
@Value("${qsp.master-special-note-disp-item-batch-url}")
private String qspMasterSpecialNoteDispItemBatchUrl;
private SpecialNoteSyncResponse SpecialNoteDispItemSyncResponse;
public SpecialNoteDispItemJobConfiguration(InterfaceQsp interfaceQsp,
SpecialNoteService specialNoteService, DisplayItemService displayItemService) {
this.interfaceQsp = interfaceQsp;
this.specialNoteService = specialNoteService;
this.displayItemService = displayItemService;
}
@Override
public void beforeJob(JobExecution jobExecution) {
log.info("Job 시작: 초기화 메서드 호출 중...");
try {
this.SpecialNoteDispItemSyncResponse = interfaceQsp.callApiData(HttpMethod.GET,
qspMasterSpecialNoteDispItemBatchUrl, null, SpecialNoteSyncResponse.class);
log.info("API 호출 완료, 항목 수: {}",
this.SpecialNoteDispItemSyncResponse.getSdOrderSpnList().size());
} catch (Exception e) {
log.error("specialNoteDispItemSyncResponse 갱신 중 오류: {}", e.getMessage());
}
}
@Bean
public Job specialNoteDispItemAdditionalJob(JobRepository jobRepository, Step specialNoteStep,
Step specialNoteItemStep, Step storeDispItemStep) {
return new JobBuilder("specialNoteDispItemAdditionalJob", jobRepository).start(specialNoteStep)
.next(specialNoteItemStep).next(storeDispItemStep).listener(this).build();
}
private <T> Step buildStep(String stepName, JobRepository jobRepository,
PlatformTransactionManager transactionManager, ItemReader<T> reader, ItemWriter<T> writer) {
return new StepBuilder(stepName, jobRepository).<T, T>chunk(10, transactionManager)
.reader(reader).writer(writer).build();
}
@Bean
public Step specialNoteStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
return buildStep("specialNoteStep", jobRepository, transactionManager, specialNoteListReader(),
createWriter((items) -> {
try {
log.debug("Special Note batch processing {} items", items.size());
specialNoteService.setSpecialNoteBatch(items);
log.debug("Successfully processed Special Note batch");
} catch (Exception e) {
log.error("Error processing Special Note batch: {}", e.getMessage(), e);
throw new RuntimeException("Failed to process Special Note batch", e);
}
}, "specialNote"));
}
@Bean
public Step specialNoteItemStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
return buildStep("specialNoteItemStep", jobRepository, transactionManager,
specialNoteItemListReader(), createWriter((items) -> {
try {
log.debug("Special Note Item batch processing {} items", items.size());
specialNoteService.setSpecialNoteItemBatch(items);
log.debug("Successfully processed Special Note Item batch");
} catch (Exception e) {
log.error("Error processing Special Note Item batch: {}", e.getMessage(), e);
throw new RuntimeException("Failed to process Special Note Item batch", e);
}
}, "specialNoteItem"));
}
@Bean
public Step storeDispItemStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
return buildStep("storeDispItemStep", jobRepository, transactionManager,
storeDispItemListReader(), createWriter((items) -> {
try {
log.debug("Store Disp Item batch processing {} items", items.size());
displayItemService.setStoreDispItemBatch(items);
log.debug("Successfully processed Store Disp Item batch");
} catch (Exception e) {
log.error("Error processing Store Disp Item batch: {}", e.getMessage(), e);
throw new RuntimeException("Failed to process Store Disp Item batch", e);
}
}, "storeDispItem"));
}
private <T> ListItemReader<T> createReader(List<T> items, String readerName) {
log.info("{}Reader 호출됨...", readerName);
return new ListItemReader<>(items != null ? items : Collections.emptyList());
}
@Bean
@StepScope
public ListItemReader<SpecialNoteRequest> specialNoteListReader() {
return createReader(SpecialNoteDispItemSyncResponse != null
? SpecialNoteDispItemSyncResponse.getSdOrderSpnList()
: null, "specialNote");
}
@Bean
@StepScope
public ListItemReader<SpecialNoteItemRequest> specialNoteItemListReader() {
return createReader(SpecialNoteDispItemSyncResponse != null
? SpecialNoteDispItemSyncResponse.getSdOrderSpnItemList()
: null, "specialNoteItem");
}
@Bean
@StepScope
public ListItemReader<DisplayItemRequest> storeDispItemListReader() {
return createReader(SpecialNoteDispItemSyncResponse != null
? SpecialNoteDispItemSyncResponse.getStoreDispItemList()
: null, "storeDispItem");
}
private <T> ItemWriter<T> createWriter(Consumer<List<T>> processor, String writerName) {
return items -> {
try {
List<T> itemList = (List<T>) items.getItems();
processor.accept(itemList);
log.info("{}Writer: {} items 처리 완료", writerName, items.size());
} catch (Exception e) {
log.error("{}Writer 오류: {}", writerName, e.getMessage());
throw e;
}
};
}
}

View File

@ -1,15 +1,21 @@
package com.interplug.qcast.biz.displayItem;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.interplug.qcast.biz.displayItem.dto.DisplayItemRequest;
import com.interplug.qcast.biz.displayItem.dto.ItemDetailResponse;
import com.interplug.qcast.biz.displayItem.dto.ItemResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@ -19,6 +25,12 @@ import org.springframework.web.bind.annotation.*;
public class DisplayItemController {
private final DisplayItemService displayItemService;
/**
* 전시제품 정보 등록/수정
*
* @param displayItemRequest
* @throws Exception
*/
@Operation(description = "전시제품 정보를 등록/수정한다. (동기화)")
@PostMapping("/display-item-save")
@ResponseStatus(HttpStatus.OK)
@ -27,6 +39,13 @@ public class DisplayItemController {
displayItemService.setStoreDisplayItemSave(displayItemRequest);
}
/**
* 제품 목록 조회
*
* @param saleStoreId
* @return
* @throws Exception
*/
@Operation(description = "제품 목록을 조회한다.")
@GetMapping("/item-list")
@ResponseStatus(HttpStatus.OK)
@ -35,6 +54,13 @@ public class DisplayItemController {
return displayItemService.getItemList(saleStoreId);
}
/**
* 제품 상세 정보 조회
*
* @param itemId
* @return
* @throws Exception
*/
@Operation(description = "제품 상세 정보를 조회한다.")
@GetMapping("/item-detail")
@ResponseStatus(HttpStatus.OK)

View File

@ -1,14 +1,19 @@
package com.interplug.qcast.biz.displayItem;
import com.interplug.qcast.biz.displayItem.dto.*;
import java.util.List;
import org.springframework.stereotype.Service;
import com.interplug.qcast.biz.displayItem.dto.BomSyncResponse;
import com.interplug.qcast.biz.displayItem.dto.DisplayItemRequest;
import com.interplug.qcast.biz.displayItem.dto.ItemDetailResponse;
import com.interplug.qcast.biz.displayItem.dto.ItemResponse;
import com.interplug.qcast.biz.displayItem.dto.ItemSyncResponse;
import com.interplug.qcast.biz.displayItem.dto.PriceItemSyncResponse;
import com.interplug.qcast.biz.estimate.EstimateMapper;
import com.interplug.qcast.biz.estimate.dto.NoteRequest;
import com.interplug.qcast.biz.estimate.dto.NoteResponse;
import io.micrometer.common.util.StringUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@ -127,4 +132,22 @@ public class DisplayItemService {
}
return cnt;
}
/**
* 노출 아이템 동기화 - Batch
*
* @param displayItemList
* @throws Exception
*/
public void setStoreDispItemBatch(List<DisplayItemRequest> displayItemList) throws Exception {
// 노출 아이템 동기화
for (DisplayItemRequest displayItemRequest : displayItemList) {
try {
displayItemMapper.setStoreDisplayItemSave(displayItemRequest);
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
}

View File

@ -22,6 +22,12 @@ public class MyInfoController {
private final MyInfoService myInfoService;
/**
* 사용자 ID의 정보 조회
*
* @param myInfoRequest
* @return
*/
@Operation(description = "사용자 ID의 정보를 조회한다.")
@GetMapping("/my-profile")
@ResponseStatus(HttpStatus.OK)

View File

@ -8,7 +8,7 @@ import com.interplug.qcast.biz.myInfo.dto.MyInfoResponse;
public interface MyInfoMapper {
/**
* 사용자 정보 조회
* 사용자 ID의 정보 조회
*
* @param myInfoRequest
* @return

View File

@ -14,7 +14,7 @@ public class MyInfoService {
private final MyInfoMapper myInfoMapper;
/**
* 사용자 정보 조회
* 사용자 ID의 정보 조회
*
* @param userId
* @return MyInfoResponse

View File

@ -22,6 +22,12 @@ public class SpecialNoteController {
private final SpecialNoteService specialNoteService;
/**
* 견적 특이사항 정보 등록/수정
*
* @param specialNoteRequest
* @throws Exception
*/
@Operation(description = "견적 특이사항 정보를 등록/수정한다. (동기화)")
@PostMapping("/special-note-save")
@ResponseStatus(HttpStatus.OK)
@ -30,6 +36,12 @@ public class SpecialNoteController {
specialNoteService.setSpecialNoteSave(specialNoteRequest);
}
/**
* 견적 특이사항 ITEM 정보 등록/수정
*
* @param specialNoteItemRequest
* @throws Exception
*/
@Operation(description = "견적 특이사항 ITEM 정보를 등록/수정한다. (동기화)")
@PostMapping("/special-note-item-save")
@ResponseStatus(HttpStatus.OK)

View File

@ -7,8 +7,20 @@ import com.interplug.qcast.biz.specialNote.dto.SpecialNoteRequest;
@Mapper
public interface SpecialNoteMapper {
/**
* 견적 특이사항 저장
*
* @param specialNoteRequest
* @throws Exception
*/
void setSpecialNoteSave(SpecialNoteRequest specialNoteRequest) throws Exception;
/**
* 견적 특이사항 아이템 저장
*
* @param specialNoteItemRequest
* @throws Exception
*/
void setSpecialNoteItemSave(SpecialNoteItemRequest specialNoteItemRequest) throws Exception;
}

View File

@ -1,5 +1,6 @@
package com.interplug.qcast.biz.specialNote;
import java.util.List;
import org.springframework.stereotype.Service;
import com.interplug.qcast.biz.specialNote.dto.SpecialNoteItemRequest;
import com.interplug.qcast.biz.specialNote.dto.SpecialNoteRequest;
@ -13,13 +14,60 @@ public class SpecialNoteService {
private final SpecialNoteMapper specialNoteMapper;
/**
* 견적 특이사항 저장
*
* @param specialNoteRequest
* @throws Exception
*/
public void setSpecialNoteSave(SpecialNoteRequest specialNoteRequest) throws Exception {
specialNoteMapper.setSpecialNoteSave(specialNoteRequest);
}
/**
* 견적 특이사항 아이템 저장
*
* @param specialNoteItemRequest
* @throws Exception
*/
public void setSpecialNoteItemSave(SpecialNoteItemRequest specialNoteItemRequest)
throws Exception {
specialNoteMapper.setSpecialNoteItemSave(specialNoteItemRequest);
}
/**
* 견적 특이사항 동기화 - Batch
*
* @param specialNoteList
* @throws Exception
*/
public void setSpecialNoteBatch(List<SpecialNoteRequest> specialNoteList) throws Exception {
// 견적 특이사항 동기화
for (SpecialNoteRequest specialNoteRequest : specialNoteList) {
try {
specialNoteMapper.setSpecialNoteSave(specialNoteRequest);
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
/**
* 견적 특이사항 아이템 동기화 - Batch
*
* @param specialNoteItemList
* @throws Exception
*/
public void setSpecialNoteItemBatch(List<SpecialNoteItemRequest> specialNoteItemList)
throws Exception {
// 견적 특이사항 아이템 동기화
for (SpecialNoteItemRequest specialNoteItemRequest : specialNoteItemList) {
try {
specialNoteMapper.setSpecialNoteItemSave(specialNoteItemRequest);
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
}

View File

@ -0,0 +1,22 @@
package com.interplug.qcast.biz.specialNote.dto;
import java.util.List;
import com.interplug.qcast.biz.displayItem.dto.DisplayItemRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class SpecialNoteSyncResponse {
@Schema(description = "견적 특이사항 목록")
private List<SpecialNoteRequest> sdOrderSpnList;
@Schema(description = "견적 특이사항 아이템 목록")
private List<SpecialNoteItemRequest> sdOrderSpnItemList;
@Schema(description = "노출 아이템 목록")
private List<DisplayItemRequest> storeDispItemList;
}

View File

@ -50,6 +50,7 @@ qsp:
aes256.key: jpqcellQ123456!!
auto.login.aes256.key: _autoL!!
system-commonCode-batch-url: /api/system/commonCodeListData
master-special-note-disp-item-batch-url: /api/master/quotationDispItemInfo
#File
file:
root.path: C:\\

View File

@ -50,7 +50,7 @@ qsp:
aes256.key: jpqcellQ123456!!
auto.login.aes256.key: _autoL!!
system-commonCode-batch-url: /api/system/commonCodeListData
master-special-note-disp-item-batch-url: /api/master/quotationDispItemInfo
#File
file:
root.path: C:\\

View File

@ -50,7 +50,7 @@ qsp:
aes256.key: jpqcellQ123456!!
auto.login.aes256.key: _autoL!!
system-commonCode-batch-url: /api/system/commonCodeListData
master-special-note-disp-item-batch-url: /api/master/quotationDispItemInfo
#File
file:
root.path: C:\\