diff --git a/src/main/java/com/interplug/qcast/biz/user/UserMapper.java b/src/main/java/com/interplug/qcast/biz/user/UserMapper.java index d2ad3b01..da8ae562 100644 --- a/src/main/java/com/interplug/qcast/biz/user/UserMapper.java +++ b/src/main/java/com/interplug/qcast/biz/user/UserMapper.java @@ -55,22 +55,22 @@ public interface UserMapper { int setUserSave(UserRequest userReqList) throws Exception; /** - * 판매점의 등록 여부 체크 + * 판매점 가격 패턴 조회 * * @param storeReq * @return * @throws Exception */ - int getStoreChk(StoreRequest storeReq) throws Exception; + String getStorePricePattern(StoreRequest storeReq) throws Exception; /** - * 판매점의 가격 등록 여부 체크 + * 판매점의 정가가격 삭제 * * @param storeReq * @return * @throws Exception */ - int getStoreUnitPriceChk(StoreRequest storeReq) throws Exception; + int deleteStoreUnitPrice(StoreRequest storeReq) throws Exception; /** * 판매점의 정가가격 등록 diff --git a/src/main/java/com/interplug/qcast/biz/user/UserService.java b/src/main/java/com/interplug/qcast/biz/user/UserService.java index 69c8729a..514f8f4d 100644 --- a/src/main/java/com/interplug/qcast/biz/user/UserService.java +++ b/src/main/java/com/interplug/qcast/biz/user/UserService.java @@ -2,6 +2,7 @@ package com.interplug.qcast.biz.user; import com.interplug.qcast.biz.user.dto.*; import com.interplug.qcast.util.InterfaceQsp; +import io.micrometer.common.util.StringUtils; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -27,18 +28,19 @@ public class UserService { * @throws Exception */ public int setStoreSave(StoreRequest storeReq) throws Exception { - int storeChk = userMapper.getStoreChk(storeReq); + String prevPricePattern = userMapper.getStorePricePattern(storeReq); // 등록된 가격 랭크 조회 + String pricePattern = + StringUtils.isEmpty(storeReq.getPricePattern()) ? "" : storeReq.getPricePattern(); int resultCnt = userMapper.setStoreSave(storeReq); userMapper.setStoreInfoSave(storeReq); userMapper.setStoreSapCdSave(storeReq); userMapper.setStoreNorthModuleSave(storeReq); - // 신규판매점 등록 이면서 판매점 가격이 등록이 안되어 있는 경우 추가 - if (storeReq.getPricePattern() != null - && storeChk == 0 - && userMapper.getStoreUnitPriceChk(storeReq) == 0) { - // 등록된 가격이 없는경우 정가 가격 등록 + // 가격 패턴이 이전에 등록된 가격 패턴과 다른경우 적용 + if (storeReq.getPricePattern() != null && !prevPricePattern.equals(pricePattern)) { + // 등록된 가격이 없는경우 정가 가격 삭제후 저장 + userMapper.deleteStoreUnitPrice(storeReq); userMapper.setStoreUnitPrice(storeReq); } return resultCnt; @@ -80,17 +82,21 @@ public class UserService { // 판매점 동기화 for (StoreRequest storeRequest : storeList) { try { - int storeChk = userMapper.getStoreChk(storeRequest); + String prevPricePattern = userMapper.getStorePricePattern(storeRequest); // 등록된 가격 랭크 조회 + String pricePattern = + StringUtils.isEmpty(storeRequest.getPricePattern()) + ? "" + : storeRequest.getPricePattern(); + userMapper.setStoreSave(storeRequest); userMapper.setStoreInfoSave(storeRequest); userMapper.setStoreSapCdSave(storeRequest); userMapper.setStoreNorthModuleSave(storeRequest); - // 신규판매점 등록 이면서 판매점 가격이 등록이 안되어 있는 경우 추가 - if (storeRequest.getPricePattern() != null - && storeChk == 0 - && userMapper.getStoreUnitPriceChk(storeRequest) == 0) { - // 등록된 가격이 없는경우 정가 가격 등록 + // 가격 패턴이 이전에 등록된 가격 패턴과 다른경우 적용 + if (storeRequest.getPricePattern() != null && !prevPricePattern.equals(pricePattern)) { + // 등록된 가격이 없는경우 정가 가격 삭제후 저장 + userMapper.deleteStoreUnitPrice(storeRequest); userMapper.setStoreUnitPrice(storeRequest); } } catch (Exception e) { @@ -161,17 +167,19 @@ public class UserService { List storeList = storeSyncResponse.getStoreList(); for (StoreRequest storeRequest : storeList) { - int storeChk = userMapper.getStoreChk(storeRequest); + String prevPricePattern = userMapper.getStorePricePattern(storeRequest); // 등록된 가격 랭크 조회 + String pricePattern = + StringUtils.isEmpty(storeRequest.getPricePattern()) ? "" : storeRequest.getPricePattern(); + userMapper.setStoreSave(storeRequest); userMapper.setStoreInfoSave(storeRequest); userMapper.setStoreSapCdSave(storeRequest); userMapper.setStoreNorthModuleSave(storeRequest); - // 신규판매점 등록 이면서 판매점 가격이 등록이 안되어 있는 경우 추가 - if (storeRequest.getPricePattern() != null - && storeChk == 0 - && userMapper.getStoreUnitPriceChk(storeRequest) == 0) { - // 등록된 가격이 없는경우 정가 가격 등록 + // 가격 패턴이 이전에 등록된 가격 패턴과 다른경우 적용 + if (storeRequest.getPricePattern() != null && !prevPricePattern.equals(pricePattern)) { + // 등록된 가격이 없는경우 정가 가격 삭제후 저장 + userMapper.deleteStoreUnitPrice(storeRequest); userMapper.setStoreUnitPrice(storeRequest); } } diff --git a/src/main/resources/mappers/user/userMapper.xml b/src/main/resources/mappers/user/userMapper.xml index 4e8ee2e8..136d287e 100644 --- a/src/main/resources/mappers/user/userMapper.xml +++ b/src/main/resources/mappers/user/userMapper.xml @@ -87,7 +87,7 @@ , DISP_FAX = #{dispFax} , DISP_MAIL = #{dispMail} , SALE_STORE_LEVEL = #{saleStoreLevel} - , PRICE_PATTERN = (CASE WHEN ISNULL(PRICE_PATTERN, '') = '' AND #{secondAgentFlg} = '1' THEN '510' ELSE PRICE_PATTERN END) + , PRICE_PATTERN = #{pricePattern} , DEL_FLG = #{delFlg} , LAST_EDIT_DATETIME = GETDATE() , LAST_EDIT_USER = #{lastEditUser} @@ -145,7 +145,7 @@ , #{secondAgentFlg} , #{firstAgentId} , #{parentSaleAgentId} - , (CASE WHEN #{secondAgentFlg} = '1' THEN '510' ELSE NULL END) + , #{pricePattern} , 0 -- 출력 대비표 분류 , 0 -- 산업출력 대비표 출력 , 0 -- 정가 표시 @@ -257,23 +257,20 @@ ); - + /* sqlid : com.interplug.qcast.user.getStorePricePattern */ SELECT - COUNT(1) + PRICE_PATTERN FROM M_SALES_STORE WHERE SALE_STORE_ID = #{saleStoreId} - + + /* sqlid : com.interplug.qcast.user.deleteStoreUnitPrice */ + DELETE FROM M_SALE_STORE_PRICE + WHERE SALE_STORE_ID = #{saleStoreId} + /* sqlid : com.interplug.qcast.user.setStoreUnitPrice */