Skip to content

Commit

Permalink
Merge pull request #7 from hanaTI-team-1/yebang-checklist
Browse files Browse the repository at this point in the history
Yebang checklist
  • Loading branch information
Minjae-vincent authored Jul 15, 2024
2 parents e9eecf2 + a3a65e6 commit e6a58bd
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ public class BatchService {
private final BatchMapper batchMapper;

public String updateJeonse(List<CrawlingVO> crawlingVO) {
// batchMapper.deleteAllJeonse();
ArrayList<Jeonse> jeonseList = new ArrayList<>();
for(CrawlingVO crawling : crawlingVO){
Jeonse jeonse = crawling.convertToJeonse(crawling);
jeonse.setAddress(geoLocationService.getLoadNameAddress(crawling.getLat(), crawling.getLng()));
jeonseList.add(jeonse);
}
batchMapper.updateJeonse(jeonseList);
// log.info("jeonseList : {}", jeonseList);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package kr.ac.kopo.jeonse.domain.jeonse.controller;

import kr.ac.kopo.jeonse.domain.jeonse.domain.BuildingRegister;
import kr.ac.kopo.jeonse.domain.jeonse.domain.Jeonse;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseRateDto;
import kr.ac.kopo.jeonse.domain.jeonse.service.BuildingRegisterService;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseCheckList;
import kr.ac.kopo.jeonse.domain.jeonse.service.JeonseService;
import kr.ac.kopo.jeonse.global.payload.ApiResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,29 +11,21 @@
import org.springframework.web.bind.annotation.*;

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 javax.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/jeonse")
public class JeonseController {

private final JeonseService jeonseService;
private final BuildingRegisterService buildingRegisterService;

// @GetMapping("/{atclNo}")
// public Jeonse getJeonse(@PathVariable String atclNo) {
// return jeonseService.getJeonseByAtclNo(atclNo);
// }

@PostMapping("/register-doc")
public ResponseEntity<ByteArrayResource> getRegisterDoc(@RequestParam String address) throws IOException {
public ResponseEntity<ByteArrayResource> getRegisterDoc(@RequestParam String address) throws IOException, InterruptedException {
ByteArrayResource registerDoc = jeonseService.getRegisterDoc(address);
if (registerDoc == null) {
return ResponseEntity.notFound().build();
Expand All @@ -54,15 +43,9 @@ public ApiResponse<?> getRemainJeonse(@QueryParam("address") String address,
return ApiResponse.onSuccess(jeonseService.getRemainJeonse(address, aptName));
}

@GetMapping("/building-register")
public ApiResponse<List<BuildingRegister>> getBuildingRegister(@QueryParam("road_address") String roadAddress) {
return ApiResponse.onSuccess(buildingRegisterService.getBuildingRegisterByAddress(roadAddress));
}

@GetMapping("/rate/{atclNo}")
public ApiResponse<JeonseRateDto> getJeonseRate(@PathVariable String atclNo) {
System.out.println(atclNo);
return ApiResponse.onSuccess(jeonseService.calculateJeonseRate(atclNo));
@GetMapping("/check-list")
public ApiResponse<JeonseCheckList> jeonseCheckList(@QueryParam("actlNo") String actlNo) {
return ApiResponse.onSuccess(jeonseService.checkJeonse(actlNo));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package kr.ac.kopo.jeonse.domain.jeonse.dto;

import kr.ac.kopo.jeonse.domain.jeonse.domain.Jeonse;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
public class JeonseCheckList {

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class JeonseRate {
private boolean success;
private int salePrice;
private float jeonseSaleRate;
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class BuilderLedger {
private boolean success;
private String information;
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class CertifiedRealEstateAgent {
private boolean success;
private String licensedRealEstateAgent;
}

Jeonse jeonse;
JeonseRate jeonseRate;
BuilderLedger builderLedger;
CertifiedRealEstateAgent certifiedRealEstateAgent;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import kr.ac.kopo.jeonse.domain.jeonse.domain.BuildingRegister;
import kr.ac.kopo.jeonse.domain.jeonse.domain.Jeonse;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseCheckList;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseRateDto;
import kr.ac.kopo.jeonse.domain.jeonse.mapper.BuildingRegisterMapper;
import kr.ac.kopo.jeonse.domain.jeonse.mapper.JeonseMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -17,38 +20,30 @@
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.*;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Service;

import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Slf4j
public class JeonseService {

private final JeonseMapper jeonseMapper;

private final BuildingRegisterMapper buildingRegisterMapper;
private final RestTemplate restTemplate;

private static final String API_KEY = "65cc914ef40df38979142db76be2b32f";

private static final String REGISTER_API_IC = "https://apick.app/rest/iros/1";
private static final String REGISTER_API_DOC = "https://apick.app/rest/iros_download/1";
private static final String EXTERNAL_API_URL = "https://apick.app/rest/iros/1";

public Jeonse getJeonseByAtclNo(String atclNo) {
return jeonseMapper.selectJeonseByAtclNo(atclNo);
}

public JeonseRateDto calculateJeonseRate(String atclNo) {
return jeonseMapper.findJeonseRateByAtclNo(atclNo);
Expand All @@ -59,18 +54,11 @@ public List<Jeonse> getRemainJeonse(String address, String aptName) {
return jeonseMapper.selectRemainJeonse(address, aptName);
}

public ByteArrayResource getRegisterDoc(String address) throws IOException {
// 원본
// return getRegisterDocByIcId(getIcId(address));

// 되는 거
// return getRegisterDocByIcId("3058724");

// 안되는 거 (민재집)
return getRegisterDocByIcId("3059680");
public ByteArrayResource getRegisterDoc(String address) throws IOException, InterruptedException {
return getRegisterDocByIcId(getIcId(address));
}

private ByteArrayResource getRegisterDocByIcId(String icId) throws IOException {
private ByteArrayResource getRegisterDocByIcId(String icId) throws IOException, InterruptedException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost(REGISTER_API_DOC);
uploadFile.setHeader("CL_AUTH_KEY", API_KEY);
Expand All @@ -81,6 +69,9 @@ private ByteArrayResource getRegisterDocByIcId(String icId) throws IOException {
org.apache.http.HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);

// wait 10 seconds
TimeUnit.SECONDS.sleep(10);

CloseableHttpResponse response = httpClient.execute(uploadFile);
org.apache.http.HttpEntity responseEntity = response.getEntity();

Expand Down Expand Up @@ -124,5 +115,50 @@ private String getIcId(String address) throws IOException {
throw e;
}
}

public JeonseCheckList checkJeonse(String actlNo) {
Jeonse jeonse = jeonseMapper.selectJeonseByAtclNo(actlNo);
JeonseRateDto jeonseRateDto = calculateJeonseRate(actlNo);

List<BuildingRegister> buildingRegister = buildingRegisterMapper.findBuildingRegisterByAddress(parseAddress(jeonse.getAddress()));

boolean isBuildingRegister = true;
String buildingRegisterInfo = "";

for(BuildingRegister tmp : buildingRegister){
if (tmp.getMainUseCodeName().contains("근린생활시설") || tmp.getOtherUse().equals("근린생활시설")){
isBuildingRegister = false;
buildingRegisterInfo = "주요 용도: " + tmp.getMainUseCodeName() + " | 기타 용도: " + tmp.getOtherUse();
break;
}
buildingRegisterInfo = "주요 용도: " + tmp.getMainUseCodeName() + " | 기타 용도: " + tmp.getOtherUse();
}

return JeonseCheckList.builder()
.jeonse(jeonse)
.jeonseRate(JeonseCheckList.JeonseRate.builder()
.success(Integer.parseInt(jeonseRateDto.getJeonsePrice()) < 80 )
.salePrice(Integer.parseInt(jeonseRateDto.getJeonsePrice()))
.build())

.builderLedger(JeonseCheckList.BuilderLedger.builder()
.success(isBuildingRegister)
.information(buildingRegisterInfo)
.build())
.certifiedRealEstateAgent(JeonseCheckList.CertifiedRealEstateAgent.builder()
.success(true)
.licensedRealEstateAgent(jeonse.getRltrNm())
.build())
.build();
}

private String parseAddress(String address) {
String[] addressParts = address.split(" ");
List<String> filteredAddressParts = Arrays.stream(addressParts)
.filter(part -> !part.equals("서울"))
.collect(Collectors.toList());
String tmp = String.join(" ", filteredAddressParts);
return tmp;
}
}

2 changes: 1 addition & 1 deletion src/main/resources/mapper/BuildingRegisterMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<mapper namespace="kr.ac.kopo.jeonse.domain.jeonse.mapper.BuildingRegisterMapper">
<select id="findBuildingRegisterByAddress" resultType="kr.ac.kopo.jeonse.domain.jeonse.domain.BuildingRegister">
SELECT * FROM BUILDING_REGISTER WHERE ROAD_LAND_LOCATION LIKE '%${road_address}%'
SELECT * FROM BUILDING_REGISTER WHERE LAND_LOCATION LIKE '%${road_address}%'
</select>
</mapper>
5 changes: 5 additions & 0 deletions src/main/resources/mapper/JeonseMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
atclnm = #{aptName}
</select>

<select id="selectJeonseByAtclNo" resultType="kr.ac.kopo.jeonse.domain.jeonse.domain.Jeonse">
SELECT * FROM naver_real_estate
WHERE atclno = #{atclNo}
</select>

<select id="findJeonseRateByAtclNo" resultType="kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseRateDto">
WITH TBL AS (select address
from (SELECT address
Expand Down

0 comments on commit e6a58bd

Please sign in to comment.