Browse Source

포인트 차감 로직 추가

jsshin 5 năm trước cách đây
mục cha
commit
8a9ebb5e8d

+ 32 - 0
src/main/java/com/style24/core/biz/dao/TscPointDao.java

@@ -5,6 +5,8 @@ import org.springframework.stereotype.Repository;
 import com.style24.core.support.annotation.ShopDs;
 import com.style24.persistence.domain.Point;
 
+import java.util.Collection;
+
 
 /**
  * 포인트 Dao
@@ -74,4 +76,34 @@ public interface TscPointDao {
 	 */
 	int getOrderDecisionPointHstCount(Point point);
 
+	/**
+	 * 가용포인트 목록
+	 *
+	 * @param custNo - 고객번호
+	 * @return Collection<Point> - 가용 포인트 목록
+	 * @author jsshin
+	 * @since 2021. 06. 14
+	 */
+	Collection<Point> getCustomerRmPntAmtList(Integer custNo);
+
+	/**
+	 * 포인트 차감
+	 *
+	 * @param point - 차감포인트, 포인트 일련번호
+	 * @return int - 결과
+	 * @author jsshin
+	 * @since 2021. 06. 14
+	 */
+	int updatePointDeduction(Point point);
+
+	/**
+	 * 가용포인트 합산
+	 *
+	 * @param custNo - 고객번호
+	 * @return int - 가용 포인트
+	 * @author jsshin
+	 * @since 2021. 06. 14
+	 */
+	int getCustomerSumRmPntAmt(Integer custNo);
+
 }

+ 46 - 3
src/main/java/com/style24/core/biz/service/TscPointService.java

@@ -11,6 +11,8 @@ import com.style24.persistence.domain.Point;
 
 import lombok.extern.slf4j.Slf4j;
 
+import java.util.Collection;
+
 
 /**
  * 포인트 Service
@@ -32,15 +34,45 @@ public class TscPointService {
 	private TscOrderService orderService;
 
 	/**
-	 * 포인트 적립
+	 * 포인트 적립 / 차감
 	 * @param point - 포인트 정보
 	 * @author jsshin
 	 * @since 2021. 01. 27
 	 */
 	@Transactional("shopTxnManager")
 	public void saveCustomerPoint(Point point) {
-		pointDao.createCustomerPoint(point);
-		pointDao.createCustomerPointHst(point);
+		if ("+".equals(point.getSignGb())) {
+			pointDao.createCustomerPoint(point);
+			pointDao.createCustomerPointHst(point);
+		} else {
+			int sumRmPntAmt = pointDao.getCustomerSumRmPntAmt(point.getCustNo());
+				sumRmPntAmt += point.getRmPntAmt();
+			if (sumRmPntAmt < 0 ) {
+				throw new IllegalStateException("보유 포인트 금액이 차감 포인트 금액 보다 작습니다.");
+			}
+			Collection<Point> rmPntAmtList = pointDao.getCustomerRmPntAmtList(point.getCustNo());
+			int rmPntAmt = point.getRmPntAmt() * -1; // 차감금액 :  -1000 * -1
+			for (Point rmPntAmtInfo: rmPntAmtList) {
+				if (rmPntAmt > 0 ) {
+					if (rmPntAmt < rmPntAmtInfo.getRmPntAmt()) {
+						rmPntAmtInfo.setPntAmt(rmPntAmt * -1);
+						rmPntAmt -= rmPntAmt;
+					} else {
+						rmPntAmtInfo.setPntAmt(rmPntAmtInfo.getRmPntAmt() * -1);
+						rmPntAmt -= rmPntAmtInfo.getRmPntAmt();
+					}
+					rmPntAmtInfo.setCustNo(point.getCustNo());
+					rmPntAmtInfo.setOccurGb(point.getOccurGb());
+					rmPntAmtInfo.setPntUploadStat(point.getPntUploadStat());
+					rmPntAmtInfo.setOccurDtlDesc(point.getOccurDtlDesc());
+					rmPntAmtInfo.setRegNo(point.getRegNo());
+					rmPntAmtInfo.setUpdNo(point.getUpdNo());
+					pointDao.createCustomerPointHst(rmPntAmtInfo);
+					pointDao.updatePointDeduction(rmPntAmtInfo);
+				}
+			}
+		}
+
 	}
 
 	/**
@@ -106,4 +138,15 @@ public class TscPointService {
 		return pointDao.getOrderDecisionPointHstCount(point);
 	}
 
+	/**
+	 * 가용 포인트
+	 * @param custNo - 고객번호
+	 * @return int - 가용포인트 합
+	 * @author jsshin
+	 * @since 2021. 06. 14
+	 */
+	public int getCustomerSumRmPntAmt(Integer custNo) {
+		return pointDao.getCustomerSumRmPntAmt(custNo);
+	}
+
 }

+ 5 - 5
src/main/java/com/style24/core/support/util/CryptoUtils.java

@@ -23,7 +23,7 @@ public class CryptoUtils {
 	/**
 	 * AES 암호화 처리
 	 * @param rawValue - 원시문자열
-	 * @return
+	 * @return String - 암호화문자열
 	 */
 	public static String encryptAES(String rawValue) {
 		String encryptedValue = "";
@@ -37,7 +37,7 @@ public class CryptoUtils {
 				encryptedValue = Base64.encodeBase64String(cipher.doFinal(rawValue.getBytes("UTF-8")));
 			}
 		} catch (Exception e) {
-			log.error(e.getMessage());
+			//log.error(e.getMessage());
 			encryptedValue = rawValue;
 		}
 
@@ -46,8 +46,8 @@ public class CryptoUtils {
 
 	/**
 	 * AES 복호화 처리
-	 * @param encodedValue - 암호화된 문자열
-	 * @return
+	 * @param encryptedValue - 암호화된 문자열
+	 * @return String - 복호화문자열
 	 */
 	public static String decryptAES(String encryptedValue) {
 		String decryptedValue = "";
@@ -64,7 +64,7 @@ public class CryptoUtils {
 				}
 			}
 		} catch (Exception e) {
-			log.error(e.getMessage());
+			//log.error(e.getMessage());
 			decryptedValue = encryptedValue;
 		}
 

+ 36 - 0
src/main/java/com/style24/persistence/mybatis/shop/TscPoint.xml

@@ -159,4 +159,40 @@
 		   AND OCCUR_GB IN ('G069_12', 'G069_13')
 		   AND PNT_UPLOAD_STAT = 'G070_10'
 	</select>
+
+	<!-- 가용포인트 리스트 -->
+	<select id="getCustomerRmPntAmtList" parameterType="Integer" resultType="Point">
+		/* TscPoint.getCustomerRmPntAmtList */
+		SELECT CP.CUST_PNT_SQ
+		     , CP.RM_PNT_AMT
+		     , CP.EXP_BE_DT
+		FROM   TB_CUST_POINT CP
+		WHERE  CP.CUST_NO = #{custNo}
+		AND    CP.EXP_BE_DT > NOW()
+		AND    CP.EXP_CMP_DT IS NULL
+		AND    CP.RM_PNT_AMT > 0
+		ORDER BY CP.EXP_BE_DT, CP.CUST_PNT_SQ
+	</select>
+
+	<!--포인트 차감 -->
+	<update id="updatePointDeduction" parameterType="Point">
+		/* TscPoint.updatePointDeduction */
+		UPDATE TB_CUST_POINT
+		SET    RM_PNT_AMT = RM_PNT_AMT + #{pntAmt}
+		     , US_PNT_AMT = US_PNT_AMT - #{pntAmt}
+		     , UPD_DT = NOW()
+		     , UPD_NO = #{updNo}
+		WHERE  CUST_PNT_SQ = #{custPntSq}
+	</update>
+
+	<!-- 가용포인트 합산 -->
+	<select id="getCustomerSumRmPntAmt" parameterType="Integer" resultType="int">
+		/* TscPoint.getCustomerSumRmPntAmt */
+		SELECT IFNULL(SUM(CP.RM_PNT_AMT), 0) AS RM_PNT_AMT
+		FROM   TB_CUST_POINT CP
+		WHERE  CP.CUST_NO = #{custNo}
+		AND    CP.EXP_BE_DT > NOW()
+		AND    CP.EXP_CMP_DT IS NULL
+	</select>
+
 </mapper>