Prechádzať zdrojové kódy

Merge branch 'eskim' into develop

eskim 5 rokov pred
rodič
commit
a1c4e3b5c5

+ 18 - 0
style24.batch/src/main/java/com/style24/batch/biz/dao/TsbGoodsDao.java

@@ -5,6 +5,7 @@ import java.util.Collection;
 import com.style24.core.support.annotation.ShopDs;
 import com.style24.persistence.domain.Coupon;
 import com.style24.persistence.domain.Goods;
+import com.style24.persistence.domain.GoodsSafeNo;
 import com.style24.persistence.domain.GoodsSummary;
 
 /**
@@ -222,4 +223,21 @@ public interface TsbGoodsDao {
 	 */
 	void saveGoodsSummary();
 
+	/**
+	 * 안전인증대상 상품 조회
+	 *
+	 * @author eskim
+	 * @since 2020. 12. 04
+	 */
+	Collection<GoodsSafeNo> getGoodsSafeNoList();
+
+	/**
+	 * 안전인증대상 상품 저장
+	 *
+	 * @author eskim
+	 * @since 2020. 12. 04
+	 */
+	void saveGoodsSafeNo();
+
+
 }

+ 52 - 0
style24.batch/src/main/java/com/style24/batch/biz/job/goods/TsbGoodsInfantsSafeNoJob.java

@@ -0,0 +1,52 @@
+package com.style24.batch.biz.job.goods;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.style24.batch.biz.job.TsbAbstractJob;
+import com.style24.batch.biz.service.TsbGoodsService;
+import com.style24.persistence.domain.Goods;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 영유아상품 인증번호 수신
+ *
+ * @author eskim
+ * @since 2020. 12. 04
+ */
+@Component
+@Slf4j
+public class TsbGoodsInfantsSafeNoJob extends TsbAbstractJob<Goods, Goods, Goods> {
+
+	@Autowired
+	private TsbGoodsService goodsService;
+
+	private int succCnt = 0;
+	private int failCnt = 0;
+
+	@Override
+	public Goods read() throws Exception {
+
+		Goods goods = new Goods();
+		return goods;
+	}
+
+	@Override
+	public Goods process(Goods goods) throws Exception {
+		return goods;
+	}
+
+	@Override
+	public Goods write(Goods goods) throws Exception {
+
+		goodsService.saveGoodsSafeNo();
+		return goods;
+	}
+
+	@Override
+	public void notify(Goods goods) throws Exception {
+		super.printResult(succCnt, failCnt);
+	}
+
+}

+ 0 - 5
style24.batch/src/main/java/com/style24/batch/biz/job/goods/TsbGoodsTnmJob.java

@@ -5,7 +5,6 @@ import org.springframework.stereotype.Component;
 
 import com.style24.batch.biz.job.TsbAbstractJob;
 import com.style24.batch.biz.service.TsbGoodsService;
-import com.style24.core.biz.thirdparty.SafetyKoreaApi;
 import com.style24.persistence.domain.Goods;
 
 import lombok.extern.slf4j.Slf4j;
@@ -23,10 +22,6 @@ public class TsbGoodsTnmJob extends TsbAbstractJob<Goods, Goods, Goods> {
 	@Autowired
 	private TsbGoodsService goodsService;
 
-	@Autowired
-	private SafetyKoreaApi safetyKoreaApi;
-
-
 	private int succCnt = 0;
 	private int failCnt = 0;
 

+ 39 - 0
style24.batch/src/main/java/com/style24/batch/biz/service/TsbGoodsService.java

@@ -10,12 +10,18 @@ import org.springframework.transaction.annotation.Transactional;
 import com.style24.batch.biz.dao.TsbGoodsDao;
 import com.style24.batch.support.env.TsbConstants;
 import com.style24.core.biz.service.TscEnvsetService;
+import com.style24.core.biz.thirdparty.SafetyKoreaApi;
 import com.style24.persistence.domain.Coupon;
 import com.style24.persistence.domain.Goods;
+import com.style24.persistence.domain.GoodsSafeNo;
 import com.style24.persistence.domain.GoodsSummary;
 
+import io.netty.util.internal.StringUtil;
+
 import lombok.extern.slf4j.Slf4j;
 
+import com.gagaframework.web.parameter.GagaMap;
+
 /**
  * 상품 Service
  *
@@ -32,6 +38,10 @@ public class TsbGoodsService {
 	@Autowired
 	private TscEnvsetService envsetService;
 
+	@Autowired
+	private SafetyKoreaApi safetyKoreaApi;
+
+
 	/**
 	 * 상품 타이틀예약 작업
 	 *
@@ -272,4 +282,33 @@ public class TsbGoodsService {
 
 	}
 
+	/**
+	 * 영유아상품 인증번호 수신
+	 *
+	 * @return
+	 * @author eskim
+	 * @since 2020. 12. 04
+	 */
+	@Transactional("shopTxnManager")
+	public void saveGoodsSafeNo() {
+
+		// 1. 대상 상품 조회
+		Collection<GoodsSafeNo> goodsSafeNoList = goodsDao.getGoodsSafeNoList();
+		// 2. 인증테이블 적용
+		for(GoodsSafeNo goodsSafeNo: goodsSafeNoList) {
+			try {
+				GagaMap result = safetyKoreaApi.getKoreaCertifyNo(goodsSafeNo.getGoodsNum()); // 품번으로 처리
+				if (result != null || !StringUtil.isNullOrEmpty(result.get("certNum").toString())) {
+					goodsSafeNo.setCertDt(result.get("certDt").toString());
+					goodsSafeNo.setCertNum(result.get("certNum").toString());
+					goodsSafeNo.setRegNo(TsbConstants.REG_NO);
+					goodsSafeNo.setUpdNo(TsbConstants.REG_NO);
+					goodsDao.saveGoodsSafeNo();
+				}
+			} catch (Exception e) {
+				// do nothing
+			}
+		}
+	}
+
 }

+ 19 - 0
style24.batch/src/main/java/com/style24/batch/biz/task/TsbGoodsTask.java

@@ -6,6 +6,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import com.style24.batch.biz.job.goods.TsbGoodsBenefitPriceJob;
+import com.style24.batch.biz.job.goods.TsbGoodsInfantsSafeNoJob;
 import com.style24.batch.biz.job.goods.TsbGoodsPriceJob;
 import com.style24.batch.biz.job.goods.TsbGoodsRelateScoreJob;
 import com.style24.batch.biz.job.goods.TsbGoodsSnmJob;
@@ -41,6 +42,10 @@ public class TsbGoodsTask {
 	@Autowired
 	private TsbGoodsSummaryJob goodsSummaryJob;
 
+	@Autowired
+	private TsbGoodsInfantsSafeNoJob goodsInfantsSafeNoJob;
+
+
 	/**
 	 * 초 분 시 일 월 주(년)
 	 * 0 0 12 * * ?" : 아무 요일, 매월, 매일 12:00:00
@@ -136,4 +141,18 @@ public class TsbGoodsTask {
 	public void tsbGoodsSummaryJob() throws Exception {
 		goodsSummaryJob.run("cron.goods.summary");
 	}
+
+	/**
+	 * 영유아상품 인증번호 수신 : 일배치 - 매일 3시 5분
+	 *
+	 * @throws Exception
+	 */
+	@Scheduled(cron = "${cron.goods.infants.safe}")
+	//@Scheduled(fixedDelay = 3500000)
+	@Async
+	public void tsbGoodsInfantsSafeNoJob() throws Exception {
+		goodsInfantsSafeNoJob.run("cron.goods.infants.safe");
+	}
+
+
 }

+ 22 - 0
style24.batch/src/main/java/com/style24/persistence/domain/GoodsSafeNo.java

@@ -0,0 +1,22 @@
+package com.style24.persistence.domain;
+
+import com.style24.persistence.TscBaseDomain;
+
+import lombok.Data;
+
+/**
+ * 상품 안전인증 Domain
+ *
+ * @author eskim
+ * @since 2020. 11. 04
+ */
+@SuppressWarnings("serial")
+@Data
+public class GoodsSafeNo extends TscBaseDomain {
+
+	private String goodsCd;
+	private String goodsNum;
+	private String certNum;
+	private String certDt;
+
+}

+ 48 - 0
style24.batch/src/main/java/com/style24/persistence/mybatis/shop/TsbGoods.xml

@@ -1001,4 +1001,52 @@
 		WHERE A.GOODS_CD = GS.GOODS_CD
 	</insert>
 	
+	<!--  안전인증대상 상품 조회 -->
+	<select id="getGoodsSafeNoList" >
+		/* TsbGoods.getGoodsSafeNoList */
+		SELECT B.GOODS_CD
+		     , B.GOODS_NUM
+		     , A.ITEMKIND_CD 
+		     , C.CERT_NUM 
+		     , C.CERT_DT 
+		FROM TB_ITEMKIND A
+		INNER JOIN TB_GOODS B ON A.ITEMKIND_CD = B.ITEMKIND_CD AND B.SELF_GOODS_YN = 'Y'  /* 자사상품 */
+		INNER JOIN TB_BRAND D ON B.BRAND_CD = D.BRAND_CD AND D.USE_YN = 'Y'
+		LEFT OUTER JOIN TB_GOODS_SAFE_NO C ON B.GOODS_CD = C.GOODS_CD
+		                                   AND (CERT_NUM IS NULL
+		                                        <![CDATA[
+		                                        OR CERT_DT < DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -5 YEAR), '%Y%m%d')  /*인증유효 5년 경과*/
+		                                        ]]>
+		                                       )
+		WHERE A.NI_CLSF_CD = 'G004_23'  /*고시 유아용품*/
+	</select>
+	
+	<!--  안전인증대상 상품 조회 -->
+	<insert id="saveGoodsSafeNo"  parameterType="GoodsSafeNo">
+		/* TsbGoods.saveGoodsSafeNo */
+		INSERT INTO TB_GOODS_SAFE_NO (
+		    GOODS_CD
+		  , CERT_NUM
+		  , CERT_DT
+		  , REG_NO
+		  , REG_DT
+		  , UPD_NO
+		  , UPD_DT
+		)
+		VALUES (
+		    #{goodsCd}
+		  , #{certNum}
+		  , #{certDt}
+		  , #{regNo}
+		  , NOW()
+		  , #{updNo}
+		  , NOW()
+		)
+		ON DUPLICATE KEY UPDATE
+		       CERT_NUM = #{certNum}
+		     , CERT_DT = #{certDt}
+		     , UPD_NO = #{updNo}
+		     , UPD_DT = NOW()
+	</insert>
+	
 </mapper>

+ 9 - 4
style24.core/src/main/java/com/style24/core/biz/thirdparty/SafetyKoreaApi.java

@@ -18,9 +18,11 @@ import com.style24.persistence.domain.KCertifyNo;
 
 import lombok.extern.slf4j.Slf4j;
 
+import com.gagaframework.web.parameter.GagaMap;
+
 /**
  * KC인증번호 조회 (www.safetykorea.kr open API)
- * 
+ *
  * @author gagamel
  * @since 2020. 12. 1
  */
@@ -53,7 +55,8 @@ public class SafetyKoreaApi {
 	 * @author gagamel
 	 * @since 2020. 12. 1
 	 */
-	public String getKoreaCertifyNo(String goodsCd) throws Exception {
+	public GagaMap getKoreaCertifyNo(String goodsCd) throws Exception {
+		GagaMap result = new GagaMap();
 		// Header
 		HttpHeaders headers = new HttpHeaders();
 		headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
@@ -107,10 +110,12 @@ public class SafetyKoreaApi {
 		KCertifyNo kcNo = gson.fromJson(responseJson, KCertifyNo.class);
 
 		if (kcNo.getResultCode() != null && kcNo.getResultCode().equals("2000")) { // 성공
-			return kcNo.getResultData().iterator().next().getCertNum();
+			result.set("certNum", kcNo.getResultData().iterator().next().getCertNum());
+			result.set("certDt", kcNo.getResultData().iterator().next().getCertChgDate() );
+			return result;
 		}
 
-		return "";
+		return result;
 	}
 
 }