From ff25eb4565a24b9de5cc61ab12d3eac6f029b556 Mon Sep 17 00:00:00 2001 From: Daseul Kim Date: Wed, 12 Feb 2025 17:42:00 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20service=20=EB=82=B4=20transaction,?= =?UTF-8?q?=20throw=20QcastException=20=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CanvasBasicSettingController.java | 3 +- .../CanvasBasicSettingService.java | 47 +++++---- .../CanvasGridSettingController.java | 12 +-- .../CanvasGridSettingService.java | 19 +++- .../CanvasSettingController.java | 10 +- .../canvasSetting/CanvasSettingService.java | 33 ++++--- .../biz/canvasStatus/CanvasStatusService.java | 98 ++++++++++++------- .../displayItem/DisplayItemController.java | 14 +-- .../biz/displayItem/DisplayItemService.java | 75 ++++++++------ 9 files changed, 192 insertions(+), 119 deletions(-) diff --git a/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingController.java b/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingController.java index 1e4ff0a6..6a4b7f5b 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingController.java +++ b/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingController.java @@ -23,7 +23,8 @@ public class CanvasBasicSettingController { @Operation(description = "Canvas Basic Setting 정보를 조회 한다.") @GetMapping("/canvas-basic-settings/by-object/{objectNo}") - public List selectCanvasBasicSetting(@PathVariable String objectNo) { + public List selectCanvasBasicSetting(@PathVariable String objectNo) + throws QcastException { log.debug("Basic Setting 조회 ::::: " + objectNo); diff --git a/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingService.java b/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingService.java index 6b6dc436..50be0da3 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingService.java +++ b/src/main/java/com/interplug/qcast/biz/canvasBasicSetting/CanvasBasicSettingService.java @@ -13,19 +13,27 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Slf4j @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class CanvasBasicSettingService { private final CanvasBasicSettingMapper canvasBasicSettingMapper; // Canvas Basic Setting 조회(objectNo) - public List selectCanvasBasicSetting(String objectNo) { - return canvasBasicSettingMapper.selectCanvasBasicSetting(objectNo); + public List selectCanvasBasicSetting(String objectNo) + throws QcastException { + try { + return canvasBasicSettingMapper.selectCanvasBasicSetting(objectNo); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } } // Canvas Basic Setting 등록 + @Transactional public Map insertCanvasBasicSetting(CanvasBasicSettingInfo csi) throws QcastException { @@ -56,9 +64,6 @@ public class CanvasBasicSettingService { canvasBasicSettingMapper.insertRoofMaterialsAdd(rma); } - response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.confirm.mark"); - } else { // 도면/치수/각도 정보 update canvasBasicSettingMapper.updateCanvasBasicSetting(csi); @@ -70,14 +75,12 @@ public class CanvasBasicSettingService { // 신규 지붕재추가 정보 insert canvasBasicSettingMapper.updateRoofMaterialsAdd(rma); } - - response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.confirm.mark"); } + response.put("objectNo", csi.getObjectNo()); + response.put("returnMessage", "common.message.confirm.mark"); } catch (Exception e) { - response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.save.error"); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } // 생성된 objectNo 반환 @@ -85,6 +88,7 @@ public class CanvasBasicSettingService { } // 지붕면 할당 Setting 등록 + @Transactional public Map insertRoofAllocSetting(RoofAllocationSettingInfo rasi) throws QcastException { @@ -107,8 +111,7 @@ public class CanvasBasicSettingService { response.put("objectNo", rasi.getObjectNo()); response.put("returnMessage", "common.message.confirm.mark"); } catch (Exception e) { - response.put("objectNo", rasi.getObjectNo()); - response.put("returnMessage", "common.message.save.error"); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } // 생성된 objectNo 반환 @@ -116,20 +119,26 @@ public class CanvasBasicSettingService { } // 지붕재추가 삭제 + @Transactional public void deleteRoofMaterialsAdd(String objectNo) throws QcastException { if (objectNo == null || objectNo.trim().isEmpty()) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } - // 먼저 데이터가 존재하는지 확인 - RoofMaterialsAddInfo cntData = canvasBasicSettingMapper.getRoofMaterialsCnt(objectNo); + try { + // 먼저 데이터가 존재하는지 확인 + RoofMaterialsAddInfo cntData = canvasBasicSettingMapper.getRoofMaterialsCnt(objectNo); - // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 - if (cntData.getRoofCnt().intValue() > 0) { - canvasBasicSettingMapper.deleteRoofMaterialsAdd(objectNo); - } else { - throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 지붕재가 존재하지 않습니다."); + // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 + if (cntData.getRoofCnt().intValue() > 0) { + canvasBasicSettingMapper.deleteRoofMaterialsAdd(objectNo); + } else { + throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 지붕재가 존재하지 않습니다."); + } + } catch (Exception e) { + if (e instanceof QcastException) throw e; + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } } } diff --git a/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingController.java b/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingController.java index a09f0f43..f245d333 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingController.java +++ b/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingController.java @@ -1,14 +1,12 @@ package com.interplug.qcast.biz.canvasGridSetting; import com.interplug.qcast.biz.canvasGridSetting.dto.CanvasGridSettingInfo; - +import com.interplug.qcast.config.Exception.QcastException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -22,7 +20,8 @@ public class CanvasGridSettingController { @Operation(description = "Canvas Grid Setting 정보를 조회 한다.") @GetMapping("/canvas-grid-settings/by-object/{objectNo}") - public CanvasGridSettingInfo selectCanvasGridSetting(@PathVariable String objectNo) { + public CanvasGridSettingInfo selectCanvasGridSetting(@PathVariable String objectNo) + throws QcastException { log.debug("Grid Setting 조회 ::::: " + objectNo); @@ -32,7 +31,8 @@ public class CanvasGridSettingController { @Operation(description = "Canvas Grid Setting 정보를 등록 한다.") @PostMapping("/canvas-grid-settings") @ResponseStatus(HttpStatus.CREATED) - public Map insertCanvasGridStatus(@RequestBody CanvasGridSettingInfo csi) { + public Map insertCanvasGridStatus(@RequestBody CanvasGridSettingInfo csi) + throws QcastException { log.debug("Grid Setting 등록 ::::: " + csi.getObjectNo()); diff --git a/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingService.java b/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingService.java index dcfc9986..8b0d8e93 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingService.java +++ b/src/main/java/com/interplug/qcast/biz/canvasGridSetting/CanvasGridSettingService.java @@ -2,25 +2,35 @@ package com.interplug.qcast.biz.canvasGridSetting; import com.interplug.qcast.biz.canvasGridSetting.dto.CanvasGridSettingInfo; +import com.interplug.qcast.config.Exception.ErrorCode; +import com.interplug.qcast.config.Exception.QcastException; import lombok.RequiredArgsConstructor; import java.util.HashMap; import java.util.Map; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class CanvasGridSettingService { private final CanvasGridSettingMapper canvasGridSettingMapper; // Canvas Setting 조회(objectNo) - public CanvasGridSettingInfo selectCanvasGridSetting(String objectNo) { - return canvasGridSettingMapper.selectCanvasGridSetting(objectNo); + public CanvasGridSettingInfo selectCanvasGridSetting(String objectNo) throws QcastException { + try { + return canvasGridSettingMapper.selectCanvasGridSetting(objectNo); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } } // Canvas Setting 등록 - public Map insertCanvasGridSetting(CanvasGridSettingInfo csi) { + @Transactional + public Map insertCanvasGridSetting(CanvasGridSettingInfo csi) + throws QcastException { Map response = new HashMap<>(); @@ -31,8 +41,7 @@ public class CanvasGridSettingService { response.put("returnMessage", "common.message.confirm.mark"); } catch (Exception e) { - response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.save.error"); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } // 생성된 objectNo 반환 diff --git a/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingController.java b/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingController.java index f1a91853..c2cc8193 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingController.java +++ b/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingController.java @@ -2,14 +2,11 @@ package com.interplug.qcast.biz.canvasSetting; import com.interplug.qcast.biz.canvasSetting.dto.CanvasSettingInfo; import com.interplug.qcast.config.Exception.QcastException; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -23,7 +20,8 @@ public class CanvasSettingController { @Operation(description = "Canvas Setting 정보를 조회 한다.") @GetMapping("/canvas-settings/by-object/{objectNo}") - public CanvasSettingInfo selectCanvasSetting(@PathVariable String objectNo) { + public CanvasSettingInfo selectCanvasSetting(@PathVariable String objectNo) + throws QcastException { log.debug("Setting 조회 ::::: " + objectNo); @@ -43,7 +41,7 @@ public class CanvasSettingController { @Operation(description = "Canvas Setting 정보를 수정 한다.") @PutMapping("/canvas-settings") - public void updateCanvasStatus(@RequestBody CanvasSettingInfo csi) { + public void updateCanvasStatus(@RequestBody CanvasSettingInfo csi) throws QcastException { log.debug("Setting 수정 ::::: " + csi.getObjectNo()); diff --git a/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingService.java b/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingService.java index 239c5655..c9fb2f6e 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingService.java +++ b/src/main/java/com/interplug/qcast/biz/canvasSetting/CanvasSettingService.java @@ -7,18 +7,25 @@ import java.util.HashMap; import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class CanvasSettingService { private final CanvasSettingMapper canvasSettingMapper; // Canvas Setting 조회(objectNo) - public CanvasSettingInfo selectCanvasSetting(String objectNo) { - return canvasSettingMapper.selectCanvasSetting(objectNo); + public CanvasSettingInfo selectCanvasSetting(String objectNo) throws QcastException { + try { + return canvasSettingMapper.selectCanvasSetting(objectNo); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } } // Canvas Setting 등록 + @Transactional public Map insertCanvasSetting(CanvasSettingInfo csi) throws QcastException { Map response = new HashMap<>(); @@ -35,20 +42,13 @@ public class CanvasSettingService { // 데이터가 존재하지 않으면 insert if (cntData.getCnt().intValue() < 1) { canvasSettingMapper.insertCanvasSetting(csi); - - response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.confirm.mark"); - } else { canvasSettingMapper.updateCanvasSetting(csi); - - response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.confirm.mark"); } - - } catch (Exception e) { response.put("objectNo", csi.getObjectNo()); - response.put("returnMessage", "common.message.save.error"); + response.put("returnMessage", "common.message.confirm.mark"); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } // 생성된 objectNo 반환 @@ -56,7 +56,12 @@ public class CanvasSettingService { } // Canvas Setting 수정 - public void updateCanvasSetting(CanvasSettingInfo csi) { - canvasSettingMapper.updateCanvasSetting(csi); + @Transactional + public void updateCanvasSetting(CanvasSettingInfo csi) throws QcastException { + try { + canvasSettingMapper.updateCanvasSetting(csi); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } } } diff --git a/src/main/java/com/interplug/qcast/biz/canvasStatus/CanvasStatusService.java b/src/main/java/com/interplug/qcast/biz/canvasStatus/CanvasStatusService.java index 5b0abd71..c2e5e606 100644 --- a/src/main/java/com/interplug/qcast/biz/canvasStatus/CanvasStatusService.java +++ b/src/main/java/com/interplug/qcast/biz/canvasStatus/CanvasStatusService.java @@ -8,9 +8,11 @@ import com.interplug.qcast.config.Exception.QcastException; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class CanvasStatusService { private final CanvasStatusMapper canvasStatusMapper; @@ -18,10 +20,15 @@ public class CanvasStatusService { public List selectAllCanvasStatus(String userId) throws QcastException { List result = null; - if (userId != null && !userId.trim().isEmpty()) { - result = canvasStatusMapper.selectAllCanvasStatus(userId); - } else { - throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); + try { + if (userId != null && !userId.trim().isEmpty()) { + result = canvasStatusMapper.selectAllCanvasStatus(userId); + } else { + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); + } + } catch (Exception e) { + if (e instanceof QcastException) throw e; + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } return result; @@ -32,16 +39,22 @@ public class CanvasStatusService { throws QcastException { List result = null; - if (objectNo != null && !objectNo.trim().isEmpty()) { - result = canvasStatusMapper.selectObjectNoCanvasStatus(objectNo); - } else { - throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); + try { + if (objectNo != null && !objectNo.trim().isEmpty()) { + result = canvasStatusMapper.selectObjectNoCanvasStatus(objectNo); + } else { + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); + } + } catch (Exception e) { + if (e instanceof QcastException) throw e; + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } return result; } // 캔버스 등록 + @Transactional public Integer insertCanvasStatus(CanvasStatus cs) throws QcastException { Integer id = 0; @@ -56,7 +69,7 @@ public class CanvasStatusService { id = maxId.get(0).getId(); } catch (Exception e) { - throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "캔버스 등록 중 오류 발생"); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } // 생성된 id 반환 @@ -64,63 +77,82 @@ public class CanvasStatusService { } // 캔버스 수정 + @Transactional public void updateCanvasStatus(CanvasStatus cs) throws QcastException { if (cs.getId() == null) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } - // 먼저 데이터가 존재하는지 확인 - List existingStatus = canvasStatusMapper.getIdCanvasStatus(cs.getId()); + try { + // 먼저 데이터가 존재하는지 확인 + List existingStatus = canvasStatusMapper.getIdCanvasStatus(cs.getId()); - // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 - if (existingStatus.size() > 0) { - canvasStatusMapper.updateCanvasStatus(cs); - } else { - throw new QcastException(ErrorCode.NOT_FOUND, "수정할 캔버스가 존재하지 않습니다."); + // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 + if (existingStatus.size() > 0) { + canvasStatusMapper.updateCanvasStatus(cs); + } else { + throw new QcastException(ErrorCode.NOT_FOUND, "수정할 캔버스가 존재하지 않습니다."); + } + } catch (Exception e) { + if (e instanceof QcastException) throw e; + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } } // 물건번호(objectNo)에 해당하는 캔버스 삭제 + @Transactional public void deleteObjectNoCanvasStatus(String objectNo) throws QcastException { if (objectNo == null || objectNo.trim().isEmpty()) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } - // 먼저 데이터가 존재하는지 확인 - List existingStatus = - canvasStatusMapper.getObjectNoCanvasStatus(objectNo); + try { + // 먼저 데이터가 존재하는지 확인 + List existingStatus = + canvasStatusMapper.getObjectNoCanvasStatus(objectNo); - // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 - if (existingStatus.size() > 0) { - canvasStatusMapper.deleteObjectNoCanvasStatus(objectNo); - } else { - throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 캔버스가 존재하지 않습니다."); + // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 + if (existingStatus.size() > 0) { + canvasStatusMapper.deleteObjectNoCanvasStatus(objectNo); + } else { + throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 캔버스가 존재하지 않습니다."); + } + } catch (Exception e) { + if (e instanceof QcastException) throw e; + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } } // id에 해당하는 캔버스 삭제 + @Transactional public void deleteIdCanvasStatus(Integer id) throws QcastException { if (id == null) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } - // 먼저 데이터가 존재하는지 확인 - List existingStatus = canvasStatusMapper.getIdCanvasStatus(id); + try { + // 먼저 데이터가 존재하는지 확인 + List existingStatus = canvasStatusMapper.getIdCanvasStatus(id); - // 데이터가 존재하지 않으면 처리하지 않고 예외를 던짐 - if (existingStatus.size() > 0) { - // 데이터를 삭제하는 기존 방식에서 데이터를 삭제하지 않고 deleted 데이터를 바꾸는 방식으로 변경 (2025.02.11) - // canvasStatusMapper.deleteIdCanvasStatus(id); - canvasStatusMapper.updateDeletedCanvasStatus(id); - } else { - throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 캔버스가 존재하지 않습니다."); + // 데이터가 존재하지 않으면 처리하지 않고 예외를 던짐 + if (existingStatus.size() > 0) { + // 데이터를 삭제하는 기존 방식에서 데이터를 삭제하지 않고 deleted 데이터를 바꾸는 방식으로 변경 (2025.02.11) + // canvasStatusMapper.deleteIdCanvasStatus(id); + canvasStatusMapper.updateDeletedCanvasStatus(id); + } else { + throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 캔버스가 존재하지 않습니다."); + } + } catch (Exception e) { + if (e instanceof QcastException) throw e; + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); } } // 캔버스 복사 후 등록 + @Transactional public int copyCanvasStatus(CanvasStatusCopyRequest cs) throws QcastException { try { canvasStatusMapper.copyCanvasStatus(cs); diff --git a/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemController.java b/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemController.java index d4c46425..47543967 100644 --- a/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemController.java +++ b/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemController.java @@ -4,6 +4,7 @@ import com.interplug.qcast.biz.displayItem.dto.DisplayItemRequest; import com.interplug.qcast.biz.displayItem.dto.ItemDetailResponse; import com.interplug.qcast.biz.displayItem.dto.ItemRequest; import com.interplug.qcast.biz.displayItem.dto.ItemResponse; +import com.interplug.qcast.config.Exception.QcastException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; @@ -30,13 +31,13 @@ public class DisplayItemController { * 전시제품 정보 등록/수정 * * @param displayItemRequest - * @throws Exception + * @throws QcastException */ @Operation(description = "전시제품 정보를 등록/수정한다. (동기화)") @PostMapping("/display-item-save") @ResponseStatus(HttpStatus.OK) public void setStoreDisplayItemSave(@RequestBody DisplayItemRequest displayItemRequest) - throws Exception { + throws QcastException { displayItemService.setStoreDisplayItemSave(displayItemRequest); } @@ -45,12 +46,13 @@ public class DisplayItemController { * * @param itemRequest * @return - * @throws Exception + * @throws QcastException */ @Operation(description = "제품 목록을 조회한다.") @PostMapping("/item-list") @ResponseStatus(HttpStatus.OK) - public List getItemList(@RequestBody ItemRequest itemRequest) throws Exception { + public List getItemList(@RequestBody ItemRequest itemRequest) + throws QcastException { return displayItemService.getItemList(itemRequest); } @@ -59,12 +61,12 @@ public class DisplayItemController { * * @param itemId * @return - * @throws Exception + * @throws QcastException */ @Operation(description = "제품 상세 정보를 조회한다.") @GetMapping("/item-detail") @ResponseStatus(HttpStatus.OK) - public ItemDetailResponse getItemDetail(@RequestParam String itemId) throws Exception { + public ItemDetailResponse getItemDetail(@RequestParam String itemId) throws QcastException { return displayItemService.getItemDetail(itemId); } } diff --git a/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemService.java b/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemService.java index d90211c8..ceb9ec5c 100644 --- a/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemService.java +++ b/src/main/java/com/interplug/qcast/biz/displayItem/DisplayItemService.java @@ -4,15 +4,19 @@ 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; +import org.springframework.transaction.annotation.Transactional; @Slf4j @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class DisplayItemService { private final EstimateMapper estimateMapper; @@ -23,10 +27,15 @@ public class DisplayItemService { * 판매점 노출 아이템 정보 저장 * * @param displayItemRequest - * @throws Exception + * @throws QcastException */ - public void setStoreDisplayItemSave(DisplayItemRequest displayItemRequest) throws Exception { - displayItemMapper.setStoreDisplayItemSave(displayItemRequest); + @Transactional + public void setStoreDisplayItemSave(DisplayItemRequest displayItemRequest) throws QcastException { + try { + displayItemMapper.setStoreDisplayItemSave(displayItemRequest); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } } /** @@ -34,9 +43,14 @@ public class DisplayItemService { * * @param itemRequest * @return + * @throws QcastException */ - public List getItemList(ItemRequest itemRequest) { - return displayItemMapper.getItemList(itemRequest); + public List getItemList(ItemRequest itemRequest) throws QcastException { + try { + return displayItemMapper.getItemList(itemRequest); + } catch (Exception e) { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } } /** @@ -45,36 +59,39 @@ public class DisplayItemService { * @param itemId * @return */ - public ItemDetailResponse getItemDetail(String itemId) { + public ItemDetailResponse getItemDetail(String itemId) throws QcastException { + try { + ItemDetailResponse itemDetailResponse = displayItemMapper.getItemDetail(itemId); - ItemDetailResponse itemDetailResponse = displayItemMapper.getItemDetail(itemId); + if (itemDetailResponse != null) { + // BOM 헤더 아이템인 경우 BOM List를 내려준다. + if ("ERLA".equals(itemDetailResponse.getItemCtgGr())) { + List itemBomList = displayItemMapper.selectItemBomList(itemId); - if (itemDetailResponse != null) { - // BOM 헤더 아이템인 경우 BOM List를 내려준다. - if ("ERLA".equals(itemDetailResponse.getItemCtgGr())) { - List itemBomList = displayItemMapper.selectItemBomList(itemId); + itemDetailResponse.setItemBomList(itemBomList); + } - itemDetailResponse.setItemBomList(itemBomList); + // 견적특이사항 관련 데이터 셋팅 + String[] arrItemId = {itemId}; + + NoteRequest noteRequest = new NoteRequest(); + noteRequest.setArrItemId(arrItemId); + noteRequest.setSchSpnTypeCd("PROD"); + List noteItemList = estimateMapper.selectEstimateNoteItemList(noteRequest); + + String spnAttrCds = ""; + for (NoteResponse noteResponse : noteItemList) { + spnAttrCds += !StringUtils.isEmpty(spnAttrCds) ? "、" : ""; + spnAttrCds += noteResponse.getCode(); + } + + itemDetailResponse.setSpnAttrCds(spnAttrCds); } - // 견적특이사항 관련 데이터 셋팅 - String[] arrItemId = {itemId}; - - NoteRequest noteRequest = new NoteRequest(); - noteRequest.setArrItemId(arrItemId); - noteRequest.setSchSpnTypeCd("PROD"); - List 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()); } - - return itemDetailResponse; } /**