瀏覽代碼

로그인 후 장바구니 Update

gagamel 5 年之前
父節點
當前提交
76a8cb710c

+ 168 - 116
src/main/java/com/style24/front/biz/dao/TsfCartDao.java

@@ -15,120 +15,172 @@ import com.style24.persistence.domain.Order;
  */
 @ShopDs
 public interface TsfCartDao {
-    /**
-     * 장바구니 대상 상품 수량 조회
-     * @param Cart
-     * @return
-     * @author xodud1202
-     * @since 2021. 02. 01
-     */
-   int getHasGoodsCartCnt(Cart cart);
-
-    /**
-     * 장바구니 등록 상품 확인
-     * @param Cart
-     * @return
-     * @author xodud1202
-     * @since 2021. 02. 01
-     */
-    Collection<Integer> selectHasSetItemCartList(Cart param);
-
-    /**
-     * 장바구니 등록 상품 확인
-     * @param Cart
-     * @return
-     * @author xodud1202
-     * @since 2021. 02. 01
-     */
-    Collection<Integer> selectHasNormalDealItemCartList(Cart param);
-
-    /**
-     * 장바구니 신규 등록
-     * @param Cart
-     * @return void
-     * @author xodud1202
-     * @since 2021. 02. 01
-     */
-    void insertCartInfo(Cart param);
-
-    /**
-     * 장바구니 상세 신규 등록
-     * @param Cart
-     * @return void
-     * @author xodud1202
-     * @since 2021. 02. 01
-     */
-    void insertCartDetailInfo(Cart param);
-
-    /**
-     * 장바구니 상세 신규 등록
-     * @param Cart
-     * @return void
-     * @author xodud1202
-     * @since 2021. 02. 01
-     */
-    void updateCartInfo(Cart param);
-
-    /**
-     * 장바구니 이력 정보 저장
-     * @param Cart
-     * @return void
-     * @author xodud1202
-     * @since 2021. 02. 02
-     */
-    void insertCartHst(Cart param);
-
-    /**
-     * 장바구니 상세 이력 정보 저장
-     * @param Cart
-     * @return void
-     * @author xodud1202
-     * @since 2021. 02. 02
-     */
-    void insertCartDetailHst(Cart param);
-
-    /**
-     * 다다익선 기본 상품 조회
-     * @param Cart
-     * @return void
-     * @author xodud1202
-     * @since 2021. 02. 04
-     */
-    Collection<Order> selectMoreBetterApplyCartList(Order param);
-
-   /**
-    * 다다익선 적용 상품 SUM DATA 조회
-    * @param Cart
-    * @return void
-    * @author xodud1202
-    * @since 2021. 02. 04
-    */
-   Collection<Order> selectApplyMoreBetterCartInfoList(Order param);
-
-    /**
-     * 다다익선 SECTION 적용 조건 조회
-     * @param List<Integer>
-     * @return Collection<Order>
-     * @author xodud1202
-     * @since 2021. 02. 04
-     */
-    Collection<Order> selectTmtbSectionValList(List<Integer> param);
-
-    /**
-     * 장바구니 상품 조회
-     * @param Order
-     * @return Order
-     * @author xodud1202
-     * @since 2021. 02. 08
-     */
-    Collection<Order> getCartGoodsList(Order param);
-
-    /**
-     * 장바구니 상품 조회
-     * @param Order
-     * @return Order
-     * @author xodud1202
-     * @since 2021. 02. 08
-     */
-    Collection<Order> getCartListDelvFeeInfoList(Order param);
+
+	/**
+	 * 장바구니 대상 상품 수량 조회
+	 * @param Cart
+	 * @return
+	 * @author xodud1202
+	 * @since 2021. 02. 01
+	 */
+	int getHasGoodsCartCnt(Cart cart);
+
+	/**
+	 * 장바구니 등록 상품 확인
+	 * @param Cart
+	 * @return
+	 * @author xodud1202
+	 * @since 2021. 02. 01
+	 */
+	Collection<Integer> selectHasSetItemCartList(Cart param);
+
+	/**
+	 * 장바구니 등록 상품 확인
+	 * @param Cart
+	 * @return
+	 * @author xodud1202
+	 * @since 2021. 02. 01
+	 */
+	Collection<Integer> selectHasNormalDealItemCartList(Cart param);
+
+	/**
+	 * 장바구니 신규 등록
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 01
+	 */
+	void insertCartInfo(Cart param);
+
+	/**
+	 * 장바구니 상세 신규 등록
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 01
+	 */
+	void insertCartDetailInfo(Cart param);
+
+	/**
+	 * 장바구니 상세 신규 등록
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 01
+	 */
+	void updateCartInfo(Cart param);
+
+	/**
+	 * 장바구니 이력 정보 저장
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 02
+	 */
+	void insertCartHst(Cart param);
+
+	/**
+	 * 장바구니 상세 이력 정보 저장
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 02
+	 */
+	void insertCartDetailHst(Cart param);
+
+	/**
+	 * 다다익선 기본 상품 조회
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 04
+	 */
+	Collection<Order> selectMoreBetterApplyCartList(Order param);
+
+	/**
+	 * 다다익선 적용 상품 SUM DATA 조회
+	 * @param Cart
+	 * @return void
+	 * @author xodud1202
+	 * @since 2021. 02. 04
+	 */
+	Collection<Order> selectApplyMoreBetterCartInfoList(Order param);
+
+	/**
+	 * 다다익선 SECTION 적용 조건 조회
+	 * @param List<Integer>
+	 * @return Collection<Order>
+	 * @author xodud1202
+	 * @since 2021. 02. 04
+	 */
+	Collection<Order> selectTmtbSectionValList(List<Integer> param);
+
+	/**
+	 * 장바구니 상품 조회
+	 * @param Order
+	 * @return Order
+	 * @author xodud1202
+	 * @since 2021. 02. 08
+	 */
+	Collection<Order> getCartGoodsList(Order param);
+
+	/**
+	 * 장바구니 상품 조회
+	 * @param Order
+	 * @return Order
+	 * @author xodud1202
+	 * @since 2021. 02. 08
+	 */
+	Collection<Order> getCartListDelvFeeInfoList(Order param);
+
+	/**
+	 * 장바구니담긴상품 고객번호 Update
+	 * @param cart - 장바구니 정보
+	 * @return 처리건수
+	 * @author gagamel
+	 * @date 2021. 2. 24
+	 */
+	int updateCartOfCustNo(Cart cart);
+
+	/**
+	 * 로그인 후 처리할 장바구니 목록 조회
+	 * @param cart - 장바구니 정보
+	 * @return
+	 * @author gagamel
+	 * @date 2021. 2. 24
+	 */
+	Collection<Cart> getCartListAfterLogin(Cart cart);
+
+	/**
+	 * 로그인 후 장바구니 수정
+	 * @param cart - 장바구니 정보
+	 * @author gagamel
+	 * @date 2021. 2. 24
+	 */
+	void updateCartAfterLogin(Cart cart);
+
+	/**
+	 * 로그인 후 장바구니단품 삭제
+	 * @param cart - 장바구니 정보
+	 * @author gagamel
+	 * @date 2021. 2. 24
+	 */
+	void deleteCartItemAfterLogin(Cart cart);
+
+	/**
+	 * 로그인 후 장바구니 삭제
+	 * @param cart - 장바구니 정보
+	 * @author gagamel
+	 * @date 2021. 2. 24
+	 */
+	void deleteCartAfterLogin(Cart cart);
+
+	/**
+	 * 로그인 후 장바구니이력 생성
+	 * @param cart - 장바구니 정보
+	 * @author gagamel
+	 * @date 2021. 2. 24
+	 */
+	void createCartHistoryAfterLogin(Cart cart);
+
 }

+ 116 - 77
src/main/java/com/style24/front/biz/service/TsfCartService.java

@@ -2,29 +2,26 @@ package com.style24.front.biz.service;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.thymeleaf.util.StringUtils;
 
-import com.gagaframework.web.parameter.GagaMap;
 import com.style24.core.biz.service.TscOrderService;
 import com.style24.core.support.env.TscConstants;
 import com.style24.core.support.session.TscSession;
 import com.style24.front.biz.dao.TsfCartDao;
 import com.style24.front.support.security.session.TsfSession;
 import com.style24.persistence.domain.Cart;
-import com.style24.persistence.domain.Coupon;
 import com.style24.persistence.domain.Goods;
 import com.style24.persistence.domain.GoodsStock;
 import com.style24.persistence.domain.Order;
 
 import lombok.extern.slf4j.Slf4j;
 
+import com.gagaframework.web.parameter.GagaMap;
+
 /**
  * 장바구니 Service
  *
@@ -54,12 +51,11 @@ public class TsfCartService {
 		Cart cart = new Cart();
 		// JSESSION_ID 저장
 
-
 		// 로그인 유무 확인 (로그인이 되어 있지 않으면 regNo 를 0으로 장바구니에 저장한다.)
 		// TODO 로그인여부체크
 
 		// 장바구니 상품 및 재고 가능 여부 체크
-		for(Cart param : params) {
+		for (Cart param : params) {
 			cart.setJsessionId(TscSession.getSessionId());
 			cart.setRegNo(0);
 			cart.setUpdNo(0);
@@ -71,7 +67,7 @@ public class TsfCartService {
 			if (goods == null) {
 				throw new IllegalArgumentException("상품 정보가 존재하지 않습니다.");
 			}
-			if(TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
+			if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
 				throw new IllegalArgumentException("품절입니다.");
 			}
 
@@ -84,13 +80,13 @@ public class TsfCartService {
 			checkParam.setGoodsType(param.getGoodsType());
 			String stockResult = goodsService.getCheckStock(checkParam);
 
-			if(!"SUCCESS".equals(stockResult)) {
+			if (!"SUCCESS".equals(stockResult)) {
 				throw new IllegalArgumentException(stockResult);
 			}
 
 			cart.setGoodsCd(param.getGoodsCd());
 			int goodsCartCnt = cartDao.getHasGoodsCartCnt(param);
-			if(param.getGoodsQty() + goodsCartCnt > goods.getDayMaxOrdQty()) {
+			if (param.getGoodsQty() + goodsCartCnt > goods.getDayMaxOrdQty()) {
 				throw new IllegalArgumentException("1일 구매한도 수량이 초과되었습니다.");
 			}
 
@@ -98,7 +94,7 @@ public class TsfCartService {
 		}
 
 		// 장바구니 정보 수정
-		if(cart.getGoodsType().equals(TscConstants.GoodsType.SET.value())) {
+		if (cart.getGoodsType().equals(TscConstants.GoodsType.SET.value())) {
 			// 세트상품일 경우
 			saveSetTypeCartInfo(params);
 		} else {
@@ -122,16 +118,16 @@ public class TsfCartService {
 
 		// 장바구니 보유 CART_SQ 쿼리
 		int i = 1;
-		for(Cart param : params) {
+		for (Cart param : params) {
 			sb.append("SELECT CD.CART_SQ \n FROM TB_CART_DETAIL CD \n INNER JOIN TB_CART C \n ON CD.CART_SQ = C.CART_SQ \n WHERE C.CUST_NO = ");
 			// TODO 로그인 정보 확인
-			if(cart.getCustNo() == 0) {
+			if (cart.getCustNo() == 0) {
 				sb.append(cart.getCustNo()).append("\n AND JSESSION_ID = '").append(cart.getJsessionId()).append("'");
 			} else {
 				sb.append(cart.getCustNo());
 			}
 			sb.append("\n AND CD.ITEM_CD = '").append(param.getItemCd()).append("' \n AND CD.OPT_CD = '").append(param.getOptCd()).append("'");
-			if(i < params.size()) {
+			if (i < params.size()) {
 				i++;
 				sb.append("\n UNION ALL \n");
 			}
@@ -147,10 +143,10 @@ public class TsfCartService {
 		cart.setGoodsType(params.iterator().next().getGoodsType());
 		cart.setItemCdSql(sb.toString());
 
-		if("C".equals(params.iterator().next().getCartGb())) {
+		if ("C".equals(params.iterator().next().getCartGb())) {
 			cart.setCartGb(TscConstants.CartGb.CART.value());
-		} else if("O".equals(params.iterator().next().getCartGb())) {
-			if("P".equals(TsfSession.getFrontGb())) {
+		} else if ("O".equals(params.iterator().next().getCartGb())) {
+			if ("P".equals(TsfSession.getFrontGb())) {
 				cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
 			} else {
 				cart.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
@@ -162,8 +158,8 @@ public class TsfCartService {
 		// 같은 장바구니 상품 확인
 		Collection<Integer> cartSqList = cartDao.selectHasSetItemCartList(cart);
 
-		if(cartSqList != null && cartSqList.size() > 0) {		// 장바구니 기존재
-			if(cartSqList.size() > 1) {							// 장바구니 조회 결과 이상시 insert or select 수정 필요
+		if (cartSqList != null && cartSqList.size() > 0) {		// 장바구니 기존재
+			if (cartSqList.size() > 1) {							// 장바구니 조회 결과 이상시 insert or select 수정 필요
 				throw new IllegalArgumentException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
 			} else {
 				cart.setCartSq(cartSqList.iterator().next());
@@ -173,7 +169,7 @@ public class TsfCartService {
 		} else {
 			cartDao.insertCartInfo(cart);					// 장바구니 마스터 정보 저장
 			cartDao.insertCartHst(cart);                    // 장바구니 이력 정보 저장
-			for(Cart param : params) {
+			for (Cart param : params) {
 				param.setCartSq(cart.getCartSq());
 				param.setRegNo(cart.getRegNo());
 				param.setCustNo(cart.getCustNo());
@@ -193,10 +189,10 @@ public class TsfCartService {
 		param.setCustNo(1000006);
 		param.setUpdNo(1000006);
 
-		if("C".equals(param.getCartGb())) {
+		if ("C".equals(param.getCartGb())) {
 			param.setCartGb(TscConstants.CartGb.CART.value());
-		} else if("O".equals(param.getCartGb())) {
-			if("P".equals(TsfSession.getFrontGb())) {
+		} else if ("O".equals(param.getCartGb())) {
+			if ("P".equals(TsfSession.getFrontGb())) {
 				param.setCartGb(TscConstants.CartGb.PC_ORDER.value());
 			} else {
 				param.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
@@ -208,8 +204,8 @@ public class TsfCartService {
 		// 같은 장바구니 상품 확인
 		Collection<Integer> cartSqList = cartDao.selectHasNormalDealItemCartList(param);
 
-		if(cartSqList != null && cartSqList.size() > 0) {		// 장바구니 기존재
-			if(cartSqList.size() > 1) {							// 장바구니 조회 결과 이상시 insert or select 수정 필요
+		if (cartSqList != null && cartSqList.size() > 0) {		// 장바구니 기존재
+			if (cartSqList.size() > 1) {							// 장바구니 조회 결과 이상시 insert or select 수정 필요
 				throw new IllegalArgumentException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
 			} else {
 				param.setCartSq(cartSqList.iterator().next());
@@ -245,8 +241,8 @@ public class TsfCartService {
 		Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
 
 		// 품절 아닌 상품만 체크
-		for(Order goods : cartGoodsList) {
-			if("N".equals(goods.getSoldoutYn())) {
+		for (Order goods : cartGoodsList) {
+			if ("N".equals(goods.getSoldoutYn())) {
 				cartSqs.add(goods.getCartSq());
 			}
 		}
@@ -257,9 +253,9 @@ public class TsfCartService {
 		Collection<Order> moreBetterAmtList = getMoreBetterAmtList(order);
 
 		// 다다익선 할인 정보 및 상품 정보 장바구니에 등록
-		for(Order cart : cartGoodsList) {
-			for(Order info : moreBetterAmtList) {
-				if(cart.getCartSq() == info.getCartSq()) {
+		for (Order cart : cartGoodsList) {
+			for (Order info : moreBetterAmtList) {
+				if (cart.getCartSq() == info.getCartSq()) {
 					cart.setTmtbDcAmt(info.getTmtbDcAmt());
 					cart.setApplyAmtSectionYn(info.getApplyAmtSectionYn());
 					cart.setApplyQtySectionYn(info.getApplyQtySectionYn());
@@ -269,11 +265,11 @@ public class TsfCartService {
 					cart.setAmtTmtbSq(info.getAmtTmtbSq());
 				}
 			}
-			if(cart.getCartSq() == 8) {
-				log.info("CHECK CART >> {}, {}, {}",cart.getCurrPrice(),cart.getGoodsQty(), cart.getTmtbDcAmt());
+			if (cart.getCartSq() == 8) {
+				log.info("CHECK CART >> {}, {}, {}", cart.getCurrPrice(), cart.getGoodsQty(), cart.getTmtbDcAmt());
 			}
 
-			if(cart.getTmtbDcAmt() == 0) {
+			if (cart.getTmtbDcAmt() == 0) {
 				cart.setTmtbDcAmt(cart.getCurrPrice() * cart.getGoodsQty());
 			}
 		}
@@ -310,12 +306,12 @@ public class TsfCartService {
 		List<Integer> applySq = new ArrayList<Integer>();
 		List<Integer> qtyApplySq = new ArrayList<Integer>();
 		List<Integer> amtApplySq = new ArrayList<Integer>();
-		for(Order tmtbApply : tmtbApplyList) {
-			if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb()) || TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
-				if(tmtbApply.getQtyTmtbSq() > 0) {
+		for (Order tmtbApply : tmtbApplyList) {
+			if (TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb()) || TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
+				if (tmtbApply.getQtyTmtbSq() > 0) {
 					applySq.add(tmtbApply.getQtyTmtbSq());
 				}
-				if(tmtbApply.getAmtTmtbSq() > 0) {
+				if (tmtbApply.getAmtTmtbSq() > 0) {
 					applySq.add(tmtbApply.getAmtTmtbSq());
 				}
 			}
@@ -324,10 +320,10 @@ public class TsfCartService {
 
 		// 섹션 정보 조회 후 할인 여부 판단
 		Collection<Order> tmtbQtySectionList = cartDao.selectTmtbSectionValList(applySq);
-		for(Order applyInfo : tmtbApplyList) {								// 기준 상품 및 다다익선 정보 조회
+		for (Order applyInfo : tmtbApplyList) {								// 기준 상품 및 다다익선 정보 조회
 			// 다다익선 할인 조건 조회
-			for(Order section : tmtbQtySectionList) {
-				if(applyInfo.getQtyTmtbSq() == section.getTmtbSq()) {
+			for (Order section : tmtbQtySectionList) {
+				if (applyInfo.getQtyTmtbSq() == section.getTmtbSq()) {
 
 					// 수량 적용 다다익선
 					if (section.getSectionVal() <= applyInfo.getQtyTmtbSumQty()) {                // 장바구니 수량 할인 기준 달성시
@@ -344,17 +340,17 @@ public class TsfCartService {
 					}
 				}
 
-				if(applyInfo.getAmtTmtbSq() == section.getTmtbSq()) {
+				if (applyInfo.getAmtTmtbSq() == section.getTmtbSq()) {
 					// 금액 적용 다다익선
-					if(section.getSectionVal() <= applyInfo.getAmtTmtbSumAmt()) {				// 장바구니 수량 할인 기준 달성시
-						if(applyInfo.getSectionVal() <= section.getSectionVal()) {			// 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
+					if (section.getSectionVal() <= applyInfo.getAmtTmtbSumAmt()) {				// 장바구니 수량 할인 기준 달성시
+						if (applyInfo.getSectionVal() <= section.getSectionVal()) {			// 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
 							applyInfo.setSectionVal(section.getSectionVal());
 							applyInfo.setApplyAmtSectionYn("Y");
 							applyInfo.setDcWay(section.getDcWay());
 							applyInfo.setDcVal(section.getDcVal());
 						}
 					} else {
-						if(applyInfo.getSectionVal() < 1 && applyInfo.getAmtGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
+						if (applyInfo.getSectionVal() < 1 && applyInfo.getAmtGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
 							applyInfo.setApplyAmtSectionYn("N");
 						}
 					}
@@ -365,8 +361,8 @@ public class TsfCartService {
 		// 수량 다다익선 적용 상품 할인 금액 계산
 		int leftAmt = 0;
 		int i = 0;
-		for(Order resultAmt : tmtbApplyList) {
-			if("Y".equals(resultAmt.getApplyQtySectionYn())) {
+		for (Order resultAmt : tmtbApplyList) {
+			if ("Y".equals(resultAmt.getApplyQtySectionYn())) {
 				if (TscConstants.DcWay.AMT.value().equals(resultAmt.getDcWay())) {        // 할인 방식 금액일경우
 					i++;
 					int tempAmt = resultAmt.getCurrPrice();
@@ -385,12 +381,12 @@ public class TsfCartService {
 					}
 				} else {                                                                // 할인 방식 할인율일 경우
 					int tempAmt = resultAmt.getCurrPrice();
-					tempAmt = (int) (tempAmt - (tempAmt * (resultAmt.getDcVal() / 100.0)));
+					tempAmt = (int)(tempAmt - (tempAmt * (resultAmt.getDcVal() / 100.0)));
 					resultAmt.setTmtbDcAmt(tempAmt);
 				}
 			}
 
-			if(resultAmt.getTmtbDcAmt() > 0) {
+			if (resultAmt.getTmtbDcAmt() > 0) {
 				resultAmt.setCurrPrice(resultAmt.getTmtbDcAmt());
 			} else {
 				resultAmt.setCurrPrice(resultAmt.getCurrPrice());
@@ -400,8 +396,8 @@ public class TsfCartService {
 		// 금액 다다익선 할인 계산
 		leftAmt = 0;
 		i = 0;
-		for(Order resultAmt : tmtbApplyList) {
-			if("Y".equals(resultAmt.getApplyAmtSectionYn())) {
+		for (Order resultAmt : tmtbApplyList) {
+			if ("Y".equals(resultAmt.getApplyAmtSectionYn())) {
 				if (TscConstants.DcWay.AMT.value().equals(resultAmt.getDcWay())) {        // 할인 방식 금액일경우
 					i++;
 					int tempAmt = resultAmt.getCurrPrice();
@@ -420,16 +416,16 @@ public class TsfCartService {
 					}
 				} else {                                                                // 할인 방식 할인율일 경우
 					int tempAmt = resultAmt.getCurrPrice();
-					tempAmt = (int) (tempAmt - (tempAmt * (resultAmt.getDcVal() / 100.0)));
+					tempAmt = (int)(tempAmt - (tempAmt * (resultAmt.getDcVal() / 100.0)));
 					resultAmt.setTmtbDcAmt(tempAmt);
 				}
 			}
 		}
 
 		// 장바구니 정보에 수량 다다익선 정보 입력
-		for(Order cart : cartGoodsList) {
-			for(Order apply : tmtbApplyList) {
-				if(cart.getCartSq() == apply.getCartSq()) {
+		for (Order cart : cartGoodsList) {
+			for (Order apply : tmtbApplyList) {
+				if (cart.getCartSq() == apply.getCartSq()) {
 					cart.setTmtbDcAmt(apply.getTmtbDcAmt());
 					cart.setApplyQtySectionYn(apply.getApplyQtySectionYn());
 					cart.setQtyTmtbNm(apply.getQtyTmtbNm());
@@ -457,8 +453,8 @@ public class TsfCartService {
 		// 1. 장바구니 상품 배송단위별 건수 체크 로직 (자사:총알배송, 자사:일반배송, 입점업체, 예약배송)
 		Order delvOrder = new Order();
 
-		Collection<Order> wmsCartList 	= new ArrayList<Order>();
-		Collection<Order> delvCartList 	= new ArrayList<Order>();
+		Collection<Order> wmsCartList = new ArrayList<Order>();
+		Collection<Order> delvCartList = new ArrayList<Order>();
 
 		for (Order order : cartGoodsList) {
 			// 1.1 세트상품 옵션별 배열로 담기
@@ -495,7 +491,7 @@ public class TsfCartService {
 		List<Integer> cartSqArr = new ArrayList<Integer>();
 
 		// 장바구니 일련번호 세팅
-		for(Order param : params) {
+		for (Order param : params) {
 			cartSqArr.add(param.getCartSq());
 		}
 		delvInfo.setCartSqArr(cartSqArr.stream().mapToInt(Integer::intValue).toArray());
@@ -505,16 +501,16 @@ public class TsfCartService {
 
 		// 업체별 상품 합계 금액 저장
 		int compCnt = 0;
-		for(Order delv : delvFeeInfo) {
+		for (Order delv : delvFeeInfo) {
 			compCnt = 0;
-			for(Order param : params) {
-				if(param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {
+			for (Order param : params) {
+				if (param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {
 					compCnt++;
-					if("N".equals(param.getSoldoutYn())) {
+					if ("N".equals(param.getSoldoutYn())) {
 						delv.setCompSumPrice(delv.getCompSumPrice() + (param.getCurrPrice() * param.getGoodsQty()));
 					}
 
-					if(compCnt == 1) {
+					if (compCnt == 1) {
 						param.setFirstCompYn("Y");
 					}
 					/* else {
@@ -525,13 +521,13 @@ public class TsfCartService {
 		}
 
 		// 장바구니 업체별 합계 금액으로 무료배송 여부 저장
-		for(Order delv : delvFeeInfo) {
-			for(Order param : params) {
-				if(param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {		// TODO 자사 배송비는 어떤 금액으로 처리하는지 확인 후 조건 수정 필요 (WMS는 DELV_FEE_CD 동일한거 없음)
+		for (Order delv : delvFeeInfo) {
+			for (Order param : params) {
+				if (param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {		// TODO 자사 배송비는 어떤 금액으로 처리하는지 확인 후 조건 수정 필요 (WMS는 DELV_FEE_CD 동일한거 없음)
 					param.setCompCnt(delv.getCompCnt());
-					if(TscConstants.DelvFeeCrite.FREE.value().equals(delv.getDelvFeeCrite())) {
+					if (TscConstants.DelvFeeCrite.FREE.value().equals(delv.getDelvFeeCrite())) {
 						param.setDelvFee(0);
-					} else if(TscConstants.DelvFeeCrite.NORMAL.value().equals(delv.getDelvFeeCrite()) && delv.getCompSumPrice() > delv.getMinOrdAmt()) {
+					} else if (TscConstants.DelvFeeCrite.NORMAL.value().equals(delv.getDelvFeeCrite()) && delv.getCompSumPrice() > delv.getMinOrdAmt()) {
 						param.setDelvFee(0);
 					} else {
 						param.setDelvFee(delv.getDelvFee());
@@ -543,20 +539,20 @@ public class TsfCartService {
 		// TODO 자사 배송비는 어떤 금액으로 처리하는지 확인 후 수정 필요
 		int wmsSumPrice = 0;
 		compCnt = 0;
-		for(Order param : params) {
+		for (Order param : params) {
 			compCnt++;
-			if("WMS".equals(param.getDelvFeeCd())) {
+			if ("WMS".equals(param.getDelvFeeCd())) {
 				wmsSumPrice = wmsSumPrice + (param.getCurrPrice() * param.getGoodsQty());
-				if(compCnt == 1) {
+				if (compCnt == 1) {
 					param.setFirstCompYn("Y");
 				}
 			}
 		}
 
 		// TODO 자사 배송비는 어떤 금액으로 처리하는지 확인 후 수정 필요
-		for(Order param : params) {
-			if("WMS".equals(param.getDelvFeeCd())) {
-				if(wmsSumPrice > 40000) {
+		for (Order param : params) {
+			if ("WMS".equals(param.getDelvFeeCd())) {
+				if (wmsSumPrice > 40000) {
 					param.setDelvFee(0);
 				} else {
 					param.setDelvFee(2500);
@@ -568,21 +564,21 @@ public class TsfCartService {
 	public void setCartListTotAmtInfo(Collection<Order> cartGoodsList, Order order) {
 		// 장바구니 합계 금액 계산
 		int notSoldoutCnt = 0;
-		for(Order cart : cartGoodsList) {
-			if("N".equals(cart.getSoldoutYn())) {
+		for (Order cart : cartGoodsList) {
+			if ("N".equals(cart.getSoldoutYn())) {
 				notSoldoutCnt++;
 				// 상품 금액 합계
 				order.setSumOrdAmt(order.getSumOrdAmt() + cart.getCurrPrice());
 
 				// 할인 제외 금액 총계
-				if(cart.getTmtbDcAmt() == 0) {
+				if (cart.getTmtbDcAmt() == 0) {
 					order.setSumRealPayAmt(order.getSumRealPayAmt() + cart.getCurrPrice());
 				} else {
 					order.setSumRealPayAmt(order.getSumRealPayAmt() + cart.getTmtbDcAmt());
 				}
 
 				// 배송비 합계
-				if("Y".equals(cart.getFirstCompYn())) {
+				if ("Y".equals(cart.getFirstCompYn())) {
 					order.setTotDelvFee(order.getTotDelvFee() + cart.getDelvFee());
 				}
 			}
@@ -594,4 +590,47 @@ public class TsfCartService {
 		// 장바구니 총액 계산 상품 총 수량
 		order.setTotCartCnt(notSoldoutCnt);
 	}
+
+	/**
+	 * 로그인 후 장바구니 Update
+	 * 		회원 로그인 후 호출됨으로 세션 정보 있음
+	 * @param custNo - 고객번호
+	 * @author gagamel
+	 * @since 2021. 2. 24
+	 */
+	@Transactional("shopTxnManager")
+	public void updateCartToAfterLogin(Integer custNo) {
+		Cart cart = new Cart();
+		cart.setJsessionId(TsfSession.getSessionId());
+		cart.setCustNo(custNo);
+		cart.setUpdNo(custNo);
+		log.info("cart: {}", cart);
+
+		// 로그인 후 고객번호 Update
+		int procCnt = cartDao.updateCartOfCustNo(cart);
+
+		if (procCnt > 0) {
+			// 로그인 후 처리할 장바구니 목록
+			Collection<Cart> cartList = cartDao.getCartListAfterLogin(cart);
+
+			for (Cart updCart : cartList) {
+				updCart.setCustNo(custNo);
+
+				// 로그인 후 장바구니 수정
+				cartDao.updateCartAfterLogin(updCart);
+
+				// 로그인 후 장바구니단품 삭제
+				cartDao.deleteCartItemAfterLogin(updCart);
+
+				// 로그인 후 장바구니 삭제
+				cartDao.deleteCartAfterLogin(updCart);
+
+				// 로그인 후 장바구니 이력 생성(삭제할 장바구니번호가 있을 때만)
+				if (updCart.getDelCartSq() > 0) {
+					cartDao.createCartHistoryAfterLogin(updCart);
+				}
+			}
+		}
+	}
+
 }

+ 7 - 0
src/main/java/com/style24/front/support/security/handler/TsfLoginSuccessHandler.java

@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
 
+import com.style24.front.biz.service.TsfCartService;
 import com.style24.front.biz.service.TsfLoginService;
 import com.style24.front.support.env.TsfConstants;
 import com.style24.front.support.security.TsfLoginDetails;
@@ -50,6 +51,9 @@ public class TsfLoginSuccessHandler implements AuthenticationSuccessHandler {
 	@Autowired
 	private TsfLoginService loginService;
 
+	@Autowired
+	private TsfCartService cartService;
+
 	@Override
 	public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
 		// 로그인 상세 정보
@@ -105,6 +109,9 @@ public class TsfLoginSuccessHandler implements AuthenticationSuccessHandler {
 			returnUrl = "/";
 		}
 
+		// 로그인 후 장바구니 Update
+		cartService.updateCartToAfterLogin(custNo);
+
 		GagaMap result = new GagaMap();
 		result.setString("status", "OK");
 		result.setString("returnUrl", returnUrl);

+ 7 - 4
src/main/java/com/style24/persistence/domain/Cart.java

@@ -1,11 +1,9 @@
 package com.style24.persistence.domain;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonInclude;
 import com.style24.persistence.TscBaseDomain;
-import lombok.Data;
 
-import java.util.List;
+import lombok.Data;
 
 /**
  * 장바구니
@@ -18,7 +16,7 @@ import java.util.List;
 public class Cart extends TscBaseDomain {
 	// 장바구니 정보
 	private int cartSq;				// 장바구니 번호
-	private int cartDtlSq;          // 장바구니 상세 번호
+	private int cartDtlSq;			// 장바구니 상세 번호
 	private int custNo;				// 고객번호
 	private int planDtlSq;			// 기획전상세번호
 	private int goodsQty;			// 장바구니 등록 수량
@@ -58,4 +56,9 @@ public class Cart extends TscBaseDomain {
 	private String cpnNm;
 	private String rdCpnNm;
 	private String usedDt;
+
+	private String itemOpts;	// 단품옵션
+	private Integer updCartSq;	// 업데이트할 장바구니번호
+	private Integer delCartSq;	// 삭제할 장바구니번호(0이면 삭제할 장바구니번호 없음)
+
 }

+ 121 - 0
src/main/java/com/style24/persistence/mybatis/shop/TsfCart.xml

@@ -618,4 +618,125 @@
 			 , DFP.DELV_FEE_CD
 			 , DFP.DELV_FEE
 	</select>
+	
+	<!-- 장바구니담긴상품 고객번호 Update -->
+	<update id="updateCartOfCustNo" parameterType="Cart">
+		/* TsfCart.updateCartOfCustNo */
+		UPDATE TB_CART
+		SET    CUST_NO = #{custNo}
+		     , UPD_NO = #{updNo}
+		     , UPD_DT = NOW()
+		WHERE  JSESSION_ID = #{jsessionId}
+	</update>
+	
+	<!-- 로그인 후 처리할 장바구니 목록 조회 -->
+	<select id="getCartListAfterLogin" parameterType="Cart" resultType="Cart">
+		/* TsfCart.getCartListAfterLogin */
+		SELECT A.CART_GB
+		     , A.GOODS_CD
+		     , A.ITEM_OPTS
+		     , IFNULL(B.CART_SQ,A.CART_SQ) AS UPD_CART_SQ /*업데이트할 장바구니번호*/
+		     , CASE WHEN B.CART_SQ IS NOT NULL THEN
+		                A.CART_SQ
+		            ELSE
+		                0
+		       END                         AS DEL_CART_SQ /*삭제할 장바구니번호(0이면 삭제할 장바구니번호 없음)*/
+		FROM   (
+		        /*장바구니에 담을 상품 목록*/
+		        SELECT C.CART_SQ
+		             , C.CART_GB
+		             , C.GOODS_CD
+		             , GROUP_CONCAT(CONCAT(CD.ITEM_CD,':',CD.OPT_CD1,':',CD.OPT_CD2) ORDER BY CD.ITEM_CD, CD.OPT_CD1, CD.OPT_CD2 SEPARATOR ';') AS ITEM_OPTS
+		        FROM   TB_CART C
+		             , TB_CART_DETAIL CD
+		        WHERE  C.CART_SQ = CD.CART_SQ
+		        AND    C.CUST_NO = #{custNo}
+		        AND    C.JSESSION_ID = #{jsessionId}
+		        GROUP  BY C.CART_SQ, C.CART_GB, C.GOODS_CD
+		       ) A
+		LEFT OUTER JOIN (
+		        /*장바구니에 담긴 기존 상품 목록*/
+		        SELECT C.CART_SQ
+		             , C.CART_GB
+		             , C.GOODS_CD
+		             , GROUP_CONCAT(CONCAT(CD.ITEM_CD,':',CD.OPT_CD1,':',CD.OPT_CD2) ORDER BY CD.ITEM_CD, CD.OPT_CD1, CD.OPT_CD2 SEPARATOR ';') AS ITEM_OPTS
+		        FROM   TB_CART C
+		             , TB_CART_DETAIL CD
+		        WHERE  C.CART_SQ = CD.CART_SQ
+		        AND    C.CUST_NO = #{custNo}
+		        AND    C.JSESSION_ID <![CDATA[<>]]> #{jsessionId}
+		        GROUP  BY C.CART_SQ, C.CART_GB, C.GOODS_CD
+		       ) B
+		ON     A.CART_GB = B.CART_GB
+		AND    A.GOODS_CD = B.GOODS_CD
+		AND    A.ITEM_OPTS = B.ITEM_OPTS
+	</select>
+
+	<!-- 로그인 후 장바구니 수정 -->
+	<update id="updateCartAfterLogin" parameterType="Cart">
+		/* TsfCart.updateCartAfterLogin */
+		UPDATE TB_CART X
+		SET    GOODS_QTY = X.GOODS_QTY + IFNULL((SELECT GOODS_QTY
+		                                         FROM   TB_CART
+		                                         WHERE  CART_SQ = #{delCartSq}
+		                                         AND    CUST_NO = #{custNo}
+		                                        ),0)
+		WHERE  CART_SQ = #{updCartSq}
+		AND    CUST_NO = #{custNo}
+	</update>
+
+	<!-- 로그인 후 장바구니단품 삭제 -->
+	<delete id="deleteCartItemAfterLogin" parameterType="Cart">
+		/* TsfCart.deleteCartItemAfterLogin */
+		DELETE FROM TB_CART_DETAIL
+		WHERE  CART_SQ IN (SELECT CART_SQ
+		                   FROM   TB_CART
+		                   WHERE  CART_SQ = #{delCartSq}
+		                   AND    CUST_NO = #{custNo}
+		                  )
+	</delete>
+
+	<!-- 로그인 후 장바구니 삭제 -->
+	<delete id="deleteCartAfterLogin" parameterType="Cart">
+		/* TsfCart.deleteCartAfterLogin */
+		DELETE FROM TB_CART
+		WHERE  CART_SQ = #{delCartSq}
+		AND    CUST_NO = #{custNo}
+	</delete>
+	
+	<!-- 로그인 후 장바구니이력 생성 -->
+	<update id="createCartHistoryAfterLogin" parameterType="Cart">
+		/* TsfCart.createCartHistoryAfterLogin */
+		INSERT INTO TB_CART_HST (
+		       CART_SQ
+		     , CART_GB
+		     , GOODS_CD
+		     , GOODS_QTY
+		     , DEAL_GOODS_CD
+		     , ORD_NO
+		     , CUST_NO
+		     , AF_LINK_CD
+		     , ITHR_CD
+		     , CONTENTS_LOC
+		     , PLAN_DTL_SQ
+		     , REG_NO
+		     , REG_DT
+		)
+		SELECT CART_SQ
+		     , CART_GB
+		     , GOODS_CD
+		     , GOODS_QTY
+		     , DEAL_GOODS_CD
+		     , ORD_NO
+		     , CUST_NO
+		     , AF_LINK_CD
+		     , ITHR_CD
+		     , CONTENTS_LOC
+		     , PLAN_DTL_SQ
+		     , #{regNo}
+		     , NOW()
+		FROM   TB_CART C
+		WHERE  CART_SQ = #{updCartSq}
+	</update>
+	
 </mapper>