Skip to content

Commit

Permalink
Merge pull request #11 from hanaTI-team-1/yebang-checklist
Browse files Browse the repository at this point in the history
Feat: Connect with analysis server
  • Loading branch information
Minjae-vincent authored Jul 16, 2024
2 parents 7294697 + 4012387 commit 49c53e0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import kr.ac.kopo.jeonse.domain.jeonse.dto.InfraDTO;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseCheckList;
import kr.ac.kopo.jeonse.domain.jeonse.dto.RecommendRequest;
import kr.ac.kopo.jeonse.domain.jeonse.service.JeonseService;
import kr.ac.kopo.jeonse.global.payload.ApiResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -39,7 +40,7 @@ public ResponseEntity<ByteArrayResource> getRegisterDoc(@RequestParam String add
.body(registerDoc);
}

@PostMapping("/remain")
@GetMapping("/remain")
public ApiResponse<?> getRemainJeonse(@QueryParam("address") String address,
@QueryParam("aptName") String aptName) {
return ApiResponse.onSuccess(jeonseService.getRemainJeonse(address, aptName));
Expand All @@ -55,5 +56,12 @@ public ApiResponse<List<InfraDTO>> infraList() {
return ApiResponse.onSuccess(jeonseService.getInfraList());
}

@GetMapping("/recommend")
public ApiResponse<List<JeonseCheckList>> recommend(@RequestBody RecommendRequest recommendRequest) {
return ApiResponse.onSuccess(jeonseService.recommendJeonse(recommendRequest));
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import lombok.*;

@Getter
@RequiredArgsConstructor

@Data
@AllArgsConstructor

public class JeonseRateDto {
private final String jeonsePrice;
private final String maemaePrice;
private final String rate;
private String jeonsePrice;
private String maemaePrice;
private String rate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kr.ac.kopo.jeonse.domain.jeonse.dto;

import lombok.Data;

@Data
public class RecommendRequest {
private String dongNm;
private int school;
private int publicSecurity;
private int busStop;
private int subway;
private int mart;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kr.ac.kopo.jeonse.domain.jeonse.dto.InfraDTO;
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.dto.RecommendRequest;
import kr.ac.kopo.jeonse.domain.jeonse.mapper.BuildingRegisterMapper;
import kr.ac.kopo.jeonse.domain.jeonse.mapper.JeonseMapper;
import kr.ac.kopo.jeonse.global.utils.NullToEmptyStringUtil;
Expand Down Expand Up @@ -122,6 +123,14 @@ public JeonseCheckList checkJeonse(String actlNo) {
Jeonse jeonse = jeonseMapper.selectJeonseByAtclNo(actlNo);
JeonseRateDto jeonseRateDto = calculateJeonseRate(actlNo);

if(jeonseRateDto.getJeonsePrice() == null) {
jeonseRateDto.setJeonsePrice("0");
}
//
// if (jeonseRateDto.getRate() == null) {
// jeonseRateDto.setRate("90");
// }

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

boolean isBuildingRegister = true;
Expand All @@ -141,8 +150,9 @@ public JeonseCheckList checkJeonse(String actlNo) {
return JeonseCheckList.builder()
.jeonse(jeonse)
.jeonseRate(JeonseCheckList.JeonseRate.builder()
.success(Integer.parseInt(jeonseRateDto.getJeonsePrice()) < 80)
.success(Integer.parseInt(jeonseRateDto.getRate()) < 80)
.salePrice(Integer.parseInt(jeonseRateDto.getJeonsePrice()))
.jeonseSaleRate(Float.parseFloat(jeonseRateDto.getRate()))
.build())
.builderLedger(JeonseCheckList.BuilderLedger.builder()
.success(isBuildingRegister)
Expand All @@ -159,11 +169,11 @@ public JeonseCheckList checkJeonse(String actlNo) {
.mart(appropriateJeonsePrice.getInfrastructureNum().getMart())
.build())
.build())
.certifiedRealEstateAgent(JeonseCheckList.CertifiedRealEstateAgent.builder()
.success(true)
.licensedRealEstateAgent(jeonse.getRltrNm())
.build())
.build();
.certifiedRealEstateAgent(JeonseCheckList.CertifiedRealEstateAgent.builder()
.success(true)
.licensedRealEstateAgent(jeonse.getRltrNm())
.build())
.build();
}

private AppropriateJeonse getAppropriateJeonsePrice(Jeonse jeonse) {
Expand All @@ -172,6 +182,9 @@ private AppropriateJeonse getAppropriateJeonsePrice(Jeonse jeonse) {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");


Jeonse jeonse1 = transformJeonse(jeonse);

HttpEntity<Jeonse> entity = new HttpEntity<>(transformJeonse(jeonse), headers);

ResponseEntity<String> response = restTemplate.exchange(FLASK_API_URL, HttpMethod.POST, entity, String.class);
Expand Down Expand Up @@ -201,18 +214,26 @@ private Jeonse transformJeonse(Jeonse jeonse) {
String tmp = jeonse.getFlrInfo();
String[] flrInfo = tmp.split("/");
if (flrInfo.length == 1) {
jeonse.setFlrInfo(flrInfo[0]);
jeonse.setFlrInfo(flrInfo[0]+"/1");
} else {
String firstValue = flrInfo[0];
int secondValue = Integer.parseInt(flrInfo[1]);
int calculatedFloor = switch (firstValue) {
case "저" -> (int) Math.round(secondValue / 3.0);
case "중" -> (int) Math.round(2 * secondValue / 3.0);
case "고" -> secondValue;
default -> Integer.parseInt(String.valueOf(firstValue.toCharArray()[1])) * -1;
if (firstValue.contains("B")) {
jeonse.setFlrInfo(Integer.parseInt(String.valueOf(firstValue.toCharArray()[1])) * -1 +"/1");
return jeonse;
}
String calculatedFloor = switch (firstValue) {
case "저" -> String.valueOf((int) Math.round(secondValue / 3.0));
case "중" -> String.valueOf((int) Math.round(2 * secondValue / 3.0));
default -> firstValue;
};

jeonse.setFlrInfo(String.valueOf(calculatedFloor));
jeonse.setFlrInfo(calculatedFloor + "/1");
}

if(!jeonse.getAddress().contains("-")){
jeonse.setAddress(jeonse.getAddress() + "-0");

}

return jeonse;
Expand Down Expand Up @@ -293,5 +314,48 @@ private List<InfraDTO.BusStation> getBusStations(String gu) {
.build())
.collect(Collectors.toList());
}

public List<JeonseCheckList> recommendJeonse(RecommendRequest recommendRequest) {
// String[] atclNos = getRecommendationList(recommendRequest);

String[] atclNos = {"2430006535", "2433524070", "2433775697", "2434392198", "2431314046", "2429677439", "2432722911", "2430296803", "2433186783"};

List<JeonseCheckList> recommendList = new ArrayList<>();

for (String atclNo : atclNos) {
int tmp = 0;
JeonseCheckList jeonseCheckList = checkJeonse(atclNo);
if (jeonseCheckList.getJeonseRate().isSuccess()) {
tmp++;
}
if (jeonseCheckList.getBuilderLedger().isSuccess()) {
tmp++;
}
if (jeonseCheckList.getAppropriateJeonsePrice().isSuccess()) {
tmp++;
}
if (jeonseCheckList.getCertifiedRealEstateAgent().isSuccess()) {
tmp++;
}
if (tmp >= 3) {
recommendList.add(jeonseCheckList);
}
}

return recommendList;
}

private String[] getRecommendationList(RecommendRequest recommendRequest) {
final String FLASK_API_URL = "http://34.64.201.85:5000/run-b";

HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");

HttpEntity<RecommendRequest> entity = new HttpEntity<>(recommendRequest, headers);

ResponseEntity<String[]> response = restTemplate.exchange(FLASK_API_URL, HttpMethod.POST, entity, String[].class);

return response.getBody();
}
}

0 comments on commit 49c53e0

Please sign in to comment.