Просмотр исходного кода

네이버 판매지수EP 생성 로직 - 페이징 처리해서 파일을 write 하도록 변경

gagamel 4 лет назад
Родитель
Сommit
b3fa76064a

+ 12 - 1
src/main/java/com/style24/batch/biz/dao/TsbGoodsEpDao.java

@@ -142,19 +142,29 @@ public interface TsbGoodsEpDao {
 
 	/**
 	 * 네이버 EP 페이징 목록
+	 * @param goodsEp - 상품EP 정보
 	 * @return
 	 * @author gagamel
 	 * @since 2021. 6. 14
 	 */
 	Collection<GoodsEp> getNaverEpPagingList(GoodsEp goodsEp);
 
+	/**
+	 * 네이버 판매지수EP 총건수
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 9. 23
+	 */
+	int getNaverSellEpTotalCount();
+
 	/**
 	 * 네이버 판매지수EP 목록
+	 * @param goodsEp - 상품EP 정보
 	 * @return
 	 * @author gagamel
 	 * @since 2021. 6. 15
 	 */
-	Collection<GoodsEp> getNaverSellEpList();
+	Collection<GoodsEp> getNaverSellEpList(GoodsEp goodsEp);
 
 	/**
 	 * EP다음 정보 삭제
@@ -207,6 +217,7 @@ public interface TsbGoodsEpDao {
 
 	/**
 	 * 다음 EP 페이징 목록
+	 * @param goodsEp - 상품EP 정보
 	 * @return
 	 * @author gagamel
 	 * @since 2021. 6. 14

+ 53 - 25
src/main/java/com/style24/batch/biz/job/goods/TsbNaverSellEp.java

@@ -26,7 +26,7 @@ import com.gagaframework.web.util.GagaFileUtil;
  */
 @Component
 @Slf4j
-public class TsbNaverSellEp extends TsbAbstractJob<Collection<GoodsEp>, Collection<GoodsEp>, String> {
+public class TsbNaverSellEp extends TsbAbstractJob<String, String, String> {
 
 	@Autowired
 	private TsbGoodsEpService naverEpService;
@@ -34,36 +34,60 @@ public class TsbNaverSellEp extends TsbAbstractJob<Collection<GoodsEp>, Collecti
 	@Autowired
 	private Environment env;
 
+	private static final int PAGE_SIZE = 10000;
+
 	@Override
-	public Collection<GoodsEp> read() throws Exception {
-		// 네이버 판매지수EP 목록
-		return naverEpService.getNaverSellEpList();
+	public String read() throws Exception {
+		return "OK";
 	}
 
 	@Override
-	public Collection<GoodsEp> process(Collection<GoodsEp> goodsEpList) throws Exception {
-		return goodsEpList;
+	public String process(String result) throws Exception {
+		return "OK";
 	}
 
 	@Override
-	public String write(Collection<GoodsEp> goodsEpList) throws Exception {
-		if (goodsEpList != null && !goodsEpList.isEmpty()) {
-			StringBuilder sb = new StringBuilder();
-			this.setEpTitle(sb);
+	public String write(String result) throws Exception {
+		// 총건수
+		int totCnt = naverEpService.getNaverSellEpTotalCount();
+		log.info("totCnt: {}", totCnt);
 
-			for (GoodsEp goodsEp : goodsEpList) {
-				this.setEpInfo(sb, goodsEp);
-			}
+		if (totCnt < 1) {
+			return "OK";
+		}
+
+		String uploadPath = GagaFileUtil.getConcatenationPath(env.getProperty("ep.file.path"), "iStyle24ProductFeed_NaverEP_SellingIndex_new.txt");
+		log.info("네이버 판매지수EP 파일 경로: {}", uploadPath);
+
+		int totPage = totCnt / PAGE_SIZE;
+		log.info("totalPage: {}", totPage);
 
-			String uploadPath = GagaFileUtil.getConcatenationPath(env.getProperty("ep.file.path"), "iStyle24ProductFeed_NaverEP_SellingIndex_new.txt");
-			log.info("네이버 판매지수EP 파일 경로: {}", uploadPath);
+		if (totCnt % PAGE_SIZE > 0) {
+			totPage++;
+		}
+
+		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(uploadPath)), "UTF-8"));
+
+		// 타이틀 Write
+		bw.append(this.getEpTitle());
+
+		for (int page = 0; page < totPage; page++) {
+			int limitStartRow = (page * PAGE_SIZE + 1) - 1;
+			GoodsEp goodsEp = new GoodsEp();
+			goodsEp.setLimitStartRow(limitStartRow);
+			goodsEp.setPageSize(PAGE_SIZE);
 
-			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(uploadPath)), "UTF-8"));
-			bw.write(sb.toString());
-			bw.flush();
-			bw.close();
+			// 네이버 판매지수EP 목록
+			Collection<GoodsEp> goodsEpList = naverEpService.getNaverSellEpList(goodsEp);
+
+			for (GoodsEp goodsEpInfo : goodsEpList) {
+				bw.append(this.getEpInfo(goodsEpInfo));
+			}
+			log.info("{} Page data wrote successfully!", (page + 1));
 		}
 
+		bw.close();
+
 		return "OK";
 	}
 
@@ -73,24 +97,28 @@ public class TsbNaverSellEp extends TsbAbstractJob<Collection<GoodsEp>, Collecti
 	}
 
 	/**
-	 * EP 타이틀 설정
-	 * @param sb - StringBuilder
+	 * Get EP 타이틀
+	 * @return
 	 */
-	private void setEpTitle(StringBuilder sb) {
+	private String getEpTitle() {
+		StringBuilder sb = new StringBuilder();
 		sb.append("id\t").append("sale_count\t").append("sale_price\t").append("order_count\t").append("dt\n");
+		return sb.toString();
 	}
 
 	/**
-	 * EP 정보 설정
-	 * @param sb - StringBuilder
+	 * Get EP 정보
 	 * @param goodsEp - 상품EP 정보
+	 * @return
 	 */
-	private void setEpInfo(StringBuilder sb, GoodsEp goodsEp) {
+	private String getEpInfo(GoodsEp goodsEp) {
+		StringBuilder sb = new StringBuilder();
 		sb.append(goodsEp.getId()).append("\t");
 		sb.append(goodsEp.getSaleCount()).append("\t");
 		sb.append(goodsEp.getSalePrice()).append("\t");
 		sb.append(goodsEp.getOrderCount()).append("\t");
 		sb.append(goodsEp.getDt()).append("\n");
+		return sb.toString();
 	}
 
 }

+ 14 - 3
src/main/java/com/style24/batch/biz/service/TsbGoodsEpService.java

@@ -47,7 +47,7 @@ public class TsbGoodsEpService {
 			// 1.1. 상품 이미지 정보 truncate
 			goodsEpDao.truncateEpGoodsImage();
 			log.info("1.1. 상품 이미지 정보 truncate");
-			
+
 			// 1.2. 상품 이미지 정보 생성
 			cnt = goodsEpDao.createEpGoodsImage(goodsEp);
 			log.info("1.2. 상품 이미지 정보 생성: {}건", cnt);
@@ -177,14 +177,25 @@ public class TsbGoodsEpService {
 		return goodsEpDao.getNaverEpPagingList(goodsEp);
 	}
 
+	/**
+	 * 네이버 판매지수EP 총건수
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 9. 23
+	 */
+	public int getNaverSellEpTotalCount() {
+		return goodsEpDao.getNaverSellEpTotalCount();
+	}
+
 	/**
 	 * 네이버 판매지수EP 목록
+	 * @param goodsEp - 상품EP 정보
 	 * @return
 	 * @author gagamel
 	 * @since 2021. 6. 15
 	 */
-	public Collection<GoodsEp> getNaverSellEpList() {
-		return goodsEpDao.getNaverSellEpList();
+	public Collection<GoodsEp> getNaverSellEpList(GoodsEp goodsEp) {
+		return goodsEpDao.getNaverSellEpList(goodsEp);
 	}
 
 	/**

+ 27 - 0
src/main/java/com/style24/persistence/mybatis/shop/TsbGoodsEp.xml

@@ -914,9 +914,35 @@
 		<include refid="selectForPagingFooter"/>
 	</select>
 	
+	<!-- 네이버 판매지수EP 총건수 -->
+	<select id="getNaverSellEpTotalCount" resultType="int">
+		/* TsbGoodsEp.getNaverSellEpTotalCount */
+		SELECT COUNT(*) AS CNT
+		FROM   (
+		        SELECT DATE_FORMAT(DATE_ADD(CURRENT_DATE(),INTERVAL -1 DAY),'%Y-%m-%d') AS DT          /*일자*/
+		             , OD.GOODS_CD                                                      AS ID          /*상품ID*/
+		             , SUM(OD.ORD_QTY - OD.CNCL_RTN_QTY)                                AS SALE_COUNT  /*판매수량*/
+		             , SUM(OD.ORD_AMT - OD.CNCL_RTN_AMT)                                AS SALE_PRICE  /*판매금액*/
+		             , COUNT(DISTINCT OD.ORD_NO)                                        AS ORDER_COUNT /*주문수량*/
+		        FROM   TB_ORDER O
+		             , TB_ORDER_DETAIL OD
+		        WHERE  O.ORD_NO = OD.ORD_NO
+		        AND    O.PAY_DT <![CDATA[>]]> DATE_ADD(CURRENT_DATE(), INTERVAL -2 DAY)
+		        AND    O.PAY_DT <![CDATA[<]]> CURRENT_DATE()
+		        AND    OD.ORD_DTL_STAT IN ('G013_20','G013_30','G013_35','G013_40','G013_50','G013_55','G013_60','G013_70')
+		        AND    OD.AF_LINK_CD IN (SELECT AF_LINK_CD
+		                                 FROM   TB_AF_LINK
+		                                 WHERE  AF_CHANNEL = 'G053_02' /*네이버*/
+		                                 AND    USE_YN = 'Y'
+		                                )
+		        GROUP  BY DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY),'%Y-%m-%d'), OD.GOODS_CD
+		       ) Z
+	</select>
+	
 	<!-- 네이버 판매지수EP 목록 -->
 	<select id="getNaverSellEpList" resultType="GoodsEp">
 		/* TsbGoodsEp.getNaverSellEpList */
+		<include refid="selectForPagingHeader"/>
 		SELECT DATE_FORMAT(DATE_ADD(CURRENT_DATE(),INTERVAL -1 DAY),'%Y-%m-%d') AS DT          /*일자*/
 		     , OD.GOODS_CD                                                      AS ID          /*상품ID*/
 		     , SUM(OD.ORD_QTY - OD.CNCL_RTN_QTY)                                AS SALE_COUNT  /*판매수량*/
@@ -934,6 +960,7 @@
 		                         AND    USE_YN = 'Y'
 		                        )
 		GROUP  BY DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY),'%Y-%m-%d'), OD.GOODS_CD
+		<include refid="selectForPagingFooter"/>
 	</select>
 	
 	<!-- EP다음 정보 삭제 -->