qcast-api/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemService.java

163 lines
4.7 KiB
Java

package com.interplug.qcast.biz.displayItem;
import com.interplug.qcast.biz.displayItem.dto.*;
import com.interplug.qcast.biz.estimate.EstimateMapper;
import com.interplug.qcast.biz.estimate.dto.NoteRequest;
import com.interplug.qcast.biz.estimate.dto.NoteResponse;
import com.interplug.qcast.config.Exception.ErrorCode;
import com.interplug.qcast.config.Exception.QcastException;
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
@RequiredArgsConstructor
public class DisplayItemService {
private final EstimateMapper estimateMapper;
private final DisplayItemMapper displayItemMapper;
/**
* 판매점 노출 아이템 정보 저장
*
* @param displayItemRequest
* @throws QcastException
*/
public void setStoreDisplayItemSave(DisplayItemRequest displayItemRequest) throws QcastException {
try {
displayItemMapper.setStoreDisplayItemSave(displayItemRequest);
} catch (Exception e) {
throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
/**
* 아이템 목록 조회
*
* @param itemRequest
* @return
* @throws QcastException
*/
public List<ItemResponse> getItemList(ItemRequest itemRequest) throws QcastException {
try {
return displayItemMapper.getItemList(itemRequest);
} catch (Exception e) {
throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
/**
* 아이템 상세 정보 조회
*
* @param itemId
* @return
*/
public ItemDetailResponse getItemDetail(String itemId) throws QcastException {
try {
ItemDetailResponse itemDetailResponse = displayItemMapper.getItemDetail(itemId);
if (itemDetailResponse != null) {
// BOM 헤더 아이템인 경우 BOM List를 내려준다.
if ("ERLA".equals(itemDetailResponse.getItemCtgGr())) {
List<ItemResponse> itemBomList = displayItemMapper.selectItemBomList(itemId);
itemDetailResponse.setItemBomList(itemBomList);
}
// 견적특이사항 관련 데이터 셋팅
String[] arrItemId = {itemId};
NoteRequest noteRequest = new NoteRequest();
noteRequest.setArrItemId(arrItemId);
noteRequest.setSchSpnTypeCd("PROD");
List<NoteResponse> noteItemList = estimateMapper.selectEstimateNoteItemList(noteRequest);
String spnAttrCds = "";
for (NoteResponse noteResponse : noteItemList) {
spnAttrCds += !StringUtils.isEmpty(spnAttrCds) ? "" : "";
spnAttrCds += noteResponse.getCode();
}
itemDetailResponse.setSpnAttrCds(spnAttrCds);
}
return itemDetailResponse;
} catch (Exception e) {
throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
/**
* 아이템 정보 동기화
*
* @param itemSyncList 아이템 목록
* @return
* @throws Exception
*/
public int setItemSyncSave(List<ItemSyncResponse> itemSyncList) throws Exception {
int cnt = 0;
for (ItemSyncResponse itemSyncData : itemSyncList) {
cnt += displayItemMapper.setItemSyncSave(itemSyncData);
cnt += displayItemMapper.setItemInfoSyncSave(itemSyncData);
}
return cnt;
}
/**
* 아이템 정보 동기화
*
* @param bomSyncList 아이템 목록
* @return
* @throws Exception
*/
public int setBomSyncSave(List<BomSyncResponse> bomSyncList) throws Exception {
int cnt = 0;
for (BomSyncResponse bomSyncData : bomSyncList) {
if ("D".equals(bomSyncData.getStatCd())) {
// Bom 아이템 삭제 처리
cnt += displayItemMapper.deleteBomSync(bomSyncData);
} else {
// Bom 아이템 수정/등록 처리
cnt += displayItemMapper.setBomSyncSave(bomSyncData);
}
}
return cnt;
}
/**
* 아이템 가격 정보 동기화
*
* @param priceItemSyncList 가격 목록
* @return
* @throws Exception
*/
public int setPriceSyncSave(List<PriceItemSyncResponse> priceItemSyncList) throws Exception {
int cnt = 0;
for (PriceItemSyncResponse priceItemSyncResponse : priceItemSyncList) {
cnt += displayItemMapper.setPriceItemSyncSave(priceItemSyncResponse);
}
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());
}
}
}
}