| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- package com.style24.front.biz.thirdparty;
- import java.io.UnsupportedEncodingException;
- import java.net.URI;
- import java.net.URLEncoder;
- import java.util.ArrayList;
- import java.util.Collection;
- import javax.annotation.PostConstruct;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Component;
- import org.springframework.web.client.RestTemplate;
- import com.google.gson.Gson;
- import com.style24.front.biz.dao.TsfGoodsDao;
- import com.style24.front.support.security.session.TsfSession;
- import com.style24.persistence.domain.Cart;
- import com.style24.persistence.domain.Goods;
- import com.style24.persistence.domain.eigene.Eigeneai;
- import com.style24.persistence.domain.eigene.Eigeneai.Result;
- import com.style24.persistence.domain.eigene.Item;
- import lombok.extern.slf4j.Slf4j;
- /**
- * 추천솔루션 - Eigene.ai
- *
- * @author gagamel
- * @since 2021. 5. 14
- */
- @Component
- @Slf4j
- public class EigeneaiApi {
- private String apiUrl = "https://api.eigene.io/rec";
- private String rtsApiUrl = "https://rts-api.eigene.io/api";
- private String cuid = "1252aed4-78dc-46e8-b784-94ac42e86dd4";
- @Autowired
- private RestTemplate restTemplate;
- @Autowired
- private TsfGoodsDao goodsDao;
- @PostConstruct
- public void init() {
- log.debug("\n\n---- Eigene.ai initialization started ----");
- log.debug("apiUrl: [{}]", apiUrl);
- log.debug("cuid: [{}]", cuid);
- log.debug("\n--- Eigene.ai initialization completed ----\n");
- }
- /**
- * 카테고리별 주간판매베스트추천상품 목록
- * 사용되는 화면 영역)
- * 메인 > 베스트 영역
- * 카테고리메인 > 베스트 상품
- * 베스트 > 카테고리별 베스트
- * @param size - 결과에 포함할 상품수
- * @param cate1No - 카테고리번호1
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Result> getCategoryWeeklySellBestGoodsList(int size, Integer cate1No) {
- String requestUrl = apiUrl + "/m060?cuid=" + cuid + "&size=" + size + "&incids=" + cate1No;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- // /**
- // * 매출급상승 카테고리 목록
- // * 사용되는 화면 영역)
- // * 메인 > MD추천상품
- // * @return
- // * @author gagamel
- // * @since 2021. 6. 30
- // */
- // public Collection<Result> getSoaringSalesCategoryList() {
- // String requestUrl = apiUrl + "/m063?cuid=" + cuid;
- //
- // Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- // if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- // return eigeneai.getResults();
- // }
- //
- // return new ArrayList<Result>();
- // }
- //
- // /**
- // * MD추천상품 목록. 매출급상승 카테고리별 상품 목록
- // * 사용되는 화면 영역)
- // * 메인 > MD추천상품
- // * @param size - 결과에 포함할 상품수
- // * @param cateId - 카테고리ID
- // * @return
- // * @author gagamel
- // * @since 2021. 6. 30
- // */
- // public Collection<GagaMap> getMdRecommendGoodsList(int size, String cateId) {
- // // 1.매출급상승 카테고리 목록
- // String requestUrl = apiUrl + "/m063?cuid=" + cuid;
- // Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- // if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- // Collection<Result> cateList = eigeneai.getResults();
- //
- // if (cateList != null && !cateList.isEmpty()) {
- // for (Result cateInfo : cateList) {
- // if (StringUtils.isNotBlank(cateInfo.getCategoryId())) {
- // GagaMap dataMap = new GagaMap();
- // dataMap.setString("styleNm", cateInfo.getCategoryId());
- //
- // // 2.카테고리별 상품 목록
- // requestUrl = apiUrl + "/c001?cuid=" + cuid + "&size=" + size + "&cids=" + cateInfo.getCategoryId();
- // eigeneai = this.getEigeneaiInfo(requestUrl);
- // if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- // dataMap.set("", eigeneai.getResults());
- // }
- // }
- // }
- // }
- // }
- //
- // return new ArrayList<GagaMap>();
- // }
- /**
- * 주간판매베스트추천상품 목록
- * 사용되는 화면 영역)
- * 베스트 > 전체 베스트
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Result> getWeeklySellBestGoodsList(int size) {
- String requestUrl = apiUrl + "/m061?cuid=" + cuid + "&size=" + size;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 브랜드 주간판매베스트추천상품 목록
- * 사용되는 화면 영역)
- * 브랜드메인 > 베스트 상품
- * @param size - 결과에 포함할 상품수
- * @param brandGroupNo - 브랜드그룹번호
- * @return
- * @author gagamel
- * @since 2021. 6. 30
- */
- public Collection<Result> getBrandWeeklySellBestGoodsList(int size, Integer brandGroupNo) {
- String requestUrl = apiUrl + "/m061?cuid=" + cuid + "&size=" + size + "&inbids=" + brandGroupNo;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 아울렛 주간판매베스트추천상품 목록
- * 사용되는 화면 영역)
- * 아울렛메인 > 베스트
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 6. 30
- */
- public Collection<Result> getOutletWeeklySellBestGoodsList(int size) {
- String requestUrl = apiUrl + "/m064?cuid=" + cuid + "&size=" + size;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 브랜드 월간클릭베스트추천상품 목록
- * 사용되는 화면 영역)
- * 브랜드메인 > MD Pick
- * @param size - 결과에 포함할 상품수
- * @param brandGroupNo - 브랜드그룹번호
- * @return
- * @author gagamel
- * @since 2021. 6. 30
- */
- public Collection<Result> getBrandMonthlyClickBestGoodsList(int size, Integer brandGroupNo) {
- String requestUrl = apiUrl + "/m062?cuid=" + cuid + "&size=" + size + "&inbids=" + brandGroupNo;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 아울렛 월간클릭베스트추천상품 목록
- * 사용되는 화면 영역)
- * 아울렛메인 > MD Pick
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 6. 30
- */
- public Collection<Result> getOutletMonthlyClickBestGoodsList(int size) {
- String requestUrl = apiUrl + "/m065?cuid=" + cuid + "&cids=" + "" + "&size=" + size;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 실시간 많이 조회되고 있는 상품 목록
- * 사용되는 화면 영역)
- * 퀵메뉴 > 쇼핑백 (담은 상품 없는 경우)
- * 쇼핑백 > 추천상품 (담은 상품 없는 경우)
- * 검색 > 검색 시작화면
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 6. 30
- */
- public Collection<Item> getRealtimeViewGoodsList(int size) {
- Collection<Item> dataList = new ArrayList<Item>();
- String requestUrl = rtsApiUrl + "/stream?cuid=" + cuid + "&size=" + size + "&type=view";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getItems() != null && !eigeneai.getItems().isEmpty()) {
- Collection<Item> items = eigeneai.getItems();
- StringBuilder sql = new StringBuilder();
- int idx = 1;
- for (Item item : items) {
- if (idx++ > 1) {
- sql.append("UNION ALL");
- }
- sql.append(" SELECT ").append(item.getCount()).append(" AS COUNT");
- sql.append(" , '").append(item.getItemId()).append("' AS ITEM_ID");
- sql.append(" , '").append(item.getImageUrl()).append("' AS IMAGE_URL");
- sql.append(" , '").append(item.getItemName()).append("' AS ITEM_NAME");
- sql.append(" , '").append(item.getItemUrl()).append("' AS ITEM_URL");
- sql.append(" , '").append(item.getCategoryId()).append("' AS CATEGORY_ID");
- sql.append(" , '").append(item.getBrandId()).append("' AS BRAND_ID");
- sql.append(" , ").append(idx).append(" AS RK FROM DUAL\n");
- }
- Goods goods = new Goods();
- goods.setSql(sql.toString());
- if (TsfSession.isLogin()) {
- goods.setCustNo(TsfSession.getInfo().getCustNo());
- }
- goods.setFrontGb(TsfSession.getFrontGb());
- goods.setCustGb(TsfSession.getCustGb());
- dataList.addAll(goodsDao.getGoodsAddInfoList(goods));
- }
- return dataList;
- }
- /**
- * 실시간 많이 조회되고 있는 베스트 상품 목록
- * 사용되는 화면 영역)
- * 베스트 > 베스트상품_실시간 베스트
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 6. 30
- */
- public Collection<Item> getRealtimeViewBestGoodsList(int size , String cate1No) {
- String requestUrl = "";
- if(cate1No.equals(null) || "null".equals(cate1No) || "".equals(cate1No)){
- requestUrl = rtsApiUrl + "/stats-transition?cuid=" + cuid + "&size=" + size + "&type=view&interval=30&span=30&offset=0&categoryid1=";
- }else{
- requestUrl = rtsApiUrl + "/stats-transition?cuid=" + cuid + "&size=" + size + "&type=view&interval=30&span=30&offset=0&categoryid1="+cate1No;
- }
- //&type=view&interval=5&span=10
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getItems() != null && !eigeneai.getItems().isEmpty()) {
- return eigeneai.getItems();
- }
- return new ArrayList<Item>();
- }
- /**
- * 매출급상승 카테고리별 상품 목록
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Eigeneai getSalesSoaringGoodsList() {
- // TODO: 매출급상승 카테고리 5개 조회 후 카테고리별 상품 7개 조회
- String requestUrl = apiUrl + "/m010?cuid=" + cuid + "&size=5";
- return this.getEigeneaiInfo(requestUrl);
- }
- /**
- * 고객의 최근검색어별 상품 목록
- * 사용되는 화면 영역)
- * 검색 > 검색결과 추천상품
- * 메인 > 당신을 위한 제안 > 검색어 연관상품 추천
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Eigeneai> getCustomerKeywordGoodsList() {
- Collection<Eigeneai> dataList = new ArrayList<>();
- // 고객별 최근검색어 목록. TODO: 아이겐에서 미개발
- String requestUrl = apiUrl + "/m010?cuid=" + cuid + "&size=5";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- Collection<Eigeneai.Result> resultList = eigeneai.getResults();
- if (resultList == null || resultList.isEmpty()) {
- return dataList;
- }
- try {
- // 고객별 최근검색어 기준 검색어연관상품 목록 조회
- for (Eigeneai.Result result : resultList) {
- dataList.add(this.getKeywordGoodsList(10, result.getCategoryId()));
- }
- } catch (UnsupportedEncodingException e) {
- // Do nothing
- }
- return dataList;
- }
- /**
- * 검색어 연관상품 목록
- * 사용되는 화면 영역)
- * 검색 > 검색결과 추천상품
- * @param size - 결과에 포함할 상품수
- * @param keyword - 키워드
- * @exception UnsupportedEncodingException
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- private Eigeneai getKeywordGoodsList(int size, String keyword) throws UnsupportedEncodingException {
- String requestUrl = apiUrl + "/s003?cuid=" + cuid + "&size=" + size + "&st=" + URLEncoder.encode(keyword, "UTF-8") + "&cps=true&cpt=m004";
- return this.getEigeneaiInfo(requestUrl);
- }
- /**
- * 연관상품 목록
- * 사용되는 화면 영역)
- * 상품상세 > 함께 본 상품
- * @param goodsCd - 상품코드
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Result> getRelatedGoodsList(String goodsCd, int size) {
- String requestUrl = apiUrl + "/a037?cuid=" + cuid + "&size=" + size + "&iids=" + goodsCd + "&cps=true&cpt=m001";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 연관상품 목록
- * 사용되는 화면 영역)
- * 쇼핑백 > 추천상품 (담은 상품이 있는 경우)
- * @param cartList - 장바구니목록
- * @param size - 결과에 포함할 상품수
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Result> getRelatedGoodsList(Collection<Cart> cartList, int size) {
- if (cartList != null && !cartList.isEmpty()) {
- StringBuilder sb = new StringBuilder();
- int idx = 0;
- for (Cart cart : cartList) {
- if (idx++ > 0) {
- sb.append(",");
- }
- sb.append(cart.getGoodsCd());
- }
- String requestUrl = apiUrl + "/a037?cuid=" + cuid + "&size=" + size + "&iids=" + sb.toString() + "&cps=true&cpt=m001";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- }
- return new ArrayList<Result>();
- }
- /**
- * 브랜드 연관상품 목록
- * 사용되는 화면 영역)
- * 상품상세 > 브랜드연관상품
- * @param size - 결과에 포함할 상품수
- * @param goodsCd - 상품코드
- * @param brandGroupNo - 브랜드그룹번호
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Result> getBrandRelatedGoodsList(int size, String goodsCd, Integer brandGroupNo) {
- String requestUrl = apiUrl + "/a038?cuid=" + cuid + "&size=" + size + "&iids=" + goodsCd + "&cps=true&cpt=b004&bids=" + brandGroupNo;
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 동일 카테고리 연관상품 목록
- * 사용되는 화면 영역)
- * 상품상세 > 비슷한 상품
- * @param size - 결과에 포함할 상품수
- * @param goodsCd - 상품코드
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public Collection<Result> getSameCategoryRelatedGoodsList(int size, String goodsCd) {
- String requestUrl = apiUrl + "/a039?cuid=" + cuid + "&size=" + size + "&iids=" + goodsCd + "&cps=true&cpt=m002";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 상품의 실시간 조회수
- * 사용되는 화면 영역)
- * 상품상세 > 실시간 뷰
- * @param goodsCd - 상품코드
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- public int getRealtimeViewCount(String goodsCd) {
- String requestUrl = rtsApiUrl + "/stat?cuid=" + cuid + "&itemid=" + goodsCd + "&type=view";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getItem() != null) {
- return eigeneai.getItem().getCount();
- }
- return 0;
- }
- /**
- * 아이겐 정보 조회
- * @param requestUrl - Reqeust URL
- * @return
- * @author gagamel
- * @since 2021. 5. 14
- */
- private Eigeneai getEigeneaiInfo(String requestUrl) {
- log.info("requestUrl: {}", requestUrl);
- URI url = URI.create(requestUrl);
- // GET방식으로 호출
- ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
- log.info("responseEntity.getStatusCode(): {} ", responseEntity.getStatusCode());
- String responseJson = responseEntity.getBody();
- log.info("responseEntity.getBody(): {}", responseJson);
- if (!responseEntity.getStatusCode().equals(HttpStatus.OK)) {
- return null;
- }
- Gson gson = new Gson();
- return gson.fromJson(responseJson, Eigeneai.class);
- }
- /**
- * 검색어 연관 상품 추천 목록
- * @return
- * @author bin2107
- * @since 2021. 7. 26
- */
- public Collection<Result> getRecommendItemList(int size, String keyword) {
- String requestUrl = "";
-
- // 2021.09.02 공백처리
- try {
- keyword = URLEncoder.encode(keyword, "UTF-8");
- requestUrl = apiUrl + "/s003?size="+size+"&cuid=" + cuid + "&st=" + keyword + "&cps=true&cpt=m004";
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
-
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- /**
- * 당신을 위한 제안
- * 사용되는 화면 영역)
- * 메인 > 당신을 위한 제안
- * @param goodsCd - 상품코드
- * @param size - 결과에 포함할 상품수
- * @return
- * @author bin2107
- * @since 2021. 9. 23
- */
- public Collection<Result> getRecommendForYouList(String goodsCd, int size) {
- String requestUrl = apiUrl + "/a037?cuid=" + cuid + "&size=" + size + "&iids=" + goodsCd + "&cps=true&cpt=m001";
- Eigeneai eigeneai = this.getEigeneaiInfo(requestUrl);
- if (eigeneai.getResults() != null && !eigeneai.getResults().isEmpty()) {
- return eigeneai.getResults();
- }
- return new ArrayList<Result>();
- }
- }
|