diff --git a/docker/db/mysql/init/init.sql b/docker/db/mysql/init/init.sql index 41dccec..caa6398 100644 --- a/docker/db/mysql/init/init.sql +++ b/docker/db/mysql/init/init.sql @@ -73,13 +73,6 @@ select * from pv_goods; select * from pv_item; select * from pv_goods where goods_no =1; -select * from od_order; -select * from od_order_dtl; -select * from od_order_deli; -select * from od_order_pay; -select * from od_order_goods; -select * from od_order_bene; - /* 주문자 관리 기본 정보 마스터 */ CREATE TABLE IF NOT EXISTS od_order( order_no INT(11) NOT NULL AUTO_INCREMENT, @@ -89,14 +82,14 @@ CREATE TABLE IF NOT EXISTS od_order( cell_no VARCHAR(30) NOT NULL, insert_dtime DATETIME DEFAULT now(), update_dtime DATETIME DEFAULT now(), - CONSTRAINT od_ord_master_pk PRIMARY KEY(order_no), + CONSTRAINT od_ord_master_pk PRIMARY KEY(order_no) ); /* 상품단위 주문 정보 */ CREATE TABLE IF NOT EXISTS od_order_dtl( order_no INT(11) NOT NULL AUTO_INCREMENT, - order_step INT(11) NOT NULL AUTO_INCREMENT, /* 단계 주문/취소/반품/ */ - order_status /*주문상태 결제대기 결제중 */ + order_step VARCHAR(4) NOT NULL, /* 단계 주문/취소/반품/ */ + order_status VARCHAR(4) NOT NULL, /*주문상태 결제대기 결제중 */ goods_no INT(11) NOT NULL, goods_nm VARCHAR(30) NOT NULL, item_no INT(11) NOT NULL, @@ -113,8 +106,15 @@ CREATE TABLE IF NOT EXISTS od_order_dtl( CONSTRAINT od_order_dtl_pk PRIMARY KEY(order_no), foreign key (order_no) references od_order(order_no) ); - +/* +select * from od_order; +select * from od_order_dtl; +select * from od_order_deli; +select * from od_order_pay; +select * from od_order_goods; +select * from od_order_bene; drop table pv_item; drop table pv_goods;commit; + */ select count(*) over(), a.* from pv_goods a ; select a.goods_nm ,b.item_nm,a.* from pv_goods a, pv_item b where a.goods_no = b.goods_no ; diff --git a/module-api/src/main/java/com/cosmetics/api/controller/GoodsController.java b/module-api/src/main/java/com/cosmetics/api/controller/GoodsController.java index 7ff54f9..a988017 100644 --- a/module-api/src/main/java/com/cosmetics/api/controller/GoodsController.java +++ b/module-api/src/main/java/com/cosmetics/api/controller/GoodsController.java @@ -25,55 +25,46 @@ public class GoodsController { @GetMapping(value = "/{goodsNo}") public CompletableFuture findGoods(@PathVariable Long goodsNo) { - - CompletableFuture goodsResponseFuture = CompletableFuture.supplyAsync(() -> { - log.error("findGoodsThread = {}", Thread.currentThread().getName()); - GoodsManagement goodsManagement = goodsService.findByGoodsNo(goodsNo); - return GoodsManagementResponse.toResponseDto(goodsManagement); - - }).thenApplyAsync( //callback + return goodsService.findByGoodsNo(goodsNo).thenApplyAsync(goodsManagement -> { + return GoodsManagementResponse.fromDto(goodsManagement); + }).thenApplyAsync( (GoodsManagementResponse response) -> { log.error("findGoods thenApplayAsync= {}", Thread.currentThread().getName()); response.updateSuccess("0000", "조회성공"); return response; } ); - - return goodsResponseFuture; } @PostMapping @ResponseStatus(HttpStatus.CREATED) public CompletableFuture registerGoods(@RequestBody @Valid GoodsManagementRequest goodsManagementRequest) throws ExecutionException, InterruptedException { - - CompletableFuture goodsResponseFuture = CompletableFuture.supplyAsync(() -> { - log.error("goodsName = {}, registerGoodsThread = {}", goodsManagementRequest.getGoodsNm(), Thread.currentThread().getName()); //ForkJoinPool.commonPool-worker-1 - return goodsService.save(goodsManagementRequest.toServiceDto()); //등록 - - }).thenApplyAsync( - //dto -> + CompletableFuture goodsResponseFuture = goodsService.save(goodsManagementRequest.toDto()).thenApplyAsync( (goodsManagement) -> { - log.error("goodsName = {}, goodsNo = {}", goodsManagementRequest.getGoodsNm(), goodsManagement.getGoodsNo()); + log.error("saveAfter goodsName = {}, goodsNo = {}", goodsManagement.getGoodsNm(), goodsManagement.getGoodsNo()); log.error("registerGoodsThread thenApplyAsync = {}", Thread.currentThread().getName()); //ForkJoinPool.commonPool-worker-1 - GoodsManagementResponse response = GoodsManagementResponse.toResponseDto(goodsManagement); + GoodsManagementResponse response = GoodsManagementResponse.fromDto(goodsManagement); response.updateSuccess("0000", "등록성공"); return response; } + ).thenApplyAsync( + (response) -> { + if("0000".equals(response.getResultCode())){ + smsService.smsMessage(response.getGoodsNo()); //Cosmetics-Thread-Pool1 + } + return response; + } ); - - //등록에 성공하면 메세지를 보낸다고 가정 - if ("0000".equals(goodsResponseFuture.get().getResultCode())) { - smsService.smsMessage(goodsResponseFuture.get().getGoodsNo()); //Cosmetics-Thread-Pool1 - } return goodsResponseFuture; } + @DeleteMapping(value = "/{goodsNo}") public GoodsManagementResponse deleteGoods(@PathVariable Long goodsNo) { log.error("deleteGoods : {}", goodsNo); GoodsManagement goodsManagement = goodsService.deleteByGoodsNo(goodsNo); //dto -> responseDto - GoodsManagementResponse responseGoodsManagement = GoodsManagementResponse.toResponseDto(goodsManagement); + GoodsManagementResponse responseGoodsManagement = GoodsManagementResponse.fromDto(goodsManagement); responseGoodsManagement.updateSuccess("0000", "삭제성공"); return responseGoodsManagement; } diff --git a/module-api/src/main/java/com/cosmetics/config/AsyncConfig.java b/module-api/src/main/java/com/cosmetics/config/AsyncConfig.java index 8792535..ff7612c 100644 --- a/module-api/src/main/java/com/cosmetics/config/AsyncConfig.java +++ b/module-api/src/main/java/com/cosmetics/config/AsyncConfig.java @@ -1,6 +1,9 @@ package com.cosmetics.config; +import com.cosmetics.api.exception.handler.CosmeticsAsyncExceptionHandler; +import com.cosmetics.api.exception.handler.CosmeticsExceptionHandler; import lombok.extern.slf4j.Slf4j; +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.EnableAsync; @@ -30,4 +33,8 @@ public Executor getAsyncExecutor() { //상황에 따라 최소 스레드 수 최대 스레드 수 대기 큐의 크기를 조절해야하는데 그 상황이 어떤 상황에 따라 어떤 걸 보고 어떻게 지정해야할 지 //궁금합니다 } + @Override + public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + return new CosmeticsAsyncExceptionHandler(); + } } diff --git a/module-api/src/test/java/com/cosmetics/api/application/GoodsApiApplicationTest.java b/module-api/src/test/java/com/cosmetics/api/application/GoodsApiApplicationTest.java index 0dc5fae..a5f8894 100644 --- a/module-api/src/test/java/com/cosmetics/api/application/GoodsApiApplicationTest.java +++ b/module-api/src/test/java/com/cosmetics/api/application/GoodsApiApplicationTest.java @@ -112,7 +112,7 @@ private static GoodsManagementRequest requestGoods(int i) { String url = "http://localhost:" + port + "/v1/goods/{goodsNo}"; ResponseEntity responseEntity = testRestTemplate.getForEntity(url, GoodsManagementResponse.class, goodsNo); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(responseEntity.getBody().getGoodsNm()).isEqualTo("닥터스킨"); + assertThat(responseEntity.getBody().getGoodsNm()).isEqualTo("닥터스"); } @DisplayName("상품 삭제") diff --git a/module-api/src/test/java/com/cosmetics/controller/VendControllerTest.java b/module-api/src/test/java/com/cosmetics/controller/VendControllerTest.java index 7de659f..eb5cde6 100644 --- a/module-api/src/test/java/com/cosmetics/controller/VendControllerTest.java +++ b/module-api/src/test/java/com/cosmetics/controller/VendControllerTest.java @@ -41,7 +41,7 @@ public void validVendorTest() throws Exception { .andDo(print()) .andExpect(jsonPath("errorCode").value("INVALID_PARAMETER")) .andExpect(jsonPath("errorMessage").value("유효하지 않는 값입니다")) - .andExpect(jsonPath("$.fieldErrorList[0].field").value(anyOf(is("vendorNm"), is("postNo")))) + .andExpect(jsonPath("$.fieldErrorList[0].field").value(anyOf(is("vendorNm"), is("postNo"), is("addr")))) .andExpect(jsonPath("$.fieldErrorList[0].message").value("must not be blank")); } diff --git a/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagement.java b/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagement.java index 8525839..c21d690 100644 --- a/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagement.java +++ b/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagement.java @@ -69,7 +69,7 @@ public GoodsManagement(Long goodsNo, this.addImage = addImage; } - public static GoodsManagement toDto(GoodsManagementEntity goodsManagementEntity) { + public static GoodsManagement fromEntity(GoodsManagementEntity goodsManagementEntity) { return GoodsManagement.builder() .goodsNo(goodsManagementEntity.getGoodsNo()) .goodsNm(goodsManagementEntity.getGoodsNm()) diff --git a/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagementRequest.java b/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagementRequest.java index 6344c58..0ce1daf 100644 --- a/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagementRequest.java +++ b/module-domain/src/main/java/com/cosmetics/domain/goods/dto/GoodsManagementRequest.java @@ -95,7 +95,7 @@ public List toGoodsItemManagementList(List new IllegalArgumentException("상품이 존재하지 않습니다.")); - //entity -> dto - return GoodsManagement.toDto(goodsManagementEntity); + public CompletableFuture findByGoodsNo(Long goodsNo) { + return CompletableFuture.supplyAsync(() -> { + log.error("GoodsService Thread = {}", Thread.currentThread().getName()); + GoodsManagementEntity goodsManagementEntity = goodsRepository.findByGoodsNo(goodsNo).orElseThrow(() -> new IllegalArgumentException("상품이 존재하지 않습니다.")); + return GoodsManagement.fromEntity(goodsManagementEntity); + }); } @Transactional - public GoodsManagement save(GoodsManagement goodsManagement) { - //Service단은 따로 작업을 안했는데 이게 맞을까요? - GoodsManagementEntity resultGoodsManagementEntity = goodsRepository.save(goodsManagement.toEntity()); - - //entity -> dto - return GoodsManagement.toDto(resultGoodsManagementEntity); + public CompletableFuture save(GoodsManagement goodsManagement) { + CompletableFuture goodsManageFuture = CompletableFuture.supplyAsync(() -> { + log.error("GoodsService Thread = {}", Thread.currentThread().getName()); + GoodsManagementEntity resultGoodsManagementEntity = goodsRepository.save(goodsManagement.toEntity()); + return GoodsManagement.fromEntity(resultGoodsManagementEntity); + }); + return goodsManageFuture; } @Transactional public GoodsManagement deleteByGoodsNo(Long goodsNo) { GoodsManagementEntity goodsManagementEntity = goodsRepository.findByGoodsNo(goodsNo).orElseThrow(() -> new IllegalArgumentException("상품이 존재하지 않습니다.")); long deleteCnt = goodsRepository.deleteByGoodsNo(goodsNo); - //entity -> dto - return GoodsManagement.toDto(goodsManagementEntity); + return GoodsManagement.fromEntity(goodsManagementEntity); } }