1. 서론
저번에 카오스 던전 수확 데이터를 DB에 저장하고 웹에 출력하였다
여기서 거래가능 재화를 추려서 1수에 얼마나 버는지 알아보려고한다.
2. 개발
2 - 1. 재련재료 데이터 저장
[Controller]
@ResponseBody
@GetMapping("/api/saveCode50000")
public JSONArray SaveCode50000() {
JSONArray result = marketApiService.CallMarketCategories(50000);
result.forEach((data) -> {
ItemsDto itemsDto = new ItemsDto((JSONObject) data);
Items save = itemsService.save(itemsDto);
});
return result;
}
[DTO]
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ItemsDto {
private int Id;
private String Name;
private String Grade;
private String Icon;
private int BundleCount;
private int TradeRemainCount;
private double YDayAvgPrice;
private int RecentPrice;
private int CurrentMinPrice;
public ItemsDto(JSONObject testData) {
this.Id = Integer.parseInt(testData.get("Id").toString());
this.Name = testData.get("Name").toString();
this.Grade = testData.get("Grade").toString();
this.Icon = testData.get("Icon").toString();
this.BundleCount = Integer.parseInt(testData.get("BundleCount").toString());
if(testData.get("TradeRemainCount") != null) {
this.TradeRemainCount = Integer.parseInt(testData.get("TradeRemainCount").toString());
}
this.YDayAvgPrice = Double.parseDouble(testData.get("YDayAvgPrice").toString());
this.RecentPrice = Integer.parseInt(testData.get("RecentPrice").toString());
this.CurrentMinPrice = Integer.parseInt(testData.get("CurrentMinPrice").toString());
}
public Items toEntity() {
return Items.builder()
.id(Id)
.name(Name)
.grade(Grade)
.icon(Icon)
.bundleCount(BundleCount)
.tradeRemainCount(TradeRemainCount)
.yDayAvgPrice(YDayAvgPrice)
.recentPrice(RecentPrice)
.currentMinPrice(CurrentMinPrice)
.build();
}
}
JSONObject를 엔티티로 변환해야 하니 생성자를 추가로 생성하였다.
[Service]
@Transactional
public Items save(ItemsDto itemsDto) {
Items itemsEntity = itemRepository.save(itemsDto.toEntity());
return itemsEntity;
}
[결과]
2 - 2. 1수당 얻은 골드로 변환하는 메소드
이제 1수당 얻은 재화와 거래소 데이터를 연산해서 1수당 얻은 골드로 변환하는 메소드를 만든다.
여기서 파괴석, 수호석등은 거래소 데이터로 가능하지만,
보석은 거래소 데이터로 불가능하니 따로 API에서 최저가를 불러오는 메소드를 만들어야 한다.
아래에서 apiService.AuctionItems(21000, "1레벨")로 3티어 1레벨보석 데이터를 판매가격 낮은 순위로 불러온 후 첫번째 값을 연산에 사용하였다.
[DTO]
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ChaosDungeonItemsDto {
private int level;
private double destructionStone;
private double guardianStone;
private double jewelry;
private double gold;
private double total;
}
[ApiService]
public JSONObject AuctionItems(int CategoryCode, String ItemName) {
try {
URL url = new URL("https://developer-lostark.game.onstove.com/auctions/items");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); // 서버 연결
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("authorization", "Bearer "+ LostarkApiKey);
httpURLConnection.setRequestProperty("accept","application/json");
httpURLConnection.setRequestProperty("content-Type","application/json");
httpURLConnection.setDoOutput(true);
String parameter = "{"
+ "Sort : \"BUY_PRICE\""
+ ",CategoryCode : " + CategoryCode
+ ",ItemTier : 3"
+ ",ItemName : \""+ ItemName +"\""
+ ",PageNo : 1"
+ ",SortCondition : \"ASC\""
+ "}";
byte[] out = parameter.getBytes(StandardCharsets.UTF_8);
OutputStream stream = httpURLConnection.getOutputStream();
stream.write(out);
int result = httpURLConnection.getResponseCode();
InputStream inputStream;
if(result == 200) {
inputStream = httpURLConnection.getInputStream();
} else {
inputStream = httpURLConnection.getErrorStream();
}
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
JSONParser parser = new JSONParser();
JSONObject object = (JSONObject) parser.parse(inputStreamReader);
return object;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
[ChaosDugeonService]
public ArrayList<ChaosDungeonItemsDto> getChaosDungeonGold(List<ChaosDungeon> chaosDungeonStatistics) {
NumberFormat formatter = new DecimalFormat("0.##");
ArrayList<ChaosDungeonItemsDto> chaosDungeonItemsDtos = new ArrayList<>();
JSONArray jewelryArray = (JSONArray) apiService.AuctionItems(210000, "1레벨").get("Items");
JSONObject jewelryObject = (JSONObject) jewelryArray.get(0);
JSONObject jewelry = (JSONObject) jewelryObject.get("AuctionInfo");
chaosDungeonStatistics.forEach((data) -> {
ChaosDungeonItemsDto dto = new ChaosDungeonItemsDto();
dto.setLevel(data.getLevel());
if(data.getLevel() < 1490) {
dto.setDestructionStone(data.getDestructionStone() * itemRepository.findByName("파괴석 결정").getYDayAvgPrice()/10);
dto.setGuardianStone(data.getGuardianStone() * itemRepository.findByName("수호석 결정").getYDayAvgPrice()/10);
} else if (data.getLevel() >= 1580) {
dto.setDestructionStone(data.getDestructionStone() * itemRepository.findByName("정제된 파괴강석").getYDayAvgPrice()/10);
dto.setGuardianStone(data.getGuardianStone() * itemRepository.findByName("정제된 수호강석").getYDayAvgPrice()/10);
} else {
dto.setDestructionStone(data.getDestructionStone() * itemRepository.findByName("파괴강석").getYDayAvgPrice()/10);
dto.setGuardianStone(data.getGuardianStone() * itemRepository.findByName("수호강석").getYDayAvgPrice()/10);
}
dto.setGold(data.getGold());
dto.setJewelry(data.getJewelry() * Double.parseDouble(jewelry.get("BuyPrice").toString()));
//소수점 제거 및 합산
dto.setDestructionStone(Double.parseDouble(formatter.format(dto.getDestructionStone())));
dto.setGuardianStone(Double.parseDouble(formatter.format(dto.getGuardianStone())));
dto.setJewelry(Double.parseDouble(formatter.format(dto.getJewelry())));
dto.setTotal(Double.parseDouble(formatter.format(dto.getDestructionStone()+dto.getGuardianStone()+dto.getJewelry()+dto.getGold())));
chaosDungeonItemsDtos.add(dto);
});
return chaosDungeonItemsDtos;
}
[Controller]
@GetMapping("/contents/ChaosDungeon/statistics")
public String chaosDungeonStatistics(Model model) {
List<ChaosDungeon> chaosDungeonStatistics = chaosDungeonService.getChaosDungeonStatistics();
ArrayList<ChaosDungeonItemsDto> chaosDungeonGold = chaosDungeonService.getChaosDungeonGold(chaosDungeonStatistics);
model.addAttribute("chaosDungeonStatistics", chaosDungeonStatistics);
model.addAttribute("chaosDungeonGold", chaosDungeonGold);
return "contents/ChaosDungeon/statistics";
}
[결과]
3. 정리 및 후기
- 1445 ~ 1490까지는 차이가 미미한 수준..
- 1520 ~ 1560까지도 차이 미미
- 카던 도는 배럭은 1520은 찍어둘까