스프링

 

json 데이터

// 20221001100706
// http://localhost/api/mainProducts

[
  {
    "id": "13837691",
    "thumbLink": "https://prod.danawa.com/info/?pcode=13837691&cate=11236452",
    "thumbImage": "//img.danawa.com/prod_img/500000/691/837/img/13837691_1.jpg?shrink=130:130&_v=20220621104623",
    "prodName": "레노버 V15 Gen2 82KD000UKR 8GB램",
    "specList": "노트북 / 운영체제(OS): 미포함(프리도스) / 구성변경상품 / 용도: 사무/인강용 / 화면정보 39.62cm(15.6인치) / 1920x1080(FHD) / NTSC: 45% / 250nit / 눈부심 방지 / TN / 슬림형 베젤 / 프로세서 AMD / 라이젠5-4세대 / 루시엔 / 5500U (2.1GHz) / 헥사코어 / 메모리 DDR4 / 메모리 용량: 8GB / 메모리 교체: 가능(1슬롯) / 저장장치 M.2(NVMe) / 256GB / 저장 슬롯: 2개 / 그래픽 내장그래픽 / Radeon Graphics / 네트워크 무선랜: 802.11ac(Wi-Fi 5) / 유선랜: 기가비트 / 영상입출력 HDMI / 웹캠 / 단자 USB-C: 지원 / USB 3.0 / USB 2.0 / 부가기능 웹캠OFF 지원 / 고속충전 / 입력장치 침수지연키보드 / ㅡ형 방향키 / 숫자 키패드(4열) / 파워 배터리: 38Wh / 충전단자: DC / 주요제원 두께: 19.9mm / 무게: 1.7kg / 색상: 그레이",
    "mtDate": "2021.03.",
    "price": 440940,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "12625265",
    "thumbLink": "https://prod.danawa.com/info/?pcode=12625265&cate=112747",
    "thumbImage": "//img.danawa.com/prod_img/500000/265/625/img/12625265_1.jpg?shrink=130:130",
    "prodName": "AMD 라이젠5-4세대 5600X (버미어) (멀티팩(정품))",
    "specList": "AMD(소켓AM4) / 4세대(Zen3) / 7nm / 6코어 / 12쓰레드 / 기본 클럭: 3.7GHz / 최대 클럭: 4.6GHz / L3 캐시: 32MB / TDP: 65W / PCIe4.0 / 메모리 규격: DDR4 / 3200MHz / 내장그래픽: 미탑재 / 기술 지원: StoreMI, Ryzen Master, VR Ready 프리미엄 / 쿨러: Wraith Stealth 포함",
    "mtDate": "2020.11.",
    "price": 218990,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "16084070",
    "thumbLink": "https://prod.danawa.com/info/?pcode=16084070&cate=112751",
    "thumbImage": "//img.danawa.com/prod_img/500000/070/084/img/16084070_1.jpg?shrink=130:130",
    "prodName": "ASUS PRIME B660M-K D4 인텍앤컴퍼니",
    "specList": "인텔(소켓1700) / 인텔 B660 / M-ATX (24.4x21.1cm) / 전원부: 6+1+1페이즈 / 메모리 DDR4 / 5333MHz (PC4-42600) / 2개 / 메모리 용량: 최대 64GB / XMP / 옵테인 / 확장슬롯 VGA 연결: PCIe4.0 x16 / PCIe버전: PCIe4.0, PCIe3.0, PCIe / PCIex16: 1개 / PCIex1: 2개 / 저장장치 SATA3: 4개 / M.2: 2개 / PCIe / NVMe / PCIe4.0 / 후면단자 D-SUB / HDMI / USB 3.0 / USB 2.0 / RJ-45 / 오디오잭 / PS/2 / 랜/오디오 Realtek 계열 / 최대 기가비트 / RJ-45: 1개 / Realtek 계열 / 7.1채널(8ch) / 내부I/O RGB 헤더(4핀): 1개 / 시스템팬 헤더(4핀): 1개 / USB2.0 헤더: 2개 / USB3.0 헤더: 1개 / 특징 UEFI / LED 헤더 / TPM헤더",
    "mtDate": "2022.01.",
    "price": 136720,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "13612532",
    "thumbLink": "https://prod.danawa.com/info/?pcode=13612532&cate=112753",
    "thumbImage": "//img.danawa.com/prod_img/500000/532/612/img/13612532_1.jpg?shrink=130:130",
    "prodName": "ASUS DUAL 지포스 RTX 3060 O12G OC D6 12GB",
    "specList": "RTX 3060 / 8nm / 부스트클럭: 1867MHz / 스트림 프로세서: 3584개 / PCIe4.0x16 / GDDR6(DDR6) / 출력단자: HDMI2.1, DP1.4 / 부가기능: 제로팬(0-dB기술), 8K 해상도 지원, 4K 해상도 지원, HDR 지원, HDCP 2.3 / 정격파워 650W 이상 / 전원 포트: 8핀 x1개 / 2개 팬 / 가로(길이): 200mm / 백플레이트 / LED 라이트 / AURA SYNC / 2021년 7월부로 LHR(채굴제한) 모델 유통",
    "mtDate": "2021.03.",
    "price": 448900,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "16587548",
    "thumbLink": "https://prod.danawa.com/info/?pcode=16587548&cate=112760",
    "thumbImage": "//img.danawa.com/prod_img/500000/548/587/img/16587548_1.jpg?shrink=130:130",
    "prodName": "Western Digital WD BLACK SN770 M.2 NVMe (500GB)",
    "specList": "내장형SSD / M.2 (2280) / PCIe4.0x4 (64GT/s) / NVMe 1.4 / 3D낸드 / [성능] 순차읽기: 5,000MB/s / 순차쓰기: 4,000MB/s / 읽기IOPS: 460K / 쓰기IOPS: 800K / [지원기능] TRIM / S.M.A.R.T / 전용 S/W / [환경특성] MTBF: 175만시간 / TBW: 300TB / A/S기간: 5년, 제한보증 / 방열판 미포함 / 두께: 2.38mm / 5.5g",
    "mtDate": "2022.03.",
    "price": 81150,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "16304876",
    "thumbLink": "https://prod.danawa.com/info/?pcode=16304876&cate=11236849",
    "thumbImage": "//img.danawa.com/prod_img/500000/876/304/img/16304876_1.jpg?shrink=130:130",
    "prodName": "다나와표준PC 온라인강의용 220208 (8GB, SSD 500GB)",
    "specList": "인텔 / 코어i5-12세대 / 엘더레이크 / i5-12400 (2.5GHz) / (인텔) H610 / DDR4 / 8GB / SSD / 500GB / UHD 그래픽스 730 / 1Gbps 유선 / HDMI / DP포트 / DVI / D-SUB / USB 3.0(5Gbps) / 500W / 운영체제 미포함 / 미들타워 / 용도: 사무/인강용",
    "mtDate": "2022.01.",
    "price": 666270,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "17535233",
    "thumbLink": "https://prod.danawa.com/info/?pcode=17535233&cate=112752",
    "thumbImage": "//img.danawa.com/prod_img/500000/233/535/img/17535233_1.jpg?shrink=130:130",
    "prodName": "TeamGroup DDR5-4800 CL40 Elite 서린 (16GB)",
    "specList": "데스크탑용 / DDR5 / 4800MHz (PC5-38400) / 램타이밍: CL40-40-40-77 / 1.10V / 램개수: 1개 / 온다이ECC / 히트싱크: 미포함",
    "mtDate": "2022.07.",
    "price": 97000,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  },
  {
    "id": "15462545",
    "thumbLink": "https://prod.danawa.com/info/?pcode=15462545&cate=11236463",
    "thumbImage": "//img.danawa.com/prod_img/500000/545/462/img/15462545_1.jpg?shrink=130:130&_v=20220628155302",
    "prodName": "APPLE 2021 맥북프로16 MK183KH/A",
    "specList": "노트북 / 운영체제(OS): macOS Monterey / 일반유통상품 / 용도: 그래픽작업용, 사무/인강용 / 화면정보 41.05cm(16.2인치) / 3456x2234 / DCI-P3: 지원 / 1000nit / 주사율: 120Hz / miniLED / 트루톤 / 프로세서 애플(ARM) / 실리콘 M1 PRO / APL1103 / 10코어(8+2) / 메모리 메모리 용량: 16GB / 메모리 교체: 불가능 / 저장장치 SSD / 512GB / 그래픽 내장그래픽 / M1 PRO 16 core / 네트워크 무선랜: 802.11ax(Wi-Fi 6) / 영상입출력 HDMI / 웹캠(FHD) / 단자 썬더볼트4: 3개(USB-C겸용) / USB 4.0 / SD카드 / 부가기능 지문 인식 / 고속충전 / USB-PD / DP Alt Mode / 입력장치 키보드 라이트 / ㅗ형 방향키 / 파워 배터리: 100Wh / 어댑터: 140W / 충전단자: MagSafe 3 / 주요제원 두께: 16.8mm / 무게: 2.1kg / 쿨링팬: 2개 / 색상: 그레이 / 16코어 Neural Engine / 최대 200GB/s 메모리 대역폭 / 미디어 엔진 (디코딩+인코딩+ProRes) / 노치형 디스플레이",
    "mtDate": "2021.10.",
    "price": 2831740,
    "boost": 0,
    "siteLogo": null,
    "deliveryPrice": null,
    "pimg": null
  }
]

 

 

 

 

 

package com.pcw.prod;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;


import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pcw.prod.model.DanawProductDTO;
import com.pcw.utils.DanawProductCrawling;

@RestController
@RequestMapping("/api")
public class DanawProductApiController {
	
	 
    public static String getIndexCachData(){    	
    	StringBuffer result=new StringBuffer();
        try {        	
        	ClassPathResource resource = new ClassPathResource("data/cache.txt");        	
		    Path path = Paths.get(resource.getURI());
		    List<String> content= Files.readAllLines(path);
		    content.forEach(s ->result.append(s));		   			
        } catch (Exception ie) {
            ie.printStackTrace();
        }
        return result.toString();
    }
	
    
    public static int setIndexCachData(String content){    	
    	 int resultCount = 0;
    	try {        	
        	ClassPathResource resource = new ClassPathResource("data/cache.txt");        	
		    Path path = Paths.get(resource.getURI());		    
            		         
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path.toString(), false));
            bufferedWriter.write(content);
            bufferedWriter.newLine();
            bufferedWriter.flush();
            bufferedWriter.close();			
        } catch (Exception ie) {
            ie.printStackTrace();
        }
    	return resultCount;
    }

	/**
	 * 인덱스 메인화면 cache 데이터 상품 목록 가져오기
	 * @return
	 * url :/api/mainProducts
	 * @throws JsonProcessingException 
	 * @throws JsonMappingException 
	 */
	@GetMapping(value = "/mainProducts")
	public ResponseEntity<?> mainProducts(DanawProductCrawling danawProductCrawling) throws Exception {		
		String data=getIndexCachData();
		if(data!=null && !data.equals("")) {			
			ObjectMapper objectMapper =new ObjectMapper();
			List<DanawProductDTO> getDataJson=objectMapper.readValue(data, new TypeReference<List<DanawProductDTO>>(){});	
			return ResponseEntity.status(HttpStatus.OK).body(getDataJson);
		}		
		return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
	}
	
	/**
	 * 인덱스 메인화면 cache 데이터 상품 목록 업데이트
	 * @param danawProductCrawling
	 * @return
	 * @throws Exception
	 */
	@GetMapping(value = "/mainProductsUpdate")
	public ResponseEntity<?> mainProductsUpdate(DanawProductCrawling danawProductCrawling) throws Exception {		
		//다나와 메인 인덱스 화면 제품만 가져오기
		List<DanawProductDTO> product=danawProductCrawling.getMainProducts();	
		ObjectMapper obj =new ObjectMapper();
		String json= obj.writeValueAsString(product);
		setIndexCachData(json);		
		return ResponseEntity.status(HttpStatus.OK).body(product);
	}
	
	
	// vga 데이터를 최저가 순으로 가져온다.
	@GetMapping(value = "/vga")
	public ResponseEntity<List<DanawProductDTO>> getVga(DanawProductCrawling danawProductCrawling) {
		List<DanawProductDTO> product=danawProductCrawling.getVga();
		return ResponseEntity.status(HttpStatus.OK).body(product);
	}
	// vga 데이터를 부스트클럭순으로 역순으로 정렬하여 가져온다.
	@GetMapping(value = "/vga2")
	public ResponseEntity<List<DanawProductDTO>> getVga2(DanawProductCrawling danawProductCrawling) {
		List<DanawProductDTO> product=danawProductCrawling.getVga2();
		return ResponseEntity.status(HttpStatus.OK).body(product);
	}
	
	
	//탑메뉴 클릭시 categoryProducts
	@GetMapping(value = "/categoryProducts/{product}")
	public ResponseEntity<List<DanawProductDTO>> categoryProducts(DanawProductCrawling danawProductCrawling, @PathVariable String product) {
		List<DanawProductDTO> products=danawProductCrawling.getTopMeunProductList(product);
		return ResponseEntity.status(HttpStatus.OK).body(products);
	}
	

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 60  라이트

세상의 다른 대륙에는 원숭이가 있지만, 유럽에는 프랑스인들이 있다. -쇼펜하우어

댓글 ( 4)

댓글 남기기

작성